net.beadsproject.beads.ugens
Class LPRezFilter

java.lang.Object
  extended by net.beadsproject.beads.core.Bead
      extended by net.beadsproject.beads.core.UGen
          extended by net.beadsproject.beads.ugens.IIRFilter
              extended by net.beadsproject.beads.ugens.LPRezFilter
All Implemented Interfaces:
DataBeadReceiver

public class LPRezFilter
extends IIRFilter
implements DataBeadReceiver

A simple 2nd-order resonant low-pass filter optimized for single-channel processing. Faster than a BiquadFilter because its algorithm is of the form:

y(n) = b0 * x(n) + a1 * y(n-1) + a2 * y(n-2)

so it doesn't compute unnecessary parts of the biquad formula.

Takes two parameters: cut-off frequency and resonance (0 for no resonance, 1 for maximum resonance). These parameters can be set using setFreq() and setRes(), or by passing a DataBead with "frequency" and "resonance" properties to setParams(DataBead). (Messaging this object with a DataBead achieves the same.)

Version:
0.9.5
Author:
Benito Crawford

Nested Class Summary
 
Nested classes/interfaces inherited from class net.beadsproject.beads.ugens.IIRFilter
IIRFilter.IIRFilterAnalysis
 
Nested classes/interfaces inherited from class net.beadsproject.beads.core.UGen
UGen.OutputInitializationRegime, UGen.OutputPauseRegime
 
Field Summary
protected  float _2pi_over_sr
           
protected  float a1
           
protected  float a2
           
protected  float b0
           
protected  float cosw
           
protected  float freq
           
protected  UGen freqUGen
           
protected  boolean isFreqStatic
           
protected  boolean isResStatic
           
protected  float res
           
protected  UGen resUGen
           
 
Fields inherited from class net.beadsproject.beads.core.UGen
bufferSize, bufIn, bufOut, context, ins, outputInitializationRegime, outputPauseRegime, outs
 
Constructor Summary
LPRezFilter(AudioContext con)
          Constructor for a single-channel LPRezFilter with default values for frequency and resonance.
LPRezFilter(AudioContext con, float freq, float res)
          Constructor for a single-channel LPRezFilter with frequency and resonance specified by floats.
LPRezFilter(AudioContext con, float freq, UGen res)
          Constructor for a single-channel LPRezFilter with frequency specified by a float and resonance specified by a UGen.
LPRezFilter(AudioContext con, int channels)
          Constructor for a multi-channel LPRezFilter with default values for frequency and resonance.
LPRezFilter(AudioContext con, int channels, float freq, float res)
          Constructor for a multi-channel LPRezFilter with frequency and resonance specified by floats.
LPRezFilter(AudioContext con, int channels, float freq, UGen res)
          Constructor for a multi-channel LPRezFilter with frequency specified by a float and resonance specified by a UGen.
LPRezFilter(AudioContext con, int channels, UGen freq, float res)
          Constructor for a multi-channel LPRezFilter with frequency specified by a UGen and resonance specified by a float.
LPRezFilter(AudioContext con, int channels, UGen freq, UGen res)
          Constructor for a multi-channel LPRezFilter with frequency and resonance specified by UGens.
LPRezFilter(AudioContext con, UGen freq, float res)
          Constructor for a single-channel LPRezFilter with frequency specified by a UGen and resonance specified by a float.
LPRezFilter(AudioContext con, UGen freq, UGen res)
          Constructor for a single-channel LPRezFilter with frequency and resonance specified by UGens.
 
Method Summary
 void calculateBuffer()
          Called by the signal chain to update this UGen's ouput data.
protected  void calcVals()
           
 IIRFilter.IIRFilterAnalysis getFilterResponse(float freq)
           
 float getFreq()
          Deprecated. Use getFrequency().
 float getFrequency()
          Gets the current cut-off frequency.
 UGen getFrequencyUGen()
          Gets the frequency UGen, if it exists.
 UGen getFreqUGen()
          Deprecated. Use getFrequencyUGen().
 DataBead getParams()
          Gets a DataBead with properties "frequency" and "resonance" set to the corresponding filter parameters.
 float getRes()
          Gets the current resonance value.
 UGen getResUGen()
          Gets the resonance UGen, if it exists.
 DataBead getStaticParams()
          Gets a DataBead with properties "frequency" and "resonance" set to static float values corresponding to the current filter parameters.
 void messageReceived(Bead message)
          Responds to an incoming message.
 void reset()
          Resets the filter in case it "explodes".
 DataBeadReceiver sendData(DataBead db)
          Sets the filter's parameters with properties from a DataBead.
 LPRezFilter setFreq(float freq)
          Deprecated. Use setFrequency(float).
 LPRezFilter setFreq(UGen freqUGen)
          Deprecated. Use setFrequency(UGen).
 LPRezFilter setFrequency(float freq)
          Sets the cut-off frequency to a float.
 LPRezFilter setFrequency(UGen freqUGen)
          Sets a UGen to specify the cut-off frequency.
 LPRezFilter setParams(DataBead paramBead)
          Sets the filter parameters with a DataBead.
 LPRezFilter setRes(float r)
          Sets the filter resonance to a float value.
 LPRezFilter setRes(UGen r)
          Sets a UGen to specify the filter resonance.
 
