Every sound in every Gerk Games game comes from Web Audio API. No library, no framework, no audio files. Just raw oscillator nodes and gain envelopes.

Why Web Audio API Beats Audio Files

Audio files need to load, decode, and buffer. On a slow connection, that's 2-5 seconds PER SOUND. Web Audio API generates sounds procedurally — zero network overhead, zero file size, zero loading time. A game with 10 sound effects using procedural audio loads instantly.

Our engine is one function: an oscillator with frequency, duration, waveform, and a fade-to-zero gain envelope. That's literally it. Everything from the Snake Arena eating sound to the Pixel Jumper jump sound is just different parameters to the same function.

Web Audio API Architecture

Building a game audio engine from scratch using the Web Audio API requires understanding three core components: the AudioContext, audio nodes, and the connection graph. An AudioContext manages the audio hardware and creates a timeline. Audio nodes (oscillators, gain nodes, buffer sources) connect in a directed graph to produce sound. The connection graph determines routing — an oscillator connects to a gain node which connects to the destination. This node-based architecture is more flexible than loading pre-recorded audio files because sounds can be generated in real-time.

Procedural Sound Design for Games

For game sound effects like coin pickups, jump noises, and collision impacts, procedural generation offers two major advantages: zero download size and infinite variation. A coin pickup can be synthesized with a brief sine wave pitch sweep from 200Hz to 800Hz over 100ms with an exponential decay envelope. A collision sound can be generated by passing white noise through a band-pass filter with rapidly decaying gain. These effects sound natural because they mimic physical acoustic phenomena.

Performance Considerations

Audio processing shares the main thread with game rendering unless explicitly offloaded to AudioWorklet. For performance-critical games, we recommend creating all audio nodes during game initialization rather than during gameplay. Node creation involves memory allocation, which can cause frame drops. Pre-create your oscillator and gain nodes, connect them to the destination, and simply call start() and stop() on the oscillator during gameplay. This approach reduces per-frame audio overhead from approximately 0.5ms to effectively zero.

Building a Complete Sound Set

A complete game requires at least six distinct sound categories: positive feedback (correct selections, pickups), negative feedback (collisions, errors), transition sounds (level start, level complete), ambient loops (background hum), UI sounds (button clicks), and reward sounds (achievement unlocked). Each category can be generated with a different algorithmic approach. Positive feedback uses ascending pitch sweeps. Negative feedback uses noise bursts with rapid decay. Ambient loops use oscillating filters on constant tones. Rewards use layered harmonic sequences.

Testing Audio Timing Under Load

One subtle bug we encountered during development: audio playback timing drifts when the game's frame rate drops. If the game runs at 30fps instead of 60fps, audio events scheduled with setTimeout fire at unpredictable offsets from their visual counterparts. The fix was to schedule all audio events using the AudioContext's internal clock rather than JavaScript timers. The AudioContext.currentTime property provides a hardware-synchronized timestamp that remains accurate regardless of frame rate. This guarantees that sound effects stay synchronized with visual events even on low-end devices where frame rates fluctuate.

Browser Compatibility Testing

Our audio engine has been tested on Chrome 90+, Firefox 90+, Safari 15+, and Edge 90+. Safari was the most challenging target because its Web Audio API implementation has historically lagged behind Chrome and Firefox. Safari does not support AudioWorklet, which means all audio processing must run on the main thread — a significant constraint for games running at 60fps. Our workaround for Safari: reduce audio complexity during gameplay (simpler oscillator shapes, fewer simultaneous voices) and restore full audio quality during menu screens where frame rate is less critical.