From 02532148107b3ec8b05a114ef95335b03bd73b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Tue, 22 Jun 2021 22:53:51 +0200 Subject: [PATCH] lowpass: make it work for k=0 --- dsp/src/lowpass.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dsp/src/lowpass.rs b/dsp/src/lowpass.rs index 265929b..7573e28 100644 --- a/dsp/src/lowpass.rs +++ b/dsp/src/lowpass.rs @@ -25,7 +25,6 @@ impl Lowpass { /// Filtered output y. pub fn update(&mut self, x: i32, k: u8) -> i32 { debug_assert!(k & 31 == k); - debug_assert!((k - 1) & 31 == k - 1); // This is an unrolled and optimized first-order IIR loop // that works for all possible time constants. // Note T-DF-I and the zeros at Nyquist. @@ -35,6 +34,6 @@ impl Lowpass { *y += dy; x = *y - (dy >> 1); } - x.saturating_add((self.y.len() as i32) << (k - 1)) + x.saturating_add((self.y.len() as i32) << (k - 1).max(0)) } }