What’s the basic strategy in getting accurate timing in JavaScript/NextJs?
Uses Web Audio API’s scheduling system
It uses a function that allows you to store (in seconds) exactly when you want something to play
What do you read when you see ‘SCHEDULE_DEADLINE’
while (NEXT_NOTE_TIME() < SCHEDULE_DEADLINE()) {
scheduleNote(currentBeat, NEXT_NOTE_TIME());
nextNote();
}The next 25 milliseconds
Explain nextNote()
const scheduler = useCallback(() => {
const audioContext = audioContextRef.current;
if (!audioContext) return;
while (NEXT_NOTE_TIME() < SCHEDULE_DEADLINE()) {
scheduleNote(currentBeat, NEXT_NOTE_TIME());
nextNote();
}
timerIdRef.current = setTimeout(scheduler, lookAhead);
}, [currentBeat]);Please explain the code of the flow
Using the code logic.. Doesn’t it mean that the first note will always be skipped since the time we get to scheduleNote(), the time has already passed for NEXT_NOTE_TIME().. How come it’s still playing?
What is % (Modulo)?
Explain this line of code
timerIdRef.current = setTimeout(scheduler, lookAhead);