🎸 Neon Band
▶ Play it live — works in any modern browser, no install, sound on.
Neon Band is a five-piece band in a neon-lit room: guitar, bass, drums, piano and violin. Walk up to any instrument, play it like the real thing, build a loop for it, and send it back to the band. Stack the loops and you have a song. Every sound is generated live in code from the physics and math of real instruments. There isn't a single recorded sample in the project.
💡 Inspiration
Learning music usually means learning one instrument alone, and it takes years before you hear how your part fits into a band. I wanted something that lets anyone stand in a room with a full band, try every instrument, and hear how chords, rhythm and melody lock together, without buying gear or reading theory first. I also wanted it to feel like a place, not a tool, which is where the neon stage came from.
🎛️ What it does
- Play by hand. Pick and strum a guitar with a real capo, slide along a fretless violin with a live tuner, play a three-octave piano from your computer keyboard, and hit any piece of the drum kit.
- Build loops. Choose chords (or a famous progression like I–V–vi–IV, the 12-bar blues or Pachelbel's Canon), then a strumming pattern, groove or playing style. Press Enter and the loop joins the band on the next bar line.
- Learn theory by ear. The seven chords of any key sit on keys 1–7. Chord buttons show what a capo does to the real pitch. The piano voice-leads smoothly between chords the way a trained pianist would.
- Watch the music. Every instrument glows with its actual audio level, and the back wall is a live spectrum analyser.
- Save and share. Songs autosave, and any song can be copied or downloaded as JSON.
🛠️ How I built it
Neon Band is written in TypeScript with the Web Audio API and Vite, with zero runtime dependencies. The whole game is about 33 KB of gzipped JavaScript. I chose the browser over a game engine because Web Audio can schedule notes with sample-level accuracy and synthesize sound in real time.
Pitch-perfect tuning. Every note is a MIDI number \(m\) converted to equal-temperament frequency:
$$f(m) = 440 \cdot 2^{(m-69)/12}\ \text{Hz}$$
Plucked strings (guitar and bass) use the Karplus-Strong algorithm: a burst of noise circulates in a delay loop, losing a little energy each pass, which sounds remarkably like a string. The catch is that a delay line only comes in whole samples, which makes high notes up to ~20 cents out of tune. I split the loop delay into a whole-sample buffer \(L\), a half-sample averaging filter, and an all-pass filter that supplies the leftover fraction \(d\):
$$\frac{f_s}{f} = L + \tfrac{1}{2} + d, \qquad C = \frac{1-d}{1+d}$$
where \(C\) is the all-pass coefficient. To make low strings ring longer than high ones, the loop gain per pass is set from the target decay time \(T_{60}\):
$$g = 0.001^{\,1/(f \cdot T_{60})}$$
Piano uses additive synthesis. Real piano strings are stiff, so their overtones run slightly sharp. I model that inharmonicity with a coefficient \(B\), then normalise so the fundamental lands exactly on pitch:
$$f_n = \frac{n f_0 \sqrt{1 + B n^2}}{\sqrt{1 + B}}$$
Each partial is played by two slightly detuned "strings" for natural chorus, with a fast-then-slow two-stage decay and a felt-hammer thump.
Violin is a real-time bowed string: detuned sawtooth waves through filters that mimic the violin body's resonances (about 280, 470 and 2700 Hz), plus delayed vibrato and rosin noise. Because it runs live, the pitch can glide continuously like a fretless string.
Drums are fully synthesized: pitch-swept sine waves for kick and toms, noise plus a tonal body for the snare, and six inharmonic square waves for 808-style cymbals.
Guitar chord shapes. There are 16 chord types in 12 keys, so 192 chords. Forty common shapes are hand-picked exactly as guitarists play them. For the rest, a search tries every fingering on the neck and keeps only playable ones (root in the bass, at most 4 fingers counting barres, stretch of at most 3 frets), then scores them the way a guitarist would.
Timing. A lookahead scheduler wakes every 25 ms and books every note in the next 120 ms at exact audio-clock times, so five instruments stay locked together even when the screen is busy. Visual effects are queued to fire at the moment each note becomes audible, so the lights never run ahead of the sound.
Architecture. The whole song is one JSON object, changed only through small "actions". Each instrument is a plugin: adding a new one is one folder plus one line in a registry, and it automatically appears on stage, in the mixer, in the loop builder and in save files. The same action system is designed to support multiplayer jamming later.
I built Neon Band with help from an AI coding assistant (Claude by Anthropic) and directed the design, features and testing myself.
📏 How I tested it
I measured tuning by rendering notes and finding their pitch with autocorrelation, comparing against the target in cents:
$$\text{error} = 1200 \cdot \log_2!\left(\frac{f_{\text{measured}}}{f_{\text{target}}}\right)$$
Plucked strings land within 0.28 cents and the piano within 3 cents; most people can't hear a difference under about 5. I checked all 192 guitar chord shapes for correct notes, and ran automated browser tests that play every instrument and run all five loops together.
🧗 Challenges
- Out-of-tune strings. The textbook Karplus-Strong algorithm was audibly flat on high notes. The fractional all-pass delay fixed it.
- A sharp piano. Modelling stiff strings made the piano measure about 5 cents sharp. Normalising the fundamental brought it under 3.
- Keeping five instruments in time. Ordinary JavaScript timers drift. The lookahead scheduler solved it, and loops that start mid-song wait for the next bar line so they always land on beat one.
- Lights out of sync. Since notes are scheduled ahead, the visuals fired early at first. Queuing visual events to the audio clock fixed it.
- Small screens. On phones the guitar neck became too small to tap, so instruments now keep a playable size and scroll sideways.
- Deployment. My first GitHub Pages deploy was a blank black page, because Pages was serving the raw source files instead of the built game.
📚 What I learned
- Digital signal processing: how delay lines, filters and decay models turn math into convincing instruments.
- Music theory from the inside: chord construction, diatonic harmony, voice leading and how guitarists actually fret chords.
- How to schedule audio precisely in a browser, and why the audio clock and the screen clock must be kept separate.
- How to structure a growing project so new instruments and features don't break old ones.
🔭 What's next
- Multiplayer jam rooms where friends each play an instrument in real time.
- A daily ear-training challenge: hear a riff, rebuild it on the chord pad.
- Song sections (verse, chorus, bridge) and export to a WAV file.
- More instruments: trumpet, saxophone and synth pads.
Built With
- additive-synthesis
- canvas
- css3
- digital-signal-processing
- github
- github-actions
- html5
- javascript
- karplus-strong
- localstorage
- node.js
- npm
- playwright
- svg
- typescript
- vite
- web-animations-api
- web-audio-api