diff options
| author | ozpv <39195175+ozpv@users.noreply.github.com> | 2026-05-18 15:20:06 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-18 15:20:06 -0500 |
| commit | 88bd6307ee43f3c3609d5b2f49d440d285185765 (patch) | |
| tree | 70b96bac6e1c4734f31b90e24526ea49b67fcc48 /src/window_function.rs | |
| parent | 13e872165ed41e032246eddbe1b0750154ce7259 (diff) | |
add window function parameter
Diffstat (limited to 'src/window_function.rs')
| -rw-r--r-- | src/window_function.rs | 28 |
1 files changed, 25 insertions, 3 deletions
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<f32>) {} - 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::<Vec<f32>>(); - - 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); + } } |
