Skip to content

Commit

Permalink
implement settings (Parameter::BiquadBank) for BiquadBank
Browse files Browse the repository at this point in the history
  • Loading branch information
rhizoome committed Sep 5, 2024
1 parent 5c763b8 commit 5cec556
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/biquad_bank.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use core::marker::PhantomData;
use core::ops::Neg;
use hacker::Parameter;
use wide::{f32x8, f64x4};

use super::audionode::*;
use super::prelude::{U4, U8};
use super::*;
use crate::setting::Setting;
use numeric_array::ArrayLength;

pub trait Realx<Size: ArrayLength>: Num + Sized + Neg<Output = Self> {
Expand All @@ -15,6 +17,7 @@ pub trait Realx<Size: ArrayLength>: Num + Sized + Neg<Output = Self> {
fn sqrt(self) -> Self;
fn reduce_add(self) -> f32;
fn to_frame(self) -> Frame<f32, Size>;
fn set(&mut self, index: usize, value: f32);
}

impl Realx<U8> for f32x8 {
Expand All @@ -41,6 +44,10 @@ impl Realx<U8> for f32x8 {
fn to_frame(self) -> Frame<f32, U8> {
f32x8::to_array(self).into()
}
#[inline(always)]
fn set(&mut self, index: usize, value: f32) {
self.as_array_mut()[index] = value;
}
}

impl Realx<U4> for f64x4 {
Expand Down Expand Up @@ -69,6 +76,10 @@ impl Realx<U4> for f64x4 {
let array_f32: [f32; 4] = array_f64.map(|x| x as f32);
array_f32.into()
}
#[inline(always)]
fn set(&mut self, index: usize, value: f32) {
self.as_array_mut()[index] = value as f64;
}
}

/// BiquadBank coefficients in normalized form using SIMD.
Expand Down Expand Up @@ -169,16 +180,19 @@ where
..Default::default()
}
}

pub fn with_coefs(coefs: BiquadCoefsBank<F, Size>) -> Self {
Self {
coefs,
sample_rate: DEFAULT_SR,
..Default::default()
}
}

pub fn coefs(&self) -> &BiquadCoefsBank<F, Size> {
&self.coefs
}

pub fn set_coefs(&mut self, coefs: BiquadCoefsBank<F, Size>) {
self.coefs = coefs;
}
Expand Down Expand Up @@ -217,11 +231,16 @@ where
y0.to_frame()
}

//fn set(&mut self, setting: Setting) {
// if let Parameter::BiquadBank(a1, a2, b0, b1, b2) = setting.parameter() {
// self.set_coefs(BiquadCoefsBank::arbitrary(*a1, *a2, *b0, *b1, *b2));
// }
//}
fn set(&mut self, setting: Setting) {
if let Parameter::BiquadBank(index, a1, a2, b0, b1, b2) = setting.parameter() {
let mut coefs = self.coefs;
coefs.a1.set(*index, *a1);
coefs.a2.set(*index, *a2);
coefs.b0.set(*index, *b0);
coefs.b1.set(*index, *b1);
coefs.b2.set(*index, *b2);
}
}

//fn route(&mut self, input: &SignalFrame, frequency: f64) -> SignalFrame {
// let mut output = SignalFrame::new(self.outputs());
Expand Down
5 changes: 5 additions & 0 deletions src/setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ pub enum Parameter {
Coefficient(f32),
/// Set biquad parameters `(a1, a2, b0, b1, b2)`.
Biquad(f32, f32, f32, f32, f32),
/// Set biquadbank parameters `(index, a1, a2, b0, b1, b2)`.
/// `index` range:
/// - 0-3 for a f64x4 based BiquadBank
/// - 0-7 for a f32x8 based BiquadBank
BiquadBank(usize, f32, f32, f32, f32, f32),
/// Set delay.
Delay(f32),
/// Set response time.
Expand Down

0 comments on commit 5cec556

Please sign in to comment.