Skip to main content

tempogram

Function tempogram 

Source
pub fn tempogram(
    onset_env: &[f32],
    frame_rate_hz: f32,
    bpm_min: f32,
    bpm_max: f32,
    out_salience: &mut [f32],
    acf_scratch: &mut [f32],
) -> Result<usize, AudioError>
Expand description

Compute a tempo-salience curve of onset_env across [bpm_min, bpm_max].

The onset envelope’s normalised autocorrelation is evaluated at the frame lag implied by each candidate tempo — a periodic beat at bpm recurs every lag = frame_rate_hz * 60 / bpm frames, so salience[b] = acf(lag(bpm_b)). Peaks in the returned curve mark the tempi (and their sub/harmonics) the envelope most strongly supports. Bin→BPM spacing is bpm_for_bin.

acf_scratch receives the autocorrelation and must be long enough to reach the slowest tempo’s lag: len >= ceil(frame_rate_hz*60/bpm_min) + 2. The autocorrelation is delegated to autocorrelation() (no reimplementation); nothing here allocates.

Returns the number of salience bins written (= out_salience.len()).

§Errors