Getting Started

Learn ChiptuneSynth step by step — click "Run" to hear each example live

1

Hello, Chiptune!

Create a synth, initialize it, and play your first sound effect — all in 3 lines.

const synth = new ChiptuneSynth();
await synth.init();
synth.playPreset('coin');  // ding!
The AudioContext requires a user gesture (click) to start — that's why we use a button.
2

Play a Note by Name

Play middle C for half a second on the Lead track (track 0).

synth.playNoteByName('C', 4, 0, 0.5);
// note, octave, track, duration (seconds)
3

Play a Melody

Schedule multiple notes with timing to create a simple tune.

const melody = [
  { note:'C', oct:4, time:0 },
  { note:'E', oct:4, time:0.25 },
  { note:'G', oct:4, time:0.5 },
  { note:'C', oct:5, time:0.75 }
];
melody.forEach(n =>
  setTimeout(() =>
    synth.playNoteByName(n.note, n.oct, 0, 0.3),
    n.time * 1000
  )
);
4

Load an Instrument

Switch from the default square wave to a violin, then play a note.

synth.loadInstrument('violin', 0);
synth.playNoteByName('A', 4, 0, 1.5);
// Available: piano, violin, cello, flute, organ,
// brass, harmonica, synthLead, synthPad, synthBass,
// marimba, electricGuitar
5

Multi-Track Layering

Play different instruments on different tracks at the same time.

synth.loadInstrument('synthPad', 0);  // Lead
synth.loadInstrument('synthBass', 1); // Bass

// Play a chord on the pad
synth.playNoteByName('C', 4, 0, 2);
synth.playNoteByName('E', 4, 0, 2);
synth.playNoteByName('G', 4, 0, 2);

// Bass note underneath
synth.playNoteByName('C', 2, 1, 2);
6

Tweak the Sound

Customize envelope, vibrato, and waveform to shape your sound.

// Slow attack pad
synth.updateEnvelope(0, {
  attack: 0.5, decay: 0.3,
  sustain: 0.6, release: 1.0
});

// Add vibrato
synth.updateVibrato(0, {
  rate: 5, depth: 8
});

// Change waveform to sawtooth
synth.updateTrack(0, { type: 'sawtooth' });

synth.playNoteByName('D', 4, 0, 2.5);
7

Game SFX Combo

Chain multiple sound effects for a game sequence — collect coin, power up, shoot!

synth.playPreset('coin');
setTimeout(() => synth.playPreset('powerup'), 400);
setTimeout(() => synth.playPreset('laser'), 1200);
setTimeout(() => synth.playPreset('explosion'), 1500);
setTimeout(() => synth.playPreset('1up'), 2200);
8

Waveform Visualization

Draw the live audio waveform on a canvas — great for game UIs!

function draw() {
  const data = synth.getWaveformData();
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.strokeStyle = '#00f0ff';
  ctx.beginPath();
  data.forEach((v, i) => {
    const x = (i / data.length) * canvas.width;
    const y = (v / 255) * canvas.height;
    i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);
  });
  ctx.stroke();
  requestAnimationFrame(draw);
}
draw();