mirror of
https://github.com/RustAudio/rodio
synced 2024-11-10 06:04:16 +00:00
added q value parameter to be passed to filter functions (#515)
I have added a 2nd parameter to the filter functions low_pass, high_pass, to_low_pass, and to_high pass; allowing a q value to be passed along with the frequency. Co-authored-by: David Kleingeld <git@davidsk.dev>
This commit is contained in:
parent
eda5934a20
commit
98bae98d05
2 changed files with 53 additions and 6 deletions
|
@ -7,12 +7,27 @@ use crate::Source;
|
|||
|
||||
/// Internal function that builds a `BltFilter` object.
|
||||
pub fn low_pass<I>(input: I, freq: u32) -> BltFilter<I>
|
||||
where
|
||||
I: Source<Item = f32>,
|
||||
{
|
||||
low_pass_with_q(input, freq, 0.5)
|
||||
}
|
||||
|
||||
pub fn high_pass<I>(input: I, freq: u32) -> BltFilter<I>
|
||||
where
|
||||
I: Source<Item = f32>,
|
||||
{
|
||||
high_pass_with_q(input, freq, 0.5)
|
||||
}
|
||||
|
||||
/// Same as low_pass but allows the q value (bandwidth) to be changed
|
||||
pub fn low_pass_with_q<I>(input: I, freq: u32, q: f32) -> BltFilter<I>
|
||||
where
|
||||
I: Source<Item = f32>,
|
||||
{
|
||||
BltFilter {
|
||||
input,
|
||||
formula: BltFormula::LowPass { freq, q: 0.5 },
|
||||
formula: BltFormula::LowPass { freq, q },
|
||||
applier: None,
|
||||
x_n1: 0.0,
|
||||
x_n2: 0.0,
|
||||
|
@ -21,13 +36,14 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn high_pass<I>(input: I, freq: u32) -> BltFilter<I>
|
||||
/// Same as high_pass but allows the q value (bandwidth) to be changed
|
||||
pub fn high_pass_with_q<I>(input: I, freq: u32, q: f32) -> BltFilter<I>
|
||||
where
|
||||
I: Source<Item = f32>,
|
||||
{
|
||||
BltFilter {
|
||||
input,
|
||||
formula: BltFormula::HighPass { freq, q: 0.5 },
|
||||
formula: BltFormula::HighPass { freq, q },
|
||||
applier: None,
|
||||
x_n1: 0.0,
|
||||
x_n2: 0.0,
|
||||
|
@ -50,13 +66,23 @@ pub struct BltFilter<I> {
|
|||
impl<I> BltFilter<I> {
|
||||
/// Modifies this filter so that it becomes a low-pass filter.
|
||||
pub fn to_low_pass(&mut self, freq: u32) {
|
||||
self.formula = BltFormula::LowPass { freq, q: 0.5 };
|
||||
self.applier = None;
|
||||
self.to_low_pass_with_q(freq, 0.5);
|
||||
}
|
||||
|
||||
/// Modifies this filter so that it becomes a high-pass filter
|
||||
pub fn to_high_pass(&mut self, freq: u32) {
|
||||
self.formula = BltFormula::HighPass { freq, q: 0.5 };
|
||||
self.to_high_pass_with_q(freq, 0.5);
|
||||
}
|
||||
|
||||
/// Same as to_low_pass but allows the q value (bandwidth) to be changed
|
||||
pub fn to_low_pass_with_q(&mut self, freq: u32, q: f32) {
|
||||
self.formula = BltFormula::LowPass { freq, q };
|
||||
self.applier = None;
|
||||
}
|
||||
|
||||
/// Same as to_high_pass but allows the q value (bandwidth) to be changed
|
||||
pub fn to_high_pass_with_q(&mut self, freq: u32, q: f32) {
|
||||
self.formula = BltFormula::HighPass { freq, q };
|
||||
self.applier = None;
|
||||
}
|
||||
|
||||
|
|
|
@ -343,6 +343,7 @@ where
|
|||
blt::low_pass(self, freq)
|
||||
}
|
||||
|
||||
/// Applies a high-pass filter to the source.
|
||||
#[inline]
|
||||
fn high_pass(self, freq: u32) -> BltFilter<Self>
|
||||
where
|
||||
|
@ -351,6 +352,26 @@ where
|
|||
{
|
||||
blt::high_pass(self, freq)
|
||||
}
|
||||
|
||||
/// Applies a low-pass filter to the source while allowing the q (badnwidth) to be changed.
|
||||
#[inline]
|
||||
fn low_pass_with_q(self, freq: u32, q: f32) -> BltFilter<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
Self: Source<Item = f32>,
|
||||
{
|
||||
blt::low_pass_with_q(self, freq, q)
|
||||
}
|
||||
|
||||
/// Applies a high-pass filter to the source while allowing the q (badnwidth) to be changed.
|
||||
#[inline]
|
||||
fn high_pass_with_q(self, freq: u32, q: f32) -> BltFilter<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
Self: Source<Item = f32>,
|
||||
{
|
||||
blt::high_pass_with_q(self, freq, q)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Source for Box<dyn Source<Item = S>>
|
||||
|
|
Loading…
Reference in a new issue