0
0

Hello

I am wondering if I am doing something wrong. I have set up my SoundManager class to have 5 different channels, in my game some sounds may be played at the same time, like the gun being fired and the enemy "hurt" sound… This is how I set up FMOD and the function I call to play the sounds in a manner that they are always rewound to the start:

[code:3szc509v]
void SoundMgr::init(){

System_Create(&fmodsys);
fmodsys->init(5, FMOD_INIT_NORMAL, 0)

}

void SoundMgr::play(string name, int chan){
if(chan == 1){
fmodsys->playSound(FMOD_CHANNEL_FREE, soundMap.find(name)->second, true, &chn1);
chn1->setMode(FMOD_LOOP_OFF);
chn1->setPosition(0, FMOD_TIMEUNIT_PCM);
chn1->setPaused(false);
} else if(chan == 2){
fmodsys->playSound(FMOD_CHANNEL_FREE, soundMap.find(name)->second, true, &chn2);
chn2->setMode(FMOD_LOOP_OFF);
chn2->setPosition(0, FMOD_TIMEUNIT_PCM);
chn2->setPaused(false);
} else if(chan == 3){
fmodsys->playSound(FMOD_CHANNEL_FREE, soundMap.find(name)->second, true, &chn3);
chn3->setMode(FMOD_LOOP_OFF);
chn3->setPosition(0, FMOD_TIMEUNIT_PCM);
chn3->setPaused(false);
} else if(chan == 4){
fmodsys->playSound(FMOD_CHANNEL_FREE, soundMap.find(name)->second, true, &chn4);
chn4->setMode(FMOD_LOOP_OFF);
chn4->setPosition(0, FMOD_TIMEUNIT_PCM);
chn4->setPaused(false);
} else if(chan == 5){
fmodsys->playSound(FMOD_CHANNEL_FREE, soundMap.find(name)->second, true, &chn5);
chn5->setMode(FMOD_LOOP_OFF);
chn5->setPosition(0, FMOD_TIMEUNIT_PCM);
chn5->setPaused(false);
}

}
[/code:3szc509v]

And in the game I have (this is just an instance but it happens with most sounds):
[code:3szc509v]
....
sMgr->play("gunshot", 1);
....

sMgr->play("rat_hurt", 3);

...
[/code:3szc509v]

However the result is very random, with the two sounds playing rarely at the same time whereas most time only one of the two plays…

I there anything very wrong with this set up?

Thank you in advance for any help you may be able to provide.

  • You must to post comments
0
0

FMOD channel are inexpensive init the System with something like 1024 channels. This is just the size of the FMOD Channel pool, those channels back onto software channels which are real sounds. I wouldn’t reccomend trying handle the channel management yourself, FMOD is already very efficient.

With regard to playing two sounds at the same time, the mixer runs in a seperate thread, so the only way to garuntee two sounds start together is to either a) lock the mixer, or b) schedule them in the future.

  • You must to post comments
0
0

Thank you for your reply… could you elaborate then on what is a good way to initialise two sounds simultaneously? If not by addressing two specific channels? In case I initialise with 1024 channels as you said…

Also, say you want to have a background looping music and other sounds playing sporadically, with my current setting the background loop plays ok but randomly it is stopped when other sounds start. This is How I play the loop:
[code:3aeffmse]
void SoundMgr::playRepeat(string name, int chan){
if(chan == 1){
fmodsys->playSound(FMOD_CHANNEL_FREE, soundMap.find(name)->second, true, &chn1);
chn1->setMode(FMOD_LOOP_NORMAL);
chn1->setPosition(0, FMOD_TIMEUNIT_PCM);
chn1->setPaused(false);
} else if(chan == 2)

....

[/code:3aeffmse]

So if I playRepeat on channel 7 and then play an effect on channel 1, most times channel seven would stop?

Thanks again for your help

  • You must to post comments
0
0

This setup actually works fine when I initialize FMOD with 1024 like Peter suggested, the other with direct channel addressing work just fine then.

Thanks a lot for the pointer!

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.