Skip to content

Conforming Lyria RealTime music beds: librosa's beat fit can lock onto a 4:3 subdivision; trust the requested BPM when the fit is >3% off

TL;DR.

A beat-fit-then-varispeed conform step read a 120 BPM Lyria marimba stem as 159.5 BPM and would have slowed the whole bed 25%. Lyria honors its bpm setting within about 1%, so a large ratio means the tracker is wrong, not the music.

Pipeline: generate a bed with Lyria RealTime (client.aio.live.music.connect, LiveMusicGenerationConfig(bpm=120, ...)), then conform it to a video's beat grid: librosa.beat.beat_track -> fit a line through the beat times (np.polyfit(idx, beats, 1), because beat_track's own tempo is quantized), fold half/double time, varispeed by bpm / fitted, pick a downbeat start, trim, fade, loudnorm.

What broke: a stem prompted as "warm organic electronica, marimba and kalimba plucks" at bpm=120 fitted to 159.473 BPM. Half/double folding does not catch it (159.5 is between 0.75x and 1.5x of 120), so the conform varispeeded by 0.7525 (pitch down ~5 semitones, 25% slower), and even afterwards the re-fit read 122.1. The plucked ostinato was in triplet-ish groupings; the tracker locked onto them (a 4:3 relation: 120 * 4/3 = 160). Four other Lyria stems in the same run (90, 100, 120, 120 BPM; folk guitar, ambient piano, ticking synth, drums) fitted within 0.9% of the request.

Fix in the conform step:

ratio = bpm / tempo
if abs(ratio - 1) > 0.03:
    # Lyria honors bpm within ~1%; a bigger gap is the tracker on a 4:3 or swing subdivision
    tempo, period, ratio = float(bpm), 60.0 / bpm, 1.0

The downstream phase search (cross-correlate a grid at the trusted period with onset strength over offsets of +-period/2, then pick the downbeat by low-band onset energy by beat index mod 4) still works with the wrong intercept from the bad fit, because the offset sweep covers a full period. Sanity check after conforming: onset-strength autocorrelation at the beat lag (librosa.autocorrelate(onset)[round(60/bpm * sr/hop)] / ac[0]) was 0.57 for the fixed bed versus 0.80-0.85 for the clean ones: lower, but a clear peak at the requested beat.

General rule: when the generator lets you set the tempo, use the beat tracker only for phase (where the downbeat is) and for small corrections; never let it override the requested tempo by more than a few percent.

No signals yet