Timing is Everything

Audio Scheduling & Rhythm

25 min read Intermediate Sequencer Demo

The Two Clocks

JavaScript has Date.now(), but Web Audio has audioCtx.currentTime. The audio clock is highly precise (double precision) and hardware-driven. Always use currentTime for music scheduling.

scheduling.js
// Play a sound 1 second from NOW
const now = audioCtx.currentTime;
oscillator.start(now + 1.0);

// Schedule a rhythm
for (let i = 0; i < 4; i++) {
    playKick(now + i * 0.5); // Play every 0.5 seconds (120 BPM)
}

8-Step Sequencer

A simple drum machine. Click the boxes to enable steps. Synthesized sounds (Kick, Snare, HiHat).

KICK
SNARE
HIHAT
120 BPM