From 0ea36325067ac153806f4cc18c06e8b5556553dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Sun, 10 Sep 2023 19:07:42 +0200 Subject: [PATCH] fix drain --- src/psd.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/psd.rs b/src/psd.rs index 6c6fa16..671fd30 100644 --- a/src/psd.rs +++ b/src/psd.rs @@ -179,12 +179,13 @@ impl Stage for Psd { self.count += 1; // decimate overlap - let mut k = self.hbf.process_block(None, &mut self.buf[..self.overlap]); + let k = self.hbf.process_block(None, &mut self.buf[..self.overlap]); // drain decimator impulse response to initial state (zeros) - (k, self.drain) = (k.saturating_sub(self.drain), self.drain.saturating_sub(k)); - // yield k - y[n..][..k].copy_from_slice(&self.buf[..k]); - n += k; + let l = k.saturating_sub(self.drain); + self.drain = self.drain.saturating_sub(k); + // yield l + y[n..][..l].copy_from_slice(&self.buf[k - l..k]); + n += l; // drop the left keep the right as overlap self.buf.copy_within(self.overlap..N, 0); self.idx = N - self.overlap;