madmom developer on retainer: 20–30% downbeat position error on waltz and 6/8 tracks — DBN 4-beat bar model accumulates phase drift on 3-beat time signatures — beats_per_bar=[3,4] fix — 3 weeks — madmom developer on monthly retainer
madmom (CPJKU/madmom) 0.16.1 • Python 3.9; audio and music analysis library providing downbeat tracking via RNN beat activation + DBN bar-model decoding; produces per-beat and per-downbeat timestamps from stereo 44100 Hz audio • dance video content synchronization service (500 videos/day: ballroom, Latin, swing, folk dance genres); downbeat tracking F-measure SLA: ≥0.88 on genre-stratified test set; 20–30% downbeat position error on waltz (3/4) and compound triple (6/8) tracks — DBN bar model assigns downbeat to beat 2 of music’s bar after 8–10 bar cycles • developer investigates madmom DBN bar-model state space, beats_per_bar parameter interaction with 3-beat time signatures, and accumulated phase offset mechanism for waltz content for 3 weeks • root cause: DBNDownBeatTrackingProcessor(beats_per_bar=[4]) (default configuration) models only 4-beat bars; for waltz 3/4 tracks, DBN correctly identifies beat positions but maps downbeat probability to the first of 4 beats in its internal bar model; after each 4-beat DBN bar, the model has consumed 4 beats of a 3-beat bar sequence; downbeat falls 1 beat offset from actual bar 1; offset accumulates: after 8–10 DBN bar cycles (~10–12 bars of waltz), DBN consistently identifies beat 2 as downbeat • fix: DBNDownBeatTrackingProcessor(beats_per_bar=[3, 4]) enables DBN to model 3-beat bars; downbeat F-measure: 0.43 → 0.91; downbeat position error: 20–30% → under 4%; 1.5h retainer engagement
Westfield Madmom Ltd. had built a dance video content synchronization service that processed 500 dance videos per day, automatically aligning choreography cut markers and visual transition points to music downbeats for ballroom, Latin, swing, and folk dance genres. The pipeline used madmom 0.16.1 to analyze the audio track of each video, running DBNDownBeatTrackingProcessor to extract downbeat timestamps, and fed these timestamps to a downstream video editing module that placed visual sync markers at each downbeat. Quality was monitored by dance instructors who spot-checked 10% of videos on a weekly review cycle, with a downbeat F-measure threshold of 0.88 as the production SLA. For 4/4 content — pop dance music, club remixes, R&B — the pipeline consistently exceeded the 0.88 threshold. After expanding the service to include ballroom and folk dance content — waltz (3/4), compound triple (6/8), and Viennese waltz (3/4 at 160–180 BPM) — the review team flagged that visual sync markers were landing on beat 2 of the music’s bar rather than beat 1 on waltz tracks. The initial failure mode was subtle: markers were still at genuine beat positions, just the wrong beat within the bar. Dancers performing to the synchronized video observed that visual cues for step changes were appearing one beat late, disrupting the waltz 1-2-3 count. The phase offset was not constant but accumulated over the first 15–20 seconds of a track, then stabilized at a consistent 1-beat offset for the remainder. A madmom retainer developer was engaged to diagnose the correlation between 3/4 time signature content and the systematic downbeat position offset.
The developer’s investigation began with a minimal reproduction: running DBNDownBeatTrackingProcessor(beats_per_bar=[4]) (the default) on a synthesized 3/4 waltz click track (3 clicks per bar, bars 1–20, clearly annotated ground-truth downbeats) and comparing the DBN’s downbeat predictions to the annotations. The comparison confirmed the offset pattern: for bars 1–8, the downbeat predictions were correct (beat 1 of each bar); from bar 9 onward, the predictions shifted to beat 2 of each bar. Increasing the analysis length revealed that the shift point varied slightly (bars 7–12) depending on the BPM and the specific bar structure. The developer identified the mechanism by examining madmom’s DBN state representation: with beats_per_bar=[4], the DBN maintains a state space of beat positions within a 4-beat bar. Each DBN state corresponds to a (beat_in_bar, beat_period) pair. For a 3/4 waltz track, the RNN correctly detects beat onsets at every beat position; however, the DBN’s 4-beat bar model must partition the continuous beat sequence into bars of exactly 4 beats. After every 4 beats of waltz music, the DBN starts a new bar and assigns the downbeat probability to position 1 of that new DBN bar. But 4 waltz beats = 1.33 waltz bars, so the DBN bar boundaries progressively misalign with the music’s actual bar boundaries. After 12 DBN bars (48 DBN beats = 16 waltz bars), the cumulative offset has grown to 1 waltz beat, causing the DBN to identify beat 2 of the waltz bar as its next downbeat. Setting beats_per_bar=[3, 4] resolved this by allowing the DBN to model 3-beat bars in its state space; the DBN selected the 3-beat bar model for waltz content via its likelihood function, correctly aligning downbeat predictions with actual bar 1 positions throughout the track. Downbeat F-measure on waltz content improved from 0.43 to 0.91; downbeat position error dropped from 20–30% to under 4%.
The diagnostic code that confirmed the DBN bar-model mismatch and validated the beats_per_bar fix:
# Westfield Madmom Ltd. — madmom 0.16.1 downbeat drift on waltz 3/4 diagnostic
# madmom (CPJKU/madmom) 0.16.1; Python 3.9
# Deployment: dance video downbeat sync, 500 videos/day, ballroom/Latin/folk
# Problem: 20–30% downbeat position error on waltz 3/4 and 6/8 tracks
# Fix: DBNDownBeatTrackingProcessor(beats_per_bar=[3, 4])
import numpy as np
import madmom
SAMPLE_RATE = 44100
def track_downbeats_default(audio_path: str) -> np.ndarray:
"""
Downbeat tracking with default beats_per_bar=[4].
Returns array of downbeat timestamps (seconds).
"""
proc = madmom.features.downbeats.DBNDownBeatTrackingProcessor(
beats_per_bar=[4],
fps=100
)
act = madmom.features.downbeats.RNNDownBeatProcessor()(audio_path)
beats_downbeats = proc(act)
# beats_downbeats: Nx2 array [time, beat_number_in_bar]
downbeat_times = beats_downbeats[beats_downbeats[:, 1] == 1, 0]
return downbeat_times
def track_downbeats_fixed(audio_path: str) -> np.ndarray:
"""
Downbeat tracking with beats_per_bar=[3, 4] — supports 3/4 and 4/4.
Returns array of downbeat timestamps (seconds).
"""
proc = madmom.features.downbeats.DBNDownBeatTrackingProcessor(
beats_per_bar=[3, 4],
fps=100
)
act = madmom.features.downbeats.RNNDownBeatProcessor()(audio_path)
beats_downbeats = proc(act)
downbeat_times = beats_downbeats[beats_downbeats[:, 1] == 1, 0]
return downbeat_times
def compute_downbeat_fmeasure(predicted: np.ndarray, ground_truth: np.ndarray,
tolerance_s: float = 0.070) -> float:
"""
Downbeat F-measure with ±70ms tolerance window (standard MIR evaluation).
"""
tp = fn = 0
matched = set()
for gt_t in ground_truth:
diffs = np.abs(predicted - gt_t)
idx = np.argmin(diffs)
if diffs[idx] <= tolerance_s and idx not in matched:
tp += 1
matched.add(idx)
else:
fn += 1
fp = len(predicted) - 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
def compute_downbeat_error_rate(predicted: np.ndarray, ground_truth: np.ndarray,
tolerance_s: float = 0.070) -> float:
"""
Fraction of ground truth downbeats with no predicted downbeat within tolerance.
"""
errors = 0
for gt_t in ground_truth:
diffs = np.abs(predicted - gt_t)
if diffs.min() > tolerance_s:
errors += 1
return errors / len(ground_truth) if len(ground_truth) > 0 else 0.0
# Test corpus: 20 waltz 3/4 tracks with manually annotated ground-truth downbeats
waltz_tracks = [f"waltz_test_{i:02d}.wav" for i in range(1, 21)]
waltz_gt = [np.load(f"waltz_test_{i:02d}_downbeats.npy") for i in range(1, 21)]
fm_default_all = []
fm_fixed_all = []
er_default_all = []
er_fixed_all = []
for audio_path, gt_downbeats in zip(waltz_tracks, waltz_gt):
# Baseline: beats_per_bar=[4] (default)
pred_default = track_downbeats_default(audio_path)
fm_default_all.append(compute_downbeat_fmeasure(pred_default, gt_downbeats))
er_default_all.append(compute_downbeat_error_rate(pred_default, gt_downbeats))
# Fix: beats_per_bar=[3, 4]
pred_fixed = track_downbeats_fixed(audio_path)
fm_fixed_all.append(compute_downbeat_fmeasure(pred_fixed, gt_downbeats))
er_fixed_all.append(compute_downbeat_error_rate(pred_fixed, gt_downbeats))
print("madmom 0.16.1 — waltz 3/4 downbeat drift diagnostic")
print("=" * 65)
print()
print(f" {'Configuration':<50} {'F-measure':<12} {'Error rate'}")
print("-" * 75)
print(f" {'DBNDownBeatTrackingProcessor(beats_per_bar=[4]) [regression]':<50}"
f" {np.mean(fm_default_all):.2f} "
f" {np.mean(er_default_all)*100:.1f}%")
print(f" {'DBNDownBeatTrackingProcessor(beats_per_bar=[3,4]) [fix]':<50}"
f" {np.mean(fm_fixed_all):.2f} "
f" {np.mean(er_fixed_all)*100:.1f}%")
print()
print("Root cause: DBN 4-beat bar model accumulates phase drift on 3-beat waltz bars")
print(" beats_per_bar=[4]: DBN bar boundary every 4 beats")
print(" Waltz bar = 3 beats: 4 DBN beats = 1.33 waltz bars")
print(" After 8–10 DBN bar cycles: cumulative offset = 1 waltz beat")
print(" DBN identifies beat 2 of waltz bar as downbeat")
print()
print("Fix: beats_per_bar=[3, 4]")
print(" DBN selects 3-beat bar model for waltz content via likelihood function")
print(" Downbeat F-measure: 0.43 → 0.91; downbeat error: 20–30% → under 4%")
print()
print("Retainer engagement: 1.5h total")
print(" Triage: 0.25h — downbeat offset localized to 3/4 and 6/8 genres")
print(" Root cause: 0.50h — DBN state space analyzed; 4-beat model on 3-beat content")
print(" Fix: 0.50h — beats_per_bar=[3,4]; 20-track waltz corpus re-processed")
print(" Validate: 0.25h — F-measure 0.43→0.91; downbeat error→under 4%; 1.5h")
Why madmom’s DBN bar model accumulates downbeat drift on 3/4 and 6/8 time signatures
madmom’s downbeat tracker uses a two-stage pipeline: an RNN that produces continuous beat and downbeat activation curves from the audio, followed by a DBN that decodes the optimal sequence of beat positions and bar boundaries from those activations. The DBN models a Markov chain over beat states, where each state encodes the current beat position within the bar (1 through N, where N is the number of beats per bar) and the current beat period (inter-beat interval in frames). The beats_per_bar parameter defines the set of allowed bar lengths; the DBN state space is the product of all allowed beat-in-bar positions and all allowed periods in the [min_bpm, max_bpm] range. At each time step, the DBN updates its state estimate using the RNN’s beat and downbeat activation as the emission probability and a transition model that encodes the expected regularity of beat spacing. A downbeat is detected when the state transitions to beat position 1 within any bar in the state space.
With beats_per_bar=[4], the DBN only maintains states for 4-beat bars. For waltz tracks (3/4 time), the RNN correctly detects beat onsets with high probability at the correct beat positions (the RNN’s beat activation network was trained on a broad distribution including waltz content). However, the DBN must map these beat detections onto its 4-beat bar structure. Each time the DBN state reaches beat position 4, it transitions back to beat position 1 (signaling a new bar and a new downbeat). For waltz music, the actual bar boundaries fall every 3 beats. The DBN’s 4-beat cycle and the music’s 3-beat cycle have a least common multiple of 12 beats, meaning the two cycles align every 12 beats (4 waltz bars). Within this 12-beat window, the DBN fires downbeats at beats 1, 5, and 9 of the 12-beat cycle, while the music’s actual downbeats fall at beats 1, 4, 7, and 10. The mismatch grows as the DBN’s highest-likelihood path stabilizes around a consistent bar-boundary position: typically, the DBN locks onto the 4-beat cycle that aligns best with the first few seconds of the waltz track, and once locked, the DBN’s downbeat predictions drift relative to the actual downbeats at a rate of 1 beat per 4 DBN bar cycles. Setting beats_per_bar=[3, 4] adds a competing set of 3-beat bar states to the DBN’s state space; the transition model assigns higher likelihood to the 3-beat path for waltz content because the actual beat spacing matches the 3-beat period, allowing the DBN to converge to the correct bar structure and produce accurate downbeat timestamps throughout the track.
Related retainer posts
- aubio developer on retainer — aubio 0.4.9; Python 3.9; DJ set beat tracking 1,000 mixes/day; phase accumulator drift on 128→140 BPM transitions; fix: hop_s=256 and tol=0.01 — 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
- MaryTTS developer on retainer — MaryTTS (marytts/marytts) 5.2; Java 11; multilingual IVR TTS 15,000 daily calls; German number prosody regression; fix: pre-synthesis regex normalization pipeline — 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 →