Skip to content

Commit

Permalink
Merge pull request #186 from electro-smith/quick-style-fix
Browse files Browse the repository at this point in the history
Updated indentations, etc. for style.
  • Loading branch information
stephenhensley committed Jun 12, 2023
2 parents 79b1179 + 51496ff commit 4f9a962
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 57 deletions.
54 changes: 28 additions & 26 deletions Source/Filters/soap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -55,7 +56,8 @@ void Soap::SetCenterFreq(float f)
return;
}

void Soap::SetFilterBandwidth(float b) {
void Soap::SetFilterBandwidth(float b)
{
soap_bandwidth_ = b;
return;
}
59 changes: 28 additions & 31 deletions Source/Filters/soap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
};

0 comments on commit 4f9a962

Please sign in to comment.