MUSIC SYNCRHONIZATION
This section will describe how to synchronize graphics with sound effectively using FMOD functions.
It usually involves either polling against a music value to trigger your effect, or getting a callback from FMOD.
The best way to synchronize a stream, such as a wav or mp3 is by using FSOUND_Stream_SetSynchCallback.
All you have to do is drop 'markers' into a wav editing program like SoundForge, and FMOD will automatically generate callbacks as the stream plays when the play cursor runs over the markers!.
The strings that you label markers with are even passed into the callback.
Note that only WAV files and MP3 with RIFF wrappers will work here. The markers are saved in a RIFF chunk.
If you dont have this luxury or want to use a format that doesnt support this feature, then the next best way to synchronize a stream, such as a wav or mp3 is by using FSOUND_Stream_GetTime.
You can create your time offsets in a wav editing program like SoundForge, and use these to poll against while FMOD plays the song back.
Note that this method may have some very slight accuracy problems, usually to do with framerate, or innacurate sound drivers. An example is that if your framerate is only 10fps, you are only checking in 100ms increments, which is innacruate. If you have a decent framerate it shouldnt be noticable, not to mention the fact if you are executing a graphical effect, you wont be able to see it until the next frame anyway.
A nice way to poll events would look something like this..
#define MAX_TIMES 4
int times[MAX_TIMES] = { 1000, 2500, 10000, 20000 };
int current = 0;
do
{
if (FSOUND_Stream_GetTime(stream) >= times[current] && current < MAX_TIMES)
{
TriggerEvent();
current++;
}
} while (running);
And there you have it! You have a list of time offsets you want to synchronize against, and it cycles through, triggering each event as it occurs!