8000 feat(sync): coarse-to-fine pipeline + per-stage progress by johannboehme · Pull Request #25 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

feat(sync): coarse-to-fine pipeline + per-stage progress - #25

Merged
johannboehme merged 1 commit into
mainfrom
claude/pensive-blackburn-5cfcce
May 3, 2026
Merged

johannboehme merged 1 commit into
mainfrom
claude/pensive-blackburn-5cfcce

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

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)

Tier Stage Status Purpose
0 RMS-envelope cross-correlation new Cheap loudness-shape match, robust against mic EQ / verb / codec; produces coarse seed
1 chroma + onset NCC unchanged Pitch-class + spectral-flux fusion
2 PHAT refinement fixed Multi-seed alternates must now beat primary by ≥1.5× (was: any margin)
3 Salient-anchor consensus new (replaces uniform chunking) K spectrally-unique 8-s windows in the cleaner track, sample-level PHAT each, bucket-vote
4 Drift correction unchanged Linear clock-drift slope
— DTW fallback unchanged Long-tail non-linear warping

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_cleaner heuristic 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.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 %. The existing syncAudioPcm() entrypoint is preserved for backwards-compat — callers without an onProgress opt-in see identical behaviour.

Verification

16-min beat-making session, noisy mic vs clean master:

Pipeline Offset Error vs truth (-2900 ms)
Before -3991 ms 1091 ms
Fix #1 (PHAT margin) -2978 ms 78 ms
Fix #1+#2 (uniform consensus) -2947 ms 47 ms
Final (envelope + salient anchors) -2895 ms 4.4 ms
  • Pipeline runtime: 1.6 s native ≈ 590× realtime on 16-min audio
  • All 40 unit tests pass
  • bench_real_music identity / ±100ms / ±500ms / ±2000ms / noise+200ms / quiet+800ms scenarios green on the user-beatmaking fixtures

New files

  • src/envelope.rs — Tier 0 RMS-envelope match
  • src/salience.rs — Novelty curve + anchor selection
  • src/consensus.rs — Extended with salient_phat_consensus
  • examples/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 harness

Test plan

  • Upload the user's beat-making files (mp3 master + mp4 video, 15 min each) and verify the matcher lands within ~50 ms of truth without nudging
  • Watch the progress bar during sync — should move continuously through 40 → 55 % with stage labels visible (envelope, chroma, consensus, etc.)
  • Sanity check on a previously-working clean track: identity / small offset still match perfectly
  • cargo test --release in frontend/wasm/sync-core/ — all 40 tests green

🤖 Generated with Claude Code

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>
@johannboehme
johannboehme merged commit 8893518 into main May 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0