pub struct Window {
pub window_type: WindowType,
pub size: usize,
/* private fields */
}Expand description
Pre-computed window function with SIMD-accelerated application
Fields§
§window_type: WindowTypeWindow type
size: usizeWindow size (number of samples)
Implementations§
Source§impl Window
impl Window
Sourcepub fn new(window_type: WindowType, size: usize) -> Self
pub fn new(window_type: WindowType, size: usize) -> Self
Create a new window function
Uses a global cache for common sizes (256, 512, 1024, 2048, 4096, 8192) to avoid recomputing cos() repeatedly. Uncommon sizes are computed on-demand.
§Arguments
window_type- Type of window functionsize- Window size in samples (typically FFT size)
§Example
let hann = Window::new(WindowType::Hann, 2048); // From cache (fast!)
let blackman = Window::new(WindowType::Blackman, 4096); // From cache (fast!)Sourcepub fn apply(&self, buffer: &mut [f32])
pub fn apply(&self, buffer: &mut [f32])
Apply window to audio buffer using SIMD acceleration
Multiplies each sample by the corresponding window coefficient. Uses true SIMD operations for 4-8x speedup on modern CPUs.
§Arguments
buffer- Audio buffer to window (modified in-place)
§Panics
Panics if buffer length doesn’t match window size
§Example
let window = Window::new(WindowType::Hann, 1024);
let mut audio = vec![1.0; 1024];
window.apply(&mut audio); // SIMD-accelerated windowingSourcepub fn gain(&self) -> f32
pub fn gain(&self) -> f32
Get the window gain (for normalization)
Returns the sum of all window coefficients divided by window size. Useful for normalizing the energy after windowing.
Sourcepub fn coherent_gain(&self) -> f32
pub fn coherent_gain(&self) -> f32
Get the coherent gain (for amplitude-preserving normalization)
This is the average of the window coefficients. Multiply your signal by 1/coherent_gain after windowing to preserve amplitude.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Window
impl RefUnwindSafe for Window
impl Send for Window
impl Sync for Window
impl Unpin for Window
impl UnsafeUnpin for Window
impl UnwindSafe for Window
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more