Oonepole
INSTRUMENT design -- simple one-pole filter object
The Oonepole object instantiates a simple
one-pole IIR filter, based on designs found in
Computer Music: Synthesis, Composition, and Performance
by Charles Dodge and Thomas Jerse and the
Synthesis ToolKit (STK)
authored by Perry Cook and Gary Scavone. The general recursive filter
equation used for this object is:
y[n] = a*x[n] + b*y[n-1]
where y[n] and y[n-1] are the current and previous
outputs of the equation, respectively, and x[n] is the
current input. a and b are the coefficients to
the equation that determine what kind of filter is constructed.
Simple low-pass and high-pass filters are possible with characteristics
depending upon the values of the a and b
coefficients.
The
OonepoleTrack
object does the same thing as Oonepole except that it
'tracks' changes to the state of the filter and only performs
computations if the cutoff frequency or lag time of the filter
has changed. More generally, the older functions
reson
and
resonz
do similar kinds of filtering operations. See also the
Oequalizer
object for filtering capabilities.
Constructors
Access Methods
void Oonepole::setfreq(float freq)
-
sets the cutoff point of the constructed filter to freq.
void Oonepole::setlag(float lag)
-
is an alternative to the setfreq method for use in control-rate
signals. The lag determines how long the filter will
take to travel to the next data point. lag is in the range
[0, 1] and is inversely proportional to the way the cutoff frequency
operates. Values closer to 1 will result in lower cutoff frequencies.
The conversion to filter cutoff frequency is:
-
#define LAGFACTOR 12.0
#define MAXCF 500.0
cutoff = MAXCF * pow(2, -lag * LAGFACTOR);
John Gibson determined the parameters in order to achieve a linear
"feel" to the lag range.
void Oonepole::clear()
-
will reinitialize the filter by setting the 'past history' of this
recursive filter to 0.0.
void Oonepole::setpole(float coefficient)
-
sets the "b" term of the filter equation:
-
y[n] = a*x[n] + b*y[n-1]
to coefficient. The "a" term is set to 1.0 - coefficient
if "b" is greater than 0.0, otherwise it is set to 1.0 + coefficient.
float Oonepole::next(float input)
-
returns the next floating-point sample value from the filter
and places an incoming sample into the
filter (input).
Examples
#include <Ougens.h>
Oonepole *thefilt;
// this instrument has a delay line
int MYINSTRUMENT::init(float p[], int n_args)
{
...
thefilt = new Oonepole(SR, -100.0); // high-pass filter, cutoff at 100.0 Hz
...
}
int MYINSTRUMENT::run()
{
float out[2];
float sample;
...
for (int i = 0; i < framesToRun(); i++)
{
sample = someSampleGeneratingProcess();
out[0] = thefilt->next(sample);
}
...
}
See Also