Package toxi.audio

Class IIRFilter

java.lang.Object
toxi.audio.IIRFilter

public class IIRFilter extends Object
This class provides a simple IIR filter implementation with one of lowpass, highpass or bandpass characteristics. The class can filter individual samples or entire signal buffers. The filter function always has this form:
 y = 1 / a0 * (b0 * x0 + b1 * x1 + b2 * x2 - a1 * q1 - a2 * q2)
 
http://en.wikipedia.org/wiki/Infinite_impulse_response
  • Constructor Details

    • IIRFilter

      public IIRFilter(IIRFilter.Type type, float sampleRate)
      Parameters:
      type -
      sampleRate -
  • Method Details

    • calculateAmplitude

      public float calculateAmplitude(float[] in)
      Just calculates the amplitude of the filtered signal, but doesn't actually apply the filter.
      Parameters:
      in -
      Returns:
      amplitude
    • clear

      public IIRFilter clear()
    • filter

      public float filter(float in)
      Applies filter to a single sample value.
      Parameters:
      in -
      Returns:
      filtered sample
    • filter

      public float filter(float[] in)
      Destructively filters a the given signal buffer. The original samples are overwritten.
      Parameters:
      in -
      Returns:
      amplitude of filtered signal
    • getDecay

      public float getDecay()
      Returns:
      the decay
    • init

      public IIRFilter init(float freq, float q)
      Initializes the filter to the given cutoff frequency and Q (resonance) settings. This function needs to be called at least once before the filter can be used.
      Parameters:
      freq -
      q -
      Returns:
      itself
    • setDecay

      public IIRFilter setDecay(float decay)
      Parameters:
      decay - the decay to set
      Returns:
      itself