Advertisement

FMod stop all channels

Started by January 27, 2015 10:48 PM
4 comments, last by Brain 10 years, 1 month ago

Hi,

I've been trying to figure out a way to stop all Fmod channels that are playing (simply because I don't keep track of all channels that can play a sound).

Here's what I've come up with, but unfortunately it doesn't work:


void CAudio::StopAll()
{
	int *playingChannels = NULL;
	mFModSystem->getChannelsPlaying(playingChannels);

	for(int j=0;j<sizeof(playingChannels);++j)
	{
		FMOD::Channel *tempChannel;
		mFModSystem->getChannel(playingChannels[j], &tempChannel);
		tempChannel->stop();
	}
	delete[] playingChannels;
}

Any ideas?

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

The System::getChannelsPlaying() function returns a count of channels playing into its parameter, not an array of playing channel IDs. The code that you've written there is sure to crash or have otherwise horrible behavior.

In order to stop all playing channels, you'll want to do something like this:


// This is the number of channels that you pass into the first parameter of System::init()
const int NumChannels = 32;

for(int i=0; i<NumChannels; i++)
{
  FMOD::Channel* pChannel = nullptr;
  FMOD_RESULT res = mFModSystem->getChannel(i, &pChannel);

  if(res == FMOD_OK && pChannel)
  {
    pChannel->stop();
  }
}

Hope that helps!

Advertisement
Thanks. I'll try it out, with the define I assume you mean the max number of channels in my application, because I don't keep track of the actual number

Update: just noticed your code comment, I know which number to use. Thanks again

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

It works as a charm

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Glad to hear it!

Is there a reason that you don't track the channel ids though? This would provide a cleaner way of stopping playback and/or any individual channel...

This topic is closed to new replies.

Advertisement