From 592a9081329898dd93b495424675d404b3b2f540 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 6 Mar 2022 14:48:41 +0100 Subject: [PATCH] Fix samples until next window calculation --- plugins/examples/stft/src/lib.rs | 2 ++ src/util/stft.rs | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/examples/stft/src/lib.rs b/plugins/examples/stft/src/lib.rs index 95f4e5c7..344123d8 100644 --- a/plugins/examples/stft/src/lib.rs +++ b/plugins/examples/stft/src/lib.rs @@ -7,6 +7,7 @@ struct Stft { params: Pin>, stft: util::StftHelper, + window_function: Vec, } #[derive(Params)] @@ -18,6 +19,7 @@ impl Default for Stft { params: Box::pin(StftParams::default()), stft: util::StftHelper::new(2, WINDOW_SIZE), + window_function: util::window::hann(WINDOW_SIZE), } } } diff --git a/src/util/stft.rs b/src/util/stft.rs index f1021167..8be4d78e 100644 --- a/src/util/stft.rs +++ b/src/util/stft.rs @@ -131,11 +131,13 @@ impl StftHelper { let main_buffer_len = main_buffer.len(); let num_channels = main_buffer.channels(); let block_size = self.main_input_ring_buffers[0].len(); - let window_interval = block_size / overlap_times; + let window_interval = (block_size / overlap_times) as i32; let mut already_processed_samples = 0; while already_processed_samples < main_buffer_len { let remaining_samples = main_buffer_len - already_processed_samples; - let samples_until_next_window = (window_interval - self.current_pos) % window_interval; + let samples_until_next_window = ((window_interval - self.current_pos as i32 - 1) + .rem_euclid(window_interval) + + 1) as usize; let samples_to_process = samples_until_next_window.min(remaining_samples); // Copy the input from `main_buffer` to the ring buffer while copying last block's