Methods inherited from class net.beadsproject.beads.ugens.IIRFilter
analyzeFilter, calculateFilterResponse, calculateGroupDelay, getAmplitudeResponse, getGroupDelay, getPhaseDelay, getPhaseResponse
 
Methods inherited from class net.beadsproject.beads.core.UGen
addDependent, addInput, addInput, clearDependents, clearInputConnections, containsInput, crossfadeInput, getConnectedInputs, getContext, getEnvelopes, getIns, getNumberOfConnectedUGens, getNumberOfDependents, getOutBuffer, getOuts, getTimeTakenLastUpdate, getValue, getValue, getValueDouble, getValueDouble, initializeOuts, isTimerMode, isUpdated, noInputs, pause, printInBuffers, printInputList, printOutBuffers, removeAllConnections, removeConnection, removeDependent, setOutsToPause, setTimerMode, setValue, update, zeroIns, zeroOuts
 
Methods inherited from class net.beadsproject.beads.core.Bead
getKillListener, getName, isDeleted, isPaused, kill, message, setKillListener, setName, start, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

freq

protected float freq

res

protected float res

_2pi_over_sr

protected float _2pi_over_sr

cosw

protected float cosw

freqUGen

protected UGen freqUGen

resUGen

protected UGen resUGen

a1

protected float a1

a2

protected float a2

b0

protected float b0

isFreqStatic

protected boolean isFreqStatic

isResStatic

protected boolean isResStatic
Constructor Detail

LPRezFilter

public LPRezFilter(AudioContext con)
Constructor for a single-channel LPRezFilter with default values for frequency and resonance.

Parameters:
con - The audio context.

LPRezFilter

public LPRezFilter(AudioContext con,
                   int channels)
Constructor for a multi-channel LPRezFilter with default values for frequency and resonance.

Parameters:
con - The audio context.
channels - The number of channels.

LPRezFilter

public LPRezFilter(AudioContext con,
                   float freq,
                   float res)
Constructor for a single-channel LPRezFilter with frequency and resonance specified by floats.

Parameters:
con - The audio context.
freq - The filter cut-off frequency.
res - The resonance.

LPRezFilter

public LPRezFilter(AudioContext con,
                   UGen freq,
                   float res)
Constructor for a single-channel LPRezFilter with frequency specified by a UGen and resonance specified by a float.

Parameters:
con - The audio context.
freq - The filter cut-off frequency UGen.
res - The resonance.

LPRezFilter

public LPRezFilter(AudioContext con,
                   float freq,
                   UGen res)
Constructor for a single-channel LPRezFilter with frequency specified by a float and resonance specified by a UGen.

Parameters:
con - The audio context.
freq - The filter cut-off frequency.
res - The resonance UGen.

LPRezFilter

public LPRezFilter(AudioContext con,
                   UGen freq,
                   UGen res)
Constructor for a single-channel LPRezFilter with frequency and resonance specified by UGens.

Parameters:
con - The audio context.
freq - The filter cut-off frequency UGen.
res - The resonance UGen.

LPRezFilter

public LPRezFilter(AudioContext con,
                   int channels,
                   float freq,
                   float res)
Constructor for a multi-channel LPRezFilter with frequency and resonance specified by floats.

Parameters:
con - The audio context.
channels - The number of channels.
freq - The filter cut-off frequency.
res - The resonance.

LPRezFilter

public LPRezFilter(AudioContext con,
                   int channels,
                   UGen freq,
                   float res)
Constructor for a multi-channel LPRezFilter with frequency specified by a UGen and resonance specified by a float.

Parameters:
con - The audio context.
channels - The number of channels.
freq - The filter cut-off frequency UGen.
res - The resonance.

LPRezFilter

public LPRezFilter(AudioContext con,
                   int channels,
                   float freq,
                   UGen res)
Constructor for a multi-channel LPRezFilter with frequency specified by a float and resonance specified by a UGen.

Parameters:
con - The audio context.
channels - The number of channels.
freq - The filter cut-off frequency.
res - The resonance UGen.

