macc_i32: move to tools
This commit is contained in:
parent
83496205b3
commit
1805961d5d
|
@ -1,3 +1,4 @@
|
|||
use super::tools::macc_i32;
|
||||
use core::f64::consts::PI;
|
||||
use miniconf::StringSet;
|
||||
use serde::Deserialize;
|
||||
|
@ -40,17 +41,6 @@ impl Coeff for Vec5 {
|
|||
}
|
||||
}
|
||||
|
||||
fn macc(y0: i32, x: &[i32], a: &[i32], shift: u32) -> i32 {
|
||||
// Rounding bias, half up
|
||||
let y0 = ((y0 as i64) << shift) + (1 << (shift - 1));
|
||||
let y = x
|
||||
.iter()
|
||||
.zip(a)
|
||||
.map(|(x, a)| *x as i64 * *a as i64)
|
||||
.fold(y0, |y, xa| y + xa);
|
||||
(y >> shift) as i32
|
||||
}
|
||||
|
||||
/// Integer biquad IIR
|
||||
///
|
||||
/// See `dsp::iir::IIR` for general implementation details.
|
||||
|
@ -86,7 +76,7 @@ impl IIR {
|
|||
// Store x0 x0 x1 x2 y1 y2
|
||||
xy[0] = x0;
|
||||
// Compute y0 by multiply-accumulate
|
||||
let y0 = macc(0, xy, &self.ba, IIR::SHIFT);
|
||||
let y0 = macc_i32(0, xy, &self.ba, IIR::SHIFT);
|
||||
// Limit y0
|
||||
// let y0 = y0.max(self.y_min).min(self.y_max);
|
||||
// Store y0 x0 x1 y0 y1 y2
|
||||
|
|
|
@ -77,6 +77,17 @@ where
|
|||
.fold(y0, |y, xa| y + xa)
|
||||
}
|
||||
|
||||
pub fn macc_i32(y0: i32, x: &[i32], a: &[i32], shift: u32) -> i32 {
|
||||
// Rounding bias, half up
|
||||
let y0 = ((y0 as i64) << shift) + (1 << (shift - 1));
|
||||
let y = x
|
||||
.iter()
|
||||
.zip(a)
|
||||
.map(|(x, a)| *x as i64 * *a as i64)
|
||||
.fold(y0, |y, xa| y + xa);
|
||||
(y >> shift) as i32
|
||||
}
|
||||
|
||||
/// Combine high and low i32 into a single downscaled i32, saturating the type.
|
||||
pub fn saturating_scale(lo: i32, hi: i32, shift: u32) -> i32 {
|
||||
debug_assert!(shift & 31 == shift);
|
||||
|
|
Loading…
Reference in New Issue