Topic 11 · Audio
Mixers, snapshots, ducking and loudness
Route sounds through mixer groups, switch moods with snapshots, duck by routing and keep master below clipping.
How the mixer works
- An Audio Mixer is an asset with a tree of groups under an always-present Master group. Each AudioSource routes to a group; effects, sends and returns process the group's signal. A mixer's output can be routed into a group of another mixer.
- Snapshots capture all of a mixer's parameter values; transitioning between them changes mood or theme.
AudioMixerSnapshot.TransitionTo(timeToReach)interpolates to the snapshot over that time (reference). - Ducking changes one group based on what another group is doing, for example lowering ambience while something else plays.
- Exposed parameters and snapshots don't mix. Per the
SetFloat reference, once
AudioMixer.SetFloatsets an exposed parameter, snapshots no longer control it. Do not call it inAwake,OnEnableorAfterSceneLoad; call it inStartor later. It returns false when the parameter is not found. - Settings sliders. Expose one volume parameter per user-facing category (music, effects, voice) on the parent
group, and drive it with
SetFloat. Leave other parameters to snapshots.
MIXER-GRAPH-FROM-CODE
- There is no public API to add mixer groups or effects. The Editor's internal
UnityEditor.Audio.AudioMixerControllerdoes it with the calls the Audio Mixer window makes:CreateNewGroup+AddChildToParent;new AudioMixerEffectController(name)+AssetDatabase.AddObjectToAsset+PreallocateGUIDs+AudioMixerGroupController.InsertEffect;SetValueForParameterwith names fromMixerEffectDefinitions.GetEffectParameters. A Send needssendTargetplusSetValueForMixLevel(0): it defaults to -80 dB, which is silent. Read the mixer back from disk after saving. - Shape that worked: a compressor on Master after the fader as a safety limiter (threshold -6 dB, attack 10 ms, release 150 ms, no make-up gain); under SFX, a Combat group carrying Duck Volume (threshold -30 dB, ratio 4, attack 0.05 s, release 0.6 s) and a Moments group with a 0 dB Send into that ducker. High-priority moments route to Moments and duck combat in the mixer, with no code timer. Keep the exposed volume parameter on the parent group so the settings slider still covers both children. Measured after: master peak -8.2 dBFS, 0 clipped frames.
NEW-GAIN-FIELD-IS-DB
- A new serialized field loads as 0 on every existing row. A linear "volume" multiplier added that way silences the whole bank. Author per-row gain in dB (0 = unchanged) and jitter as +/- dB and +/- pitch fraction, so the default is today's behaviour.
Related
- Audio topic: every audio page in reading order.
- Next: Spatial and 3D audio.