Skip to main content

pitch_salience

Function pitch_salience 

Source
pub fn pitch_salience(
    peak_freqs: &[f32],
    peak_mags: &[f32],
    n_peaks: usize,
    f_min_hz: f32,
    bins_per_semitone: f32,
    n_bins: usize,
    out_salience: &mut [f32],
) -> Result<(), AudioError>
Expand description

Accumulate a harmonic pitch-salience curve from the frame’s spectral peaks.

The salience grid is logarithmic: bin b is the pitch f_min_hz * 2^(b / (12 * bins_per_semitone)), i.e. a constant 100 / bins_per_semitone cents per bin. A peak at f_i with magnitude m_i contributes, for each harmonic number h, to the candidate fundamental f0 = f_i / h: the vote m_i * HARMONIC_ALPHA^(h-1) is spread over the grid bins within one semitone of f0 with a cos² window (zero at ±1 semitone), which softens grid quantisation without smearing across notes.

  • peak_freqs / peak_mags: the frame’s spectral peaks (Hz, linear magnitude), as produced by crate::features::peaks::spectral_peaks(). Only the first n_peaks entries are read.
  • f_min_hz: frequency of salience bin 0 (the low edge of the pitch range).
  • bins_per_semitone: grid resolution (e.g. 10.0 → 10 cents per bin).
  • n_bins: number of salience bins to fill.
  • out_salience: caller buffer, cleared then filled in [0, n_bins).

§Errors