i want to play two sounds end to end. i use the channel::setCallback in main.cpp, and wait the FMOD_CHANNEL_CALLBACKTYPE_END in the callback function. But i found that channel::setCallback depend on the system::update. Now I face a problem that i must call the system::update continuously, but it is high cpu intensive. What should I do to make channel::setCallback automatically trigger? Or are there other ways no sooner the sound play end than I get the message?
[code:26m0z3gy]FMOD_CHANNEL_CALLBACKTYPE type, void * commanddata1, void * commanddata2)
FMOD::Channel *cppchannel = (FMOD::Channel *)channel;
if(type == FMOD_CHANNEL_CALLBACKTYPE_END)
[code:26m0z3gy] /**** ****/
WaitForSingleObject (hSoundOverEvent, INFINITE);[/code:26m0z3gy]
- brian_zhao asked 6 years ago
Thanks peter and brett, im testing this solution.
Hi, brett, my sound is .wav file and 44.1kHz, my "FMOD_DELAYTYPE" is "FMOD_DELAYTYPE_DSPCLOCK_START", if i want to delay 3ms, where do i set the lag value and how much is the value of delay?
FMOD_64BIT_ADD(sysHi, sysLo, 0, 44100*3/1000);
system->createSound( 0, mode, &createsoundexinfo, &sound);
system->playSound( FMOD_CHANNEL_FREE, sound, 0, &channel)
channel->setDelay(FMOD_DELAYTYPE_DSPCLOCK_START, sysHi, sysLo)[/code:22jhexa4]
Am i right?
you’re going about joining 2 sounds together incorrectly.
You should be using Sound::setSubSoundSentence to chain 2 sounds together, or you should use Channel::setDelay to play the 2nd sound at a point in time in the future that is exactly at the point the first sound ends.
The sound will end in the mixer but the callback will be fired from System::update. Since these are in different threads, you cannot get a callback the exact instance it finishes. Calling System::update more frequently will increase the accuracy slightly, but the closest you can get is one mix block which in the common case is 1024/44100 = 23.2ms delay.
Thanks Peter. I do have a timer of 20ms. But length of my created sound is about 25ms. i do not have to use the "WaitForSingleObject (hSoundOverEvent, INFINITE)", i only want to get the message at once when the sound play over. I’m troubled: what can i do getting the message at once when the sound play end?( i’m new to FMOD and c++ 😳 )
[quote:1lzfqk8x]Now I face a problem that i must call the system::update continuously, but it is high cpu intensive.[/quote:1lzfqk8x]
I’m not sure what you mean exactly by ‘coninuously’. If you are calling it repeatedly in a loop you should put a Sleep in the loop so the thread can yeild control. If you are calling as part of your render loop then it should not be CPU intensive.
Edit: looking at your code it seems you are working more on a event driven system in which case you should try to set up a ‘timer’ which will regularly call system::update for you.
Please login first to submit.