Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FMOD - play multiple sounds simultaneously?

Tags:

c++

audio

fmod

I am trying to set up my Sound Manager (FMOD) to play a background music and other action sounds on different channels, as I understand that this is the only way of having simultaneous sounds with FMOD.... My setup is below, if I call playRepeat and then playOnce the first track stops!

void SoundMgr::addSound(char *path, string n){
    Sound* s;
    fmodsys->createSound(path, FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &s);


    soundMap.insert(pair<string,Sound*>(n, s));
}

void SoundMgr::playOnce(string name){

    fmodsys->playSound(FMOD_CHANNEL_FREE,
        soundMap.find(name)->second, true, &fmodchn);
    fmodchn->setPosition(0, FMOD_TIMEUNIT_PCM);
    fmodchn->setPaused(false);
}

void SoundMgr::playRepeat(string name){

    fmodsys->playSound(FMOD_CHANNEL_FREE,
        soundMap.find(name)->second, true, &backChn);
    backChn->setMode(FMOD_LOOP_NORMAL);
    backChn->setPosition(0, FMOD_TIMEUNIT_PCM);
    backChn->setPaused(false);

}

...despite the fact that I AM using two separate channels.... am I missing something?

like image 539
Alex Avatar asked Jun 23 '26 06:06

Alex


1 Answers

The issue was that I was only initialising FMOD with one channel

fmodsys->init(1,FMOD_INIT_NORMAL,0);

Changing that to a higher number made the setup above work ok!

like image 90
Alex Avatar answered Jun 25 '26 18:06

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!