pub struct Spectrum {
pub bins: Vec<Complex32>,
pub fft_size: usize,
}Expand description
Post-FFT frequency-domain representation.
Fields§
§bins: Vec<Complex32>Complex FFT bins (full N/2+1 half-spectrum or full N).
fft_size: usizeThe FFT size used.
Implementations§
Source§impl Spectrum
impl Spectrum
pub fn new(bins: Vec<Complex32>, fft_size: usize) -> Self
Sourcepub fn frequency_of_bin(&self, k: usize, sample_rate: f32) -> f32
pub fn frequency_of_bin(&self, k: usize, sample_rate: f32) -> f32
Frequency of bin k given sample rate.
Sourcepub fn magnitude_spectrum(&self) -> Vec<f32>
pub fn magnitude_spectrum(&self) -> Vec<f32>
All magnitudes.
Sourcepub fn power_spectrum(&self) -> Vec<f32>
pub fn power_spectrum(&self) -> Vec<f32>
Power spectrum (magnitude²).
Sourcepub fn dominant_frequency(&self, sample_rate: f32) -> f32
pub fn dominant_frequency(&self, sample_rate: f32) -> f32
Frequency of the dominant (peak) bin.
Sourcepub fn spectral_centroid(&self, sample_rate: f32) -> f32
pub fn spectral_centroid(&self, sample_rate: f32) -> f32
Spectral centroid — weighted mean frequency.
Sourcepub fn spectral_spread(&self, sample_rate: f32) -> f32
pub fn spectral_spread(&self, sample_rate: f32) -> f32
Spectral spread — weighted standard deviation of frequency.
Sourcepub fn spectral_flux(&self, other: &Spectrum) -> f32
pub fn spectral_flux(&self, other: &Spectrum) -> f32
Spectral flux: sum of positive differences between consecutive frames.
Sourcepub fn spectral_flatness(&self) -> f32
pub fn spectral_flatness(&self) -> f32
Spectral flatness (Wiener entropy): geometric mean / arithmetic mean.
Sourcepub fn spectral_rolloff(&self, threshold: f32) -> f32
pub fn spectral_rolloff(&self, threshold: f32) -> f32
Spectral rolloff: frequency below which threshold fraction of energy is contained.
Sourcepub fn spectral_rolloff_hz(&self, threshold: f32, sample_rate: f32) -> f32
pub fn spectral_rolloff_hz(&self, threshold: f32, sample_rate: f32) -> f32
Spectral rolloff frequency in Hz (not normalized).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Spectrum
impl RefUnwindSafe for Spectrum
impl Send for Spectrum
impl Sync for Spectrum
impl Unpin for Spectrum
impl UnsafeUnpin for Spectrum
impl UnwindSafe for Spectrum
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.