8000 fix(tempo): Rayleigh prior on tempo detection — kill octave-doubling by johannboehme · Pull Request #26 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

fix(tempo): Rayleigh prior on tempo detection — kill octave-doubling - #26

Merged
johannboehme merged 1 commit into
mainfrom
claude/tempo-octave-fix
May 3, 2026
Merged

johannboehme merged 1 commit into
mainfrom
claude/tempo-octave-fix

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

Summary

User's lo-fi swing-hip-hop master (~85-90 BPM by ear) was being detected as 180 BPM. Classic tempo-octave-aliasing failure: with a kick on every beat (85 BPM events) and a hat on every off-beat (170 BPM events), the autocorrelation surface peaks at BOTH lags — and the unprior'd picker landed on the doubled tempo because the existing octave-voting summed the on-beat AC into the doubled lag's score.

Fix

Multiply the voted autocorrelation by a Rayleigh prior centred at 110 BPM (Klapuri / Davies-style perceptual-tempo prior). The prior peaks where typical music sits and tapers smoothly toward the search limits — drum'n'bass at 170 still wins if its AC is genuinely strong, but lofi/swing at 85 lands on its true octave.

Approximate weights:

BPM Prior
60 0.83
90 0.95
110 1.00 (peak)
150 0.85
180 0.59
200 0.43

Verification

On the user's actual master mp3 PCM (16-min lo-fi hip-hop session): 180 BPM → 90.08 BPM.

Existing 90 BPM and 120 BPM click-track tests still pass; new regression test reproduces the 85 + 170 hat pattern.

Test plan

  • cargo test --release n/a (TS-only change)
  • npx vitest run --project=unit src/local/render/audio-analysis/analyze.test.ts — 13 tests green
  • Re-import the user's lofi master in the editor and verify the BPM display reads ~90 instead of ~180
  • Sanity: existing track imports at typical pop/rock/dance tempos (90-130) unchanged

🤖 Generated with Claude Code

User's lo-fi-swing-hip-hop master detected as 180 BPM instead of the
audibly-correct ~90 BPM. Classic tempo-octave-aliasing failure: with
a kick on every beat (85 BPM) and a hat on every off-beat (170 BPM
events), the autocorrelation surface peaks at BOTH lags — and the
unprior'd picker landed on the doubled tempo because the existing
octave-voting summed the on-beat AC into the doubled lag's score.

Fix: multiply the voted AC by a Rayleigh prior centred at 110 BPM
(Klapuri / Davies-style perceptual-tempo prior). The prior's shape
peaks where typical music sits and tapers smoothly toward the search
limits — drum'n'bass at 170 still wins if its AC is genuinely
strong, but lofi/swing at 85 lands on its true octave.

Verified on the user's actual master mp3 PCM: 180 BPM → 90.08 BPM.
Existing 90/120 BPM click-track tests still green; new regression
test reproduces the 85 + 170 hat pattern.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@johannboehme
johannboehme merged commit e0309c0 into main May 3, 2026
1 check passed
@johannboehme
johannboehme deleted the claude/tempo-octave-fix branch May 3, 2026 14:33
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

117F
0