Audio tutorial for Unity: the Audio Mixer
Learn how to use the Audio Mixer in Unity to create immersive audio experiences for your games. This tutorial covers everything you need to know. By Jeff Fisher.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Audio tutorial for Unity: the Audio Mixer
25 mins
Routing and Mixing
You have an Audio Mixer with a bunch of Groups set up, but no Audio Sources are outputting to any Groups. Currently, your Audio Sources are routed directly to the Audio Listener.
What you want is for the Audio Sources to output to an appropriate Group that will then output to the Audio Mixer, which will in turn output to the Audio Listener.
Locate the GameObject named Audio Objects in the Hierarchy window.
Now select the Trumpet child object of Audio Objects. Then jump over to the Inspector window, and scroll down until you see the Audio Source attached to the Trumpet. You should see an Output field underneath the AudioClip field. Click on the icon next to the Output field and select the Music group.
Awesome job — you just routed your first Audio Source! With the Audio Mixer window still open, run the game, and click on the Trumpet object. Notice when the Trumpet is playing, the Music group is showing Attenuation, as is the Master group, because the Music group is a child of the Master group.
Click the Edit in Play Mode button while the game is still running. You can adjust the Music volume slider to that of your liking, and the changes will persist outside of Play Mode.
So now you have one Audio Source currently routed, but you need to route all of the SFX sounds.
Go through the remaining children under the Audio Objects game object in the Hierarchy window, and set their Audio Source Output fields to an appropriate Group:
- AirConditioner: Environment
- Phone: SFX
- Grenades: Grenade
- FireAlarm: SFX
- AssaultRifle: SFX
- Cans: SFX (For both attached Audio Sources)
- Sink: Sink
- Radio: SFX (For the First/Top Audio Source)
- Radio: Radio (For the Second/Bottom Audio Source)
There’s also one more Audio Source on the AudioManager GameObject for a room tone sound. Set the Ouput field for that one to Environment.
Now run the project, and start clicking away. If you take a look at the Audio Mixer window, and you should start to see all of your Groups being put to use as you click the various objects in the scene.
Play around with the Solo and Mute buttons to see just exactly how they work with the Audio Mixer. For instance, muting the SFX group will mute all sound that routes through that group.
Effects
You can add various effects to Groups just like you can add effects to Audio Sources. To add an effect simply, select the Group you wish to add an effect to and click on Add Effect in the Inspector window.
Unity provides a bunch of audio effects right out of the box. You’ll be using the following for the remainder of this tutorial:
- SFX Reverb to make all the sound in the game feel like part of the room.
- Highpass to cutoff low frequency sounds.
- Lowpass to cutoff high frequency sounds.
- Compressor to balance the volume of sounds.
- Distortion to help simulate a radio transmission.
Groups can have as many effects as you’d like, with Attenuation being the default effect for every Group. Effects are executed from top to bottom, meaning the order of effects can impact the final output of the sound. You can re-order effects at anytime by simply moving them up or down in the Strip View.
A common practice in audio mixing is to create separate Groups for complicated or frequently used effects.
Create two additional Groups. Name one Reverb and the other Distortion. Mark them both as green for readability and move them up front next to the Master.
Reverb
Instead of adding a SFX Reverb to each Group, you can simply add it to the Reverb group. Do this now.
You’re probably wondering how this will do anything if your Audio Sources are not routed to the Reverb group. You’re right — it won’t. You will have to add another effect named Receive to your Reverb group, and make sure it is above the Reverb effect as order matters.
Then you can add the opposite effect named Send on the Music and SFX groups.
Select the Music group and in the Inspector window under the Send effect, connect the Receive field to the Reverb\Receive option, and set the Send Level to 0.00 dB.
Then do the same thing with the SFX group.
With all that sending and receiving set up, jump back over to your Reverb group. In the Inspector window, under SFX Reverb, change the following fields to the indicated value:
- Room: -1000.00 mB
- Room HF: -1200.00 mB
- Decay Time: 1.49 s
- Decay HF Ratio: 0.54
- Reflections: -370.00 mB
- Reflect Delay: 0.00
- Reverb: 1030.00 mB
- Reverb Delay: 0.01 s
- Density: 60.00 %
These settings will give your audio a nice empty-room effect, and will help unify the audio as if it’s all coming from the same room.
Save and run your project, and start making some noise! You should see the Reverb group in the Audio Mixer window picking up noise as you click on various objects.
Try starting and abruptly stopping the Trumpet sound. You should hear the Reverb echoing and decaying quite nicely.
You can also use the Bypass button to have the Reverb group bypass its effects, so you can hear the difference with and without the SFX Reverb.
For some finishing touches, add a Lowpass filter to the Grenade group and the Sink group. The default values should be just fine. This will help remove some of the high frequency signals being created from the Reverb group.
Distortion
With the Reverb working nicely, it’s time to add the next effect — Distortion.
Run the game and click the radio, then wait until you hear the phrase Ladies and Gentlemen.
Right now, that phrase doesn’t sound like it’s coming from a radio at all. To fix that, you’ll first need to add a Receive effect to the Distortion group, and then have the Radio group send to the newly created Receive channel.
Don’t forget to set the Send Level field to 0.00 dB under the Radio group in the Inspector window. Otherwise the Distortion group will have no effect.
Now it’s time to create the actual Distorting effect. To really get it sounding like a radio transmission, you’ll need to do a little bit of layering.
Add the following effects:
- Highpass to remove any low frequency room tone noises.
- Compressor to bring the decibel levels to an equilibrium.
- Distortion to simulate a radio transmission.
- Another Distortion to really help sell the effect.
- Lowpass to remove any high-pitched screeching created from the distortion.
Now select the Distortion group. Go to the Inspector window and set the values for all of the effects accordingly:
- Pitch: 100%
- Volume: -10dB
- Cutoff freq: 2909.00 Hz
- Resonance: 1.00
- Threshold: -9.80 dB
- Attack: 50.00 ms
- Release: 50.00 ms
- Make up gain: 0.00 dB
- Level: 0.96
- Level: 0.96
- Cutoff freq: 2064.00 Hz
- Resonance: 1.00
When finished, run the project again and click on the radio.
The Distortion effect should sound similar to this:
With all of the effects in place, you can pat yourself on the back for setting up your first Audio Mixer!
As a final touch, you can adjust some of the decibel levels. Music and Environment should be more of a background noise, so lower their decibel levels. Also, you don’t want to give your player a heart attack when the Grenade goes off so lower that a bit too. :]
In the next section you’ll learn how to change some of the Audio Mixer fields via scripting.