#[derive(Debug, Clone, Copy)]
pub struct BiquadState {
x1: f64, x2: f64, y1: f64, y2: f64, }
impl BiquadState {
#[must_use]
pub fn new() -> Self {
Self {
x1: 0.0,
x2: 0.0,
y1: 0.0,
y2: 0.0,
}
}
}
impl Default for BiquadState {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, Copy)]
pub struct BiquadCoeffs {
pub b0: f64,
pub b1: f64,
pub b2: f64,
pub a1: f64,
pub a2: f64,
}
#[inline]
pub fn apply_biquad(x: f64, coeffs: &BiquadCoeffs, state: &mut BiquadState) -> f64 {
let y = coeffs.b0 * x + coeffs.b1 * state.x1 + coeffs.b2 * state.x2
- coeffs.a1 * state.y1
- coeffs.a2 * state.y2;
state.x2 = state.x1;
state.x1 = x;
state.y2 = state.y1;
state.y1 = y;
y
}
#[must_use]
pub fn shelving_coeffs() -> BiquadCoeffs {
BiquadCoeffs {
b0: 1.535_124_859_586_97,
b1: -2.691_696_189_406_38,
b2: 1.198_392_810_852_85,
a1: -1.690_659_293_182_41,
a2: 0.732_480_774_215_85,
}
}
#[must_use]
pub fn high_pass_coeffs() -> BiquadCoeffs {
BiquadCoeffs {
b0: 1.0,
b1: -2.0,
b2: 1.0,
a1: -1.990_047_454_833_98,
a2: 0.990_072_250_366_21,
}
}