# MUSIC SYNCRHONIZATION

Introduction

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.

Streams

The best way to synchronize a stream, such as a wav or mp3 is by using FSOUND_Stream_SetSyncCallback.
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 don't have this luxury or want to use a format that doesn't support this feature, then the next best way to synchronize a stream is by using custom sync points. This way you can add and remove your own points that wav markers would normally generate. See FSOUND_Stream_AddSyncPoint.
Add your markers manually with this and set your sync point callback with FSOUND_Stream_SetSyncCallback
Your callback could then look something like this but you can put what you like in the callback function.
signed char endcallback(FSOUND_STREAM *stream, void *buff, int len, int param)
{

// end of stream callback doesn't have a 'buff' value, if it doesn't it could be a sync point.
if (buff)
{

printf("\nSYNCPOINT : \"%s\"\n", buff);

}
return TRUE;

}
Remember FMOD is a real-time system and the amount of time spent in a callback has to be low, or you could cause buffer underrun or stuttering.

MODs

To synchronize graphics with mod music, try these functions.
- FMUSIC_SetZxxCallback
- FMUSIC_SetRowCallback
- FMUSIC_SetOrderCallback
- FMUSIC_SetInstCallback
  This allows you to set callbacks on row, order, instrument or Zxx mod effect events.
  There is also a time based function FMUSIC_GetTime.