net.beadsproject.beads.ugens
Class WaveShaper

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

public class WaveShaper
extends UGen
implements DataBeadReceiver

A simple wave-shaper. WaveShaper takes an incoming signal, maps it onto a stored wave shape, and outputs the result. For each sample it:

  1. Multiplies by the preGain.
  2. Clips between -1 and 1, and maps onto the stored wave shape, with linear interpolation.
  3. Multiplies by the postGain.
  4. Limits the result between -limit and limit.
  5. Mixes the result with the original signal according to wetMix. (1 is none of the original signal; 0 is only the original signal.)

This UGen is a DataBeadReceiver, so you can set its parameters with a DataBead.

Version:
0.9.5
Author:
Benito Crawford

Nested Class Summary
 
Nested classes/interfaces inherited from class net.beadsproject.beads.core.UGen
UGen.OutputInitializationRegime, UGen.OutputPauseRegime
 
Field Summary
protected  int channels
           
protected  boolean isLimitStatic
           
protected  boolean isPostGainStatic
           
protected  boolean isPreGainStatic
           
protected  boolean isWetMixStatic
           
protected  float limit
           
protected  UGen limitUGen
           
protected  float postGain
           
protected  UGen postGainUGen
           
protected  float preGain
           
protected  UGen preGainUGen
           
protected  float[] shape
           
protected  int shapeLen
           
protected  float wetMix
           
protected  UGen wetMixUGen
           
 
Fields inherited from class net.beadsproject.beads.core.UGen
bufferSize, bufIn, bufOut, context, ins, outputInitializationRegime, outputPauseRegime, outs
 
Constructor Summary
WaveShaper(AudioContext context)
          Constructor for a mono-channel wave shaper that uses a default cosine-based wave shape.
WaveShaper(AudioContext context, Buffer shapeBuffer)
          Constructor for a mono-channel wave shaperthat uses the float array from a Buffer for its wave shape.
WaveShaper(AudioContext context, float[] shape)
          Constructor for a mono-channel wave shaper that uses the provided float array for its wave shape.
WaveShaper(AudioContext context, int channels)
          Constructor for a multi-channel wave shaper that uses a default cosine-based wave shape.
WaveShaper(AudioContext context, int channels, Buffer shapeBuffer)
          Constructor for a multi-channel wave shaper that uses the float array from a Buffer for its wave shape.
WaveShaper(AudioContext context, int channels, float[] shape)
          Constructor for a multi-channel wave shaper that uses the provided float array for its wave shape.
 
Method Summary
 void calculateBuffer()
          Called by the signal chain to update this UGen's ouput data.
static float[] generateCosineShape(int length)
          Generates a nice cosine-based waveform in a float array that will provide a little warmth when used for wave-shaping.
static float[] generateExponentialShape(int length, float exponent)
          Generates an exponentially-based waveform in a float array.
 float getLimit()
          Gets the current limit.
 UGen getLimitUGen()
          Gets the limit UGen, if there is one.
 DataBead getParams()
          Gets a new DataBead filled with the various parameter values stored in the properties "preGain", "postGain", "limit", "wetMix", and "shape".
 float getPostGain()
          Gets the current post-gain.
 UGen getPostGainUGen()
          Gets the post-gain UGen, if there is one.
 float getPreGain()
          Gets the current pre-gain.
 UGen getPreGainUGen()
          Gets the pre-gain UGen, if there is one.
 float[] getShape()
          Gets the array of floats that represents the wave used for shaping.
 DataBead getStaticParams()
          Gets a new DataBead filled with the various parameter values stored in the properties "preGain", "postGain", "limit", "wetMix", and "shape".
 float getWetMix()
          Gets the current wet-mix.
 UGen getWetMixUGen()
          Gets the wet-mix UGen, if there is one.
 DataBeadReceiver sendData(DataBead db)
          Sets parameters with a DataBead.
 WaveShaper setLimit(float limit)
          Sets the limit to a static float value.
 WaveShaper setLimit(UGen limitUGen)
          Sets the limit to be controlled by a UGen.
 WaveShaper setPostGain(float postGain)
          Sets the post-gain to a static float value.
 WaveShaper setPostGain(UGen postGainUGen)
          Sets the post-gain to be controlled by a UGen.
 WaveShaper setPreGain(float preGain)
          Sets the pre-gain to a static float value.
 WaveShaper setPreGain(UGen preGainUGen)
          Sets the pre-gain to be controlled by a UGen.
 WaveShaper setShape(float[] shape)
          Sets the array of floats to be used for WaveShaping.
 WaveShaper setWetMix(float wetMix)
          Sets the wet-mix to a static float value.
 WaveShaper setWetMix(UGen wetMixUGen)
          Sets the wetMix to be controlled by a UGen.
 
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, messageReceived, setKillListener, setName, start, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

preGain

protected float preGain

postGain

protected float postGain

limit

protected float limit

wetMix

protected float wetMix

preGainUGen

protected UGen preGainUGen

postGainUGen

protected UGen postGainUGen

limitUGen

protected UGen limitUGen

wetMixUGen

protected UGen wetMixUGen

isPreGainStatic

protected boolean isPreGainStatic

isPostGainStatic

protected boolean isPostGainStatic

isLimitStatic

protected boolean isLimitStatic

isWetMixStatic

protected boolean isWetMixStatic

shape

protected float[] shape

shapeLen

protected int shapeLen

channels

protected int channels
Constructor Detail

WaveShaper

