FMod Music in C++
How to Use FMod to Play Mod or Midi Music in Visual C++
Below is an example of how to use FMod to play mod or midi music in Microsoft Visual C++.FMod Includes
Firstly we include "fmodvc.lib" for Visual C++:#pragma comment(lib, "fmodvc.lib")
And we include the "fmod.h" header file:
#include "fmod.h"
FMod Initialization
To initialize FMod, we need to tell it the frequency, the number of channels and any flags:FSOUND_Init(44100, 32, 0));
So the first parameter is the output frequency in hertz, the second is the number of channels and the third is for FMod flags.
Load Music
First we set up an FMUSIC_MODULE variable (Song_1 in the below example) for our first music file:FMUSIC_MODULE *Song_1 = NULL;
Now we load the music file ("song1.mod" in the below example) into our variable:
Song_1 = FMUSIC_LoadSong("song1.mod");
Play Music
We can set the volume that we want our song to play at with the following line:FMUSIC_SetMasterVolume(Song_1, 200);
The second parameter gives the volume, with 0 being the minimum and 256 the maximum.
To start our song playing we use:
FMUSIC_PlaySong(Song_1);
The following will stop the music playing:
FMUSIC_StopAllSongs();
Close Down FMod
When you are finished with the song you should use the following line to free the memory for the song:FMUSIC_FreeSong(mod);
And you should use the following line to shut down FMod when you are done:
FSOUND_Close();
Back to Home

