Answered
0
0

Hi,

The following might be explained in the manual somewhere, but for now I have not been able to find it.

I have two play sound commands after each other. Both play the same sound file in the same channel, but in different frequencies, and both are played in a loop. When I use the set paused command to stop the sounds, the last one stops, but not the first. Whatever I do after that, the first sound continues. I have also tried channel stop and channel set mute, but without success. What can I do to stop all the sounds at once?

Thanks in advance.

  • You must to post comments
Best Answer
2
0

Hi Ketil,

You cannot play two sounds on the same channel. I’m guessing what’s happening (please post source if I’m wrong) is that you are passing the same channel pointer to two playSound calls, which means you lose your handle to the first channel and can no longer control it.

// Create a system with two channels allocated, call them sys_channel0 and sys_channel1
int NUM_CHANNELS = 2
system->init(NUM_CHANNELS, FMOD_INIT_NORMAL, nullptr)

// INCORRECT CODE

FMOD::Channel* mychannel;
system->playSound(sound0, nullptr, false, &mychannel); 
// sound1 is now playing on sys_channel0, pointed to by mychannel

system->playSound(sound1, nullptr, false, &mychannel); 
// sound2 is now playing on sys_channel1, pointed to by mychannel, 
// but I've lost my handle to sys_channel0 and can no longer control it
mychannel->setPaused(true); // this will only affect sys_channel1

// CORRECT SOLUTION
FMOD::Channel* mychannel0;
FMOD::Channel* mychannel1;
system->playSound(sound0, nullptr, false, &mychannel0); 
system->playSound(sound1, nullptr, false, &mychannel1); 
mychannel0->setPaused(true);
mychannel1->setPaused(true);

// EVEN BETTER SOLUTION
FMOD::ChannelGroup* mygroup;
system->createChannelGrou("my group", &mygroup);
FMOD::Channel* mychannel0;
FMOD::Channel* mychannel1;
system->playSound(sound0, mygroup, false, &mychannel0); 
system->playSound(sound1, mygroup, false, &mychannel1); 
// all commands on the channel group affect both channels
mygroup->setPaused(true);
  • You must to post comments
0
0

Ok, I understand. I have to play each sound in a seperate channel, which is something I needed to know, so thank you very much for your answer. Thanks also for your thorough explanation. Good idea to use a channelgroup for simpler coding.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.