Skip to content

Commit

Permalink
fix(biquad): merge conflicting biquad modules
Browse files Browse the repository at this point in the history
  • Loading branch information
SolarLiner committed Mar 22, 2024
1 parent 3709c35 commit 0d1fe6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 286 deletions.
284 changes: 0 additions & 284 deletions src/filters/biquad.rs

This file was deleted.

18 changes: 16 additions & 2 deletions src/filters/biquad/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
//! Transposed Direct Form II Biquad implementation - nonlinearities based on https://jatinchowdhury18.medium.com/complex-nonlinearities-episode-5-nonlinear-feedback-filters-115e65fc0402
//! Transposed Direct Form II Biquad implementation
//!
//! Nonlinearities based on <https://jatinchowdhury18.medium.com/complex-nonlinearities-episode-5-nonlinear-feedback-filters-115e65fc0402>
//!
//! # Usage
//!
//! ```rust
//! use valib::dsp::DSP;
//! use valib::filters::biquad::Biquad;
//! use valib::saturators::Tanh;
//! let mut lowpass = Biquad::<f32, Tanh>::lowpass(0.25 /* normalized frequency */, 0.707 /* Q */);
//! let output = lowpass.process([0.0]);
//! ```
use nalgebra::Complex;
use numeric_literals::replace_float_literals;
Expand All @@ -13,7 +25,7 @@ use crate::{
#[cfg(never)]
pub mod design;

/// Biquad struct in Transposed Direct Form II. Optionally, a [`Saturator`](crate::saturators::Saturator) instance can be used
/// Biquad struct in Transposed Direct Form II. Optionally, a [`Saturator`] instance can be used
/// to apply waveshaping to the internal states.
#[derive(Debug, Copy, Clone)]
pub struct Biquad<T, S> {
Expand All @@ -23,6 +35,7 @@ pub struct Biquad<T, S> {
sats: [S; 2],
}

// TODO: No need to restrict this on dynamic saturators only
impl<T> Biquad<T, Dynamic<T>> {
/// Apply these new saturators to this Biquad instance, returning a new instance of it.
pub fn with_saturators(mut self, a: Dynamic<T>, b: Dynamic<T>) -> Biquad<T, Dynamic<T>> {
Expand All @@ -43,6 +56,7 @@ impl<T: Copy, S> Biquad<T, S> {
}
}

// TODO: Make those return linear biquads, where the user can then pass their saturators directly through `with_saturators`
impl<T: Scalar, S: Default> Biquad<T, S> {
/// Create a new instance of a Biquad with the provided poles and zeros coefficients.
pub fn new(b: [T; 3], a: [T; 2]) -> Self {
Expand Down

0 comments on commit 0d1fe6c

Please sign in to comment.