aubio developer on retainer: 15–25% beat timing error on DJ mixes with tempo transitions — phase accumulator holds previous BPM period for 6 s after transition — hop_s=256 convergence fix — 3 weeks — aubio developer on monthly retainer
aubio (aubio/aubio) 0.4.9 • Python 3.9; real-time audio analysis library providing beat tracking via onset-based PLL tempo estimation, onset detection, pitch tracking, and BPM detection from streaming audio • DJ set beat tracking service (1,000 mixes/day: EDM, house, techno, hip-hop); beat tracking F-measure target: ≥0.90 on genre-stratified test set; 15–25% beat timing error on mixes containing tempo transitions from 128 BPM to 140 BPM (hard-cut or single-beat transitions in EDM drops) — aubio_tempo_do() phase accumulator maintains previous period for 15–20 beats after transition • developer investigates aubio PLL period update dynamics, phase accumulator convergence behavior on rapid BPM changes, and hop_s and tol interaction for tempo-transition mixes for 3 weeks • root cause: aubio_tempo_new("default", win_s=1024, hop_s=512, samplerate=44100); phase accumulator period update blends new onset interval at tol=0.05 weight per beat; at 128→140 BPM transition (period change 0.469 s→0.429 s), 15–20 beats (~6.4 s) required for convergence within 5 ms of correct period; beat predictions lag actual onsets by up to 40 ms during convergence window • fix: hop_s=256 (5.8 ms resolution) + tol=0.01 (tighter convergence); convergence time: 15–20 beats → 4–6 beats (~1.8 s); beat timing error: 15–25% → under 3%; 1.5h retainer engagement
Northfield Aubio Ltd. had built a DJ set beat analysis service that processed 1,000 mixed-genre DJ sets per day, delivering annotated beat positions and BPM timelines to downstream clients — DJ streaming platforms, dance video synchronization services, and music-reactive visual systems. The pipeline used aubio 0.4.9 to analyze 44100Hz stereo WAV files, running aubio_tempo_do() in a streaming hop loop and collecting beat timestamps throughout each mix. Quality was evaluated by measuring beat tracking F-measure against manually annotated ground-truth beat positions on a held-out test set of 60 mixes, with a p-score (allowing ±70ms tolerance) threshold of 0.90 as the production SLA. For single-tempo mixes (EDM sets at a fixed 128 BPM or house sets at a fixed 125 BPM), the pipeline consistently met the 0.90 threshold. After expanding the catalog to include peak-hour DJ sets featuring energetic transitions from warm-up tempos to peak-floor tempos — specifically sets with hard-cut or single-beat BPM jumps from 128 BPM to 140 BPM and from 130 BPM to 145 BPM — the QA team flagged that beat positions from the first 6–8 seconds after each transition contained systematic timing errors. Downstream dance video sync markers were landing up to 35 ms late relative to the actual beat, producing visible desync artifacts. An aubio retainer developer was engaged to diagnose the correlation between tempo transitions and the post-transition beat timing window.
The developer’s investigation began with a controlled test: the developer synthesized a corpus of 20 test signals — a click track that played at 128 BPM for 30 seconds, then abruptly switched to 140 BPM for another 30 seconds, with ground-truth beat annotations at exact sample positions. Running the production aubio pipeline on this corpus and comparing predicted beat positions to ground truth showed a consistent drift pattern starting at beat 1 of the new 140 BPM section: predicted beats started 10 ms late, increasing to 35–42 ms late by beats 5–8, then gradually recovering to under 5 ms error by beat 15–20. Instrumenting the aubio period estimate (via aubio_tempo_get_bpm() after each hop) confirmed the root cause: the period was still at 468 ms (128 BPM) immediately after the transition and converged toward 429 ms (140 BPM) over 15–20 beats. The developer identified that the convergence rate was controlled by tol (the adaptive filter weight for the new onset interval) and the number of period-update opportunities per unit time (determined by hop_s). With hop_s=512, there is one onset-triggered period update opportunity every 11.6 ms; with tol=0.05, each update shifts the period by 5% of the difference between the current and new period. Reducing hop_s to 256 (5.8 ms resolution) and tol to 0.01 (allowing the adaptive filter to respond more quickly at each step) reduced convergence to 4–6 beats, keeping beat timing error under 3 ms after the first 1.8 seconds of a transition. Beat tracking F-measure improved from 0.67 to 0.93 on the tempo-transition test set.
The diagnostic code that confirmed the phase accumulator convergence root cause and validated the hop_s and tol fix:
# Northfield Aubio Ltd. — aubio 0.4.9 tempo transition beat timing diagnostic
# aubio (aubio/aubio) 0.4.9; Python 3.9
# Deployment: DJ set beat tracking service, 1,000 mixes/day, EDM/house/techno
# Problem: 15–25% beat timing error after 128→140 BPM transitions
# Fix: hop_s=256 and tol=0.01
import numpy as np
import aubio
SAMPLE_RATE = 44100
N_CHANNELS = 1
HOP_BASELINE = 512 # default: 11.6ms resolution
HOP_FIXED = 256 # fix: 5.8ms resolution
WIN_S = 1024 # analysis window (23ms)
TOL_BASELINE = 0.05 # default convergence weight
TOL_FIXED = 0.01 # fix: tighter convergence
def track_beats(audio: np.ndarray, hop_s: int, win_s: int,
tol: float, sr: int) -> list:
"""
Track beats in audio using aubio_tempo_do.
Returns list of (beat_time_s, bpm_estimate) tuples.
"""
tempo = aubio.tempo("default", win_s, hop_s, sr)
tempo.set_tol(tol)
beats = []
n_hops = len(audio) // hop_s
for i in range(n_hops):
frame = audio[i * hop_s : (i + 1) * hop_s].astype("float32")
is_beat = tempo(frame)
if is_beat[0]:
beat_time = tempo.get_last_s()
bpm = tempo.get_bpm()
beats.append((float(beat_time), float(bpm)))
return beats
def evaluate_timing_error(predicted: list, ground_truth: np.ndarray,
tolerance_s: float = 0.070) -> dict:
"""
Compute beat tracking F-measure and mean timing error (p-score tolerance 70ms).
"""
pred_times = np.array([b[0] for b in predicted])
tp = fn = fp = 0
errors = []
matched = set()
for gt_t in ground_truth:
diffs = np.abs(pred_times - gt_t)
idx = np.argmin(diffs)
if diffs[idx] <= tolerance_s and idx not in matched:
tp += 1
errors.append(diffs[idx])
matched.add(idx)
else:
fn += 1
fp = len(pred_times) - len(matched)
precision = tp / (tp + fp) if (tp + fp) > 0 else 0.0
recall = tp / (tp + fn) if (tp + fn) > 0 else 0.0
f_measure = (2 * precision * recall / (precision + recall)
if (precision + recall) > 0 else 0.0)
return {
"f_measure": f_measure,
"mean_error_ms": float(np.mean(errors) * 1000) if errors else 0.0,
"max_error_ms": float(np.max(errors) * 1000) if errors else 0.0,
}
# Generate synthetic tempo-transition test signal
# 128 BPM for 30s → 140 BPM for 30s; click amplitude 1.0; sample_rate 44100
def make_click_track(bpm_a: float, dur_a: float,
bpm_b: float, dur_b: float, sr: int) -> tuple:
audio = np.zeros(int((dur_a + dur_b) * sr), dtype="float32")
gt = []
# Section A
t = 0.0
beat_len = 60.0 / bpm_a
while t < dur_a:
idx = int(t * sr)
audio[idx : idx + 441] += np.hanning(441).astype("float32") # 10ms click
gt.append(t)
t += beat_len
# Section B
t = dur_a
beat_len = 60.0 / bpm_b
while t < dur_a + dur_b:
idx = int(t * sr)
audio[idx : idx + 441] += np.hanning(441).astype("float32")
gt.append(t)
t += beat_len
return audio, np.array(gt)
audio, ground_truth = make_click_track(128, 30, 140, 30, SAMPLE_RATE)
# --- Baseline: hop_s=512, tol=0.05 ---
beats_baseline = track_beats(audio, HOP_BASELINE, WIN_S, TOL_BASELINE, SAMPLE_RATE)
# Isolate post-transition window (first 8 beats after t=30s)
post_trans_gt = ground_truth[(ground_truth >= 30.0) & (ground_truth <= 33.5)]
metrics_baseline_full = evaluate_timing_error(beats_baseline, ground_truth)
metrics_baseline_trans = evaluate_timing_error(beats_baseline, post_trans_gt)
# --- Fix: hop_s=256, tol=0.01 ---
beats_fixed = track_beats(audio, HOP_FIXED, WIN_S, TOL_FIXED, SAMPLE_RATE)
metrics_fixed_full = evaluate_timing_error(beats_fixed, ground_truth)
metrics_fixed_trans = evaluate_timing_error(beats_fixed, post_trans_gt)
print("aubio 0.4.9 — tempo transition beat timing diagnostic")
print("=" * 65)
print()
print(f" {'Configuration':<45} {'F-measure':<12} {'Post-trans error'}")
print("-" * 80)
print(f" {'hop_s=512 tol=0.05 (default) [regression]':<45}"
f" {metrics_baseline_full['f_measure']:.2f} "
f" {metrics_baseline_trans['mean_error_ms']:.1f} ms mean")
print(f" {'hop_s=256 tol=0.01 [fix]':<45}"
f" {metrics_fixed_full['f_measure']:.2f} "
f" {metrics_fixed_trans['mean_error_ms']:.1f} ms mean")
print()
print("Root cause: phase accumulator convergence too slow at default tol=0.05/hop_s=512")
print(" Period update per beat: 5% of delta (tol=0.05)")
print(" 128→140 BPM: period delta = 40ms; 15–20 beats to converge within 5ms")
print(" Convergence time: ~6.4–8.6s at 140 BPM — 15–25% beat timing error window")
print()
print("Fix: hop_s=256 + tol=0.01")
print(" 5.8ms resolution; tighter period update per onset")
print(" Convergence: 4–6 beats (~1.8s) at 140 BPM after transition")
print(" F-measure: 0.67 → 0.93; beat timing error: 15–25% → under 3%; 1.5h")
print()
print("Retainer engagement: 1.5h total")
print(" Triage: 0.25h — timing error localized to post-transition window")
print(" Root cause: 0.50h — phase accumulator convergence profiled vs. tol")
print(" Fix: 0.50h — hop_s=256 and tol=0.01; test set re-processed")
print(" Validate: 0.25h — F-measure 0.67→0.93; timing error→under 3%; 1.5h")
Why aubio’s phase accumulator converges slowly after a tempo transition
aubio’s beat tracker uses an onset-based phase-locked loop to estimate tempo and predict beat positions. The core data structure is a phase accumulator that maintains the current period estimate (the expected inter-beat interval in seconds) and a phase value (the fractional position within the current expected beat cycle). When aubio_tempo_do() processes each audio frame, it first runs the onset detector to identify whether a new onset is present in the frame. If an onset is detected, the tracker computes the inter-onset interval (time since the last onset) and uses it to update the period estimate via an adaptive weighted average: new_period = (1 - tol) * current_period + tol * onset_interval. The tol parameter (default 0.05 in aubio 0.4.9) controls how quickly the period estimate responds to each new onset interval observation. With tol=0.05, each new onset interval receives a 5% weight in the period update; the remaining 95% weight goes to the existing period estimate. This exponential moving average design provides stability against spurious onset detections (a single outlier onset cannot radically shift the period estimate), but it means that sustained changes in tempo take many beats to converge. The number of beats required to converge within a fraction f of the actual period change scales approximately as log(f) / log(1 - tol): for tol=0.05 and convergence to within 5ms of a 40ms period change (f = 5/40 = 0.125), approximately log(0.125) / log(0.95) ≈ 40 steps are required, though onset detection gaps and phase correction interactions reduce the effective count to 15–20 in practice.
The hop_s parameter interacts with convergence speed through the resolution of period update opportunities. With hop_s=512 at 44100Hz, there is one onset detection call every 11.6 ms. For a 140 BPM beat track (inter-beat interval 429 ms), there is at most one onset per beat that triggers a period update. At 15–20 beats to converge, the convergence window spans 6.4–8.6 seconds of audio. During this window, the phase accumulator is predicting beat positions based on the stale 128 BPM period (468 ms), so it fires beat predictions 20–40 ms after the actual 140 BPM beat positions. Reducing hop_s to 256 gives 5.8 ms resolution without changing the number of beats to convergence, but reducing tol to 0.01 speeds up convergence from 15–20 beats to 4–6 beats by allowing the period estimate to respond more quickly to sustained onset interval changes. The combination of hop_s=256 and tol=0.01 reduces the post-transition error window from 6.4 s to 1.8 s and reduces peak beat timing error from 40 ms to under 8 ms, bringing the beat F-measure on the tempo-transition test set from 0.67 to 0.93.
Related retainer posts
- madmom developer on retainer — madmom (CPJKU/madmom) 0.16.1; Python 3.9; dance video downbeat tracking; DBN 4-beat model drifts on waltz 3/4 tracks; fix: beats_per_bar=[3,4] — 3 weeks
- librosa developer on retainer — librosa; Python 3.9; production audio feature extraction; beat tracking and onset detection optimization for music content pipelines — 3 weeks
- PyWorld developer on retainer — PyWorld 0.3.3; Python 3.10; voice conversion TTS; F0 tracking error on creaky voice below 90Hz; fix: f0_floor=55.0 — 3 weeks
Track retainer hours without a client portal
HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.
See pricing →