Skip to main content

track_beats

Function track_beats 

Source
pub fn track_beats(
    onset_env: &[f32],
    frame_rate_hz: f32,
    out_beat_frames: &mut [u32],
) -> Result<(usize, f32), AudioError>
Expand description

Estimate global tempo and place beat frames for onset_env.

onset_env is a per-frame onset-strength curve (e.g. the spectral-flux novelty behind super::spectral_flux_onset::onset_detection); frame_rate_hz is its sampling rate (sample_rate / hop). The tempo is the dominant peak of the autocorrelation tempogram (highest-salience detect_peaks maximum, falling back to the salience argmax). Given the beat period P = frame_rate_hz*60/bpm frames, a comb filter scores every integer phase offset o ∈ [0, round(P)) by the summed onset strength at o, o+P, o+2P, … and keeps the best; beats are then laid at that phase and period and written (as frame indices) to out_beat_frames.

If the frame rate is so high that BPM_MIN’s lag exceeds ACF_CAP, the effective low bound is raised to keep the lag in range (documented, not silent failure — the returned BPM reflects the searched band).

Returns (n_beats, bpm).

§Errors