1
/*******************************************/
4
by Perry R. Cook, 1995-96.
5
Added methods by Julius Smith, 2000.
7
The parameter gain is an additional
8
gain parameter applied to the filter
9
on top of the normalization that takes
10
place automatically. So the net max
11
gain through the system equals the
12
value of gain. sgain is the combina-
13
tion of gain and the normalization
14
parameter, so if you set the poleCoeff
15
to alpha, sgain is always set to
16
gain * (1.0 - fabs(alpha)).
18
/*******************************************/
22
OnePole :: OnePole() : Filter()
24
poleCoeff = (MY_FLOAT) 0.9;
25
gain = (MY_FLOAT) 1.0;
26
sgain = (MY_FLOAT) 0.1;
27
outputs = (MY_FLOAT *) malloc(sizeof(MY_FLOAT));
28
outputs[0] = (MY_FLOAT) 0.0;
29
lastOutput = (MY_FLOAT) 0.0;
32
OnePole :: OnePole(MY_FLOAT thePole) : Filter()
35
gain = (MY_FLOAT) 1.0;
36
sgain = (MY_FLOAT) 1.0 - fabs(thePole);
37
outputs = (MY_FLOAT *) malloc(sizeof(MY_FLOAT));
38
outputs[0] = (MY_FLOAT) 0.0;
39
lastOutput = (MY_FLOAT) 0.0;
47
void OnePole :: clear()
49
outputs[0] = (MY_FLOAT) 0.0;
50
lastOutput = (MY_FLOAT) 0.0;
53
void OnePole :: setB0(MY_FLOAT aValue)
58
void OnePole :: setNum(MY_FLOAT *values)
63
void OnePole :: setA1(MY_FLOAT aValue)
68
void OnePole :: setDen(MY_FLOAT *values)
70
poleCoeff = -values[0];
73
void OnePole :: setPole(MY_FLOAT aValue)
76
// Normalize gain to 1.0 max
77
if (poleCoeff > (MY_FLOAT) 0.0)
78
sgain = gain * ((MY_FLOAT) 1.0 - poleCoeff);
80
sgain = gain * ((MY_FLOAT) 1.0 + poleCoeff);
83
void OnePole :: setGain(MY_FLOAT aValue)
87
// Normalize gain to 1.0 max
88
if (poleCoeff > (MY_FLOAT) 0.0)
89
sgain = gain * ((MY_FLOAT) 1.0 - poleCoeff);
91
sgain = gain * ((MY_FLOAT) 1.0 + poleCoeff);
94
// Perform Filter Operation
95
MY_FLOAT OnePole :: tick(MY_FLOAT sample)
97
outputs[0] = (sgain * sample) + (poleCoeff * outputs[0]);
98
lastOutput = outputs[0];