pub fn spectral_rolloff(
mag: &[f32],
sample_rate: f32,
threshold: f32,
) -> Result<f32, AudioError>Expand description
Spectral rolloff frequency of a one-sided magnitude spectrum mag.
The rolloff is the frequency below which a fraction threshold (e.g. 0.85)
of the total spectral energy Σ |X[k]|^2 is contained. The returned value
is the centre frequency of the first bin at which the running cumulative
energy reaches threshold · total.
mag spans DC..Nyquist inclusive (an N-bin spectrum came from an FFT of
size 2·(N-1)), so the bin spacing is sample_rate / (2·(N-1)) Hz.
A spectrum whose energy sits low returns a low frequency; energy sitting
high returns a high frequency. A silent spectrum returns 0.0 Hz.
Zero-heap: two passes, scalar result.
§Errors
AudioError::InvalidParameterifsample_rateis not a positive finite, ifthresholdis not in(0, 1], or ifmaghas fewer than 2 bins.