public WaveShaper(AudioContext context)
Constructor for a mono-channel wave shaper that uses a default cosine-based wave shape.

Parameters:
context - The audio context.

WaveShaper

public WaveShaper(AudioContext context,
                  int channels)
Constructor for a multi-channel wave shaper that uses a default cosine-based wave shape.

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

WaveShaper

public WaveShaper(AudioContext context,
                  float[] shape)
Constructor for a mono-channel wave shaper that uses the provided float array for its wave shape.

Parameters:
context - The audio context.
shape - The float array.

WaveShaper

public WaveShaper(AudioContext context,
                  int channels,
                  float[] shape)
Constructor for a multi-channel wave shaper that uses the provided float array for its wave shape.

Parameters:
context - The audio context.
channels - The number of channels.
shape - The float array.

WaveShaper

public WaveShaper(AudioContext context,
                  Buffer shapeBuffer)
Constructor for a mono-channel wave shaperthat uses the float array from a Buffer for its wave shape.

Parameters:
context - The audio context.
shapeBuffer - The Buffer from which to get the wave shape.

WaveShaper

public WaveShaper(AudioContext context,
                  int channels,
                  Buffer shapeBuffer)
Constructor for a multi-channel wave shaper that uses the float array from a Buffer for its wave shape.

Parameters:
context - The audio context.
channels - The number of channels.
shapeBuffer - The Buffer from which to get the wave shape.
Method Detail

generateCosineShape

public static float[] generateCosineShape(int length)
Generates a nice cosine-based waveform in a float array that will provide a little warmth when used for wave-shaping.

Parameters:
length - The length of the array.
Returns:
The generated array.

generateExponentialShape

public static float[] generateExponentialShape(int length,
                                               float exponent)
Generates an exponentially-based waveform in a float array. Negative input results in negative output.

Parameters:
length - The length of the array.
exponent - The exponent.
Returns:
The generated array.

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

getPreGain

public float getPreGain()
Gets the current pre-gain.

Returns:
The pre-gain.

setPreGain

public WaveShaper setPreGain(float preGain)
Sets the pre-gain to a static float value.

Parameters:
preGain - The pre-gain.
Returns:
This object instance.

setPreGain

public WaveShaper setPreGain(UGen preGainUGen)
Sets the pre-gain to be controlled by a UGen.

Parameters:
preGainUGen - The pre-gain UGen.
Returns:
This object instance.

getPreGainUGen

public UGen getPreGainUGen()
Gets the pre-gain UGen, if there is one.

Returns:
The pre-gain UGen.

getPostGain

public float getPostGain()
Gets the current post-gain.

Returns:
The post-gain.

setPostGain

public WaveShaper setPostGain(float postGain)
Sets the post-gain to a static float value.

Parameters:
postGain - The post-gain.
Returns:
This object instance.

setPostGain

public WaveShaper setPostGain(UGen postGainUGen)
Sets the post-gain to be controlled by a UGen.

Parameters:
postGainUGen - The post-gain UGen.
Returns:
This object instance.

getPostGainUGen

public UGen getPostGainUGen()
Gets the post-gain UGen, if there is one.

Returns:
The post-gain UGen.

getLimit

public float getLimit()
Gets the current limit.

Returns:
The limit.

setLimit

public WaveShaper setLimit(float limit)
Sets the limit to a static float value.

Parameters:
limit - The limit.
Returns:
This object instance.

setLimit

public WaveShaper setLimit(UGen limitUGen)
Sets the limit to be controlled by a UGen.

Parameters:
limitUGen - The limit UGen.
Returns:
This object instance.

getLimitUGen

public UGen getLimitUGen()
Gets the limit UGen, if there is one.

Returns:
The limit UGen.

getWetMix

public float getWetMix()
Gets the current wet-mix.

Returns:
The wet-mix.

setWetMix

public WaveShaper setWetMix(float wetMix)
Sets the wet-mix to a static float value.

Parameters:
wetMix - The wetMix.
Returns:
This object instance.

setWetMix

public WaveShaper setWetMix(UGen wetMixUGen)
Sets the wetMix to be controlled by a UGen.

Parameters:
wetMixUGen - The wet-mix UGen.
Returns:
This object instance.

getWetMixUGen

public UGen getWetMixUGen()
Gets the wet-mix UGen, if there is one.

Returns:
The wet-mix UGen.

getShape

public float[] getShape()
Gets the array of floats that represents the wave used for shaping.

Returns:
The wave shape.

setShape

public WaveShaper setShape(float[] shape)
Sets the array of floats to be used for WaveShaping.

Parameters:
shape - The array of floats.
Returns:
This object instance.

sendData

public DataBeadReceiver sendData(DataBead db)
Sets parameters with a DataBead. If the DataBead any of the properties "preGain", "postGain", "limit", "wetMix", or "shape", it sets the corresponding parameters accordingly. Each property (except "shape", which should be a float array) can be specified by either a float or a controller UGen.

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

getParams

public DataBead getParams()
Gets a new DataBead filled with the various parameter values stored in the properties "preGain", "postGain", "limit", "wetMix", and "shape". Stores UGens if the parameter is not static.

Returns:
The new DataBead.

getStaticParams

public DataBead getStaticParams()
Gets a new DataBead filled with the various parameter values stored in the properties "preGain", "postGain", "limit", "wetMix", and "shape". Stores current values as floats only, even if the parameter is controlled by a UGen.

Returns:
The new DataBead.