0
0

I’m fairly new to FMOD and have run in to a problem and I’m not really sure why. I’m working on an audio options menu for a student project and am having trouble getting the ‘universal’ volume control working correctly. For some reason, the channels aren’t correctly storing the channel group information. My current set up works like this:

[list=1:2sbwgt5f]
[:2sbwgt5f]My Initialize() function inits FMOD and creates 2 channel groups ("SFX" and "MUSIC") and adds them to the master group (all return FMOD_OK).
[/
:m:2sbwgt5f]
[:2sbwgt5f]I have a structure that holds a Channel and a Sound*. LoadSound() function creates a new structure, creates a stream, and adds my channels to the proper channel group. The structure that that data is stored in is then pushed back in to a vector. The channel stores the correct channel group through this point.
[/:m:2sbwgt5f]
[
:2sbwgt5f]PlaySound() just plays the sound.[/*:m:2sbwgt5f][/list:o:2sbwgt5f]

For some reason, when I call PlaySound(), the channel group is no longer set to the group that I set it to in LoadSound(). It is being reset to "FMOD master group." All of my setChannelGroup() calls are returning FMOD_OK, so I’m not sure what the problem is. As I mentioned, I’m pretty new to FMOD so it’s probably some small thing I’m missing. Thanks in advance for the help.

  • You must to post comments
0
0

Based on the order you are doing things I suspect you’re setting the channelgroup for an invalid channel handle. If you’re calling System::playsound after setChannelGroup that will create a new channel overwriting the old one. An (FMOD::Channel*) is really just a handle. Before you call playSound everything you do with the channel should return FMOD_ERR_INVALIDHANDLE error. You can call System::playSound in the LoadSound function so that you have a valid handle (you can use the ‘paused’ parameter to stop it from playing immediately). Then you will have a valid handle and your PlaySound function can just call channel->setPaused(false).

Hope this helps.

-Pete

  • You must to post comments
0
0

Thanks for the reply Pete. Originally, I was having that problem with FMOD_ERR_INVALIDHANDLE when I first started implementing channel groups, but I fixed that. I forgot to mention in my original post that I call playSound() in my LoadSound() function. When I step through the process in the debugger, everything returns FMOD_OK. Currently, my project only uses 2D sounds. More specifically, here is a slightly dumbed down version of what’s going on:

[code:udx95dc2]
void Initialize()
{
m_Result = FMOD::System_Create(&m_pSystem);

m_pSystem->init(128, FMOD_INIT_NORMAL, 0);

// Create channel groups and add to master group
m_Result = m_pSystem->createChannelGroup("SFX", &m_pSFXGroup);
m_Result = m_pSystem->createChannelGroup("Music", &m_pMusicGroup);
m_Result = m_pSystem->getMasterChannelGroup(&m_pMasterGroup);
m_Result = m_pMasterGroup->addGroup(m_pSFXGroup);
m_Result = m_pMasterGroup->addGroup(m_pMusicGroup);

m_bIsInitialized = true;

}

int LoadSound(const char* szFileName, const unsigned int nChannelGroup)
{
// TSound is a structure containing a Sound* and Channel*
m_tSound = new TSound();

m_Result = m_pSystem->createStream(szFileName, FMOD_DEFAULT, 0, &m_tSound->m_Sound);

m_pSystem->playSound(FMOD_CHANNEL_FREE, m_tSound->m_Sound, true, &m_tSound->m_Channel);

switch(nChannelGroup)
{
case CHANNEL_SFX:
    m_Result = m_tSound->m_Channel->setChannelGroup(m_pSFXGroup);
    break;
case CHANNEL_MUSIC:
    m_Result = m_tSound->m_Channel->setChannelGroup(m_pMusicGroup);
    break;
default:
    break;
}

// If I call getChannelGroup() on the channel at this point, it correctly returns either SFX or MUSIC.

// m_vSoundsList is a vector of TSounds
m_vSoundsList.push_back(m_tSound);

m_tSound = NULL;

// Return the sound's position in the vector.
return (int)m_vSoundsList.size() - 1;   

}

void PlaySound(const int nSoundID)
{
// When it gets to this point, if I call getChannelGroup() on the sound
// being passed in the group is set to FMOD master group
m_Result = m_pSystem->playSound(FMOD_CHANNEL_FREE,
m_vSoundsList[nSoundID]->m_Sound, false, &m_vSoundsList[nSoundID]->m_Channel);
}
[/code:udx95dc2]

What’s happening is I call setVolume on the channel group which correctly sets the group’s volume, however since the channel’s group is being changed to FMOD master group, it is not receiving the changes. The only reason I can think of is that the channel is falling out of scope when I exit LoadSound() so everything is resetting back to default values. So, besides the sloppy code, does anything stand out to you? 😛

  • You must to post comments
0
0

You’re playing your sound twice. When you call m_pSystem->playSound() in your LoadSound() function, you’re playing one instance of that sound, and attaching it to the appropriate ChannelGroup. Later, in your PlaySound() function, you’re calling m_pSystem->playSound() again, which plays a new instance of that sound.

That new instance of the sound doesn’t know about the existence of the old instance of the sound. Any settings that you changed on the instance that you created in LoadSound() don’t apply to the instance that you create in PlaySound().

You have two choices: you can either do the ChannelGroup manipulation in PlaySound() for each channel that you play (and remove it from the LoadSound() function), or you can call Channel::setPaused(…, false) in PlaySound() to unpause the sound that you started in LoadSound().

I suspect that you’ll end up with fewer problems overall if you use the former (setting the ChannelGroup in PlaySound() and not playing in Loadsound()) than the latter.

Hope that helps!

  • You must to post comments
0
0

Thank you! I removed the playSound() from LoadSound() and now everything works great. I didn’t realize that calling playSound() multiple times would mess with my settings.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.