Repository navigation
fix: keep the beat in step with the music, and make tapping it reliable - #77
Merged
Merged
Conversation
The beat maps were right (checked on a real song against librosa: same tempo, beats on the onsets, the one on the kick), but every screen placed them late, by a varying amount: - The speaker's position reports were stamped when they reached the server, so everyone lagged by the report's trip, more when it queued behind the last one. Reports now say when they were read (`at`), and the server moves the position on by up to 2 s. - Clock sync was one sample from the socket's hello, with anything under 250 ms taken as zero. A new GET /time lets each client time a few round trips and keep the quickest. Tap tempo in the beat lab: - Taps are timed on performance.now(). The room's position jumps as the server corrects it, which reset taps part way or skewed them. - A skipped beat is counted and a double tap dropped, instead of either wrecking the fit. Four taps before it applies, as the lab says. - At the analysed tempo, taps (and the ±20 ms / Move 1 buttons) shift the song's own beats into place rather than replacing them with a fixed grid, so a live band's drift is still followed.
It was fixed at 2026-10-05. Sessions last 30 days by that clock, but the test client's cookie jar runs on the real one, so from 2026-11-04 it dropped every session cookie and the signed-in tests failed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The beat looked off even when the BPM was right, and tapping the beat in the beat lab would reset part way through.
I checked Razorblades and Runways (The Revivalists) against librosa. The server's beat map is right: 101.6 BPM, beats on the onsets in every band, and the downbeat on the kick (kick on 1 and 3, snare on 2 and 4). The error is on the playback side, in where each screen thinks the song is.
Playback timing
PlayerReport.at(server clock, ms) now says when the position was read, and the engine moves the position on by that age, capped at 2 s (maxReportAge) and never backwards.GET /time. On each room-socket hello, the client times 5 round trips and keeps the offset from the quickest (measureServerClock). The hello's rough offset, which treated anything under 250 ms as zero, is now only a stopgap until the measurement lands.Tap tempo (
web/src/lib/tap-tempo.ts)performance.now()and converted to song position once, so server position corrections no longer reset or skew them. The delay calibration tap gets the same fix.Testing
tap-tempo.test.ts, plus a clock offset test).httpapiauth/invite tests (TestLogout,TestLoginAndRateLimit, …) fail identically onmainwithout this change, so they're unrelated.