A drum visualizer can feel late even when the two hits are on time. In a little Canvas sketch, we kept both sound onsets fixed and changed only how long each ring stayed visible. The result was an exactly predictable 70 ms of overlap, without moving a single audio event.
Disclosure: written and coded with AI for Sonari Studio. This is an original synthetic timing example, not a Sonari product test or a claim about a physical display.
Give the sound and the canvas one timeline
The example plays two short synthetic taps at 0 and 250 ms in each 1,000 ms cycle. Put both sounds on an audio timeline with a look-ahead scheduler; the frame callback should only ask what to draw. For the simple demonstration, scheduled onsets and the frame-age calculation both use the audio context clock. MDN’s Web Audio sequencer separates these two jobs too.
Two visual presets consume those same onsets. Set the first to 80 ms and the second to 320 ms. This is a strictly event-driven sketch, not FFT analysis or microphone input.
Make visual state a function of event age
const loopMs = 1000; const hits = [0, 250]; function ringsAt(elapsedMs, fadeMs) { if (elapsedMs < 0) return []; const cycle = Math.floor(elapsedMs / loopMs); const rings = []; // One cycle of history is sufficient for these fades (both < loopMs). for (let i = Math.max(0, cycle - 1); i <= cycle; i++) { for (const hit of hits) { const age = elapsedMs - (i * loopMs + hit); if (age >= 0 && age < fadeMs) { const progress = age / fadeMs; rings.push({ radius: 16 + 66 * progress, alpha: 0.9 * (1 - progress) }); } } } return rings; } // Inside the browser's animation callback: // const elapsedMs = (audio.currentTime - epochSeconds) * 1000; // drawLeft(ringsAt(elapsedMs, 80)); // drawRight(ringsAt(elapsedMs, 320)); The range is half-open: at age 0 the ring exists; at exactly its fade duration it no longer exists. The radius and opacity come directly from age, so a missed frame won't move the trigger or make a duration measured in milliseconds depend on refresh rate.
Freeze the second hit before judging the effect
| Model time | Visible rings, 80 ms | Visible rings, 320 ms |
|---|---|---|
| 249 ms | 0 | 1 |
| 250 ms | 1 | 2 |
| 319 ms | 1 | 2 |
| 320 ms | 1 | 1 |
For the long fade, the first ring is active from 0 until just before 320 ms. Its overlap with the second starts at 250 ms and ends at 320 ms. That is 70 ms in the model, not necessarily 70 ms of perceptible motion or a fixed number of frames on screen. Watch the same two events with and without the old ring before deciding whether a long tail helps the phrase or hides the offbeat.
The reference passed 13 time-boundary checks and mocked start, mute, stop and restart checks. Those tests cover event math and state transitions, not real display or audio-output latency. If you need tighter output alignment, look at AudioContext.getOutputTimestamp() for the relationship between audio output time and the performance clock, then check the actual display and sound path. Respect reduced-motion settings and keep audio opt-in.

