Walter Ferrell

Senior Full Stack Server Engineer @ Uncapped Games

Speaker channel gain in Unity

21 January 2022

Looking for an easy way to attenuate volume for individual speaker channels in Unity? Unity’s already built a DSP plugin just for you!

Background

Working with lower-level audio in Unity, I struggled finding a simple solution for attenuating low-frequency effects (LFE) channel gain without needing to roll up my sleeves and write a digital signal processing (DSP) effects plugin.

Although I highly recommend anyone interested in learning about audio programming to take a swing at writing their own DSP plugins, it’s a pretty deep rabbit hole for the uninitiated. Thankfully, Unity already has a solution!

Attenuating individual speaker channels

Unity provides a staggering 26 DSP plugins in their Native Audio Plugin SDK. However, the documentation ain’t so great - their link to the source currently points to a BitBucket repo that no longer exists (here’s the official GitHub repo) and they don’t go into many details about what the actual plugins do.

Here’s a quick way to get individual speaker channel attenuation working in your project:

  • Clone the GitHub repo & navigate to the Plugins folder on your computer.
  • MacOS: Locate the entire AudioPluginDemo.bundle.
  • Windows: Navigate to your particular architecture’s sub-folder (if you’re running Windows 10/11 on modern hardware, you want x86_64) and locate the AudioPluginDemo.dll
  • Pull your respective plugin artifact into your Unity project - creating an Assets/Plugins folder and putting it there is the preferable way.
  • Add the Demo - LevelMixer to your target Mixer. (Check out Unity’s manual on how Mixers work)
  • Use the sliders in the plugin to attenuate your desired speaker channel. (In the zero-based channel index, LFE is channel 3, which corresponds to Gain4 on this plugin)

Building the plugins from source

Othniel Cundangan wrote an excellent article around building the plugins from source from a MacOS perspective. If there’s any interest on how to build from source for Windows using Visual Studio, I would be glad to do a write up - let me know!

Why am I not seeing 8 channels in my Mixer?

Check out your project’s Audio settings in Edit>Project Settings>Audio - change Default Speaker Mode to Surround 7.1 forcibly show all 8 channels in your mixers.

Take note, your Unity speaker settings will still be downmixed to whatever speaker setup you have registered in your operating system’s audio settings.

Comments, criticism, or ideas for the future?

Head over to this post’s issue page and put your thoughts in there!