← All guides

Why Online Metronomes Drift Out of Time

Written by the AudioForges teamPublished August 1, 2026

Leave a lot of online metronomes running for a couple of minutes and the click gradually stops lining up with where it should be — a fraction of a second early or late at first, more noticeable the longer it runs. This isn't random bad luck. It's a well-understood consequence of how browsers handle timing, and it's fixable with a specific, deliberate technique rather than a better version of the same approach.

Why a plain JavaScript timer isn't good enough

The obvious way to build a metronome is a repeating timer that fires once per beat and plays a sound each time. The problem is that a JavaScript timer is never guaranteed to fire at exactly the interval you asked for — browser throttling, other activity in the same tab, and brief pauses for garbage collection all introduce small delays. Any individual delay is tiny and inaudible on its own, but they accumulate. A metronome that's a few milliseconds late on every single beat is noticeably out of time within a minute or two, even though nothing about the code is technically broken.

The look-ahead scheduling technique

The fix separates two things that a naive approach conflates: deciding when to schedule the next beats, and actually playing them. A lightweight timer still runs frequently in the background — every 25 milliseconds — but instead of playing a click the moment it fires, it looks ahead about a tenth of a second and schedules any beats that fall within that window directly against the audio hardware's own clock, which is sample-accurate in a way a JavaScript timer never is. That audio clock, not the background timer, is what actually determines the exact moment each click plays. The background timer only decides when to schedule the next batch of beats — a small imprecision there doesn't translate into audible drift, because playback itself is locked to hardware timing rather than to the timer that triggered the scheduling.

Why the visual beat indicator stays in sync too

A metronome that flashes a light on each beat has a second place drift can creep in: if the visual indicator runs off its own separate timer, it can fall out of sync with the audio even if the audio itself is perfectly scheduled. The fix is to drive the visual indicator off the exact same scheduled beat times used for the audio, checked against the audio clock rather than a separate visual timer — so what you see stays locked to what you actually hear instead of slowly drifting apart from it.

Why the downbeat sounds different

The first beat of each measure is generated at a higher pitch and slightly louder volume than the other beats, the same way a physical metronome or a drummer distinguishes beat one from the rest of the bar. Rather than loading a separate audio file for the accent, each click is a short synthesized tone with a fast decay — the accented beat just uses a higher frequency and more gain than the regular beats, generated the same way every time.

Our Online Metronome uses this exact scheduling approach — set a tempo from 30 to 300 BPM, pick your time signature, and it holds steady for as long as you leave it running, no account or software install needed.