I am trying to set up my Sound Manager 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!
[code:q560hf34]
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);
}
[/code:q560hf34]
…despite the fact that I AM using two separate channels…. am I missing something?
- neo187 asked 6 years ago
- You must login to post comments
Thank you Peter, that was indeed the issue, I had copied over this code from a sample
[code:18igccnt] fmodsys->init(1,FMOD_INIT_NORMAL,0);[/code:18igccnt]
Without realising that it was limiting the number of available channels.
As for the set position, I actually do want my sound to restart each time it’s played, say in the case of a gunshot where the fire button may be pressed repeatedly….is that not the right way of doing it?
- neo187 answered 6 years ago
- You must login to post comments
There is no need, there is no position information stored in the FMOD::Sound. When you create a new channel by calling playsound it will be at position 0. The channel is a playing sound, a single Sound can play on many Channels at the same time (except for streaming sounds where it is one-to-one). Whenever you play a sound just create a new channel, channels are extremely light weight, that’s what they’re there for.
FYI: Channels are cheap so call system init with something like 1024 maxchannels, and you wont have any problems.
- Guest answered 6 years ago
- You must login to post comments
What was the maxchannels specified for System::init?
Also you don’t have to call setPosition 0, it will start at 0 when you call playSound.
- Guest answered 6 years ago
- You must login to post comments
Please login first to submit.