./jerome{m}

~/Experiments/Chiptune Lab.md · experiment · 4 min · updated

Chiptune Lab

2026 · Rust · WebAssembly · Web Audio · How this site works

The Game Boy made its music with four voices and not much else: two square waves, a short loop of 4-bit samples, and noise. The Chiptune Lab is a sequencer for four channels in the shape of that chip. Pick a demo, press play, then click the grid and make it yours. A song is a link: the notes, the voices, the tempo, all of it travels in the address, so copy link shares the tune itself, not a file.

chiptune · livePress play, or click the grid to place a note: drag to hold it, click it again to take it away, stack notes on one step for an arpeggio. Space plays and stops, 1–4 pick a channel. Copy link shares the whole song.open ↗

Four voices

  • Two pulse waves. A square wave whose high part is an eighth, a quarter, a half or three quarters of each cycle. The half is hollow, a little like a clarinet; the narrower the pulse, the thinner and more nasal it gets. These carry the lead and the harmony.
  • A wave channel. Thirty-two levels from 0 to 15, played over and over as a staircase: a triangle, a saw, or anything you draw in the panel. Played low it's a bass, which is what all three demos use it for.
  • Noise. A 15-bit linear-feedback shift register: XOR the two lowest bits, shift everything right, put the result back in at the top. Clocked fast it hisses, slower it rumbles. Written into bit 6 as well, the register repeats every 127 steps and turns metallic, which is what the crash uses. Here the noise channel is a small kit, kick, snare, two hats, crash and tom, each a mix of that noise and a falling tone.

Chords, one note at a time

Each channel plays one note at a time. Chiptune's answer is the arpeggio: play a chord's notes one after another, fast enough that they blur into a chord, and the trill becomes the sound of the genre. In the lab you stack notes on one step and the channel takes care of it, moving to the next note every one to four ticks of a 60 Hz clock, the frame rate that handheld music drivers ran on. One tick is a buzz, four a ripple.

The other habits are there too: vibrato that arrives only once a note has settled, glide from one note to the next, a decay that steps down through the hardware's sixteen volume levels, and panning, as on the Game Boy, to the left, to the right or to both.

Degrees, not keys

The grid's rows are the degrees of a scale, not the keys of a piano: two octaves of A minor, say, so every note you can place fits. A song stores degrees, so changing the key moves the whole song, and changing the scale changes its mood: the nightdrive demo in dorian is a different, brighter song. Chromatic is there for when you want every semitone back.

A pattern is one bar of sixteen steps on all four channels; a song chains up to 32 of them, from a set of eight. All of it, notes, voices, the wave's shape, tempo and swing, is a few kilobytes of JSON, deflated and written into the address, as the Dither Lab does with its recipes and the shader playground with its code. The nightdrive demo, twelve bars, comes to under 600 characters. Untouched demos get a shorter link still: their name.

How it's built

The synth is a Rust crate with no dependencies, compiled to a 38 KB WebAssembly module with no bindings, like the dither lab's engine. It runs inside an AudioWorklet, the browser's audio thread, which asks it for 128 frames at a time. The sequencer is in there too, counting samples, so the timing is exact, whatever the page is doing. The page sends it songs and commands; it sends back where it is and the last samples of each channel, which become the scopes over the lanes.

Two details matter for the sound. A naive square wave aliases into whistles at high notes, because its jumps hold more harmonics than a sample rate can carry, so the pulses are band-limited with polyBLEP, which rounds each jump off over a sample on either side. The wave channel is left alone on purpose: its staircase is the sound. And like the hardware, the output goes through a gentle high-pass that keeps a pulse's offset from piling up.

Download WAV runs a second copy of the same module on the page, as fast as it will go: the nightdrive demo, 24 seconds long, renders in under a fifth of a second on my laptop.

Back to Experiments · make some pixels in the Dither Lab · see how this site works.