pub struct SpectrumAnalyzer { /* private fields */ }Expand description
Windowed FFT plus a fixed log-frequency band mapping, reused every hop.
Implementations§
Source§impl SpectrumAnalyzer
impl SpectrumAnalyzer
Sourcepub fn new(sample_rate: u32) -> Self
pub fn new(sample_rate: u32) -> Self
Plan both FFTs and precompute the Hann windows and band layout for
sample_rate.
Sourcepub fn analyze(&mut self, short: &[f32; 2048], long: &[f32]) -> [f32; 64]
pub fn analyze(&mut self, short: &[f32; 2048], long: &[f32]) -> [f32; 64]
FFT both windows and return the log-frequency band spectrum. Band value is the peak bin in the band, so a pure tone reads near its amplitude regardless of band width — and regardless of which window resolved it.
long is expected to be LOW_WINDOW_SIZE samples; a shorter slice
simply leaves the tail of the transform zeroed rather than panicking.
Sourcepub fn magnitudes(&self) -> &[f32; 1024]
pub fn magnitudes(&self) -> &[f32; 1024]
Normalized linear magnitudes of the most recent analyze call, from the
short window — consumed by onset detection, whose transient response
is deliberately not slowed by the long window.
Sourcepub fn layout(&self) -> &BandLayout
pub fn layout(&self) -> &BandLayout
The band layout this analyzer resolved for its sample rate.
Sourcepub fn band_for_freq(&self, hz: f32) -> usize
pub fn band_for_freq(&self, hz: f32) -> usize
The log-frequency band index that contains hz.