To use fmod in a program, you must first initialize it:
if (FSOUND_GetVersion() < FMOD_VERSION)
{
printf("Error: You have the wrong FMOD version"
" - you should be using FMOD %.02f\n",
FMOD_VERSION);
exit(1);
}
FSOUND_SetOutput(FSOUND_OUTPUT_OSS);
if (!FSOUND_Init(44100, 1024,
FSOUND_INIT_USEDEFAULTMIDISYNTH))
{
printf("Error: %s\n",
FMOD_ErrorString(FSOUND_GetError()));
exit(1);
}
To play a sample file (WAV format), use FSOUND_Sample_Load() and FSOUND_PlaySound():
FSOUND_SAMPLE *samplesound;
samplesound = FSOUND_Sample_Load(FSOUND_UNMANAGED,
"boing.wav",
FSOUND_NORMAL, 0);
FSOUND_Sample_SetMode(samplesound, FSOUND_LOOP_OFF);
FSOUND_PlaySound(FSOUND_FREE, samplesound);
To play a stream sound (MP3 or Ogg), use FSOUND_Stream_Load() and FSOUND_Stream_Play():
FSOUND_STREAM *mp3sound;
mp3sound = FSOUND_Stream_OpenFile("tarotplane.mp3",
FSOUND_NORMAL, 0);
FSOUND_Stream_Play(FSOUND_FREE, mp3sound);
FSOUND_PlaySound() and FSOUND_Stream_Play() return channel numbers, indicating the channel that the sound is being played on. The channel number can be used to control a playing sound, such as changing its volume (FSOUND_SetVolume()) or pausing/unpausing it (FSOUND_SetPaused()). FSOUND_PlaySoundEx() can be used to start a sample in paused mode, so that you can adjust settings on the channel before actually having it start playing. FSOUND_Stream_PlayEx() similarly lets you start a stream sound in paused mode.