INSTRUMENT design -- multi-purpose equalizer (filter) object
The Oequalizer object uses a
algorithm to instantiate a number of different filter types (low-pass,
high-pass, band-pass, etc.). The code was based on work done by
Tom St. Denis,
using formulas for the filter coeeficients from
Robert Bristow-Johnson's on-line document
The older functions
do similar signal-processing actions, but using different and
somewhat less flexible algorithms. For very simple filtering,
object may be more appropriate.
Oequalizer(float SR, OeqType filter_type)
SR is the current sampling rate (an
filter_type is the kind of filter that will be implemented
by the biquad equation. These types are defined in the OeqType
structure found in the RTcmix/genlib/Oequalizer.h file:
- OeqLowPass -- low-pass filter
- OeqHighPass -- high-pass filter
- OeqBandPassCSG -- band-pass filter with "constant skirt gain",
the peak gain will be related to the "Q" of the filter
- OeqBandPassCPG/OeqBandPass -- band-pass filter with "constant peak
gain", the peak gain will be 0 dB
- OeqNotch -- notch filter
- OeqAllPass -- allpass filter
- OeqPeaking -- peaking filter (good for creating "quacking"
sounds; used in... oh, you figure it out :-))
- OeqLowShelf -- low shelf filter
- OeqHighShelf -- high shelf filter
void Oequalizer::settype(OeqType filter_type)
sets the configuration of the biquad filter equation for a particular
kind of filter. See the list of filter_types above in the
constructor. Note that if the type is changed after the Oequalizer
object is constructed and after the setparams method is called,
the filter will 'inherit' coefficients from a different type, which
may or may not produce desirable effects.
void Oequalizer::setparams(float freq, float Q[, float gain])
freq sets the cutoff frequency (in Hz) for low-pass, high-pass,
low-shelf and high-shelf filters. It sets the midpoint of the passband
for band-pass and notch filters.
Q sets the steepness of the rolloff or the narrowness of the
passband of the filter. This number usually ranges from 0.0 to 10.0 (or
gain [optional] sets the amount of boost or cut (positive or
negative dB) for the peaking and shelf-type filters.
will set all filter coefficients to 0.0.
float Oequalizer::next(float input)
returns a floating-point sample value from the
biquad filter and places an incoming sample into the
filter equation (input).
returns the last (previous) output of the Oequalizer filter.
int MYINSTRUMENT::init(float p, int n_args)
theFilt = new Oequalizer(SR, OeqBandPass);
theFilt->setparams(700.0, 2.0); // 700 Hz midpoint, "Q" of 2.0
for (i = 0; i < framesToRun(); i++)
sample = someSampleGeneratingProcess();
out = theFilt->next(sample);