Adaptive game audio (mood crossfades and procedural sound)
game-audiocrossfadeprocedural-audioweb-audiogodotbrown-noise
Small games can get adaptive, responsive audio without a middleware engine: a two-track crossfade driven by one "intensity" value, plus procedurally generated effects. Used in Fall (Godot 4) and a vanilla-JS racer.
Two-track mood crossfade
Keep a calm track and an intense track playing in sync and map one 0..1 mood value to their volumes in
decibels: calm lerp(-6, -40, mood), intense lerp(-40, -6, mood). Smooth the mood value
frame-rate-independently (1 - exp(-3 * delta)) so the mix never jumps. In Fall, mood is the larger of
fall-speed ratio and distance-from-center ratio.
Procedural sounds (no asset files)
- Wind ambience: brown noise (integrated white noise) with volume proportional to speed.
- Collectibles: generate a short
AudioStreamWAVbuffer in code (an 880 Hz pop or bell, a rising whoosh). - Engine hum in WebAudio: a sawtooth
OscillatorNodethrough a lowpassBiquadFilterNode(about 500 Hz) into aGainNode; set frequency and gain from speed every frame. Create theAudioContexton the first user gesture (browsers block autoplay). - Beeps and chimes: a short oscillator with a gain envelope scheduled at
currentTime + delay.
Gotchas
- Kill an in-flight volume tween before starting another fade, or the two race.
- Looping OGG files break fade-out logic; use non-looping exports for crossfaded tracks.
- Always ship a mute toggle.
See also
- Generating game music loops and a countdown you can hear
- Procedural music and sound effects with the Web Audio API
- Game juice checklist (feedback layers that make a game feel good)