Resonance Audio Setup in Unity
Resonance Audio is already included as a plugin in FMOD Studio and in the FMOD-Unity integration. To activate it properly we have to follow three simple steps:
- Add the Resonance Audio plugin to Unity’s FMOD settings.
- Remove any return tracks in your FMOD Studio project.
- Add the Resonance Audio Listener effect to the Master Bus in the FMOD Studio Mixer.
Add the resonanceaudio string to the plugin section in Unity’s FMOD settings like this:
Remove the standard return channel from your mixer:
Finally add the Resonance Audio Listener to your Master Bus by clicking with right mouse button and selecting Add Effect -> Plug-in Effects -> Google -> Resonance Audio Listener:
Attention: the Resonance Audio Listener only works if placed on the Master Bus of FMOD Studio’s Mixer. The Google Resonance Documentation wrongly states that the listener can be added to event groups in the Mixer, but FMOD will give you an error about non finding the Resonance Audio Listener in Unity if you do so.
Playing FMOD Events with Resonance Audio in Unity
Playing Events with Resonance Audio is no different that doing it with stock FMOD. You can use the usual Studio Event Emitter component or C# code to play events. If you need help with that read read my tutorial about playing FMOD Events in Unity.
The only difference is the fact the Google provides its own Spatializer plugin that uses head-related transfer functions (HRTFs). Audio processed with HRTFs gives the beautiful illusion that sounds have a specific location in the 3D world. There are different HRTFs models available (Oculus itself has its own Spatializer plugin for FMOD, Steam also released its own implementation called Steam Audio), but we will use the one provided by Google Resonance, as it is already included in FMOD Studio.
Instead of using FMOD’s Spatializer plugin, we will add a Resonance Audio Source effect to the master track of one of our events. You can find this effect also under Add Effect -> Plug-in Effects -> Google -> Resonance Audio Source:
Compared to FMOD’s Spatializer Effect we can find some differences. Here are the main new features:
- Source Directivity Curve: this is the curve on the right side of the effect. You can change this curve by modifying the Directivity and Directivity Sharpness values. Increasing the Directivity parameter will shape the curve into a Omnidirectional, Cardioid or Figure-eight pattern. The Directivity Sharpness parameter allows you to create narrower emission patterns for your sound sources.
- Occlusion: this parameter simulates having virtual objects in front of the listener, attenuating the audio source by removing high frequencies from it. Attention: this doesn’t happen automatically. As far as now there is no way for FMOD to get information about the geometry that is present in Unity. You would have to build a Raycast system to detect objects that are present between the listener and the audio source and drive a parameter to change the Occlusion value.
- Near-Field FX: enables a near-field effect for sound sources less than 1 meter from the listener. It simulate the effect of sound sources being very close to the listener’s ears.
- Bypass Room: bypasses the Resonance Audio Room set up in Unity. We will cover this topic shortly.
Try to play a few events with the Resonance Audio Source effect, change some settings and listen how it sounds!
Playing Ambisonics with Resonance Audio
The Resonance Audio plugin for FMOD supports playing Ambisonics encoded in the AmbiX (ACN-SN3D) format. To play Ambisonic files we need to:
- Add an Ambisonics audio file to our FMOD event.
- Add the Resonance Audio Soundfield effect to the track or the master track of the event (by placing it on the master track you can add multiple Ambisonic recordings to the event).
- Make sure the master input is set to four channels (Surround 4.0).
- Play back the FMOD Event like usual.
The first step should be pretty obvious: drag and drop your favorite first-order AmbiX file into the event timeline. After that, add the Resonance Audio Soundfield effect to the master track by selecting Add Effect -> Plug-in Effects -> Google -> Resonance Audio Soundfield:
Change the master track input channels to four channels:
Play back the event using the Studio Event Emitter component or by playing audio by writing code. Move your head. You should be able to hear the spatialization taking effect.
Using Audio Rooms with FMOD in Unity
The Resonance Audio plugin features an interesting feature called Audio Rooms. These rooms can be set up in Unity and provide realistic early reflections and reverb, taking into account the materials of walls, floor and the ceiling.
To set up a Resonance Audio Room create an empty GameObject and add the FMODResonanceAudioRoom component to the GameObject:
Under the Surface Materials section we can find six acoustic surface materials. We can change these to our liking using the drop-down menus. The Reflectivity parameter controls the strength of early reflections in the room. Changing this parameter will make the room or space feel smaller or bigger. The Reverb Properties affect late reverberation in the audio room. Change these to fine tune the simulation to be as realistic as possibile More information about this settings can be found at Google’s Resonance Audio Documentation page.
After adding the component to a GameObject, a yellow outline representing the room boundaries will appear in the scene. Scale the GameObject so that it fits to your imaginary room, and select some materials for the walls, floor and ceiling in the component settings:
Create a GameObject containing a Studio Event Emitter component and place it inside inside this room. Select an FMOD Event that has a Resonance Audio Source as a spatializer effect. In the example scene I used a radio model to hold the FMOD Event that will play a song, but you can surely even try this out with a cube for testing:
If you play the scene and go inside the audio room, you will hear the audio playing that is affected by the room reflections. Congratulations!