1
/*******************************************/
2
/* Two Pole Filter Class, */
3
/* by Perry R. Cook, 1995-96 */
4
/* See books on filters to understand */
5
/* more about how this works. Nothing */
6
/* out of the ordinary in this version. */
7
/*******************************************/
11
TwoPole :: TwoPole() : Filter()
13
outputs = (MY_FLOAT *) malloc(2 * sizeof(MY_FLOAT));
14
poleCoeffs[0] = (MY_FLOAT) 0.0;
15
poleCoeffs[1] = (MY_FLOAT) 0.0;
16
gain = (MY_FLOAT) 1.0;
25
void TwoPole :: clear()
27
outputs[0] = (MY_FLOAT) 0.0;
28
outputs[1] = (MY_FLOAT) 0.0;
29
lastOutput = (MY_FLOAT) 0.0;
32
void TwoPole :: setPoleCoeffs(MY_FLOAT *coeffs)
34
poleCoeffs[0] = coeffs[0];
35
poleCoeffs[1] = coeffs[1];
38
void TwoPole :: setFreqAndReson(MY_FLOAT freq, MY_FLOAT reson)
40
poleCoeffs[1] = - (reson * reson);
41
poleCoeffs[0] = (MY_FLOAT) 2.0 * reson * cos(TWO_PI * (double) freq / SRATE);
44
void TwoPole :: setGain(MY_FLOAT aValue)
49
MY_FLOAT TwoPole :: tick(MY_FLOAT sample) // Perform Filter Operation
50
{ // TwoPole is a two pole filter (duh!)
51
MY_FLOAT temp; // Look it up in your favorite DSP text
53
temp += poleCoeffs[0] * outputs[0];
54
temp += poleCoeffs[1] * outputs[1];
55
outputs[1] = outputs[0];
57
lastOutput = outputs[0];