New FMOD SoundManager available in Wiki

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
User avatar
DrPain
Gnome
Posts: 349
Joined: Tue Jul 05, 2005 2:51 pm
Location: Connecticut, USA

New FMOD SoundManager available in Wiki

Post by DrPain »

It's a work in progress, but it's functional now.

http://www.ogre3d.org/wiki/index.php?ti ... undManager

Feedback welcome.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

Nice to see a FMOD sound manager for Ogre! :)
User avatar
morez
Kobold
Posts: 36
Joined: Mon Nov 14, 2005 11:40 am
Location: Verona, Italy

Post by morez »

Very very nice .. I'll try ASAP .. :)
User avatar
DrPain
Gnome
Posts: 349
Joined: Tue Jul 05, 2005 2:51 pm
Location: Connecticut, USA

Post by DrPain »

I hope you find it useful.

A few minor changes were made to the Wiki page (not the source).
Just some clarifications and got rid of a -1 which should have been INVALID_SOUND_CHANNEL.
User avatar
morez
Kobold
Posts: 36
Joined: Mon Nov 14, 2005 11:40 am
Location: Verona, Italy

Post by morez »

I tried the SoundManager yesterday. Very useful, thanks :) I found a minor problem with the stdafx.h. It includes the mmsystem.h ( or something like this I don't remember the header file name exactly sorry) which defines a PlaySound function that conflict with SoundManager::PlaySound. It raised a Link error. Probably I forget to do something, but I comment out the #include stdafx.h and all works fine.
Very nice work DrPain, thanks a lot.
User avatar
morez
Kobold
Posts: 36
Joined: Mon Nov 14, 2005 11:40 am
Location: Verona, Italy

Post by morez »

@DrPain: are you planning to add a wrapper for the FMOD geometry engine for sound occlusion?
User avatar
DrPain
Gnome
Posts: 349
Joined: Tue Jul 05, 2005 2:51 pm
Location: Connecticut, USA

Post by DrPain »

Hmmm.. I've just really started using it myself. I'll have to look into that.
I'm working on fixing a crash issue at the moment (I believe unrelated to this manager), but after that's resolved, I'll take a look at it.

Anyone know if that feature is a CPU hog?

I do have a new version to upload. But I want to resolve the crash issue first to make sure it's really not a SoundManager problem.
User avatar
SunSailor
Gnoll
Posts: 699
Joined: Sun Jan 02, 2005 5:45 pm
Location: Velbert, Germany
x 2

Post by SunSailor »

Maybe you could replace your hard-coded access code with this (You assume a fixed resource group and the code is limited to plain file access, as discussed in another thread):

Code: Select all

	FMOD_RESULT F_CALLBACK SoundManager::FModOpen(const char *pFilename,int bUnicode,unsigned int *pFileSize,void **ppHandle,void **ppUserData)
	{
		try
		{
			Ogre::String *pGroup = new Ogre::String(Ogre::ResourceGroupManager::getSingleton().findGroupContainingResource(pFilename));
			Ogre::DataStreamPtr dataStreamPtr = Ogre::ResourceGroupManager::getSingleton().openResource(pFilename,*pGroup);

			if(dataStreamPtr.isNull() == true)
				return FMOD_ERR_FILE_NOTFOUND;

			(*pFileSize) = dataStreamPtr->size();
			(*ppHandle) = new Ogre::DataStreamPtr(dataStreamPtr);
			(*ppUserData) = pGroup;

			dataStreamPtr.setNull();
		}

		catch(Ogre::Exception e)
		{

			return FMOD_ERR_FILE_NOTFOUND;
		}

		return FMOD_OK;
	}

	FMOD_RESULT F_CALLBACK SoundManager::FModClose(void *pHandle,void *pUserData)
	{
		Ogre::DataStreamPtr streamFMod = (*((Ogre::DataStreamPtr *) pHandle));

		streamFMod->close();

		delete (Ogre::String *) pUserData;
		delete (Ogre::DataStreamPtr *) pHandle;

		return FMOD_OK;
	}

	FMOD_RESULT F_CALLBACK SoundManager::FModRead(void *pHandle,void *pBuffer,unsigned int nSize,unsigned int *nRead,void *pUserData)
	{
		Ogre::DataStreamPtr streamFMod = (*(Ogre::DataStreamPtr *) pHandle);

		(*nRead) = streamFMod->read(pBuffer,nSize);

		if((*nRead) != nSize)
			return FMOD_ERR_FILE_EOF;

		return FMOD_OK;
	}

	FMOD_RESULT F_CALLBACK SoundManager::FModSeek(void *pHandle,unsigned int nPosition,void *pUserData)
	{
		Ogre::DataStreamPtr streamFMod = (*(Ogre::DataStreamPtr *) pHandle);

		streamFMod->seek(nPosition);

		return FMOD_OK;
	}

It still avoids the full scale solution with defining an own ResourceManager and Resource class, so it isn't able to precache the sample. At least it can read the files from all supported backends. Initialize it after the init call with:

Code: Select all

pSystem->setFileSystem(FModOpen,FModClose,FModRead,FModSeek,2048);
Declarations (For copy and paste):

Code: Select all

		static FMOD_RESULT F_CALLBACK FModOpen(const char *,int,unsigned int *,void **,void **);
		static FMOD_RESULT F_CALLBACK FModClose(void *,void *);
		static FMOD_RESULT F_CALLBACK FModRead(void *,void *,unsigned int,unsigned int *,void *);
		static FMOD_RESULT F_CALLBACK FModSeek(void *,unsigned int,void *);

Sorry, if there are any typos, I ripped the code out of my source code, which handles the rest a bit different.
Isomorphic
Gnoblar
Posts: 14
Joined: Wed Mar 15, 2006 4:05 am

Post by Isomorphic »

I think in SoundManager.cpp in CreateSound it should be

Code: Select all

case SOUND_TYPE_3D_SOUND:
         {
			 result = system->createSound(fileName.c_str(), FMOD_DEFAULT | FMOD_3D | FMOD_HARDWARE, 0, &sound);
         break;
         }
where FMOD_3D and FMOD_HARDWARE are added. Just because a sound isn't looped doesn't mean it shouldn't have 3D effects.

Also, I am having a wierd bug with the channels it seems. When I play too many sounds too quickly my program crashes. It seems to me that it takes a bit before the manager decides a channel is not needed anymore and if the channels fill up (to 32?) there is a crash.

Hopefully this thread isn't dead.
Last edited by Isomorphic on Thu Mar 16, 2006 2:49 pm, edited 1 time in total.
Isomorphic
Gnoblar
Posts: 14
Joined: Wed Mar 15, 2006 4:05 am

Post by Isomorphic »

Alright, I fixed the bug, not that I am really sure what was causing it. In

SoundManager::PlaySound(int soundIndex, SceneNode *soundNode, int *channelIndex)

This *channelIndex should equal -1 when it is an invalid sound channel, but for some reason, instead it equals some large number, which is the same during the run, but changes from reboot to reboot. So now, it does a quick check to see if the number is in the proper channel range.

Code: Select all

if ((*channelIndex < 0) || (*channelIndex >= MAX_SOUND_CHANNELS)) *channelIndex = INVALID_SOUND_CHANNEL;
User avatar
DrPain
Gnome
Posts: 349
Joined: Tue Jul 05, 2005 2:51 pm
Location: Connecticut, USA

Post by DrPain »

Sorry for the long delay. I've been immersed in other areas of code and am just getting back around to this.

SunSailor -
I'm actually toying with your idea of making the SoundManager a full-blown resource manager. It'll probably be a few weeks before I can get to that, but I am leaning more that way at the moment.

Isomorphic -
I've tried all kinds of scenarios to get it to crash with no luck.
Are you initializing the channelIndex to INVALID_SOUND_CHANNEL as instructed in the Wiki?
User avatar
Mikachu
Gnoll
Posts: 603
Joined: Thu Jul 28, 2005 4:11 pm
Location: Nice, France
x 35

Post by Mikachu »

Good job.
I don't know if it is implemented in FMOD, but, if so, could you add more controls about sound intensity and pitch?
For example, a spaceship reactor sound pitchs up and grow in intensity when accelerating.
tobie
Gnoblar
Posts: 1
Joined: Mon Apr 10, 2006 7:13 pm
Location: Sweden

Post by tobie »

-Mikachu

FMOD supports several effects (DSP). Here's how to add an echo effect to a channel.

Code: Select all

FMOD_RESULT result;

result = channel->addDSP(dspecho);
ERRCHECK(result);
Where dspecho has been defined as

Code: Select all

FMOD::DSP	*dspecho = fmodSystem->createDSPByType(FMOD_DSP_TYPE_ECHO, &dspecho);
The effect can then be changed using setParameter:

Code: Select all

result = dspecho->setParameter(FMOD_DSP_ECHO_WETMIX, 0.3f);
ERRCHECK(result);
User avatar
DrPain
Gnome
Posts: 349
Joined: Tue Jul 05, 2005 2:51 pm
Location: Connecticut, USA

Post by DrPain »

The SoundManager now supports loading from Archive files (zip files, or theoretically any other ResourceManager supported format).

This is brand new code. It has been tested, but not a lot.
But I figured it's better to get it out there and have the masses bang on it and report any problems.

A bug in PlaySound() was fixed that would prevent the same sound from re-playing when in the same sceneNode.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

This is appreciated! :)

