Skip to main content

spectral_contrast

Function spectral_contrast 

Source
pub fn spectral_contrast(
    mag: &[f32],
    band_edges: &[usize],
    out_contrast: &mut [f32],
) -> Result<usize, AudioError>
Expand description

Spectral contrast per sub-band of a one-sided magnitude spectrum mag.

band_edges is an ascending list of bin indices partitioning the spectrum into band_edges.len() - 1 sub-bands [edge[b], edge[b+1]). For each band the contrast is the level difference between the band’s spectral peak (maximum magnitude) and its valley (minimum magnitude), expressed in dB:

contrast_dB[b] = 20·log10(peak_b) - 20·log10(valley_b)

A flat band gives ~0 dB; a band with a sharp peak over a quiet floor gives a large positive dB. Magnitudes are floored to a tiny epsilon so an all-zero band yields 0 dB rather than a NaN. Results are written into out_contrast (one per band).

Zero-heap: single pass per band, caller-supplied output.

§Errors