midiviz

Beat, tempo and rhythm detection: a brief for #040

What the problem is, the methods that work, and why #040 uses what it does.

1. The task

Beat tracking estimates the times a listener would tap along to music. Around it sit tempo estimation (the tapping rate in BPM), meter (beats per bar and the downbeat) and rhythm description (subdivision, swing, which instruments play where). The hard parts are well known (Gouyon & Dixon 2005; Davies et al. 2021, Tempo, Beat and Downbeat Estimation, ISMIR tutorial):

2. Onset detection

Beat trackers work on an onset strength signal (an onset detection function, ODF), usually at 100 frames / s.

Band-wise fluxes (kick, snare, hat ranges) are also kept: they carry the rhythm pattern and the accents that mark the beat level and downbeat (Goto 2001; Klapuri, Eronen & Astola 2006).

3. Tempo

#040 uses the ACF comb over the last 8 s, weighted by a log-Gaussian around 120 BPM, as a soft prior for the tracker.

4. Beat tracking

#040 runs the Krebs et al. state space as a causal forward filter on SuperFlux instead of a neural activation. madmom’s observation model assumes a calibrated beat probability, so #040 uses a likelihood ratio exp(β·o) (β = 5) for the raw onset strength, which penalises off-beat onsets less (+3 F on the corpus). The posterior’s distance to the next beat is the prediction: the beat is emitted when due and timestamped at the prediction, which keeps the event on time despite the 21 ms analysis window.

The metrical level is chosen afterwards (level.js). The HMM prefers the fastest regular pulse a busy texture supports. A comparison of accents on even and odd pulses (as in Parncutt’s pulse salience and Klapuri et al.’s tatum / tactus / measure model) halves it when the slower level is clearly marked.

5. Meter and downbeats

#040 compares beat summaries (band accents, onset profile, chroma) 2, 3 and 4 beats apart for 3 vs 4 beats per bar, and accumulates a decaying score per bar position from the low band, the onsets, less hi-hat, and harmonic change (chroma of the two beats after against the two before, and one beat against the last). The weights were fitted with the true beats on the test corpus and the demo loops.

6. Swing and subdivision

The swing ratio is the long / short ratio of paired eighth notes (2 : 1 is triplet swing; jazz drummers play 1.5–3.5 depending on tempo, Friberg & Sundström 2002; Honing & de Haas 2008). #040 measures it as the position of the off-beat onset peak in a beat-normalised onset histogram (as in Gouyon, Fabig & Bonada 2003). Duple vs triple subdivision comes from the same histogram (energy at 1/2 and 1/4 against 1/3 and 2/3).

7. What other tools do

Tool Method Real time
madmom RNN / TCN activations + bar-pointer DBN online mode with a unidirectional RNN
BeatNet CRNN + particle filter yes (≈ 20 ms frames)
Aubio tempo spectral ODF + Davies & Plumbley’s context-dependent tracker yes, in C, ports to WASM
librosa beat_track onset strength + Ellis DP no
Essentia RhythmExtractor2013 multifeature (Zapata, Davies & Gómez 2014) no; BeatTrackerDegara offline
Ableton Live warp, Rekordbox / Serato proprietary, offline analysis of the file, then a fixed grid grid playback only
DJ hardware “beat sync” from line in (Pioneer DJM, etc.) proprietary, onset + tempo lock, typically 4–8 s to settle yes
Web BPM detectors (web-audio-beat-detector, realtime-bpm-analyzer) low-pass peak picking and interval histograms tempo only, no phase

8. Evaluation

mir_eval’s beat metrics (Davies, Degara & Plumbley 2009): F-measure at ±70 ms, Cemgil, P-score, CMLt / AMLt (continuity at 17.5 % phase and tempo tolerance). Datasets: Ballroom, Hainsworth, SMC, GTZAN, RWC, Beatles (Isophonics), HJDB. None is used here: they need audio that is not redistributable. #040’s corpus is rendered from MIDI and drum patterns, so beats are exact and the microphone condition can be simulated. Its numbers are not comparable with published results on real recordings.

9. What could improve #040