pub struct Filter<T> { /* private fields */ }
Expand description
Standard audio biquad filter builder
Implementations§
Source§impl<T> Filter<T>
impl<T> Filter<T>
Sourcepub fn frequency(
&mut self,
critical_frequency: T,
sample_frequency: T,
) -> &mut Self
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 assample_frequency
sample_frequency
: The sample frequency in the same units ascritical_frequency
. E.g. both in SI Hertz orrad/s
.
Sourcepub fn critical_frequency(&mut self, f0: T) -> &mut Self
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 be0 <= f0 <= 0.5
.
Sourcepub fn angular_critical_frequency(&mut self, w0: T) -> &mut Self
pub fn angular_critical_frequency(&mut self, w0: T) -> &mut Self
Set relative critical angular frequency
§Arguments
w0
: Relative critical angular frequency. Must be0 <= w0 <= π
. Defaults to0.0
.
Sourcepub fn shelf(&mut self, a: T) -> &mut Self
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 to1.0
.
Sourcepub fn shelf_db(&mut self, a_db: T) -> &mut Self
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 to0.0
.
Sourcepub fn inverse_q(&mut self, qi: T) -> &mut Self
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.
Sourcepub fn q(&mut self, q: T) -> &mut Self
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.
Sourcepub fn bandwidth(&mut self, bw: T) -> &mut Self
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
Sourcepub fn shelf_slope(&mut self, s: T) -> &mut Self
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 of1.0
is maximally steep without overshoot.
Sourcepub fn lowpass(&self) -> [T; 6]
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]);
Sourcepub fn highpass(&self) -> [T; 6]
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]);
Sourcepub fn bandpass(&self) -> [T; 6]
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:?}");
Sourcepub fn allpass(&self) -> [T; 6]
pub fn allpass(&self) -> [T; 6]
An allpass filter
Has constant gain
at all frequency but a variable phase shift.
Sourcepub fn peaking(&self) -> [T; 6]
pub fn peaking(&self) -> [T; 6]
A peaking/dip filter
Has gain*shelf_gain
at critical frequency and gain
elsewhere.
Sourcepub fn lowshelf(&self) -> [T; 6]
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:?}");