views:

24

answers:

1

Hi all,

I'm trying to set up 3D sounds with FMOD in a game which uses Ogre. The sound listener is attached to the camera which runs on a spline. I have footstep sounds attached to the player, and the volume should be determined by how far the player is from the camera.

The foot step sounds are acting as though the sound listener is not moving from its start position. At the start of the level, the footsteps are loud, and as you move away from the start they get quieter until you can't hear them anymore. If you run back to the start, they get louder. However, the position of the sound listener's scene node is updating and staying in sync with the camera.

In code there is an FMOD error being generated every frame on the following line:

result = m_system->set3DListenerAttributes(0, &pos, &vel, &forward, &up);

result is always returning FMOD_ERR_INVALID_HANDLE, with the following error string - 'An invalid object handle was used'. I can't figure out why this error is being generated. All the FMOD_VECTORs being passed in as parameters are initialised and I appear to be setting up the system correctly. The code is all over the place in different classes but here are the important bits:

// Initialise FMOD system
result = m_system->init(4093, FMOD_INIT_3D_RIGHTHANDED, 0);
result = m_system->set3DSettings(1.0f, 1.0f, 1.0f);

// Create sound
FMOD_MODE mode = FMOD_SOFTWARE;
if(a_positional)
{
    mode |= FMOD_3D;
}
FMOD_CREATESOUNDEXINFO info;
memset(&info, 0, sizeof(FMOD_CREATESOUNDEXINFO));
info.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
r = sys->_getFMODSystem()->createSound(a_file.c_str(), mode, &info, &retVal);

// Update sound listener
FMOD_VECTOR pos, vel, forward, up;

pos.x = m_sceneNode->getParentSceneNode()->_getDerivedPosition().x;
pos.y = m_sceneNode->getParentSceneNode()->_getDerivedPosition().y;
pos.z = m_sceneNode->getParentSceneNode()->_getDerivedPosition().z;

vel.x = 0;
vel.y = 0;
vel.z = 0;

forward.x = 0;
forward.y = 0;
forward.z = 1;

up.x = 0;
up.y = 1;
up.z = 0;

result = m_system->set3DListenerAttributes(0, &pos, &vel, &forward, &up);
// FMOD error: (36) An invalid object handle was used.

Any ideas as to why 'result' is returning this error? I'm assuming it's the reason why the 3D sounds aren't playing correctly.

A: 

An invalid handle error (FMOD_ERR_INVALID_HANDLE) is referring to the object you are calling functions on, in this case it means the m_system handle is invalid.

Firstly I noticed you have omited the code to create the FMOD::System object, can you confirm you are doing the following:

result = FMOD::System_Create(&m_system);

Secondly, provided you have that code somewhere can you verify that the value of m_system remains unchanged between when it is created and when it is used (perhaps something is corrupting the handle).

Finally (as a long shot) if your headers and lib are out of sync you might be getting a different error message, ensure the headers and libs you are using are all from the same version of FMOD.

Extra note, try linking with the logging version of FMOD, you should get some useful debug output on the TTY that might help your situation.

Mathew Block
You were exactly right, m_system was null. I was creating the FMOD system in another class, and was supposed to pass the pointer to m_system in this class. I was not aware that you could call functions on null pointers and the program wouldn't break if the function doesn't access member variables, so I learnt something new.
games_dev85
Excellent, and yes, as long as the class doesn't touch any member variables you can call a function on a NULL pointer. If you take a close look at FMOD 'pointers' though you will notice most of them are actually handles anyway, so values like '1' are perfectly valid.
Mathew Block