LPRezFilter

public LPRezFilter(AudioContext con,
                   int channels,
                   UGen freq,
                   UGen res)
Constructor for a multi-channel LPRezFilter with frequency and resonance specified by UGens.

Parameters:
con - The audio context.
channels - The number of channels.
freq - The filter cut-off frequency UGen.
res - The resonance UGen.
Method Detail

calcVals

protected void calcVals()

calculateBuffer

public void calculateBuffer()
Description copied from class: UGen
Called by the signal chain to update this UGen's ouput data. Subclassses of UGen should implement the UGen's DSP perform routine here. In general this involves grabbing data from UGen.bufIn and putting data into UGen.bufOut in some way. UGen.bufIn and UGen.bufOut are 2D arrays of floats of the form float[numChannels][bufferSize]. The length of the buffers is given by UGen.bufferSize, and the number of channels of the input and output buffers are given by UGen.ins and UGen.outs respectively.

Specified by:
calculateBuffer in class UGen

reset

public void reset()
Resets the filter in case it "explodes".


getFrequency

public float getFrequency()
Gets the current cut-off frequency.

Returns:
The cut-off frequency.

setFrequency

public LPRezFilter setFrequency(float freq)
Sets the cut-off frequency to a float. Removes the frequency UGen, if there is one.

Parameters:
freq - The cut-off frequency.
Returns:
This filter instance.

setFrequency

public LPRezFilter setFrequency(UGen freqUGen)
Sets a UGen to specify the cut-off frequency. Passing a null value freezes the parameter.

Parameters:
freqUGen - The frequency UGen.
Returns:
This filter instance.

getFrequencyUGen

public UGen getFrequencyUGen()
Gets the frequency UGen, if it exists.

Returns:
The frequency UGen.

getFreq

@Deprecated
public float getFreq()
Deprecated. Use getFrequency().

Gets the current cut-off frequency.

Returns:
The cut-off frequency.

setFreq

@Deprecated
public LPRezFilter setFreq(float freq)
Deprecated. Use setFrequency(float).

Sets the cut-off frequency to a float. Removes the frequency UGen, if there is one.

Parameters:
freq - The cut-off frequency.
Returns:
This filter instance.

setFreq

@Deprecated
public LPRezFilter setFreq(UGen freqUGen)
Deprecated. Use setFrequency(UGen).

Sets a UGen to specify the cut-off frequency. Passing a null value freezes the parameter.

Parameters:
freqUGen - The frequency UGen.
Returns:
This filter instance.

getFreqUGen

@Deprecated
public UGen getFreqUGen()
Deprecated. Use getFrequencyUGen().

Gets the frequency UGen, if it exists.

Returns:
The frequency UGen.

getRes

public float getRes()
Gets the current resonance value.

Returns:
The resonance.

setRes

public LPRezFilter setRes(float r)
Sets the filter resonance to a float value. This removes the resonance UGen, if it exists. (Should be >= 0 and < 1.)

Parameters:
r - The resonance.
Returns:
This filter instance.

setRes

public LPRezFilter setRes(UGen r)
Sets a UGen to specify the filter resonance. Passing a null value freezes the parameter.

Parameters:
r - The resonance UGen.
Returns:
This filter instance.

getResUGen

public UGen getResUGen()
Gets the resonance UGen, if it exists.

Returns:
The resonance UGen.

setParams

public LPRezFilter setParams(DataBead paramBead)
Sets the filter parameters with a DataBead.

Use the following properties to specify filter parameters:

Parameters:
paramBead - The DataBead specifying parameters.
Returns:
This filter instance.

messageReceived

public void messageReceived(Bead message)
Description copied from class: Bead
Responds to an incoming message. Subclasses can override this in order to handle incoming messages. Typically a Bead would send a message to another Bead with itself as the arugment.

Overrides:
messageReceived in class Bead
Parameters:
message - the message

getParams

public DataBead getParams()
Gets a DataBead with properties "frequency" and "resonance" set to the corresponding filter parameters.

Returns:
The parameter DataBead.

getStaticParams

public DataBead getStaticParams()
Gets a DataBead with properties "frequency" and "resonance" set to static float values corresponding to the current filter parameters.

Returns:
The static parameter DataBead.

sendData

public DataBeadReceiver sendData(DataBead db)
Sets the filter's parameters with properties from a DataBead.

Specified by:
sendData in interface DataBeadReceiver
Parameters:
db - The DataBead message.
Returns:
Typically, the object instance: this.
See Also:
setParams(DataBead)

getFilterResponse

public IIRFilter.IIRFilterAnalysis getFilterResponse(float freq)
Specified by:
getFilterResponse in class IIRFilter