diff --git a/src/source/blt.rs b/src/source/blt.rs index c5068686..d32b6310 100644 --- a/src/source/blt.rs +++ b/src/source/blt.rs @@ -6,7 +6,37 @@ use crate::Source; // Implemented following http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt /// Internal function that builds a `BltFilter` object. -pub fn low_pass(input: I, freq: u32, q: f32) -> BltFilter +pub fn low_pass(input: I, freq: u32) -> BltFilter +where + I: Source, +{ + BltFilter { + input, + formula: BltFormula::LowPass { freq, q: 0.5 }, + applier: None, + x_n1: 0.0, + x_n2: 0.0, + y_n1: 0.0, + y_n2: 0.0, + } +} + +pub fn high_pass(input: I, freq: u32) -> BltFilter +where + I: Source, +{ + BltFilter { + input, + formula: BltFormula::HighPass { freq, q: 0.5 }, + applier: None, + x_n1: 0.0, + x_n2: 0.0, + y_n1: 0.0, + y_n2: 0.0, + } +} + +pub fn low_pass_with_q(input: I, freq: u32, q: f32) -> BltFilter where I: Source, { @@ -21,7 +51,7 @@ where } } -pub fn high_pass(input: I, freq: u32, q: f32) -> BltFilter +pub fn high_pass_with_q(input: I, freq: u32, q: f32) -> BltFilter where I: Source, { @@ -49,13 +79,24 @@ pub struct BltFilter { impl BltFilter { /// Modifies this filter so that it becomes a low-pass filter. - pub fn to_low_pass(&mut self, freq: u32, q: f32) { + pub fn to_low_pass(&mut self, freq: u32) { + self.formula = BltFormula::LowPass { freq, q: 0.5 }; + self.applier = None; + } + + /// 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.applier = None; + } + + pub fn to_low_pass_with_q(&mut self, freq: u32, q: f32) { self.formula = BltFormula::LowPass { freq, q }; self.applier = None; } /// Modifies this filter so that it becomes a high-pass filter - pub fn to_high_pass(&mut self, freq: u32, q: f32) { + pub fn to_high_pass_with_q(&mut self, freq: u32, q: f32) { self.formula = BltFormula::HighPass { freq, q }; self.applier = None; } diff --git a/src/source/mod.rs b/src/source/mod.rs index dccd4fd5..318cf767 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -335,21 +335,38 @@ where /// Applies a low-pass filter to the source. /// **Warning**: Probably buggy. #[inline] - fn low_pass(self, freq: u32, q: f32) -> BltFilter + fn low_pass(self, freq: u32) -> BltFilter where Self: Sized, Self: Source, { - blt::low_pass(self, freq, q) + blt::low_pass(self, freq) } #[inline] - fn high_pass(self, freq: u32, q: f32) -> BltFilter + fn high_pass(self, freq: u32) -> BltFilter where Self: Sized, Self: Source, { - blt::high_pass(self, freq, q) + blt::high_pass(self, freq) + } + + fn low_pass_with_q(self, freq: u32, q: f32) -> BltFilter + where + Self: Sized, + Self: Source, + { + blt::low_pass_with_q(self, freq, q) + } + + #[inline] + fn high_pass_with_q(self, freq: u32, q: f32) -> BltFilter + where + Self: Sized, + Self: Source, + { + blt::high_pass_with_q(self, freq, q) } }