ddf.minim.effects
Class IIRFilter

java.lang.Object
  extended by ddf.minim.ugens.UGen
      extended by ddf.minim.effects.IIRFilter
All Implemented Interfaces:
AudioEffect
Direct Known Subclasses:
BandPass, ChebFilter, HighPassSP, LowPassFS, LowPassSP, NotchFilter

public abstract class IIRFilter
extends UGen
implements AudioEffect

An Infinite Impulse Response, or IIR, filter is a filter that uses a set of coefficients and previous filtered values to filter a stream of audio. It is an efficient way to do digital filtering. IIRFilter is a general IIRFilter that simply applies the filter designated by the filter coefficients so that sub-classes only have to dictate what the values of those coefficients are by defining the calcCoeff() function. When filling the coefficient arrays, be aware that b[0] corresponds to b1.

Author:
Damien Di Fede

Nested Class Summary
 
Nested classes/interfaces inherited from class ddf.minim.ugens.UGen
UGen.InputType, UGen.UGenInput
 
Field Summary
protected  float[] a
          The a coefficients.
 UGen.UGenInput audio
           
protected  float[] b
          The b coefficients.
 UGen.UGenInput cutoff
           
 
Constructor Summary
IIRFilter(float freq, float sampleRate)
          Constructs an IIRFilter with the given cutoff frequency that will be used to filter audio recorded at sampleRate.
 
Method Summary
protected abstract  void calcCoeff()
          Calculates the coefficients of the filter using the current cutoff frequency.
 float frequency()
          Returns the cutoff frequency (in Hz).
protected  void initArrays(int numChannels)
          Initializes the in and out arrays based on the number of coefficients being used.
 void printCoeff()
          Prints the current values of the coefficients to the console.
 void process(float[] signal)
          Processes signal in some way.
 void process(float[] sigLeft, float[] sigRight)
          Processes sigLeft and sigRight in some way.
 void setFreq(float f)
          Sets the cutoff/center frequency of the filter.
 void uGenerate(float[] channels)
          Implement this method when you extend UGen.
 boolean validFreq(float f)
          Returns true if the frequency is valid for this filter.
 
Methods inherited from class ddf.minim.ugens.UGen
addInput, getLastValues, patch, patch, patch, printInputs, removeInput, sampleRate, sampleRateChanged, setSampleRate, tick, unpatch, unpatch
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

audio

public final UGen.UGenInput audio

cutoff

public final UGen.UGenInput cutoff

a

protected float[] a
The a coefficients.


b

protected float[] b
The b coefficients.

Constructor Detail

IIRFilter

public IIRFilter(float freq,
                 float sampleRate)
Constructs an IIRFilter with the given cutoff frequency that will be used to filter audio recorded at sampleRate.

Parameters:
freq - the cutoff frequency
sampleRate - the sample rate of audio to be filtered
Method Detail

initArrays

protected final void initArrays(int numChannels)
Initializes the in and out arrays based on the number of coefficients being used.


uGenerate

public final void uGenerate(float[] channels)
Description copied from class: UGen
Implement this method when you extend UGen. It will be called when your UGen needs to generate one sample frame of audio. It is expected that you will assign values to the array and not simply modify the existing values. In the case where you write a UGen that takes audio input and modifies it, the pattern to follow is to have the first UGenInput you create be your audio input and then in uGenerate you will use the getLastValues method of your audio UGenInput to retrieve the audio you want to modify, which you will then modify however you need to, assigning the result to the values in channels.

Specified by:
uGenerate in class UGen
Parameters:
channels - an array representing one sample frame.

process

public final void process(float[] signal)
Description copied from interface: AudioEffect
Processes signal in some way.

Specified by:
process in interface AudioEffect
Parameters:
signal - an array of audio samples, representing a mono sound stream.

process

public final void process(float[] sigLeft,
                          float[] sigRight)
Description copied from interface: AudioEffect
Processes sigLeft and sigRight in some way.

Specified by:
process in interface AudioEffect
Parameters:
sigLeft - an array of audio samples, representing the left channel of a stereo sound stream
sigRight - an array of audio samples, representing the right channel of a stereo sound stream

setFreq

public final void setFreq(float f)
Sets the cutoff/center frequency of the filter. Doing this causes the coefficients to be recalculated.

Parameters:
f - the new cutoff/center frequency (in Hz).

validFreq

public boolean validFreq(float f)
Returns true if the frequency is valid for this filter. Subclasses can override this method if they want to limit center frequencies to certain ranges to avoid becoming unstable. The default implementation simply makes sure that f is positive.

Parameters:
f - the frequency (in Hz) to validate
Returns:
true if f is a valid frequency for this filter

frequency

public final float frequency()
Returns the cutoff frequency (in Hz).

Returns:
the current cutoff frequency (in Hz).

calcCoeff

protected abstract void calcCoeff()
Calculates the coefficients of the filter using the current cutoff frequency. To make your own IIRFilters, you must extend IIRFilter and implement this function. The frequency is expressed as a fraction of the sample rate. When filling the coefficient arrays, be aware that b[0] corresponds to the coefficient b1.


printCoeff

public final void printCoeff()
Prints the current values of the coefficients to the console.