Skip to main content

FftAnalyzer

Struct FftAnalyzer 

Source
pub struct FftAnalyzer {
    pub magnitudes: Vec<f32>,
    pub smoothed: Vec<f32>,
    /* private fields */
}
Expand description

Holds the rolling sample buffer and performs FFT analysis.

Fields§

§magnitudes: Vec<f32>

Latest magnitude spectrum (fft_size/2 bins).

§smoothed: Vec<f32>

Smoothed magnitudes for visuals.

Implementations§

Source§

impl FftAnalyzer

Source

pub fn new(fft_size: usize, sample_rate: u32) -> Self

Create an analyser with the given FFT window size and sample rate. Typical sizes: 512, 1024, 2048, 4096.

Source

pub fn set_window(&mut self, w: Window)

Source

pub fn push_samples(&mut self, samples: &[f32])

Push new audio samples (mono f32). Keeps a rolling window.

Source

pub fn freq_bands(&self, bands: usize) -> Vec<f32>

Return bands logarithmically-spaced frequency magnitudes. Index 0 = bass, index bands-1 = treble.

Source

pub fn dominant_freq(&self) -> f32

Dominant frequency in Hz (peak of magnitude spectrum).

Source

pub fn rms(&self) -> f32

RMS level of the current window.

Source

pub fn is_beat(&self) -> bool

Beat detection: true if current frame energy significantly exceeds average.

Source

pub fn beat_ratio(&self) -> f32

Beat energy ratio (1.0 = at threshold, >1 = strong beat).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.