ddf.minim.ugens
Class Wavetable

java.lang.Object
  extended by ddf.minim.ugens.Wavetable
All Implemented Interfaces:
Waveform

public class Wavetable
extends java.lang.Object
implements Waveform

Wavetable wraps a float array of any size and lets you sample array using a normalized value [0,1]. This means that if you have an array that is 2048 samples long, then value(0.5) will give you the 1024th sample. You will most often use Wavetables as the Waveform in an Oscil, but other uses are also possible. Additionally, Wavetable provides a set of methods for transforming the samples it contains.

Author:
Mark Godfrey

Constructor Summary
Wavetable(float[] waveform)
          Construct a Wavetable that will use waveform as the float array to sample from.
Wavetable(int size)
          Construct a Wavetable that contains size entries.
Wavetable(Wavetable wavetable)
          Make a new Wavetable that has the same waveform values as wavetable.
 
Method Summary
 void addNoise(float sigma)
          Adds gaussian noise to the waveform scaled by sigma.
 void flip(float in)
          Flip the values in the table around a particular value.
 float get(int i)
          Returns the value of the ith entry in this Wavetable's waveform.
 float[] getWaveform()
          Returns the underlying waveform, not a copy of it.
 void invert()
          Flips the table around 0.
 void normalize()
          Normalizes the Wavetable by finding the largest amplitude in the table and scaling the table by the inverse of that amount.
 void offset(float amount)
          Apply a DC offset to this Wavetable.
 void rectify()
          Inverts all values in the table that are less than zero.
 void scale(float scale)
          Multiplies each value of the underlying waveform by scale.
 void set(int i, float value)
          Sets the ith entry of the underlying waveform to value.
 void setWaveform(float[] waveform)
          Sets this Wavetable's waveform to the one provided.
 int size()
          Returns the length of the underlying waveform.
 void smooth(int windowLength)
          Smooths out the values in the table by using a moving average window.
 float value(float at)
          at is expected to be in the range [0,1].
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Wavetable

public Wavetable(int size)
Construct a Wavetable that contains size entries.

Parameters:
size -

Wavetable

public Wavetable(float[] waveform)
Construct a Wavetable that will use waveform as the float array to sample from. This will not copy waveform, it will use it directly.

Parameters:
waveform -

Wavetable

public Wavetable(Wavetable wavetable)
Make a new Wavetable that has the same waveform values as wavetable. This will copy the values from the provided Wavetable into this Wavetable's waveform.

Parameters:
wavetable -
Method Detail

setWaveform

public void setWaveform(float[] waveform)
Sets this Wavetable's waveform to the one provided. This will not copy the values from the provided waveform, it will use the waveform directly.

Parameters:
waveform -

get

public float get(int i)
Returns the value of the ith entry in this Wavetable's waveform.


value

public float value(float at)
at is expected to be in the range [0,1]. This will sample the waveform using this value and interpolate between actual sample values as needed.

Specified by:
value in interface Waveform
Parameters:
at - a value in the range [0, 1]
Returns:
this Wavetable sampled at the requested interval

getWaveform

public float[] getWaveform()
Returns the underlying waveform, not a copy of it.


set

public void set(int i,
                float value)
Sets the ith entry of the underlying waveform to value. This is equivalent to:

getWaveform()[i] = value;


size

public int size()
Returns the length of the underlying waveform. This is equivalent to:

getWaveform().length


scale

public void scale(float scale)
Multiplies each value of the underlying waveform by scale.


offset

public void offset(float amount)
Apply a DC offset to this Wavetable. In other words, add amount to every sample.

Parameters:
amount - the amount to add to every sample in the table

normalize

public void normalize()
Normalizes the Wavetable by finding the largest amplitude in the table and scaling the table by the inverse of that amount. The result is that the largest value in the table will now have an amplitude of 1 and everything else is scaled proportionally.


invert

public void invert()
Flips the table around 0. Equivalent to flip(0).


flip

public void flip(float in)
Flip the values in the table around a particular value. For example, if you flip around 2, values greater than 2 will become less than two by the same amount and values less than 2 will become greater than 2 by the same amount. 3 -> 1, 0 -> 4, etc.

Parameters:
in -

addNoise

public void addNoise(float sigma)
Adds gaussian noise to the waveform scaled by sigma.

Parameters:
sigma -

rectify

public void rectify()
Inverts all values in the table that are less than zero. -1 -> 1, -0.2 -> 0.2, etc.


smooth

public void smooth(int windowLength)
Smooths out the values in the table by using a moving average window.

Parameters:
windowLength - how many samples large the window should be