net.beadsproject.beads.ugens
Class RandomPWM

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

public class RandomPWM
extends UGen
implements DataBeadReceiver

A simple random-length pulse wave modulator. This UGen generates constant pulses of lengths randomly distributed between a minimum length and a maximum length (specified in samples). Additionally, the distribution of the randomly controlled by setting the pulse length exponent parameter (see setLengthExponent).

A RandomPWM instance has three modes:

Version:
0.9.6
Author:
Benito Crawford

Nested Class Summary
static class RandomPWM.Mode
           
 
Nested classes/interfaces inherited from class net.beadsproject.beads.core.UGen
UGen.OutputInitializationRegime, UGen.OutputPauseRegime
 
Field Summary
static RandomPWM.Mode ALTERNATING
           
protected  float baseVal
           
protected  float count
           
protected  float lengthDiff
           
protected  float lengthExponent
           
protected  float maxLength
           
protected  float minLength
           
protected  RandomPWM.Mode mode
           
static RandomPWM.Mode NOISE
           
static RandomPWM.Mode NOISE_ENVELOPE
           
protected  float pulseLen
           
static RandomPWM.Mode PULSING
           
static RandomPWM.Mode RAMPED_NOISE
           
static RandomPWM.Mode SAW
           
protected  float targetVal
           
protected  float valDiff
           
 
Fields inherited from class net.beadsproject.beads.core.UGen
bufferSize, bufIn, bufOut, context, ins, outputInitializationRegime, outputPauseRegime, outs
 
Constructor Summary
RandomPWM(AudioContext context, RandomPWM.Mode mode, float minl, float maxl)
          Constructor specifying mode, and minumum and maximum pulse lengths.
RandomPWM(AudioContext context, RandomPWM.Mode mode, float minl, float maxl, float lexp)
          Constructor specifying all parameters
 
Method Summary
 void calculateBuffer()
          Called by the signal chain to update this UGen's ouput data.
protected  void calcVals()
           
 float getLengthExponent()
          Gets the pulse length exponent.
 float getMaxLength()
          Gets the maximum pulse length.
 float getMinLength()
          Gets the minimum pulse length.
 RandomPWM.Mode getMode()
          Gets the pulse mode.
 DataBead getParams()
          Gets a DataBead filled with properties corresponding to this object's parameters.
 void messageReceived(Bead message)
          Responds to an incoming message.
 DataBeadReceiver sendData(DataBead db)
          Use the properties "mode", "minLength", "maxLength", and "lengthExponent" to set the corresponding parameters (type Mode for "mode", floats only for the others).
 RandomPWM setLengthExponent(float lexp)
          Sets the pulse length exponent.
 RandomPWM setMaxLength(float maxl)
          Sets the maximum pulse length.
 RandomPWM setMinLength(float minl)
          Sets the minimum pulse length.
 RandomPWM setMode(RandomPWM.Mode mode)
          Sets the pulse mode.
 RandomPWM setParams(float minl, float maxl, float lexp)
          Sets the minimum pulse length, maximum pulse length, and pulse length exponent.
 RandomPWM setParams(RandomPWM.Mode mode, float minl, float maxl, float lexp)
          Sets the pulse mode (see setMode), minimum pulse length, maximum pulse length, and pulse length exponent.
 
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

ALTERNATING

public static final RandomPWM.Mode ALTERNATING

NOISE

public static final RandomPWM.Mode NOISE

PULSING

public static final RandomPWM.Mode PULSING

SAW

public static final RandomPWM.Mode SAW

RAMPED_NOISE

public static final RandomPWM.Mode RAMPED_NOISE

NOISE_ENVELOPE

public static final RandomPWM.Mode NOISE_ENVELOPE

mode

protected RandomPWM.Mode mode

targetVal

protected float targetVal

baseVal

protected float baseVal

valDiff

protected float valDiff

count

protected float count

pulseLen

protected float pulseLen

minLength

protected float minLength

maxLength

protected float maxLength

lengthExponent

protected float lengthExponent

lengthDiff

protected float lengthDiff
Constructor Detail

RandomPWM

public RandomPWM(AudioContext context,
                 RandomPWM.Mode mode,
                 float minl,
                 float maxl)
Constructor specifying mode, and minumum and maximum pulse lengths.

Parameters:
context - The audio context.
mode - The pulse mode; see setMode.
minl - The minimum pulse length.
maxl - The maximum pulse length.

RandomPWM

public RandomPWM(AudioContext context,
                 RandomPWM.Mode mode,
                 float minl,
                 float maxl,
                 float lexp)
Constructor specifying all parameters

Parameters:
context - The audio context.
mode - The pulse mode; see setMode.
minl - The minimum pulse length.
maxl - The maximum pulse length.
lexp - The pulse length exponent.
Method Detail

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

calcVals

protected void calcVals()

setParams

public RandomPWM setParams(RandomPWM.Mode mode,
                           float minl,
                           float maxl,
                           float lexp)
Sets the pulse mode (see setMode), minimum pulse length, maximum pulse length, and pulse length exponent.

Parameters:
mode - The pulse mode.
minl - The minimum pulse length.
maxl - The maximum pulse length.
lexp - The pulse length exponent.

setParams

public RandomPWM setParams(float minl,
                           float maxl,
                           float lexp)
Sets the minimum pulse length, maximum pulse length, and pulse length exponent.

Parameters:
minl - The minimum pulse length.
maxl - The maximum pulse length.
lexp - The pulse length exponent.

setMinLength

public RandomPWM setMinLength(float minl)
Sets the minimum pulse length.

Parameters:
minl - The minimum pulse length.

getMinLength

public float getMinLength()
Gets the minimum pulse length.

Returns:
The minimum pulse length.

setMaxLength

public RandomPWM setMaxLength(float maxl)
Sets the maximum pulse length.

Parameters:
maxl - The maximum pulse length.

getMaxLength

public float getMaxLength()
Gets the maximum pulse length.

Returns:
The maximum pulse length.

setLengthExponent

public RandomPWM setLengthExponent(float lexp)
Sets the pulse length exponent. This parameter controls the distribution of pulse lengths: a value of 1 produces a linear distribution; greater than 1 skews the distribution toward the minimum length; less than one skews it toward the maximum length.

Parameters:
lexp - The pulse length exponent.

getLengthExponent

public float getLengthExponent()
Gets the pulse length exponent.

Returns:
The pulse length exponent.
See Also:
setLengthExponent(float)

setMode

public RandomPWM setMode(RandomPWM.Mode mode)
Sets the pulse mode.

Parameters:
mode - The pulse mode.

getMode

public RandomPWM.Mode getMode()
Gets the pulse mode.

Returns:
The pulse mode.
See Also:
setMode(Mode)

sendData

public DataBeadReceiver sendData(DataBead db)
Use the properties "mode", "minLength", "maxLength", and "lengthExponent" to set the corresponding parameters (type Mode for "mode", floats only for the others).

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

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 filled with properties corresponding to this object's parameters.

Returns:
The parameter DataBead.