Setting up FMOD for a C# game

Ben Driscoll
4 min readMay 7, 2023

--

I had a hard time getting FMOD set up, because all the docs I could find assumed you’re using Unity or Unreal, which we’re not. (Our game, Cobalt Core, is XNA/FNA/Monogame).

However, getting it running from any old C# project is actually pretty easy if you know the steps.

I’m gonna try to keep this as short as possible!

0: What’s FMOD?

https://www.fmod.com/

When you hear people talk about FMOD, it refers to two things:

FMOD Studio, a desktop application that looks and feels like music/audio software that musicians and sound designers are familiar with. It lets you do a lot of common dynamic audio, music, and mixing stuff easily without having to do programming. It’s pretty clever. You make your content here.

FMOD Engine, a couple of .dll files that your game needs, so it can load and play the .bank files that FMOD Studio exports.

1: Get FMOD Studio

Download FMOD Studio if you don’t already have it.

If you’re working with sound people who are providing .bank files to you, you can skip this step!

If you’re on your own, check out some FMOD Studio tutorials and make an event or two so you have something to play from your game engine to test if it’s working. Check out normal FMOD tutorials to learn how to make events!

https://www.fmod.com/download -> in the “FMOD Studio” section

2: Get FMOD Engine

Download FMOD Engine from their website. This has the .dll and .cs files you need to get it working in your engine.

The version of the sdk should match the version of FMOD studio you’re using to make content!

https://www.fmod.com/download -> in the “FMOD Engine” section.

3: Get the relevant .cs and .dll files into your C# project

You’ll need these .cs files, which are in your FMOD Engine installation folder.

in C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows

Get these files:
\api\core\inc\fmod.cs
\api\core\inc\fmod_dsp.cs
\api\core\inc\fmod_errors.cs
\api\studio\inc\fmod_studio.cs

And put them in your game’s source code somewhere. These are the .cs files that tell your program what .dll methods to call to talk to the FMOD engine at runtime.

Now, get the .dll files, which are also in the FMOD Engine installation folder:

in C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows

Get these files:
\api\core\lib\x64\fmod.dll
\api\studio\lib\x64\fmodstudio.dll

Note: you can also take the files that end with (…)L.dll if you want the debug versions of the libraries. it’s not necessary, though.

4: Load the DLL files

There are a bunch of ways to get a .dll loaded. The simplest way is to just have it next to your executable. You can add this to your .csproj file so that the dll files are copied to your build directory whenever you debug/run/build the game.

<None Include="wherever\fmod\is\in\your\project\fmod.dll">
<Link>%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="wherever\fmod\is\in\your\project\fmodstudio.dll">
<Link>%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

5: Initialize FMOD!

Wherever is convenient in your game at startup, start up FMOD.

If you haven’t already, get your .bank and .strings.bank files into your project. You’ll be exporting these from the FMOD Studio app, or getting them from your sound person!

FMOD.Studio.System.create(out var fmodStudioSystem);
fmodStudioSystem.getCoreSystem(out var fmodSystem);
fmodSystem.setDSPBufferSize(256, 4);
fmodStudioSystem.initialize(
128,
FMOD.Studio.INITFLAGS.NORMAL,
FMOD.INITFLAGS.NORMAL,
(IntPtr)0
);
fmodStudioSystem.loadBankFile(
// adjust this path to wherever you want to keep your .bank files
"Master.bank",
FMOD.Studio.LOAD_BANK_FLAGS.NORMAL,
out Bank bank
);
fmodStudioSystem.loadBankFile(
// adjust this path to wherever you want to keep your .bank files
"Master.strings.bank",
FMOD.Studio.LOAD_BANK_FLAGS.NORMAL,
out Bank strings
);

You’ll need to store fmodStudioSystem somewhere, probably your Game instance or just a static field. Up to you!

Because every frame of your game, you’ll call this method to let FMOD do some work. You gotta do this! Or FMOD will be sad.

fmodStudioSystem.update();

6: Play some sound!

var path = "event:/Big/Goose/Honk";
fmodStudioSystem.getEvent(path, out EventDescription evDesc);
evDesc.createInstance(out EventInstance evInst);
evInst.start();
evInst.release();

That’s it! You should now have FMOD up and running.

The values you set up FMOD with are all tweakable, and these are the values I’m using on Cobalt Core’s desktop build at the moment.

7: Using GUIDs (optional)

FMOD Studio has a nice helper that will export a .cs file of named GUIDs that you can use instead of strings. These are nice because they don’t give you the temptation to use string interpolation to look up events and thus create garbage. But mostly they’re nice because you get compile-time checks that your game logic is hooked up correctly to sounds!

In FMOD Studio, open the menu:

Scripts > FMOD Examples > Export GUIDS Header > C# File

Which makes a file like:

namespace FSPRO
{
public class Event
{
public static readonly FMOD.GUID Big_Goose_Honk = new FMOD.GUID { ... };
public static readonly FMOD.GUID Bigger_Goose_Honk = new FMOD.GUID { ... };
public static readonly FMOD.GUID Medium_Goose_Honk = new FMOD.GUID { ... };
public static readonly FMOD.GUID Very_Big_Goose_Honk = new FMOD.GUID { ... };
[...]
}
}

And then copy that file from the fmod project folder into your game’s source code somewhere. Now you can refer to sounds like above, but with getEventById instead of the string version.

fmodStudioSystem.getEventById(
FSPRO.Event.Big_Goose_Honk,
out EventDescription evDesc
);
[...]

You’ll need to re-export this .cs file whenever you add new fmod events, by the way!

8: The end

Thanks for reading! Hopefully this saves someone else a day or two of setup. If you’re an FMOD guru and see anything I should update, let me know!

--

--

Ben Driscoll

Ben Driscoll, artist and programmer, made Daisy Owl, Sunshine Heavy Industries , and now working on Cobalt Core 🚀