1
/*******************************************/
2
/* Sweepable Formant (2-pole) */
3
/* Filter Class, by Perry R. Cook, 1995-96*/
4
/* See books on filters to understand */
5
/* more about how this works. This drives*/
6
/* to a target at speed set by rate. */
7
/*******************************************/
11
FormSwep :: FormSwep() : 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;
17
freq = (MY_FLOAT) 0.0;
18
reson = (MY_FLOAT) 0.0;
19
currentGain = (MY_FLOAT) 1.0;
20
currentFreq = (MY_FLOAT) 0.0;
21
currentReson = (MY_FLOAT) 0.0;
22
targetGain = (MY_FLOAT) 1.0;
23
targetFreq = (MY_FLOAT) 0.0;
24
targetReson = (MY_FLOAT) 0.0;
25
deltaGain = (MY_FLOAT) 0.0;
26
deltaFreq = (MY_FLOAT) 0.0;
27
deltaReson = (MY_FLOAT) 0.0;
28
sweepState = (MY_FLOAT) 0.0;
29
sweepRate = (MY_FLOAT) 0.002;
34
FormSwep :: ~FormSwep()
39
void FormSwep :: clear()
41
outputs[0] = (MY_FLOAT) 0.0;
42
outputs[1] = (MY_FLOAT) 0.0;
45
void FormSwep :: setPoleCoeffs(MY_FLOAT *coeffs)
48
poleCoeffs[0] = coeffs[0];
49
poleCoeffs[1] = coeffs[1];
52
void FormSwep :: setFreqAndReson(MY_FLOAT aFreq, MY_FLOAT aReson)
57
currentReson = aReson;
59
poleCoeffs[1] = - (reson * reson);
60
poleCoeffs[0] = (MY_FLOAT) 2.0 * reson * (MY_FLOAT) cos(TWO_PI * freq / SRATE);
63
void FormSwep :: setStates(MY_FLOAT aFreq, MY_FLOAT aReson, MY_FLOAT aGain)
73
currentReson = aReson;
77
void FormSwep :: setTargets(MY_FLOAT aFreq, MY_FLOAT aReson, MY_FLOAT aGain)
83
deltaFreq = aFreq - currentFreq;
84
deltaReson = aReson - currentReson;
85
deltaGain = aGain - currentGain;
86
sweepState = (MY_FLOAT) 0.0;
89
void FormSwep :: setSweepRate(MY_FLOAT aRate)
94
void FormSwep :: setSweepTime(MY_FLOAT aTime)
96
sweepRate = ONE_OVER_SRATE / aTime;
99
void FormSwep :: setGain(MY_FLOAT aValue)
104
MY_FLOAT FormSwep :: tick(MY_FLOAT sample) // Perform Filter Operation
109
sweepState += sweepRate;
110
if (sweepState>= 1.0) {
111
sweepState = (MY_FLOAT) 1.0;
113
currentReson = targetReson;
115
currentFreq = targetFreq;
117
currentGain = targetGain;
121
currentReson = reson + (deltaReson * sweepState);
122
currentFreq = freq + (deltaFreq * sweepState);
123
currentGain = gain + (deltaGain * sweepState);
125
poleCoeffs[1] = - (currentReson * currentReson);
126
poleCoeffs[0] = (MY_FLOAT) 2.0 * currentReson *
127
(MY_FLOAT) cos(TWO_PI * currentFreq / SRATE);
130
temp = currentGain * sample;
131
temp += poleCoeffs[0] * outputs[0];
132
temp += poleCoeffs[1] * outputs[1];
133
outputs[1] = outputs[0];
135
lastOutput = outputs[0];