an open-source digital signal processing and sound synthesis language
about · links · contact


INSTRUMENT design -- multi-purpose equalizer (filter) object

The Oequalizer object uses a biquad filter 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 Audio-EQ-Cookbook.

The older functions reson and resonz do similar signal-processing actions, but using different and somewhat less flexible algorithms. For very simple filtering, the Oonepole object may be more appropriate.


    Oequalizer(float SR, OeqType filter_type)

    SR is the current sampling rate (an Instrument class variable).
    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

Access Methods

    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 more).
    gain [optional] sets the amount of boost or cut (positive or negative dB) for the peaking and shelf-type filters.

    void Oequalizer::clear()

    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).

    float Oequalizer::last()

    returns the last (previous) output of the Oequalizer filter.


    #include <Ougens.h>
    Oequalizer *theFilt;
    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
    int MYINSTRUMENT::run()
    	float out[2];
    	float sample;
    	for (i = 0; i < framesToRun(); i++)
    		sample = someSampleGeneratingProcess();
    		out[0] = theFilt->next(sample);

See Also