In this lesson, you will learn how to manipulate the raw audio signal of your game objects in real-time by chaining built-in audio effects to add depth and professional character to your soundscapes.
The Signal Processing Chain
Think of your audio signal as a stream of water flowing from an Audio Source toward the Audio Listener. By default, this water is pure, but by inserting Audio Effects into the path, we can filter, echo, or modify that signal before it hits the player's ears. In Unity, these effects are processed in real-time, meaning you can adjust parameters like "decay time" or "cutoff frequency" while the game is running to create dynamic, immersive experiences.
Adding Effects to Mixer Groups
While you can add effects directly to an Audio Source component, the industry-standard practice is to apply them to Audio Mixer Groups. This allows you to process multiple sounds (like all environmental background noise) through the same effect chain simultaneously.
To add an effect:
- Open your Audio Mixer window.
- Select the specific group (e.g., "Ambience").
- In the Inspector, click Add Effect.
- Choose an effect like Audio Reverb Filter, Low Pass Filter, or Chorus.
Real-time Manipulation
Because these are real-time, you can control them via scripts. For example, if your player enters a small, confined cupboard, you might want to increase the cutoff frequency of a Low Pass Filter to simulate muffled, claustrophobic sound.
using UnityEngine;
using UnityEngine.Audio;
public class MuffleAudio : MonoBehaviour
{
public AudioMixer mixer;
public void SetMuffleState(bool isMuffled)
{
// Adjust the "LowPass" parameter exposed in the Mixer inspector
float frequency = isMuffled ? 500f : 22000f;
mixer.SetFloat("LowPassCutoff", frequency);
}
}
By adjusting these parameters, you aren't just playing audio files; you are sculpting the acoustic environment to react to the player's presence. Whether it’s the "wet" echoes of a cavern or the hollow resonance of a metallic hallway, layering these effects transforms flat audio into a living, breathing world.
Key Takeaway: Real-time audio effects act as signal modifiers that you can chain together on Audio Mixer Groups to create dynamic, responsive soundscapes that react to your game's environment.