iir: copy_within is better than rotate_right

This commit is contained in:
Robert Jördens 2020-11-25 17:24:49 +01:00
parent b0e0b5144f
commit d9e4f6a052
1 changed files with 4 additions and 2 deletions

View File

@ -159,10 +159,12 @@ impl IIR {
/// * `xy` - Current filter state. /// * `xy` - Current filter state.
/// * `x0` - New input. /// * `x0` - New input.
pub fn update(&self, xy: &mut IIRState, x0: f32) -> f32 { pub fn update(&self, xy: &mut IIRState, x0: f32) -> f32 {
let n = self.ba.len();
debug_assert!(xy.len() == n);
// `xy` contains x0 x1 y0 y1 y2 // `xy` contains x0 x1 y0 y1 y2
// Increment time x1 x2 y1 y2 y3 // Increment time x1 x2 y1 y2 y3
// Rotate y3 x1 x2 y1 y2 // Rotate y3 x1 x2 y1 y2
xy.rotate_right(1); xy.copy_within(0..n - 1, 1); // unrolls better than xy.rotate_right(1)
// Store x0 x0 x1 x2 y1 y2 // Store x0 x0 x1 x2 y1 y2
xy[0] = x0; xy[0] = x0;
// Compute y0 by multiply-accumulate // Compute y0 by multiply-accumulate
@ -170,7 +172,7 @@ impl IIR {
// Limit y0 // Limit y0
let y0 = max(self.y_min, min(self.y_max, y0)); let y0 = max(self.y_min, min(self.y_max, y0));
// Store y0 x0 x1 y0 y1 y2 // Store y0 x0 x1 y0 y1 y2
xy[xy.len() / 2] = y0; xy[n / 2] = y0;
y0 y0
} }
} }