Not able to stop all the sounds in a channel

(Keitel) #1


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.

(Nicholas Wilcox) #2

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
system->init(NUM_CHANNELS, FMOD_INIT_NORMAL, nullptr)


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

FMOD::Channel* mychannel0;
FMOD::Channel* mychannel1;
system->playSound(sound0, nullptr, false, &mychannel0); 
system->playSound(sound1, nullptr, false, &mychannel1); 

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

(Keitel) #3

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.