Sign in to follow this  
cozzie

FMod stop all channels

Recommended Posts

cozzie    5029

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
Adiss    135

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
cozzie    5029
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this