Thank you for your numerous contributions so far! :D
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Katzenjoghurt
Halfling
Posts: 52
Joined: Sat Jan 22, 2005 8:44 pm

Post by Katzenjoghurt »

Hi!

As I'm still looking for a working sound manager I tried your's ... but it won't compile...

------ Build started: Project: Ogre_simpleSurround, Configuration: Release Win32 ------
Compiling...
Ogre_simpleSurround.cpp
d:\VS2005 Projects\Ogre_simpleSurround_FMOD\Ogre_simpleSurround\include\SoundManager_FMOD.h(12) : error C2059: syntax error : 'constant'
d:\VS2005 Projects\Ogre_simpleSurround_FMOD\Ogre_simpleSurround\include\SoundManager_FMOD.h(29) : error C2146: syntax error : missing ';' before identifier 'fileName'
d:\VS2005 Projects\Ogre_simpleSurround_FMOD\Ogre_simpleSurround\include\SoundManager_FMOD.h(29) : error C4430: missing type specifier - int
(...)
Build log was saved at "file://d:\VS2005 Projects\Ogre_simpleSurround_FMOD\Ogre_simpleSurround\obj\Release\BuildLog.htm"
Ogre_simpleSurround - 182 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
the
'syntax error 'constant' ' is pointing to the header's 'using namespace Ogre;'

