Instruments
Every field is optional. With none, an instrument is a soft square-wave lead.
| Field | Default | Meaning |
|---|---|---|
wave | "square" | "sine", "square", "sawtooth", "triangle", or "noise" for drums. |
attack | 0.005 | Seconds to reach full volume. |
decay | 0.1 | Seconds to fall to the sustain level. |
sustain | 0.6 | Level held while the note lasts, 0 to 1. |
release | 0.08 | Seconds to fade after the note ends. |
volume | 0.3 | Loudness, 0 to 1. Accented hits play louder. |
octave | 0 | Shift every note up or down by whole octaves. |
detune | none | Add a second oscillator this many cents apart, for a thicker, chorused sound. |
filter | none | A low-pass filter: { cutoff, q, sweep }. cutoff in Hz, q is resonance, and sweep opens the filter this many Hz higher at the start of each note, then closes it over the decay. |
drop | none | Start each note this many semitones higher and slide down to it. Kicks and "bloop" sounds. |
vibrato | none | Wobble the pitch by this many cents, 5.5 times a second. |
echo | none | Send this much (0 to 1) to a shared echo, timed to the song (a dotted eighth). |
reverb | none | Send this much (0 to 1) to a shared room reverb. |
pan | 0 | Stereo position, -1 (left) to 1 (right). |
The master bus
Everything a player makes goes through a gentle compressor, which glues the parts together, and then a limiter, so the mix never clips however many notes pile up. If your engine already masters its audio, turn it off: new Player({ master: false }).
Recipes
ts
const instruments = {
// Bouncy chiptune lead with a little space around it.
lead: { wave: "square", decay: 0.14, sustain: 0.35, volume: 0.13, echo: 0.28, vibrato: 6 },
// Squelchy bass: a resonant filter that sweeps shut on every note.
bass: { wave: "sawtooth", octave: -1, decay: 0.18, sustain: 0.4, volume: 0.22, filter: { cutoff: 380, q: 9, sweep: 1400 } },
// Warm chords under everything.
pad: { wave: "triangle", attack: 0.15, decay: 0.4, sustain: 0.5, release: 0.4, volume: 0.06, detune: 8 },
// Drums.
kick: { wave: "sine", drop: 24, decay: 0.12, sustain: 0, volume: 0.5 },
snare: { wave: "noise", decay: 0.08, sustain: 0, volume: 0.12, filter: { cutoff: 2200, q: 3 } },
hat: { wave: "noise", decay: 0.03, sustain: 0, volume: 0.08, filter: { cutoff: 9000 } },
// A cartoon "bloop": a sine that drops into each note.
bloop: { wave: "sine", drop: 7, decay: 0.12, sustain: 0.2, volume: 0.25 },
};Keep the total quiet: several instruments at full volume clip. Leads around 0.1 to 0.2, bass around 0.2, drums and pads lower.