From b071fef15c4dbd8c4b66b4f8b97cf1256592966a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Thu, 25 Feb 2021 16:38:57 +0100 Subject: [PATCH] iir_int: apply rounding bias summarily for speed --- dsp/src/lowpass.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dsp/src/lowpass.rs b/dsp/src/lowpass.rs index 5ab803d..10d5838 100644 --- a/dsp/src/lowpass.rs +++ b/dsp/src/lowpass.rs @@ -27,10 +27,10 @@ impl> Lowpass { // Note T-DF-I and the zeros at Nyquist. let mut x = x; for y in self.y.iter_mut() { - let dy = x.saturating_sub(*y).saturating_add(1 << (k - 1)) >> k; + let dy = x.saturating_sub(*y) >> k; *y += dy; x = *y - (dy >> 1); } - x + x.saturating_add((self.y.len() as i32) << (k - 1)) } }