Lesson 11 of 15

Scheduling Notes

Note Onset Times

A sequencer schedules notes at precise times. Each note's start time (onset) is calculated from its position in the sequence.

The Formula

onsetTime(step, bpm, subdivision) = step × (60 / bpm / subdivision)
  • step — position in the sequence (0-indexed)
  • bpm — tempo
  • subdivision — how many notes per beat (1=quarter, 2=eighth, 4=sixteenth)

Example at 120 BPM, Eighth Notes (subdivision=2)

step 0 → 0 × 0.25 = 0.000 s
step 1 → 1 × 0.25 = 0.250 s
step 2 → 2 × 0.25 = 0.500 s
step 4 → 4 × 0.25 = 1.000 s

Using Onset Times

const melody = [60, 62, 64, 65, 67];
melody.forEach((note, step) => {
  const t = ac.currentTime + onsetTime(step, 120, 2);
  scheduleNote(note, t);
});

Your Task

Implement onsetTime(step, bpm, subdivision) returning seconds.

Run your code to hear a melody with precisely timed notes.

Web Audio API loading...
Loading...
Click "Run" to execute your code.