I don't get it....
Better to reign in hell than serve in heaven
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

Looks like we should add a line before the using namespace Ogre line:

Code: Select all

#include <ogre.h>
:wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Katzenjoghurt
Halfling
Posts: 52
Joined: Sat Jan 22, 2005 8:44 pm

Post by Katzenjoghurt »

thx jacmoe ... alright, alright ... I'm a beginner. :)

Yet, I'm still confused... including ogre.h in the SoundManager shifts the "syntax error : 'constant' " to OgrePlatform.h ...

How do I properly integrate the two soundmanager files? :oops:
Better to reign in hell than serve in heaven
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

I had to insert an #include <windows.h> just before the include <ogre.h>. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Katzenjoghurt
Halfling
Posts: 52
Joined: Sat Jan 22, 2005 8:44 pm

Post by Katzenjoghurt »

Hmmm.... this didn't do anything good now ... :(
Better to reign in hell than serve in heaven
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

Make sure that you are using the newest FMOD.
It works perfectly here. Provided that you are using it in an OGRE application. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Katzenjoghurt
Halfling
Posts: 52
Joined: Sat Jan 22, 2005 8:44 pm

Post by Katzenjoghurt »

I downloaded FMOD just yesterday.... Ogre is 1.2.0

.. it's just, that something goes wrong with the namespace thing.

When including ogre.h in the soundmanager.h the header compiles fine .... but then VS gives me a syntax error : 'constant' at OgrePlatform.h right were Ogre namespace is defined ( namespace Ogre { )

including windows.h in the soundmanager.h didn't make a change...

----

ARGHH! silly me!
I renamed the SoundManager.h to SoundManager_FMOD.h ... and forgot to rename the cpp file as well. :oops:
Better to reign in hell than serve in heaven
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

Katzenjoghurt wrote:ARGHH! silly me!
This kind of thing happens all the time - and we are spending way too much time on such stupid mistakes, because we think the problem is bigger than that. :P
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
raicuandi
Gargoyle
Posts: 1092
Joined: Wed Nov 09, 2005 12:56 pm
Location: Adelaide, Australia

Post by raicuandi »

jacmoe wrote:
Katzenjoghurt wrote:ARGHH! silly me!
This kind of thing happens all the time - and we are spending way too much time on such stupid mistakes, because we think the problem is bigger than that. :P
I second that!
User avatar
Katzenjoghurt
Halfling
Posts: 52
Joined: Sat Jan 22, 2005 8:44 pm

Post by Katzenjoghurt »

:D
... oh well... I better shouldn't tell you that I'm a computer science student in his 6th year. Nah. I rather keep this for me. :wink:

...and it goes on and on. (yeah ... as if shame wouldn't be big enough already.... I'm stuck once more)

The sources compile now, but the test program crashes when calling
nightLoop = soundMgr->CreateSound(String("whatsdiversity.wav"));
in this line of SoundManager.cpp
int SoundManager::FindSound(String &fileName, SOUND_TYPE soundType)
{
int vectorIndex;
int vectorCapacity;
SoundInstance *nextSoundInstance;

=> vectorCapacity = soundInstanceVector->capacity(); <=
The wav is in the exe Folder. I tried the full path as well.... but I keep getting the same unhandled exception.... no matter if I type in a nonsense filename or the filename of any existing wav.

Anyone had this crash as well?
Better to reign in hell than serve in heaven