idsp::iir

Struct Filter

Source
pub struct Filter<T> { /* private fields */ }
Expand description

Standard audio biquad filter builder

https://www.w3.org/TR/audio-eq-cookbook/

Implementations§

Source§

impl<T> Filter<T>
where T: 'static + Float + FloatConst, f32: AsPrimitive<T>,

Source

pub fn frequency( &mut self, critical_frequency: T, sample_frequency: T, ) -> &mut Self

Set crititcal frequency from absolute units.

§Arguments
  • critical_frequency: “Relevant” or “corner” or “center” frequency in the same units as sample_frequency
  • sample_frequency: The sample frequency in the same units as critical_frequency. E.g. both in SI Hertz or rad/s.
Source

pub fn critical_frequency(&mut self, f0: T) -> &mut Self

Set relative critical frequency

§Arguments
  • f0: Relative critical frequency in units of the sample frequency. Must be 0 <= f0 <= 0.5.
Source

pub fn angular_critical_frequency(&mut self, w0: T) -> &mut Self

Set relative critical angular frequency

§Arguments
  • w0: Relative critical angular frequency. Must be 0 <= w0 <= π. Defaults to 0.0.
Source

pub fn gain(&mut self, k: T) -> &mut Self

Set reference gain

§Arguments
  • k: Linear reference gain. Defaults to 1.0.
Source

pub fn gain_db(&mut self, k_db: T) -> &mut Self

Set reference gain in dB

§Arguments
  • k_db: Reference gain in dB. Defaults to 0.0.
Source

pub fn shelf(&mut self, a: T) -> &mut Self

Set linear shelf gain

Used only for peaking, highshelf, lowshelf filters.

§Arguments
  • a: Linear shelf gain. Defaults to 1.0.
Source

pub fn shelf_db(&mut self, a_db: T) -> &mut Self

Set shelf gain in dB

Used only for peaking, highshelf, lowshelf filters.

§Arguments
  • a_db: Linear shelf gain. Defaults to 0.0.
Source

pub fn inverse_q(&mut self, qi: T) -> &mut Self

Set inverse Q parameter of the filter

The inverse “steepness”/“narrowness” of the filter transition. Defaults sqrt(2) which is as steep as possible without overshoot.

§Arguments
  • qi: Inverse Q parameter.
Source

pub fn q(&mut self, q: T) -> &mut Self

Set Q parameter of the filter

The “steepness”/“narrowness” of the filter transition. Defaults 1/sqrt(2) which is as steep as possible without overshoot.

This affects the same parameter as bandwidth() and shelf_slope(). Use only one of them.

§Arguments
  • q: Q parameter.
Source

pub fn bandwidth(&mut self, bw: T) -> &mut Self

Set the relative bandwidth

This affects the same parameter as inverse_q() and shelf_slope(). Use only one of them.

§Arguments
  • bw: Bandwidth in octaves
Source

pub fn shelf_slope(&mut self, s: T) -> &mut Self

Set the shelf slope.

This affects the same parameter as inverse_q() and bandwidth(). Use only one of them.

§Arguments
  • s: Shelf slope. A slope of 1.0 is maximally steep without overshoot.
Source

pub fn lowpass(&self) -> [T; 6]

Low pass filter

Builds second order biquad low pass filter coefficients.

use idsp::iir::*;
let ba = Filter::default()
    .critical_frequency(0.1)
    .gain(1000.0)
    .lowpass();
let iir = Biquad::<i32>::from(&ba);
let mut xy = [0; 4];
let x = vec![3, -4, 5, 7, -3, 2];
let y: Vec<_> = x.iter().map(|x0| iir.update(&mut xy, *x0)).collect();
assert_eq!(y, [5, 3, 9, 25, 42, 49]);
Source

pub fn highpass(&self) -> [T; 6]

High pass filter

Builds second order biquad high pass filter coefficients.

use idsp::iir::*;
let ba = Filter::default()
    .critical_frequency(0.1)
    .gain(1000.0)
    .highpass();
let iir = Biquad::<i32>::from(&ba);
let mut xy = [0; 4];
let x = vec![3, -4, 5, 7, -3, 2];
let y: Vec<_> = x.iter().map(|x0| iir.update(&mut xy, *x0)).collect();
assert_eq!(y, [5, -9, 11, 12, -1, 17]);
Source

pub fn bandpass(&self) -> [T; 6]

Band pass

use idsp::iir::*;
let ba = Filter::default()
    .frequency(1000.0, 48e3)
    .q(5.0)
    .gain_db(3.0)
    .bandpass();
println!("{ba:?}");
Source

pub fn notch(&self) -> [T; 6]

A notch filter

Has zero gain at the critical frequency.

Source

pub fn allpass(&self) -> [T; 6]

An allpass filter

Has constant gain at all frequency but a variable phase shift.

Source

pub fn peaking(&self) -> [T; 6]

A peaking/dip filter

Has gain*shelf_gain at critical frequency and gain elsewhere.

Source

pub fn lowshelf(&self) -> [T; 6]

Low shelf

Approaches gain*shelf_gain below critical frequency and gain above.

use idsp::iir::*;
let ba = Filter::default()
    .frequency(1000.0, 48e3)
    .shelf_slope(2.0)
    .shelf_db(20.0)
    .lowshelf();
println!("{ba:?}");
Source

pub fn highshelf(&self) -> [T; 6]

Low shelf

Approaches gain*shelf_gain above critical frequency and gain below.

Source

pub fn iho(&self) -> [T; 6]

I/HO

Notch, integrating below, flat shelf_gain above

Trait Implementations§

Source§

impl<T: Clone> Clone for Filter<T>

Source§

fn clone(&self) -> Filter<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Filter<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Float + FloatConst> Default for Filter<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, T> Deserialize<'de> for Filter<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: PartialEq> PartialEq for Filter<T>

Source§

fn eq(&self, other: &Filter<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for Filter<T>

Source§

fn partial_cmp(&self, other: &Filter<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Serialize for Filter<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: Copy> Copy for Filter<T>

Source§

impl<T> StructuralPartialEq for Filter<T>

Auto Trait Implementations§

§

impl<T> Freeze for Filter<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Filter<T>
where T: RefUnwindSafe,

§

impl<T> Send for Filter<T>
where T: Send,

§

impl<T> Sync for Filter<T>
where T: Sync,

§

impl<T> Unpin for Filter<T>
where T: Unpin,

§

impl<T> UnwindSafe for Filter<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,