-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Second Order All Pass Filter called Soap (#182)
* Update CMakeLists.txt and Makefile Update CMakeLists.txt and Makefile to include soap filter * update daisysp.h to include soap update daisysp.h to include soap * add soap filter add soap filter * update to cmath, floats, add output options change to <cmath> instead of math.h for trig functions. replaced doubles with floats for speed. added bandpass and bandreject output modes similar to svf filter
- Loading branch information
Showing
5 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,8 @@ mode \ | |
moogladder \ | ||
nlfilt \ | ||
svf \ | ||
tone | ||
tone \ | ||
soap | ||
#fir | ||
|
||
NOISE_MOD_DIR = Noise | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "soap.h" | ||
#include <cmath> | ||
|
||
#define PI 3.141592653589793 | ||
|
||
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; | ||
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_)); | ||
|
||
// tangent bandwidth | ||
float tf = std::tan(PI * (soap_bandwidth_/sr_)); | ||
|
||
// coefficient | ||
float c = (tf - 1.0)/(tf + 1.0); | ||
|
||
in_0_ = in; | ||
|
||
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_; | ||
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; | ||
|
||
// make factor +1.0 to create a bandreject | ||
out_bandreject_ = (in_0_ + all_output_ * 0.99) * 0.5; | ||
|
||
return; | ||
} | ||
|
||
void Soap::SetCenterFreq(float f) | ||
{ | ||
soap_center_freq_ = f; | ||
return; | ||
} | ||
|
||
void Soap::SetFilterBandwidth(float b) { | ||
soap_bandwidth_ = b; | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#pragma once | ||
|
||
/** Second Order All Pass Filter | ||
This is from Tom Erbe's synth notes. The filter | ||
can be configured to be a band pass or band reject | ||
Ported by: Brian Tice | ||
*/ | ||
class Soap | ||
{ | ||
|
||
public: | ||
Soap() {} | ||
~Soap() {} | ||
|
||
/** 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); | ||
|
||
/** | ||
Process the input signal, updating all of the outputs | ||
*/ | ||
void Process(float in); | ||
|
||
/** | ||
Sets the center frequency of the filter. | ||
*/ | ||
void SetCenterFreq(float f); | ||
|
||
/** | ||
Sets the low frequency threshold of the filter. | ||
*/ | ||
void SetFilterBandwidth(float b); | ||
|
||
/** Bandpass output | ||
\return bandpass output of the filter | ||
*/ | ||
inline float Bandpass() { return out_bandpass_; } | ||
|
||
/** 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_; | ||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters