pub fn frequency_bands(
mag: &[f32],
sample_rate: f32,
band_edges_hz: &[f32],
out_energy: &mut [f32],
) -> Result<usize, AudioError>Expand description
Sum the energy of a one-sided magnitude spectrum mag into arbitrary
frequency bands defined by ascending band_edges_hz.
band_edges_hz holds B + 1 ascending edge frequencies (Hz) partitioning
the spectrum into B bands. Band b covers [edge[b], edge[b+1])
(half-open, so a bin lands in exactly one band). out_energy[b] receives
Σ |X[k]|^2 over the bins whose centre frequency falls in band b.
mag spans DC..Nyquist inclusive, so bin k sits at
k · sample_rate / (2·(N-1)) Hz for an N-bin spectrum.
Zero-heap: single pass, caller-supplied output.
§Errors
AudioError::InvalidParameterifsample_rateis not a positive finite, ifmaghas fewer than 2 bins, if there are fewer than 2 edges, or if the edges are not strictly ascending / not finite.AudioError::OutputBufferTooSmallifout_energyis shorter than the number of bands.