• Advertisement
Sign in to follow this  

FMod stop all channels

This topic is 1116 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

 

Share this post


Link to post
Share on other sites
Advertisement

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement