Skip to content
Audio
step 1/5

Reading — step 1 of 5

Read

~2 min readResources & Rendering

Audio

Game audio:

  • Sound effects: short, triggered (gunshot, footstep).
  • Music: long, looping (BGM, level theme).
  • Voice: dialogue, narration.
  • Ambient: background loops (rain, crowd).

Audio loop:

  • Hardware: callback into your code at sample rate (44.1 kHz).
  • Buffer: ~10-20ms of samples per callback.
  • You fill buffer with mixed audio.
python

Real audio:

  • Multiple channels (stereo, 5.1).
  • Volume per source.
  • Pitch shifting (resample).
  • Effects (reverb, echo).
  • 3D positional audio: distance attenuation, panning.

3D audio:

  • Each sound has source position.
  • Listener has position + orientation.
  • Distance: louder near, quieter far. Falloff curve (linear, inverse, exponential).
  • Panning: stereo balance based on direction.
python

Doppler effect:

  • Moving sources shift pitch.
  • Approach: higher. Recede: lower.
  • Optional; adds realism.

Audio middleware:

  • FMOD: industry-standard. Free for indie.
  • Wwise: AAA standard, more features.
  • OpenAL: cross-platform 3D audio API.
  • SDL_mixer: simpler, free.
  • miniaudio: lightweight C library.

Streaming vs preloaded:

  • SFX: load whole file (small).
  • Music: stream from disk (otherwise eats RAM).

Compression: Ogg Vorbis, Opus for streaming. WAV for SFX (no decode latency).

Latency:

  • SFX-to-speaker: 50-150 ms typical.
  • Lower = better feel for action games.
  • Smaller buffer = lower latency but harder real-time.

For our toy: skip audio implementation; focus on game loop + ECS. Real engine integrates SDL_mixer or similar.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…