Add sound and music that make a browser game feel alive. Which sounds every game needs, a Web Audio mixer with music / sfx buses, unlocking audio on the first tap, pitch and volume variation so repeats don't get tiring, voice limits, ducking, looping music and crossfades, positional panning, synthesized sounds (no files) with a jsfxr-style generator, formats and file sizes, mute and settings th...
Download skill (.zip) Files on GitHubGame sound design
Finding free sounds and music, and keeping credits, is covered by bash-game-audio-credits (Openverse, Freesound, licenses).
This skill is about using sound well. Drop-in mixer: assets/audio.js (tested logic).
What needs a sound (in order)
- The core action (jump, shoot, tap, place): short, satisfying, slightly varied.
- Success (pickup, hit, match, level complete) and failure (hurt, miss, game over). These should be clearly different.
- UI: button press, back, error. Quiet.
- Music: one loop for play, optional one for menus. Quieter than effects.
- Ambience (wind, crowd, hum) for mood games.
Rules
- Unlock on first gesture: create or resume the
AudioContextinside the firstpointerdown/keydown. iOS stays silent otherwise. - Variation: each play gets ±5–10% pitch (
playbackRate) and ±10% volume. Several takes for very frequent sounds. - Voice limits: max ~4 copies of the same sound at once, and a minimum gap (~40 ms). Otherwise 30 coins at once is a wall of noise.
- Mix: music bus ~0.4–0.6, sfx ~0.8. Duck music briefly on big moments (boss roar, game over).
- Loops: music that loops seamlessly (OGG/M4A loop points or
AudioBufferSourceNode.loop = true). Crossfade between tracks (1–2 s). - Pause: suspend the context (or pause music) on pause and when the tab hides; resume on unpause.
- Spatial: pan by screen x (
StereoPannerNode, −1..1), volume by distance. Cap the distance falloff so off-screen events are still hinted. - Settings: music and sfx volume + mute, saved; the mute button always visible on title and pause.
Formats and size
- Effects: short OGG or MP3 (MP3 decodes everywhere; OGG is unsupported on older iOS). Provide MP3 or M4A as fallback if using OGG.
- Music: 96–128 kbps MP3/OGG, mono is fine for most games; a 2-minute loop is ~1.5–2 MB.
- Decode effects up front (
decodeAudioData), stream long music with an<audio>element +MediaElementSourceif memory matters. - bash-web-asset-shrinker can re-encode audio in a project.
Synthesized sounds (no files)
Great for prototypes and retro games. audio.js includes synth({ type, freq, slide, dur, vol, noise }) for blips,
lasers, coins, explosions and hits. Presets: PRESETS.coin, .jump, .laser, .hit, .explosion, .powerup, .click.
Swap to recorded sounds later without changing game code (audio.play("coin") either way).
API (audio.js)
import { createAudio, PRESETS } from "./core/audio.js";
const audio = createAudio({ storageKey: "mygame-audio" });
audio.unlockOn(window); // resumes on first pointerdown / keydown
await audio.load({ jump: "assets/sfx/jump.mp3", music1: "assets/music/loop.mp3" });
audio.define("coin", PRESETS.coin); // synthesized
audio.play("jump", { pitchVar: 0.08, pan: (x / W) * 2 - 1 });
audio.music("music1", { fade: 1.5 }); // crossfades from the current track
audio.duck(0.3, 0.6); // music to 30% for 0.6 s
audio.setVolume("music", 0.5); audio.toggleMute(); // persisted
Checklist
- Sound on the first tap on iPhone (test in the viewer preview on a phone if possible)
- Core action sound doesn’t get annoying after 100 plays
- Spamming an action doesn’t clip or distort
- Music stops on pause and when the tab is hidden; resumes after
- Mute and volumes survive a reload
CREDITS.mdlists every non-original sound with its license