Skip to content

Commit 09a8456

Browse files
committed
Fix minor error in metronome article
1 parent 721db9b commit 09a8456

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/content/writings/every-way-to-create-a-metronome-in-javascript.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ First, we resume our `AudioContext` instance to make sure that its clock is runn
222222

223223
Since `scheduleTicks` is called every 25 milliseconds, there will inevitably be redundant calls to it that do nothing because one call to it already schedules all ticks that need scheduling within the next 100 milliseconds. As wasteful as that sounds, that overlap is what assures that ticks will fire accurately because it's what covers for cases when the timer fires later than set. You can look at this [figure by Chris](https://web.dev/static/articles/audio-scheduling/image/scheduling-long-overlaps-3ceb8de6cfd55_856.png) to better visualize what I mean.
224224

225-
Thus, unless the timer fires extremely late or the BPM set is set impossibly high, there's really no chance of this approach firing a tick at the wrong time. Though these values, 25 and 100, would probably be good enough for most applications that don't do a lot of processing in the main thread, they're not set in stone. If you're planning to use this approach, you can play around with different values and find one that suits your use case the most since depending on how the metronome or music app using this approach is structured and used and how busy the main thread is with other things, having a lot of function calls like this could impact performance. So take it with a grain of salt and experiment on your own.
225+
Thus, unless the timer fires extremely late or the BPM set is impossibly high, there's really no chance of this approach firing a tick at the wrong time. Though these values, 25 and 100, would probably be good enough for most applications that don't do a lot of processing in the main thread, they're not set in stone. If you're planning to use this approach, you can play around with different values and find one that suits your use case the most since depending on how the metronome or music app using this approach is structured and used and how busy the main thread is with other things, having a lot of function calls like this could impact performance. So take it with a grain of salt and experiment on your own.
226226

227227
All that said, there you have it, we're done, no more jittering this time because we used the precise clock that comes with `AudioContext`.
228228

0 commit comments

Comments
 (0)