Integrating ODIN Voice Chat with the FMOD Audio Solution in Unity

Introduction
Welcome to this guide on integrating the ODIN Voice Chat Plugin with the FMOD Audio Solution in Unity. The code used in this guide is available on the ODIN-FMOD Git repository.
What You'll Learn:
- How the
FMODMicrophoneReader
andFMODPlaybackComponent
scripts work and how to use them in your project - How to add 3D positional voice with
FMODPlayback3DPosition
andFMODCoreListener
- How to tune the playback latency
- Properly set up ODIN in Unity when using FMOD as an audio solution
- Deal with limitations and potential pitfalls
Note: This guide assumes that your project has disabled Unity's built-in audio.
The playback uses an FMOD user stream that pulls voice data from ODIN. FMOD's default decode buffer for such streams
is 400 ms, which used to add a noticeable delay. The FMODPlaybackComponent shrinks that buffer to 40 ms by default
and keeps ODIN's own buffer small, see Latency settings.
Getting Started
To follow this guide, you'll need to have some prerequisites:
- Basic knowledge of Unity
- The FMOD Plugin for Unity, which you can get here
- The ODIN Voice Chat Plugin, available here
The sample project was created with:
- Unity 6000.3.27f1
- ODIN Voice Unity SDK 1.7.9
- FMOD for Unity 2.03.15 and FMOD Studio 2.03
To set up FMOD in your project, please follow FMOD's in-depth integration tutorial. You can find the tutorial here.
To set up the ODIN Voice Chat Plugin, please take a look at our Getting-Started guide, which you can find here:
Begin ODIN Getting Started GuideTrying out the sample
The sample scene Assets/Odin-FMod/OdinFMod.unity joins the ODIN room default on start. You can grab and move both the audio listener and the remote peers with the left mouse button to hear the 3D positional audio. Press M to mute or unmute your microphone.
To test it, create a build and start it alongside the Editor. Alternatively, use the ODIN web app together with the Editor. In that case, enter the same Auth Access Key in the web app and connect to the default room.
Project setup
Disabling the Unity audio engine
To inform ODIN that the Unity audio engine is disabled, e.g. when using FMOD exclusively for audio processing, add the ODIN_UNITY_AUDIO_ENGINE_DISABLED flag to the Scripting Define Symbols in Project Settings > Player. This flag ensures that ODIN won't try to use Unity's audio systems.
OdinHandler
The OdinHandler FMODPlaybackComponentPlayback auto creation to Manual positional audio and create the
OdinAutoJoin
script of the sample shows how to do this, see Spawning playback components.Overview
The integration consists of these scripts:
| Script | Replaces | Job |
|---|---|---|
FMODMicrophoneReader | MicrophoneReader | Records the microphone with FMOD and pushes the samples to ODIN |
FMODPlaybackComponent | PlaybackComponent | Plays one remote ODIN media stream as an FMOD user stream |
OdinAutoJoin | Playback auto creation of the OdinHandler | Joins a room and spawns or destroys one playback object per media stream |
FMODPlayback3DPosition | - | Optional: spatializes a playback component |
FMODCoreListener | - | Optional: moves the FMOD Core listener with your camera or player |
FMODMicrophoneReader
script is an essential part of the FMOD integration. It replaces the default ODINMicrophoneReader
component, taking over the microphone input responsibilities by using FMOD. This script is crucial for reading microphone data and sending it to the ODIN servers for voice chat.You can either follow the Usage setup to drop the FMODMicrophoneReader
Usage
- Add the
FMODMicrophoneReader
script to yourOdinManagerprefab. - Disable the original
MicrophoneReader
component.

