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

Oreson

INSTRUMENT design -- simple first-order IIR filter object

Oreson duplicates the functionality of the older CMIX functions reson and rsnset. It builds a simple IIR filter given a desired center frequency and bandwidth, very useful in parallel for building complicated filter response curves (see the IIR instrument for an example of Oreson use).

The general recursive filter equation used by this object is:

y[n] = a*x[n] + b0*y[n-1] - b1*y[n-2]
where y[n], y[n-1] and y[n-2] are the current and two previous outputs of the equation, and x[n] is the current input. a, b0 and b1 are the coefficients to the equation that determine the characteristics of the filter, depending upon the parameters set in the constructor. Presently the Oreson filter object does not allow for dynamic changes to the filter equation.

Constructors

    Oreson(float SR, float centerFreq, float bandwidth[, Scale scaling])

    SR is the current sampling rate (an Instrument class variable).
    centerFreq is the center frequency of the bandpass filter constructed.
    bandwidth is the distance in Hz between the half-power points of the passband centered around the centerFreq.
    scaling is an optional parameter to set how the filter normalizes the filter equation. The flags for this parameter are defined in RTcmix/genlib/Oreson.h as:
       typedef enum {
          kNoScale = 0,  // no scaling of signal
          kPeakResponse, // peak response factor of 1; use for harmonic signals
          kRMSResponse   // RMS response factor of 1; use for white noise signals
       } Scale;
    
    The default value used is kPeakResponse.



Access Methods

    void Oreson::clear()

    sets all delayed signals in the filter to 0.0.


    float Oreson::next(float sig)

    enters the incoming sample value into the filter equation, computes the equation and then returns the next filtered sample value as output.


    float Oreson::last()

    returns the current output of the filter without computing the equation.


Examples

    #include <Ougens.h>
    
    Oreson *thefilt;
    
    int MYINSTRUMENT::init(float p[], int n_args)
    {
    
    	...
    
    	// center freq at 478 Hz, 14-Hz wide bandwdith
    	thefilt = new Oreson(SR, 478.0, 14.0);
    
    	...
    
    }
    
    int MYINSTRUMENT::run()
    {
    	float out[2];
    	float sample;
    
    	...
    
    	for (int i = 0; i < framesToRun(); i++)
    	{
    		sample = someSampleGeneratingProcess();
    		out[0] = thefilt->next(sample);
    	}
    
    	...
    
    }
    


See Also