I have a couple problems synchronizing multiple music tracks and need help identifying what I’m doing wrong.
I’m creating a game on Win32, creating sounds with FMOD_LOOP_NORMAL | FMOD_SOFTWARE | FMOD_ACCURATETIME | FMOD_CREATESTREAM. I start channels paused, set a delay with FMOD_DELAYTYPE_DSPCLOCK_START and unpause.
1) Music tracks have to be synchronized to the next phrase (8 bars), so I start the first track with a delay (500 ms) from getDSPClock(), and save the delay as the synch point. To figure out the number of samples per phrase, I take samplerate from getSoftwareFormat() * number of seconds per phrase. Subsequent tracks after the first are delayed at least a short time (125 ms) from the current getDSPClock() to the next synch point + a multiple of the number of samples per phrase.
This doesn’t really work; either there’s some latency when the loop occurs, or some artefact of incrementing by the number of samples per phrase or from getDSPClock(). Is there a better way to synchronize?
2) I also have to allow some music to start right away, but in synch with everything else. I figure the way to do that is Channel::setPosition. Does FMOD_TIMEUNIT_PCM have the same units as the DSP clock? Or do I base it on the channel frequency?
3) Separate from the issues above, I’d also like to be able to pause all sound when the application doesn’t have focus. Currently I’m pausing the master channel group, but I found that getDSPClock() still ticks, so I’m keeping track of the duration paused, making my calculations based upon a bias, and increasing the delay of tracks just before unpausing.
Is there a way to stop the DSP clock? Could I do it by holding the DSP lock while nothing’s playing?
- hangar asked 10 years ago
- You must login to post comments