This tutorial will unfortunatly only work for C#. Other languages however can be used with FMOD. You will require the following installs and additional files to get you started.
After downloading from the links above extract the FMODINSTALL.ZIP and run the exe as per standard install. Copy the FMOD folder from the FMOD.ZIP file to your project folder. Add the folder to your project and its contects by right clicking on your project name select Add\Existing Item now browse to the FMOD folder and add the following 3 files to your project.
Add the fmodex.dll to your project from the “<Install Path>\FMOD soundSystem\FMOD Programmers API Win32\api” folder
select the fmodex.dll file from your projects and change the property Copy to Output Directory to Copy if newer
You are now ready to use the FMOD sound system
We need to access the entire FMOD sound system add the following variables to the top of your project
//FMOD Sound private FMOD.System fmodsystem = null; private FMOD.Channel fmodchannel = null; private bool playing = false; private FMOD.Sound fmodsound = null;
I always create a InitSound function that i call from the Form_Load
private void frmMain_Load(object sender, EventArgs e) { InitSound(); }
here is the InitSound function which can be placed just after the Form_Load function. you may at this point wish to add a Sound folder to your project Bin\Debug folder for storing the wav files.
private void InitSound() { //Create FMOD System FMOD.Factory.System_Create(ref fmodsystem); //Initialise FMOD fmodsystem.init(32, FMOD.INITFLAG.NORMAL, (IntPtr)null); //Create Sounds fmodsystem.createSound(@"Sound\beep.wav", FMOD.MODE.HARDWARE, ref fmodsound); }
Here we have created the reference to the FMOD system then Initialised the fmodsystem variable to use 32 sound channels. The last part is that we will create the sound we wish to play in this case Beep.wav from our Sound folder.
We have now setup our FMOD system initialised it and loaded a WAV file to play (beep.wav). now all we need it to actually play the sound. Add the following code where you would like the sound to play (A button or a keypress will do).
if (fmodchannel != null) fmodchannel.isPlaying(ref playing); if (!playing) { fmodsystem.playSound(FMOD.CHANNELINDEX.FREE, fmodsound, false, ref fmodchannel); }
The first part here is to check that the sound channel has actually been created, if it has then we need to check if the channel is actually playing a sound. If we try playing a sound and then play the sound again in the same channel you may experience bad sound or even lock ups. If our sound is NOT playing then we can go ahead and play the sound. NOTE that fmodsound is used from our InitSound function and the fmodchannel is created when a new sound is to be played. You MUST use a channel per sound otherwise you may experience problems again bad sound or even lock ups.
Hope this small tutorial gave you some idea of how to use FMOD i am no expert but like to pass on what i have struggled to learn. Please post any problems on the forum all comments are welcome. Thank you for reading this tutorial. Now make some noise.....