From 88bd6307ee43f3c3609d5b2f49d440d285185765 Mon Sep 17 00:00:00 2001 From: ozpv <39195175+ozpv@users.noreply.github.com> Date: Mon, 18 May 2026 15:20:06 -0500 Subject: add window function parameter --- src/window_function.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/window_function.rs') diff --git a/src/window_function.rs b/src/window_function.rs index 09c5d31..3565ea7 100644 --- a/src/window_function.rs +++ b/src/window_function.rs @@ -11,6 +11,8 @@ pub trait WindowFunction: Send { fn reverse(&mut self, data: &mut [f32]); /// Yields the amount of samples still required to apply the window fn needed(&self) -> usize; + /// Take the steps necessary to handle a resize + fn resize(&mut self, window_size: &WindowSize); } /// Effectively a chunking function @@ -29,11 +31,15 @@ impl RectangularWindow { impl WindowFunction for RectangularWindow { fn apply(&mut self, _data: &mut VecDeque) {} - fn reverse(&mut self, _data: &mut [f32]) {} + fn reverse(&mut self, data: &mut [f32]) {} fn needed(&self) -> usize { self.window_size } + + fn resize(&mut self, window_size: &WindowSize) { + *self = Self::new(&window_size); + } } /// Hann function @@ -152,6 +158,10 @@ impl WindowFunction for HannWindow { self.window_size / 2 } } + + fn resize(&mut self, window_size: &WindowSize) { + *self = Self::new(&window_size); + } } /// Hamming function @@ -180,8 +190,8 @@ impl HammingWindow { 0.53836 - (0.46164 * f32::cos((2.0 * PI * i) / (window_size_f32))) }) .collect::>(); - - let normalize = (0..half_window_size) + + let normalize = (0..half_window_size) .map(|i| { (function[i] * function[i]) + (function[i + half_window_size] * function[i + half_window_size]) @@ -258,6 +268,10 @@ impl WindowFunction for HammingWindow { self.window_size / 2 } } + + fn resize(&mut self, window_size: &WindowSize) { + *self = Self::new(&window_size); + } } /// 4-term Blackman-Harris window function @@ -378,6 +392,10 @@ impl WindowFunction for BlackmanHarrisWindow { self.window_size / 4 } } + + fn resize(&mut self, window_size: &WindowSize) { + *self = Self::new(&window_size); + } } /// 4th power of sine window function @@ -496,4 +514,8 @@ impl WindowFunction for Sine4Window { self.window_size / 4 } } + + fn resize(&mut self, window_size: &WindowSize) { + *self = Self::new(&window_size); + } } -- cgit v1.2.3