4 ms·
RAF is still imprecise for audio use. For audio in the browser, you usually want to defer all timing events that must be precise to a scheduler that uses either
by mdtusz 5y ago
RAF is still imprecise for audio use. For audio in the browser, you usually want to defer all timing events that must be precise to a scheduler that uses either the webAudio context time or even more ideally, use a lookahead scheduler to schedule events by audio frame using an internal counter and the sample rate.
A great programming exercise that forces you to wrap your head around JavaScript timing events is writing a small step sequencer that can be used while it is running with minimal latency.
- alfl 5y agoInteresting point, thank you. I was reading the docs today and encountered the following (presented fyi): It turns out that this is currently true [0] because the base audio context (BAC) time is accurate to within 20us whereas RAF is accurate to within 1ms [1]. However in future browser versions the default sensitivity for BAC is going to drop to 2ms. This is done to help improve user privacy by hampering browser fingerprinting. This is all configurable and its materiality depends on use case, but interesting read: thank you. [0] https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/currentTime https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioCo... [1] https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame https://developer.mozilla.org/en-US/docs/Web/API/window/requ...