Feb 18, 2026By Audio Alchemist•6 min read
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."

ARCHIVE RECORD #SYNTHESIZING-CHAOS-HOW-WE-BUILT-SFX-GEN-3000
#Web Audio API#DSP#Sound Design#Chiptune#Open Source
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 ($150\text{ Hz} \rightarrow 0.01\text{ Hz}$ in $0.4\text{s}$) combined with a quadratic volume envelope.
2. **The Laser Blaster:** A square wave oscillator that plunges from $1600\text{ Hz}$ down to $120\text{ Hz}$ in $0.15\text{s}$, driving an audio clipping curve for retro crunch.
3. **The Snare:** A Math.random() white noise buffer fed through a highpass resonant filter at $1000\text{ Hz}$ with a snappy $0.2\text{s}$ release.
4. **The FM Chaos Generator:** Two oscillators cross-modulating each other's frequency into a delay feedback loop with peaking resonance ($Q=20$), generating analog circuit screaming.
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, sampleRate * duration, 44100)`.
It renders all active 16-step voice channels into a raw interleaved 32-bit float buffer, encodes a standard 44-byte RIFF/WAV header with 16-bit PCM quantization, and generates an instant browser download Blob in under 20 milliseconds:
```typescript
// 16-bit PCM Quantization
const sample = Math.max(-1, Math.min(1, floatData[i]));
view.setInt16(offset, sample < 0 ? sample * 0x8000 : sample * 0x7FFF, true);
```
No backend server. No external dependencies. Just pure math and browser audio hardware.