Game Audio: Sound Effects, Music & Spatial Audio
Game audio is half the experience. A game with great graphics but bad sound feels lifeless. Audio communicates feedback (you hit something), atmosphere (wind in a forest), and emotion (triumphant music after a boss fight).
In this tutorial, you’ll learn audio sources and listeners, 2D vs 3D audio, the sound design workflow, FMOD and Wwise middleware, procedural audio, audio occlusion, mixing/ducking, and asset optimization techniques used by professional game audio designers.
What You’ll Learn
- Audio sources and listeners in Unity and Unreal
- 2D (ambient) vs 3D (positional) audio
- Sound design workflow: recording, editing, implementing
- FMOD and Wwise middleware integration
- Procedural audio generation
- Audio occlusion and obstruction
- Mixing, ducking, and dynamic volume
- Audio asset optimization
Why Game Audio Matters
Audio directly affects player performance and immersion. Studies show players react 50ms faster with spatial audio in FPS games. At DodaTech, we apply game audio techniques in Doda Browser for spatial UI feedback and environmental soundscapes.
Learning Path
flowchart LR
A[2D Animation] --> B[Multiplayer Networking]
B --> C[Game Audio<br/>You are here]
C --> D[Game Optimization]
style C fill:#f90,color:#fff
Audio Sources and Listeners
Every game engine has two fundamental audio objects:
| Component | Role | Example |
|---|---|---|
| Audio Source | Emits sound | Footstep sound on the player |
| Audio Listener | Hears sound | Attached to the main camera |
| Audio Mixer | Processes audio | Adds reverb, compression, EQ |
// Unity — playing a footstep sound
using UnityEngine;
public class FootstepAudio : MonoBehaviour
{
public AudioSource audioSource;
public AudioClip[] footstepClips;
public void PlayFootstep()
{
// Pick a random clip from the array
AudioClip clip = footstepClips[
Random.Range(0, footstepClips.Length)
];
audioSource.pitch = Random.Range(0.9f, 1.1f); // variation
audioSource.PlayOneShot(clip);
}
}Expected behavior: Each footstep plays a different random clip with slight pitch variation, preventing the repetitive “machine gun” sound effect.
2D vs 3D Audio
| Type | Behavior | Use Case |
|---|---|---|
| 2D Audio | Same volume everywhere | Music, UI sounds, narration |
| 3D Audio | Volume/pitch/pan based on distance | Gunshots, footsteps, environmental sounds |
// 3D audio setup
AudioSource source = gameObject.AddComponent<AudioSource>();
source.spatialBlend = 1f; // Fully 3D (0 = 2D, 1 = 3D)
source.minDistance = 1f; // Full volume within 1 unit
source.maxDistance = 20f; // Inaudible beyond 20 units
source.rolloffMode = AudioRolloffMode.Logarithmic; // Natural falloffExpected behavior: As the player moves away from the audio source, the sound gets quieter and pans to one ear.
Sound Design Workflow
Professional sound design follows this pipeline:
- Record — capture raw sounds (Foley, field recording)
- Edit — clean up noise, trim, normalize (Audacity, Reaper)
- Process — add effects (EQ, compression, reverb)
- Implement — import into engine, set up events
- Mix — balance volumes, add ducking
- Test — playtest with different audio setups
FMOD and Wwise Middleware
| Feature | FMOD | Wwise |
|---|---|---|
| Cost | Free (indie) / paid | Free up to 200 assets / paid |
| Learning curve | Moderate | Steep |
| Real-time mixing | Yes | Yes |
| Parameter control | Studio parameters | Game parameters + RTPCs |
| Platform support | All major platforms | All major platforms |
FMOD example — playing an event from code:
using FMODUnity;
public class PlayFMODEvent : MonoBehaviour
{
[EventRef] public string fmodEvent;
public void PlayExplosion()
{
RuntimeManager.PlayOneShot(fmodEvent, transform.position);
}
public void SetParameter(string paramName, float value)
{
RuntimeManager.StudioEventInstance(fmodEvent)
.setParameterByName(paramName, value);
}
}Expected behavior: The FMOD event plays with all its mixing, effects, and parameter modulation defined in the FMOD Studio authoring tool.
Procedural Audio
Procedural audio generates sound at runtime rather than playing pre-recorded clips. This is memory-efficient and creates infinite variation:
// Generate a simple beep tone procedurally
using UnityEngine;
public class ProceduralBeep : MonoBehaviour
{
private AudioSource audioSource;
void Start()
{
audioSource = gameObject.AddComponent<AudioSource>();
}
public void PlayBeep(float frequency = 440f, float duration = 0.1f)
{
int sampleRate = AudioSettings.outputSampleRate;
int samples = (int)(sampleRate * duration);
AudioClip clip = AudioClip.Create("Beep", samples, 1,
sampleRate, false);
float[] waveData = new float[samples];
for (int i = 0; i < samples; i++)
{
waveData[i] = Mathf.Sin(2 * Mathf.PI * frequency *
i / sampleRate);
}
clip.SetData(waveData, 0);
audioSource.PlayOneShot(clip);
}
}Expected output: A sine wave tone at 440Hz (A4) plays for 0.1 seconds. Change frequency for different pitches.
Audio Occlusion and Obstruction
Occlusion muffles sound when a wall blocks the path between source and listener. Obstruction partially blocks sound. Unity’s built-in occlusion requires the Audio Spatializer SDK, but FMOD and Wwise handle it natively.
Source (behind wall) → Occlusion calculation → Muffled output// Simple occlusion with raycast
public class SimpleOcclusion : MonoBehaviour
{
public AudioSource audioSource;
public LayerMask occludingLayers;
public float occludedVolume = 0.2f;
void Update()
{
Vector3 dir = audioSource.transform.position - transform.position;
float distance = dir.magnitude;
if (Physics.Raycast(transform.position, dir.normalized,
distance, occludingLayers))
{
audioSource.volume = occludedVolume;
audioSource.lowPassFilterEnabled = true;
}
else
{
audioSource.volume = 1f;
audioSource.lowPassFilterEnabled = false;
}
}
}Expected behavior: When an obstacle blocks the line of sight between listener and audio source, the sound becomes quieter and muffled (low-pass filtered).
Mixing and Ducking
Ducking lowers background music volume when important sounds play (dialogue, alerts):
using UnityEngine.Audio;
public class AudioDucker : MonoBehaviour
{
public AudioMixer mixer;
public void DuckMusic(float duckDuration = 2f)
{
StartCoroutine(DuckRoutine(duckDuration));
}
System.Collections.IEnumerator DuckRoutine(float duration)
{
mixer.SetFloat("MusicVolume", -20f); // Lower music
yield return new WaitForSeconds(duration);
mixer.SetFloat("MusicVolume", 0f); // Restore music
}
}Expected behavior: When a dialogue line plays, background music volume drops for 2 seconds, then fades back.
Common Mistakes
1. Not Using Audio Mixer Groups
All sounds on the same Audio Mixer group means you can’t separately control music, SFX, and dialogue volumes.
2. Ignoring Dynamic Range
A game that’s equally loud during quiet exploration and intense combat fatigues the player. Use compression to balance dynamic range.
3. No Randomization on Repeated Sounds
Playing the exact same footstep clip creates a robotic “machine gun” effect. Randomize pitch (±10%) and select from multiple clips.
4. Overly Large Audio Files
Uncompressed WAV files bloat build size. Use Vorbis (OGG) for music, ADPCM for short SFX, and target 128-192 kbps quality.
5. Not Preloading Frequently Used Sounds
Loading audio from disk on first play causes a delay. Preload common sounds on scene start.
6. Forgetting Mobile Constraints
Mobile devices have limited audio channels. Set a max of 12-16 simultaneous voices on mobile. Prioritize important sounds.
Practice Questions
1. What’s the difference between 2D and 3D audio?
2D audio is the same volume everywhere (music, UI). 3D audio changes volume/panning based on distance from the listener.
2. What does audio ducking mean?
Temporarily lowering background audio volume when an important sound plays (dialogue, alert).
3. How does audio occlusion work?
A raycast checks for obstacles between source and listener. Obstacles cause the sound to be muffled (low-pass filter applied).
4. What is procedural audio?
Audio generated at runtime using algorithms rather than pre-recorded clips. This saves memory and creates infinite variation.
5. Challenge: Create a dynamic music system.
Use FMOD or Wwise parameters to transition between combat and exploration music. The parameter changes based on whether enemies are nearby.
Mini Project: Audio Environment
Build a scene with:
- A player with footstep sounds (randomized)
- Background ambient audio (wind, birds)
- A collectible that plays a pickup sound
- Audio occlusion when the player walks behind a wall
- Music that ducks when the pickup sound plays
FAQ
What’s Next
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro