| 1 |
/***************************************************/ |
| 2 |
/*! \class OnePole |
| 3 |
\brief STK one-pole filter class. |
| 4 |
|
| 5 |
This protected Filter subclass implements |
| 6 |
a one-pole digital filter. A method is |
| 7 |
provided for setting the pole position along |
| 8 |
the real axis of the z-plane while maintaining |
| 9 |
a constant peak filter gain. |
| 10 |
|
| 11 |
by Perry R. Cook and Gary P. Scavone, 1995 - 2005. |
| 12 |
*/ |
| 13 |
/***************************************************/ |
| 14 |
|
| 15 |
#include "OnePole.h" |
| 16 |
|
| 17 |
using namespace Nyq; |
| 18 |
|
| 19 |
OnePole :: OnePole() : Filter() |
| 20 |
{ |
| 21 |
std::vector<StkFloat> b(1, 0.1); |
| 22 |
std::vector<StkFloat> a(2, 1.0); |
| 23 |
a[1] = -0.9; |
| 24 |
Filter::setCoefficients( b, a ); |
| 25 |
} |
| 26 |
|
| 27 |
OnePole :: OnePole(StkFloat thePole) : Filter() |
| 28 |
{ |
| 29 |
std::vector<StkFloat> b(1); |
| 30 |
std::vector<StkFloat> a(2, 1.0); |
| 31 |
a[1] = -thePole; |
| 32 |
|
| 33 |
// Normalize coefficients for peak unity gain. |
| 34 |
if (thePole > 0.0) |
| 35 |
b[0] = (StkFloat) (1.0 - thePole); |
| 36 |
else |
| 37 |
b[0] = (StkFloat) (1.0 + thePole); |
| 38 |
|
| 39 |
Filter::setCoefficients( b, a ); |
| 40 |
} |
| 41 |
|
| 42 |
OnePole :: ~OnePole() |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
void OnePole :: clear(void) |
| 47 |
{ |
| 48 |
Filter::clear(); |
| 49 |
} |
| 50 |
|
| 51 |
void OnePole :: setB0(StkFloat b0) |
| 52 |
{ |
| 53 |
b_[0] = b0; |
| 54 |
} |
| 55 |
|
| 56 |
void OnePole :: setA1(StkFloat a1) |
| 57 |
{ |
| 58 |
a_[1] = a1; |
| 59 |
} |
| 60 |
|
| 61 |
void OnePole :: setPole(StkFloat thePole) |
| 62 |
{ |
| 63 |
// Normalize coefficients for peak unity gain. |
| 64 |
if (thePole > 0.0) |
| 65 |
b_[0] = (StkFloat) (1.0 - thePole); |
| 66 |
else |
| 67 |
b_[0] = (StkFloat) (1.0 + thePole); |
| 68 |
|
| 69 |
a_[1] = -thePole; |
| 70 |
} |
| 71 |
|
| 72 |
void OnePole :: setGain(StkFloat gain) |
| 73 |
{ |
| 74 |
Filter::setGain(gain); |
| 75 |
} |
| 76 |
|
| 77 |
StkFloat OnePole :: getGain(void) const |
| 78 |
{ |
| 79 |
return Filter::getGain(); |
| 80 |
} |
| 81 |
|
| 82 |
StkFloat OnePole :: lastOut(void) const |
| 83 |
{ |
| 84 |
return Filter::lastOut(); |
| 85 |
} |
| 86 |
|
| 87 |
StkFloat OnePole :: tick( StkFloat input ) |
| 88 |
{ |
| 89 |
inputs_[0] = gain_ * input; |
| 90 |
outputs_[0] = b_[0] * inputs_[0] - a_[1] * outputs_[1]; |
| 91 |
outputs_[1] = outputs_[0]; |
| 92 |
|
| 93 |
return outputs_[0]; |
| 94 |
} |
| 95 |
|
| 96 |
StkFrames& OnePole :: tick( StkFrames& frames, unsigned int channel ) |
| 97 |
{ |
| 98 |
return Filter::tick( frames, channel ); |
| 99 |
} |