From 7c8da391597c89a8136df40011e9886ba7198df4 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 6 Mar 2022 18:45:34 +0100 Subject: [PATCH] Fix position increment in STFT helper This was what was causing the spectral leakage. It already sounded like parts of the buffer were being cleared too early or old parts were being reused, but I guess that makes sense now... --- src/util/stft.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/util/stft.rs b/src/util/stft.rs index f572fc48..3662a9f4 100644 --- a/src/util/stft.rs +++ b/src/util/stft.rs @@ -205,6 +205,9 @@ impl StftHelper { } } + already_processed_samples += samples_to_process; + self.current_pos = (self.current_pos + samples_to_process) % block_size; + // At this point we either have `already_processed_samples == main_buffer_len`, or // `self.current_pos % window_interval == 0`. If it's the latter, then we can process a // new block. @@ -253,10 +256,6 @@ impl StftHelper { ); } } - - // Do this after handling the block or else we'll copy the wrong samples. - already_processed_samples += samples_to_process; - self.current_pos = (self.current_pos + samples_to_process) % block_size; } } }