Synthesizing Chaos: Building a 16-Step Chiptune Sequencer & WAV Exporter in Web Audio
"How we built a procedural 8-bit drum machine, laser synth, and offline 16-bit PCM WAV exporter without relying on static MP3 samples."

01.The Problem with Static Audio Assets
In early web games, playing audio meant loading 50 separate 20KB .wav or .mp3 files over HTTP. Inevitably, network latency causes audio clips to stutter, iOS Safari drops the audio context due to user-gesture lockouts, and memory leaks accumulate from un-garbage-collected HTML5 <audio> tags.
With SFX-Gen 3000, every single sound is synthesized mathematically in real-time on your CPU using raw oscillator waveforms, white noise buffers, bi-quad filter sweeps, and FM cross-modulation.
02.The Anatomy of Procedural Sound
Here is how the core voices in SFX-Gen are built from basic physics:
- 1.The 808 Kick: An ultra-fast exponential pitch drop on a pure sine wave (160 Hz down to 0.01 Hz in 0.4s) with a matching exponential volume decay.
- 2.The Laser Blaster: A sawtooth oscillator that plunges from 1400 Hz down to 120 Hz in 0.15s.
- 3.The Snare: A Math.random() white noise buffer fed through a highpass filter at 1000 Hz with a snappy 0.2s release.
- 4.The FM Chaos Generator: A square-wave modulator drives the frequency of a sawtooth carrier. The carrier pitch, modulator pitch, and modulation depth are all re-rolled at random on every hit.
03.How Offline WAV Export Works
To allow indie devs to download these sounds directly into their Unity or Godot projects, SFX-Gen 3000 spins up an OfflineAudioContext(2, 44100 * duration, 44100).
It renders the active voices into a float buffer, writes a standard 44-byte RIFF/WAV header, quantizes the samples to 16-bit PCM, and hands the result to the browser as a download Blob:
// 16-bit PCM Quantization
sample = Math.max(-1, Math.min(1, channels[i][offset]));
sample = (0.5 + sample < 0 ? sample * 32768 : sample * 32767) | 0;
out.setInt16(pos, sample, true);No backend server. No external dependencies. Just pure math and browser audio hardware.