We rebuilt this page as a retro Macintosh desktop — draggable windows, a working terminal, seven themes, a hidden game. People asked about the sounds more than the pixel cursor or the CRT scanlines: where did you source them from?
We didn't. There are no audio files. Zero mp3s, zero wavs, zero kilobytes of audio shipped. Every one of the eighteen sounds is generated in your browser at the moment you trigger it, out of about forty lines of code. This post is the whole trick, and every widget in it is live, so turn your volume up.
An AnalyserNode sits after the master gain, so this is literally the waveform going to your speakers — not a decoration. Every button in this article draws on it.
How a sound is built
The mental model that unlocks everything: you're wiring a small modular synth. Sources make signal, processors change it, everything eventually flows into your speakers. Two shapes cover every sound on this page.
1Oscillator ──► Gain (envelope) ──► destination // tones2BufferSource ──► Bandpass ──► Gain ──► destination // noise
The oscillator is the voice. An oscillator is a wave generator: pick a shape and a frequency and it hums. Four shapes ship in the browser and they have wildly different personalities. This single choice is why each theme on this page sounds like a different machine.
| Wave | Character | Reads as |
|---|---|---|
| sine | pure, no overtones | soft, dreamy, expensive |
| triangle | mellow, few overtones | friendly, neutral, safe default |
| square | hollow, odd overtones | 8-bit, Game Boy, terminal |
| sawtooth | maximum overtones | bright, aggressive, buzzy |
Set attack to 0ms and listen for the click at the start — that pop is why every sound needs an envelope. 6ms is the sweet spot: percussive but clean.
const osc = ac.createOscillator(); osc.type = "triangle"; osc.frequency.setValueAtTime(440, t0); const g = ac.createGain(); g.gain.setValueAtTime(0.0001, t0); g.gain.exponentialRampToValueAtTime(0.28, t0 + 0.006); g.gain.exponentialRampToValueAtTime(0.0001, t0 + 0.25); osc.connect(g).connect(ac.destination); osc.start(t0); osc.stop(t0 + 0.25 + 0.02);
Frequencies worth memorising: 220Hz is low and serious, 440Hz is the A an orchestra tunes to, 880Hz is bright and clicky, and above 2kHz it starts to feel like an alarm. Almost every UI sound worth keeping lives between 300 and 1000Hz. And a frequency that moves is the difference between a beep and a gesture — rising reads as lifted, opened or succeeded; falling reads as dropped, closed or died. Our game-over sound is one line: 440Hz sliding to 110Hz on a sawtooth. Nobody has to be taught what that means.
The envelope is where the craft is. An oscillator on its own is a hearing test: it starts instantly, holds forever, and sounds like it. What makes it a sound is the volume shape over time. Two numbers control everything: attack is how fast it reaches full volume, decay is how it dies. Set attack to zero and you get an audible pop, because the speaker cone slams from rest to full deflection in a single sample. 6ms still reads as instant to a human but gives the cone a ramp instead of a cliff.
g.gain.exponentialRampToValueAtTime(0, t0 + d); // ✗ throws g.gain.exponentialRampToValueAtTime(0.0001, t0 + d); // ✓ -80dB, inaudible
Noise makes it physical. Pure tones sound synthetic because nothing in the physical world is a pure tone. Real objects make two sounds at once: a noisy transient where surfaces meet, and a resonant body tone as the material rings. Web Audio has no noise generator, so you write one: you literally fill a buffer with random numbers, then carve out one band with a filter. That filter's centre frequency is a materials palette: 400Hz is a soft thud, 1.4kHz is a paper rustle, 2.6kHz is a hard plastic tick, 5kHz and up is air.
const frames = ac.sampleRate * 0.05; const buf = ac.createBuffer(1, frames, ac.sampleRate); const data = buf.getChannelData(0); for (let i = 0; i < frames; i++) data[i] = (Math.random() * 2 - 1) * (1 - i / frames); // └─ white noise ─┘ └─ decay baked in ─┘ const bp = ac.createBiquadFilter(); bp.type = "bandpass"; bp.frequency.value = 2600; bp.Q.value = 1.6; src.connect(bp).connect(gain).connect(ac.destination);
From sounds to a system
Layering is the whole trick. This took embarrassingly long to arrive at. One sound is boring. Two stacked sounds are an object. Your brain hears a tone at 880Hz plus a 20ms noise tick at 2.6kHz as a single event: “something small and hard was pressed”. What you're really designing is a plausible physical event, and the listener's auditory system fills in the object.
Turn one off and it stops being an object. Tone alone is a beep; noise alone is a tick.
1// drop — heavier object, so lower everything2tone({ freq: 560, dur: 0.06, slideTo: 300, gain: 0.32 });3noise({ dur: 0.05, gain: 0.20, hz: 420, q: 0.7 });45// open — two notes, a rising fifth, 55ms apart6tone({ freq: 523, dur: 0.05, gain: 0.28 });7tone({ freq: 784, dur: 0.07, gain: 0.26, delay: 0.055 });89// close — the same figure, inverted10tone({ freq: 700, dur: 0.05, gain: 0.24 });11tone({ freq: 430, dur: 0.075, gain: 0.22, delay: 0.05 });
Open and close use the same shape played forwards and backwards, which is why the pair feels like one system. That 55ms delay is ac.currentTime plus 0.055, handed to the audio clock, which is sample-accurate and keeps time even while your main thread is busy laying out a table. Time anything rhythmic with setTimeout and one janky frame turns your two-note chime into two separate events.
One event, seven personalities. This page has seven themes, and switching theme changes the sound too. The part worth stealing: no call site knows about themes. Every sound is defined once in absolute terms, and a single voice table sits between the definitions and the speakers: a waveform, a semitone transpose, a length multiplier, and cents of detune on a doubled oscillator. Hacker sits a fifth up and sounds urgent. Midnight sits a fourth down and sounds sleepy. Vaporwave stretches everything to 1.5× with 14 cents of drift, which is most of why it feels woozy.
const VOICES = {
classic: { wave: "triangle", transpose: 0, length: 1, detune: 0 },
hacker: { wave: "square", transpose: 7, length: 0.8, detune: 0 },
amber: { wave: "sawtooth", transpose: -3, length: 1.1, detune: 6 },
vaporwave: { wave: "sine", transpose: 3, length: 1.5, detune: 14 },
};
// an octave is a doubling, split into 12 equal steps
const semis = (freq, n) => freq * Math.pow(2, n / 12);Adding an eighth theme is adding one row to a table. No sound gets rewritten. That is worth more than any individual sound on the page.
What we learned, and what to steal
Honest answer to how we wrote this: none of us had used the Web Audio API before this project. We built it with AI help, and it's worth being specific about what the AI was good at, because “AI wrote it” is true and useless as a description.
- —Collapsing the API surface. Web Audio has around thirty node types; a UI sound palette needs four. Describing the goal — short percussive sounds, no files, must feel physical — returned the two-graph model above immediately. The real value was the pruning.
- —Surfacing the traps before we hit them. The exponential-ramp-to-zero throw, the autoplay policy, currentTime versus setTimeout. These cost an afternoon each and barely appear in tutorials, because tutorials demo the happy path. “What will bite me here?” is now the first thing we ask of any unfamiliar API.
- —Iterating in the units that matter. Sound design is a feedback loop: play it, decide it's too harsh, change one number. Saying “make the drop feel heavier” and getting back the right three parameters — lower centre frequency, longer decay, downward glide — instead of a rewrite kept us in that feedback loop.
- —Building the explainer. Every widget in this article is a couple of hundred lines of fairly boring React wrapped around ideas we already understood. Perfect delegation, and the reason you can play with this post instead of reading static code blocks.
Where it did not help at all: it cannot tell you what sounds good. It offered a success sound that was technically a major arpeggio and emotionally a doorbell. Every number in this post was landed by ear, one at a time, over an evening. It also confidently produced a version that timed the multi-note figures with setTimeout — which worked fine until the page was doing real layout work. We only caught that because we understood the scheduling section above. AI compresses learning time. You still have to learn.
Steal this. Ten of the eighteen shipping sounds are below. Press them, then read the parameters. Rising means affirmative or opening, falling means negative or closing; that mapping is near-universal in UI audio and costs exactly one parameter.
1const ac = new AudioContext();2const beep = (freq, dur = 0.1, type = "square") => {3 const o = ac.createOscillator(), g = ac.createGain();4 o.type = type; o.frequency.value = freq;5 g.gain.setValueAtTime(0.0001, ac.currentTime);6 g.gain.exponentialRampToValueAtTime(0.2, ac.currentTime + 0.006);7 g.gain.exponentialRampToValueAtTime(0.0001, ac.currentTime + dur);8 o.connect(g).connect(ac.destination);9 o.start(); o.stop(ac.currentTime + dur + 0.02);10};1112beep(880); // a click13["sine","triangle","square","sawtooth"] // hear all four14 .forEach((t, i) => setTimeout(() => beep(440, 0.25, t), i * 350));
Paste that into DevTools on any page and start changing numbers. It's genuinely the fastest way to learn this API. Total cost of the approach: zero network requests, zero bundle size, zero latency, works offline, and every sound is a parameter you can theme. Compare that to shipping eighteen mp3s.
EOF — Himanshu Satija · 2026-08-10 · thanks for reading.
