Skip to content

Accurate Timing

Yotam Mann edited this page Oct 13, 2021 · 1 revision

Tone.js uses the Web Audio API for sample-accurate scheduling. If you are experience loose timing, double check that you are passing in the scheduled time the Transport provides into the event that you are scheduling:

INCORRECT:

Transport.schedule(() => {
  player.start();
}, 0);

CORRECT:

Transport.schedule((time) => {
  player.start(time);
}, 0);

Event Classes

This is similarly true for all of the event classes like Part, Sequence, Loop, Pattern, etc.

INCORRECT:

new Part((time, event) => {
  synth.triggerAttackRelease(event.note, event.duration);
}, events);

CORRECT:

new Part((time, event) => {
  synth.triggerAttackRelease(event.note, event.duration, time);
}, events);