Repository navigation
feat(sync): coarse-to-fine pipeline + per-stage progress - #25
Merged
Merged
Conversation
Robust matching for noisy same-source recordings (clean direct take vs
mic-recording with room verb / codec artefacts). The previous pipeline
walked 1.1 s off the true offset on a 15-min beat-making session — even
though chroma had picked the right answer, multi-seed PHAT overrode it
because every seed produced uniformly mediocre PNR (~10) and a
marginally-stronger alternate won the tie. New pipeline drops the
error to ~5 ms (sub-perceptible) on the same case while staying
identical on clean tracks.
Stages, coarse → fine:
envelope (tier 0, NEW)
RMS-envelope cross-correlation at 10 Hz. Cheap, robust against
mic EQ / room verb / codec artefacts. Produces a coarse offset
that seeds the salient-anchor search corridor.
chroma + onset (tier 1, unchanged)
Existing pitch-class + spectral-flux fusion. Now works inside the
envelope-anchored search space.
PHAT refinement (tier 2, fixed)
Multi-seed alternate may now only override the chroma primary
when its PNR is ≥ 1.5× higher. The legitimate case this guards
(real-music bench house-loop: alt PNR ≈ 2e8 vs primary ≈ 50,
ratio 4 M:1) clears trivially. The failure mode it kills:
mic-noisy long-form material where every seed lands near PNR 10
and a 1.08× ratio walked the lag onto a self-similar bar shift.
salient-anchor consensus (tier 3, NEW — replaces uniform chunking)
Picks K spectrally-unique 8-s windows in the cleaner of the two
tracks (ref_is_cleaner via peak-to-RMS heuristic), runs sample-
level GCC-PHAT for each in a ±2 s corridor around the envelope
seed, bucket-votes the offsets. Salient anchors sit on events
that don't repeat elsewhere — by construction they can't fall on
a bar-shifted impostor. Falls back to uniform chunked when no
salient anchors are found.
drift correction (tier 4, unchanged)
DTW fallback (unchanged)
Kept for non-linear time-warping in long-tail setups (wireless
audio, asynchronous SRC, tape wow & flutter).
Per-stage progress:
WASM exposes syncAudioPcmWithProgress(ref, query, sr, callback).
Worker forwards each stage transition to the UI thread; jobs.ts
maps it onto the 40-55 % per-cam progress band so the bar moves
continuously through the ~5 s match instead of freezing at 40 %.
Existing syncAudioPcm() entrypoint preserved for backwards-compat.
Verification (16-min beat-making session, noisy mic vs clean master):
before: -3991 ms (1091 ms off truth)
fix #1: -2978 ms (78 ms off, PHAT margin alone)
fix #1+#2: -2947 ms (47 ms off, uniform consensus)
final: -2895 ms (4.4 ms off, salient anchors + envelope seed)
Pipeline runtime: 1.6 s native = ~590× realtime on 16 min.
All 40 unit tests pass; real-music bench identity / ±100ms /
±500ms / ±2000ms scenarios remain green on user-beatmaking
fixtures.
New supporting files:
src/envelope.rs — tier 0
src/salience.rs — novelty curve + anchor selection
src/consensus.rs — extended with salient_phat_consensus
examples/diagnose_match.rs — signal-level probe for sync failures
examples/time_pipeline.rs — bare timing harness
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Robust matching for noisy same-source recordings. The previous pipeline walked 1091 ms off the true offset on a 15-min beat-making session (clean Master mp3 vs noisy mic-recorded mp4) — chroma had picked the right answer, but multi-seed PHAT overrode it because every seed produced uniformly mediocre PNR (~10) and a marginally-stronger alternate won the tie. New pipeline drops the error to 4.4 ms (sub-perceptible) on the same case while staying identical on clean tracks.
Pipeline (coarse → fine)
Why salient anchors
Salient anchors sit on events that don't repeat elsewhere in the track, so they can't fall on a bar-shifted impostor. They're picked on the cleaner track (
ref_is_cleanerheuristic via peak-to-RMS): events present in the clean direct take are guaranteed to also be in the dirtier mic-recording (modulo verb / EQ / codec); the reverse doesn't hold (speech, room noise, keyboard clicks captured by a mic don't exist in the direct out).Per-stage progress
WASM now exposes
syncAudioPcmWithProgress(ref, query, sr, callback). The worker forwards each stage transition (envelope,chroma,onset,ncc,phat,consensus,drift,done) to the UI thread.jobs.tsmaps it onto the 40 → 55 % per-cam progress band so the bar moves continuously through the ~5-s match instead of freezing at 40 %. The existingsyncAudioPcm()entrypoint is preserved for backwards-compat — callers without anonProgressopt-in see identical behaviour.Verification
16-min beat-making session, noisy mic vs clean master:
bench_real_musicidentity / ±100ms / ±500ms / ±2000ms / noise+200ms / quiet+800ms scenarios green on the user-beatmaking fixturesNew files
src/envelope.rs— Tier 0 RMS-envelope matchsrc/salience.rs— Novelty curve + anchor selectionsrc/consensus.rs— Extended withsalient_phat_consensusexamples/diagnose_match.rs— Signal-level probe binary for future sync failures (full pipeline + chroma profile + PHAT sweep + chunked PHAT)examples/time_pipeline.rs— Bare timing harnessTest plan
envelope,chroma,consensus, etc.)cargo test --releaseinfrontend/wasm/sync-core/— all 40 tests green🤖 Generated with Claude Code