Getting started with FMOD

Installation (VS2012)

Download the latest stable release of the FMOD Ex Programmers API for windows from the FMOD downloads page. Run the installer and follow the instructions.

Add the FMOD API directory to the system path e.g."C:\Program Files (x86)\FMOD SoundSystem\FMOD Programmers API Windows\api".

Create a new Environment Variable called FMOD_SDK, set it's value to also be the FMOD API directory e.g. "C:\Program Files (x86)\FMOD SoundSystem\FMOD Programmers API Windows\api"

Configuring a project to use FMOD

Create a new project.

In Project Properties (see screen-shot below)

  1. select "all configurations"
  2. select "VC++ Directories"
  3. add "$(FMOD_SDK)\inc" to the list of include directories
  4. add "$(FMOD_SDK)\lib" to the list of library directories
  5. setting FMOD directories

Running FMOD

Add the following lines to any source files which will use FMOD

Initialization.

The simplest way to initialize fmod is to simply call System::init. Thats it. FMOD will set up the soundcard and other factors using default parameters. Let's have a look at an example of initializing FMOD Ex.

Here we have the most basic setup of the FMOD engine. It will use 100 virtual voices.

Loading a Sound

A sound in FMOD corresponds to a audio file loaded in to memory or an audio stream. A sound object contains the data for a piece of audio. Generally each sound file is loaded once (there in only a single instance of each piece of audio). Loading a sound does not cause it to play, but we need to load it before we can play it. Bear in mind that loading a compressed mp3 file into a sound object will cause the file to be decompressed and take up a large amount of memory. For large files it is better to use streams.

Playing a Sound

Sounds are played on channels. A channel is an instance of the playing sound. e.g. in a racing car game there may be one engine sound (sound file), but the sound will be played on many channels depending on the number of cars in the game.Each channel will have it's own volume and can be stop/started independantly. When dealing with 3D audio, each cannel will have its own position, velocity etc.

In order to hear a sound we need to create a channel to play the sound on;

You do not need to store the channel handle if you do not want to. That parameter can be 0 or NULL. This is useful if you don't care about updating that instance of the sound, and if it is a one shot sound (ie it does not loop). For example:

You can start the sound paused, so you can update its attributes without the change being audible. That is what the 'paused' parameter is used for. For example, if you set it to true, set the volume to 0.5, then unpaused it, the sound would play at half volume. If you had set the paused flag to false and executed the same logic, you may hear the sound play at full volume for a fraction of a second. This can be undesirable.

A 'channel' is an instance of a sound. You can play a sound many times at once, and each time you play a sound you will get a new channel handle. Not ethat this is only if it is not a stream. Streams can only be played once at a time, and if you attempt to play it multiple times, it will simply restart the existing stream and return the same handle that it was using before. This is because streams only have 1 stream buffer, and 1 file handle. To play a stream twice at once, open and play it twice.

Always use FMOD_CHANNEL_FREE. This lets FMOD pick the channels for you, meaning that it uses FMOD's channel manager to pick a non playing channel. FMOD_CHANNEL_REUSE can be used if the desired effect is to pass in an existing channel handle and use that for the playsound. It can be used to stop a sound spawning a new instance every time System::playSound is called, and only play once at a time.

You do not have to 'free' or 'release' a channel handle. Channels come from a pool which you created by specifying a channel count in System::init. Channel handles get re-used if old sounds have stopped on them. If all channels are playing, then one of the existing channels will get stolen based on the lowest priority sound.

Update. (This is important!)

It is important that System::update be called once per frame. Do not call this more than once per frame, as this is not necessary and is just inefficient.