From 51496ffd5d19ee6c96cef56721a85e57bededb70 Mon Sep 17 00:00:00 2001 From: stephenhensley Date: Mon, 12 Jun 2023 10:19:49 -0700 Subject: [PATCH] updated indentations, etc. for style. --- Source/Filters/soap.cpp | 54 +++++++++++++++++++------------------ Source/Filters/soap.h | 59 +++++++++++++++++++---------------------- 2 files changed, 56 insertions(+), 57 deletions(-) diff --git a/Source/Filters/soap.cpp b/Source/Filters/soap.cpp index 4a21c97d..65f7a814 100644 --- a/Source/Filters/soap.cpp +++ b/Source/Filters/soap.cpp @@ -5,48 +5,49 @@ void Soap::Init(float sample_rate) { - soap_center_freq_ = 400.0; - soap_bandwidth_ = 50.0; - in_0_ = 0.0; // input x0 - din_1_ = 0.0; // delayed input x1 - din_2_ = 0.0; // delayed input x2 - dout_1_ = 0.0; // delayed output y1 - dout_2_ = 0.0; // delayed output y2 - all_output_ = 0.0; // all pass output y0 - out_bandpass_ = 0.0; // bandpass output - out_bandreject_ = 0.0; // bandreject output - sr_ = sample_rate; + soap_center_freq_ = 400.0; + soap_bandwidth_ = 50.0; + in_0_ = 0.0; // input x0 + din_1_ = 0.0; // delayed input x1 + din_2_ = 0.0; // delayed input x2 + dout_1_ = 0.0; // delayed output y1 + dout_2_ = 0.0; // delayed output y2 + all_output_ = 0.0; // all pass output y0 + out_bandpass_ = 0.0; // bandpass output + out_bandreject_ = 0.0; // bandreject output + sr_ = sample_rate; return; } void Soap::Process(float in) { // recalculate the coefficients, later move this to a lookup table - float d = -std::cos(2.0 * PI * (soap_center_freq_/sr_)); - + float d = -std::cos(2.0 * PI * (soap_center_freq_ / sr_)); + // tangent bandwidth - float tf = std::tan(PI * (soap_bandwidth_/sr_)); + float tf = std::tan(PI * (soap_bandwidth_ / sr_)); + + // coefficient + float c = (tf - 1.0) / (tf + 1.0); - // coefficient - float c = (tf - 1.0)/(tf + 1.0); + in_0_ = in; - in_0_ = in; - - all_output_ = -c*in_0_ + (d - d*c)*din_1_ + din_2_ - (d - d*c)*dout_1_ + c*dout_2_; + all_output_ = -c * in_0_ + (d - d * c) * din_1_ + din_2_ + - (d - d * c) * dout_1_ + c * dout_2_; // move samples in delay for next sample - din_2_ = din_1_; - din_1_ = in_0_; + din_2_ = din_1_; + din_1_ = in_0_; dout_2_ = dout_1_; dout_1_ = all_output_; // make factor -1.0 to create a bandpass - out_bandpass_ = (in_0_ + all_output_ * -1.0) * 0.5; + out_bandpass_ = (in_0_ + all_output_ * -1.0) * 0.5; - // make factor +1.0 to create a bandreject - out_bandreject_ = (in_0_ + all_output_ * 0.99) * 0.5; + // make factor +1.0 to create a bandreject + out_bandreject_ = (in_0_ + all_output_ * 0.99) * 0.5; - return; + return; } void Soap::SetCenterFreq(float f) @@ -55,7 +56,8 @@ void Soap::SetCenterFreq(float f) return; } -void Soap::SetFilterBandwidth(float b) { +void Soap::SetFilterBandwidth(float b) +{ soap_bandwidth_ = b; return; } \ No newline at end of file diff --git a/Source/Filters/soap.h b/Source/Filters/soap.h index e92b9548..1f72cbcf 100644 --- a/Source/Filters/soap.h +++ b/Source/Filters/soap.h @@ -9,53 +9,50 @@ Ported by: Brian Tice */ class Soap { + public: + Soap() {} + ~Soap() {} - public: - Soap() {} - ~Soap() {} - - /** Initializes the filter + /** Initializes the filter float sample_rate - sample rate of the audio engine being run, and the frequency that the Process function will be called. */ - void Init(float sample_rate); + void Init(float sample_rate); - /** + /** Process the input signal, updating all of the outputs */ - void Process(float in); + void Process(float in); - /** + /** Sets the center frequency of the filter. */ - void SetCenterFreq(float f); + void SetCenterFreq(float f); - /** + /** Sets the low frequency threshold of the filter. */ - void SetFilterBandwidth(float b); + void SetFilterBandwidth(float b); - /** Bandpass output + /** Bandpass output \return bandpass output of the filter */ - inline float Bandpass() { return out_bandpass_; } + inline float Bandpass() { return out_bandpass_; } - /** Bandreject output + /** Bandreject output \return bandreject output of the filter */ - inline float Bandreject() { return out_bandreject_; } - - private: - float soap_center_freq_; - float soap_bandwidth_; - float in_0_; - float din_1_; - float din_2_; - float dout_1_; - float dout_2_; - float all_output_; - float out_bandpass_; - float out_bandreject_; - float sr_; - - + inline float Bandreject() { return out_bandreject_; } + + private: + float soap_center_freq_; + float soap_bandwidth_; + float in_0_; + float din_1_; + float din_2_; + float dout_1_; + float dout_2_; + float all_output_; + float out_bandpass_; + float out_bandreject_; + float sr_; }; \ No newline at end of file