| scripts | |
| src | |
| .gitignore | |
| index.html | |
| package-lock.json | |
| package.json | |
| README.md | |
| tsconfig.json | |
| vite.config.ts |
instrawave-compose#
Compose rhythms with your voice, or with anything else you can do near a microphone. You teach the app a handful of named voices by example (say "doo" five times, tap the desk five times), then record a take in one pass: "doo baa doo-doo doo". The take is segmented into hits, each hit is classified back onto the voices, and the result is a timeline of timed, weighted events that renders to audio through an instrument bound to each voice.
A limitation of most rhythm entry tools is the keyboard: tapping a pad or clicking a grid discards the timing and dynamics a person can produce vocally without effort. Here the performed take is the source of truth. Times are kept exactly as performed (there is no quantization grid), and each hit's measured loudness becomes the note's strength, taken relative to the loudest hit in the take and compressed so soft hits stay audible while the ordering is preserved.
Voices, takes, and the timeline#
A voice is a named class of sound plus its training examples. Recording into a voice runs an onset detector (spectral flux against a local mean, with a sensitivity control, since a soft syllable and a sharp tap sit at very different flux levels) and shows the detected hits as markers on the waveform; each can be auditioned and excluded before the batch is committed, so a cough or a stray detection is visible rather than silently poisoning the label. Each committed hit is stored as a small feature vector: spectral centroid and rolloff, band energy ratios, zero-crossing rate, attack and decay times. Loudness is deliberately kept out of this vector; it is expression, not identity, so playing softly does not change which voice a hit lands on.
A take goes through the same detector, and each hit is classified by distance-weighted nearest neighbours over the pooled training set, z-scored per dimension. The timeline shows one lane per voice with a marker per hit, bar height showing strength. The classifier will sometimes be wrong, and the fix is one gesture: drag the marker to the right lane. "Learn" folds the corrected hit back into that voice's training set, so the labelling improves with use; there is no model to refit.
Voices and their training persist in localStorage. Takes do not; the take is a performance, and re-recording one is the cheap operation.
Rendering#
The seam is src/render/types.ts: events in, audio out. The current
renderer is a set of placeholder WebAudio drum synths (kick, snare, hat,
tom) so the whole capture-classify-arrange loop is playable end to end.
The intended renderer is instrawave, where a binding
becomes an instrument file plus parameter values and each hit becomes a
stimulus event {t, set: {vel: ...}}. Because an instrawave bake depends
only on geometry and accuracy, voices that share a bake and differ only in
tuning (a low, wide, centre-struck drum against a high edge strike) render
in a single pass; the renderer will group events by bake key and mix one
trace per group. Loudness-to-velocity is the only feature mapping for now.
Duration to decay, vocal pitch to drum pitch, and brightness to strike
position are natural next steps and the event structure leaves room for
them.
Honest limitations#
Onset detection is offline and frame-based; timing is good to a few milliseconds on sharp attacks and worse on breathy ones. The classifier is nearest-neighbour over hand-picked features, which separates a dozen distinct sounds well but has no notion of a hit it has never seen; an unfamiliar sound lands on whatever is closest. Overlapping hits closer than 50 ms merge into one. The browser's microphone processing is asked to stand down (automatic gain control would rewrite the very dynamics being tracked), but a system-level AGC outside the browser will still flatten them. Training audio is not persisted, only its features, so trained hits cannot be re-auditioned after a reload.
Running it#
npm install # expects ../instrawave alongside, per the vault layout
npm run dev # the page: voices, take, timeline, playback
npm test # onset, feature, classifier checks on synthetic audio
npm run build