A static web app for editing, visualising, and auditioning ENVELOPE parameters for the BBC Micro SOUND command.
Live: https://bitshifters.github.io/envelope-tool/
- Edit all 14
ENVELOPEparameters and the 4SOUNDparameters with live preview. - Editable BBC BASIC
ENVELOPEandSOUNDlines — paste an existing statement to populate the editor, or copy the formatted line for use in BASIC. - Visualisation of the resulting amplitude envelope (with A/D/S/R phase markers) and the absolute pitch over time.
- Web Audio playback with a sweeping playhead synced to the audio clock.
- All four channels supported: tone (1..3) plus the noise channel (0). Noise is generated by a 15-bit LFSR matching the SN76489AN — white or periodic, at any of the three documented shift rates — selected by an 8-option dropdown when channel 0 is active.
- Game-sourced presets (Sentinel, Zalaga, Elite, Chuckie Egg, Thrust), BBC User Guide example envelopes (UG #1..#9), synth-design presets (Piano, Pluck, Bell, Pad, Bass, Drum, Laser, Vibrato, Trill, Siren, Arpeggio, Wobble), and noise-channel presets (kick, snare, hat, cymbal, bass buzz, explosion).
- Shareable URL: every change is reflected in the URL bar via
?env=…&sound=…, so copying the address reproduces the exact state. - "Run in BBC emulator" button that opens the current
ENVELOPE/SOUNDin bbc.xania.org (jsbeeb) for one-click A/B against the real BBC.
Stack: Vite + TypeScript (vanilla, no framework).
npm install
npm run dev # dev server with HMR
npm run build # typecheck (tsc --noEmit) and produce dist/
npm run preview # serve the built dist/ locallyvite.config.ts sets base: "./" so the build works at either an org-page root or a project subpath. GitHub Pages deployment runs from .github/workflows/pages.yml on every push to main.
Three concerns are kept separate so each can be tested in isolation:
| Module | Responsibility |
|---|---|
src/envelope.ts |
Pure model. The 14-parameter tuple, parse/format, and expand() into a per-centisecond Sample[] stream. |
src/visualizer.ts |
Canvas rendering of the sample stream — amplitude and absolute pitch plots with phase markers and playhead. |
src/audio.ts |
Web Audio engine that consumes the same sample stream and applies it to an oscillator + scheduled gain. |
src/main.ts |
UI wiring: inputs, presets, URL state, transport. |
src/presets.ts |
Bundled envelope + sound parameter sets for one-click loading. |
The visualiser and the audio engine consume the same sample array each render — what you see is exactly what you hear.
The 14-parameter form is the source of truth. Anything in the UI must round-trip cleanly to and from ENVELOPE N, T, PI1, PI2, PI3, PN1, PN2, PN3, AA, AD, AS, AR, ALA, ALD.
A few non-obvious quirks (also documented in CLAUDE.md):
Tbit 7 polarity is inverted from intuition:T = 1..127(bit 7 clear) auto-repeats the pitch envelope;T = 128..255(bit 7 set) is single-sweep.- Pitch sections with
PN = 0are not free — the OS hitsBEQ skipToNextChannelafter loading the empty section, so each empty section costsTcs of dead time. Loop wraps and non-empty section transitions are free. - The MOS allocates exactly 4 envelope slots (
N = 1..4); higher numbers aren't usable. - Pitch is musically quantised to the BBC's own divider table (
pitchToHz()insrc/envelope.ts), not to equal temperament — higher octaves drift slightly sharp, matching the real machine. - Channel 0 noise uses only the low 3 bits of the
SOUNDPargument: bit 2 selects type (0 = periodic, 1 = white) and bits 1..0 select the LFSR shift rate (clock/512,clock/1024,clock/2048at the BBC's 4 MHz chip clock — i.e., ~7.8 / 3.9 / 2.0 kHz). PI/PN are ignored on the noise channel; the amplitude envelope works identically to tone channels.
- Noise rate "follows tone 2". Two of the eight noise modes (
P=3andP=7) clock the LFSR from channel 2's tone period, letting you sweep noise pitch under tone-channel control. The tool decodes these modes but currently audibly plays them at the medium rate; supporting the cross-channel link properly needs a virtual channel-2 pitch. - Static amplitude. Negative
SOUNDamplitude (-15..-1) selects a static volume bypassing the envelope. Currently disallowed in the UI. - Stereo / multi-channel mixing. Real BBC sequences usually involve simultaneous notes across multiple channels; this tool is single-note only.
- Authentic SN76489 timbre on tone channels. The current square oscillator is a stand-in. A
PeriodicWaveor AudioWorklet implementation of the SN76489 tone generator would give a closer match.
By Kieran Connell and Claude. Thanks to Toby Lobster's MOS disassembly — the authoritative reference used to nail down the BBC's pitch and envelope timing.