Studio5 min

How Accurate Is a Browser Metronome? Sample-Accurate Scheduling Explained

setInterval drifts. WebAudio's AudioContext clock is sample-accurate. Here's how a browser metronome stays tight to the millisecond — and how to build one.

Zro7 Metronome runs entirely in your browser via WebAudio. No sound, tempo, or telemetry is sent anywhere.

A browser metronome built on setInterval drifts audibly within seconds. A metronome built on the WebAudio AudioContext.currentTime clock is sample-accurate — better than ±1 ms at 44.1 kHz. Zro7 Metronome uses the WebAudio approach, so 120 BPM stays 120 BPM even under browser jank.

Why setInterval is wrong

setInterval(tick, 500) promises a callback every 500 ms — the browser makes no such promise. GC pauses, background tabs, and OS scheduling push the callback by 10–100 ms, and the drift accumulates.

The WebAudio pattern (Chris Wilson's scheduler)

  1. Keep a lookahead of ~25 ms and schedule ~100 ms of clicks in advance.
  2. Use setTimeout only as a coarse pump — every 25 ms wake up and schedule any clicks that fall inside the next 100 ms.
  3. Each click is osc.start(nextClickTime) — WebAudio guarantees sample-accurate playback.
  4. Advance nextClickTime += 60 / bpm. Jitter in the pump does not affect the actual click time.

Latency in practice

  • Chrome / Edge: baseLatency 5–10 ms, outputLatency 15–40 ms.
  • Firefox: similar figures with WASAPI on Windows, CoreAudio on macOS.
  • Safari: comparable on macOS; iOS depends on route (Bluetooth adds 100+ ms — nothing the browser can fix).

Steps

  1. Open Metronome.
  2. Set tempo (30–300 BPM) and time signature.
  3. Play — click the tempo dial to fine-tune while running.
  4. Optionally record yourself with Voice Recorder and check timing.

Frequently asked questions

Is it as accurate as a hardware metronome?

For practice purposes yes — WebAudio scheduling is sub-millisecond; total perceived latency is dominated by your speakers.

Does Bluetooth affect timing?

It adds output latency (100–200 ms) but not drift — the beats are still evenly spaced.

Can I use it as a click track?

Yes — the timing is stable enough for tracking, but for zero-latency monitoring use a DAW with a hardware interface.

Does it work offline?

Once loaded, yes — pure WebAudio, no network.

Any recommended tempo range?

30–300 BPM. Below 30 BPM the scheduler is fine but musically pointless.

Related posts

← Back to blog