pub fn extract_spectral_amplitudes(
fft_out: &[Complex<f32>],
f0_bin: f32,
) -> SpectralAmplitudesExpand description
Extract harmonic amplitudes from the FFT half-spectrum.
For each harmonic k from 1 to L, integrate the magnitude across
the three bins nearest to k · f0_bin (centre bin ± 1). Using a
3-bin window rather than a single round-to-nearest bin recovers
energy for harmonics that fall between bin centres (fractional
f0_bin from pitch periods that aren’t integer factors of the
FFT size). Without this, harmonics at bin offset ±0.5 drop ~3 dB
below their true amplitude — measurable on real voice captures
against the DVSI chip’s own extraction, where the missing energy
produced flat Gm vectors that the PRBA codebook search always
resolved to near-origin entries (flat envelope → no formants).
We use sum-of-squares then sqrt so the window accumulates power
rather than raw magnitudes; this is the canonical way to pool
nearby bins without the magnitude-vs-phase ambiguity.
L is limited by both the FFT size and the AMBE codec:
L = min(floor((N − 1) / f0_bin), MAX_HARMONICS).