The script records from FMOD's default recording device. Press the Mute Key (default M) to toggle the microphone,
or call SetMuted(bool) from your own code. The Muted property returns the current state.
If you're using ODIN Plugin versions older than 1.5.9, do not remove the MicrophoneReader
The script currently doesn't support automatic device switching or allow for programmatically changing devices. If you'd like to see extensions to this script, feel free to join our Discord server and let us know.
How it works
To read data from the microphone using FMOD, we'll need to perform the following steps:
- Setup and create a
FMOD.Soundobject, into which FMOD can store the microphone input data. - Start the microphone recording.
- Continually read the FMOD microphone data in 20 ms chunks and push it to the ODIN servers.
1. Setup
The setup is performed in Unity's Start() method.
Retrieve Microphone Info
First, the script checks that FMOD found at least one recording device. Then it retrieves details about the microphone, such as the sampling rate and the number of channels. We'll use this info to configure the FMOD recording sound in the next step and the ODIN microphone streams later on.
Prepare the chunk buffers
ODIN encodes mono or stereo audio. Devices with more than two channels have to be downmixed to mono. The script reads and sends the microphone data in chunks of 20 ms and allocates the buffers for these chunks once:
Configure Recording Sound Info
Next, set up the CREATESOUNDEXINFO object. This object carries essential metadata that FMOD needs for audio capture.
We use SOUND_FORMAT.PCMFLOAT because ODIN requires this format for microphone data. This avoids the need for audio
data conversions later on.
The _recordingSoundInfo.length is set to capture one second of audio. FMOD records into this sound as a ring buffer,
so it only needs to hold enough data to bridge the time between two Update() calls.
Create Recording Sound
To hold the captured audio, FMOD requires us to create a FMOD Sound object as shown below.
Here, we use the MODE.LOOP_NORMAL | MODE.OPENUSER flags in combination with the previously configured
_recordingSoundInfo to initialize the _recordingSound object.
2. Recording
At this point, we're ready to start capturing audio. To do so, call the recordStart method from FMOD's core system.
After initiating the recording, we also get the length of the recorded sound in PCM samples by calling getLength.
When the component is destroyed, the recording is stopped and the sound released:
3. Continually push microphone data
In the Update() method, we manage the ongoing capture of audio data from the FMOD microphone and the transmission to
the ODIN servers.
Initialization
The method starts by checking if there is an active OdinHandler
The next step is to find out how much audio has been recorded since the last check (in PCM frames). This way we know how much data to read from the ring buffer.
Skip stale audio
If the application stalls, e.g. during a scene load or while the Editor is paused, old audio piles up in the ring buffer. Instead of sending it late, the script skips everything but the most recent 200 ms:
Read Microphone Data
As long as at least one full 20 ms chunk is available, the script copies it from the FMOD sound into the chunk buffer
using FMOD's @lock.
Here it's important to be aware of the unit differences between FMOD, ODIN, and the system's
Marshal.Copy function:
- FMOD expects the read position and read length to be specified in bytes. One PCM frame holds one float per
channel, so
bytesPerFrameconverts frames to bytes. Marshal.Copyand ODIN expect the number of samples (floats) being copied.- The read position and the record position are counted in frames.
When a chunk reaches past the end of the ring buffer, @lock returns two pointers: ptr1 for the part up to the end of
the sound and ptr2 for the rest, which starts at the beginning of the sound. Copying both parts ensures that no audio
is lost when the buffer wraps around.
Downmix to mono
For devices with more than two channels, DownmixToMono averages the channels of each interleaved frame:
Push Microphone Data
Each chunk is pushed to the microphone stream of every joined room:
The ValidateMicrophoneStream method ensures that an ODIN microphone stream is set up and configured with the sample
rate of the device and the channel count sent to ODIN:
Muting
SetMuted calls MuteStream on the microphone stream of every room. Because a stream that was re-created by ValidateMicrophoneStream starts unmuted, the push loop above re-applies the mute state before pushing data.
FMODPlaybackComponent
replaces ODIN'sPlaybackComponent
. After setting the room name, peer id and media stream id, the component automatically connects to the ODIN media stream and plays back the voice data using the FMOD engine.Usage
- Create a prefab with the
FMODPlaybackComponent
. The sample ships with theFModPlaybackComponentprefab inAssets/Odin-FMod. - Optionally add the
FMODPlayback3DPosition
script to the prefab for 3D positional audio. - Instantiate one prefab per remote media stream and set
RoomName,PeerIdandMediaStreamId.
Spawning playback components
The OdinAutoJoin
OnMediaAdded and
OnMediaRemoved events of the OdinHandler
to spawn and destroy the playback objects:In a game, you'd usually parent the playback object to the player object that belongs to the peer, so the voice moves with the player.
Latency settings
The component exposes three settings in the Inspector:
Decode Buffer Milliseconds: size of FMOD's decode buffer for the voice stream. FMOD's default is 400 ms, the sample prefab uses 40 ms. Values of 40 to 50 ms play without dropouts, while 20 ms produces crackles. Set it to0to keep FMOD's default. You can override the value globally in builds with the-decodebuffer <ms>command line argument.Target Buffer Milliseconds: the amount of voice data ODIN should buffer internally during playback (default 40 ms). FMOD reads the voice at exactly the playback rate, so any delay that builds up in ODIN's buffer (at startup, after a network hiccup or while FMOD isn't reading) would otherwise stay forever. If ODIN buffers more than this value, the voice plays 2% faster, which is practically inaudible, until the buffer is back at the target level.Max Buffer Milliseconds: above this buffer level, the excess is discarded at once instead of played faster, e.g. after the channel was paused or the mixer suspended (default 400 ms). ODIN itself can buffer up to 2 seconds of voice data.
How it works
The playback is set up in three steps:
- Create an FMOD user stream whose PCM read callback pulls voice data from the ODIN media stream.
- Fill the stream from the callback whenever FMOD needs more data.
- Keep ODIN's buffer small by catching up or discarding excess data.
1. Create the stream
In Start(), the component configures a CREATESOUNDEXINFO with ODIN's remote sample rate and channel count, the
PCMFLOAT format and a PCM read callback. If a decode buffer size is set, it replaces FMOD's 400 ms default:
The delegate is stored in the _pcmReadCallback field, so the garbage collector doesn't collect it while FMOD still
calls it.
The 3D mode has to be set when the sound is created, because switching a playing stream to 3D is unreliable. If an
FMODPlayback3DPosition
Finally, the sound handle is registered in a static dictionary, so the static callback can find the component:
2. Fill the stream
FMOD calls PcmReadCallback on its own thread whenever the stream needs more data. The callback has to be static and
marked with [AOT.MonoPInvokeCallback] to work on IL2CPP platforms. It looks up the component by the sound handle and
reads the requested amount of samples from the ODIN media stream. If ODIN buffers more than Max Buffer Milliseconds,
the excess is discarded:
FindOdinMediaStream retrieves the stream from RoomName, PeerId and MediaStreamId on every call, so the
component never holds on to a media stream that was already removed.
3. Catch up on buffer buildup
FMOD reads at exactly the playback rate, so any delay that has built up in ODIN's buffer would never go away on its
own. In Update(), the component checks ODIN's buffer level and plays the channel 2% faster (can be adjusted) while it is above
Target Buffer Milliseconds:
When the component is destroyed, it removes its entry from the dictionary first, so a running callback can't find it anymore, and then releases the sound.
3D positional audio
FMODPlayback3DPosition
Add the FMODPlayback3DPosition
FMODPlaybackComponent
to spatialize the voice. If present, the playback component creates its FMOD stream in 3D mode. The script then updates the channel's position from the GameObject's transform every frame:Settings:
Min Distance: the voice plays at full volume up to this distance.Max Distance: the voice is silent beyond this distance (linear rolloffs), or stops getting quieter (inverse rolloff).Rolloff: how the volume falls off between min and max distance.Inverse: realistic falloff that never reaches silence.Linear: fades evenly to silence from min to max distance.LinearSquare(default): fades to silence at the max distance, dropping faster the closer you are to the speaker.
The rolloff setting is read when the playback stream is created. Changing it at runtime doesn't change the playback behaviour.
FMODCoreListener
The voice plays on FMOD Core channels, which are spatialized against the FMOD Core listener. FMOD's StudioListener
only moves the Studio listener used by Studio events, so without further changes the Core listener would stay at the
world origin.
Add the FMODCoreListener
StudioListener, usually the camera or
player object. It copies the position and orientation into the FMOD Core listener every frame:
Stereo master bus
When a Studio master bank is loaded, the Studio master bus takes over the FMOD Core master channel group, so its input format decides how many channels the final mix has. If no events are routed to the master bus, FMOD Studio may build it as mono, which mixes left and right together and removes all panning (directional audio).
To fix this, open the Mixer in FMOD Studio, select the Master Bus, right-click the input meter in the deck, set
Input Format to Stereo (or a surround format) and rebuild the banks. The sample's FMOD Studio project is already set
up this way.
Limitations and pitfalls
- Multi-channel input devices are downmixed. Devices with more than two channels are downmixed to mono by averaging all channels. On an audio interface where only one input is in use, this makes the voice quieter.
- Device changes are not handled. The
FMODMicrophoneReader
always records from the default device (_currentDeviceId = 0) and doesn't react to devices being plugged in or removed. - No automatic playback creation. The
OdinHandlercan't create FMOD playback for you. Set it toManual positional audioand spawn the playback components yourself, as shown inOdinAutoJoin
. - Too small decode buffers crackle. Keep
Decode Buffer Millisecondsat 40 ms or above. - If there is no panning despite 3D setup: Check that the
FMODCoreListener
is on your listener object and that the Studio master bus uses a stereo or surround input format.