Skip to content

Instruments ​

Every field is optional. With none, an instrument is a soft square-wave lead.

FieldDefaultMeaning
wave"square""sine", "square", "sawtooth", "triangle", or "noise" for drums.
attack0.005Seconds to reach full volume.
decay0.1Seconds to fall to the sustain level.
sustain0.6Level held while the note lasts, 0 to 1.
release0.08Seconds to fade after the note ends.
volume0.3Loudness, 0 to 1. Accented hits play louder.
octave0Shift every note up or down by whole octaves.
detunenoneAdd a second oscillator this many cents apart, for a thicker, chorused sound.
filternoneA 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.
dropnoneStart each note this many semitones higher and slide down to it. Kicks and "bloop" sounds.
vibratononeWobble the pitch by this many cents, 5.5 times a second.
echononeSend this much (0 to 1) to a shared echo, timed to the song (a dotted eighth).
reverbnoneSend this much (0 to 1) to a shared room reverb.
pan0Stereo 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.