public class Wavetable extends java.lang.Object implements Waveform
Constructor and Description |
---|
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 . |
Modifier and Type | Method and Description |
---|---|
void |
addNoise(float sigma)
Adds Gaussian noise to the waveform.
|
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)
Smooth out the values in the table by using a moving average window.
|
float |
value(float at)
Sample the Wavetable using a value in the range [0,1].
|
void |
warp(float warpPoint,
float warpTarget)
Warping works by choosing a point in the waveform, the warpPoint, and
then specifying where it should move to, the warpTarget.
|
public Wavetable(int size)
size
entries.size
- int: the number of samples the Wavetable should containpublic Wavetable(float[] waveform)
waveform
as the float
array to sample from. This will not copy waveform
,
it will use it directly.waveform
- float[]: the float array this Wavetable will samplepublic Wavetable(Wavetable wavetable)
wavetable
. This will copy the values from the
provided Wavetable into this Wavetable's waveform.wavetable
- Wavetable: the Wavetable to copypublic void setWaveform(float[] waveform)
waveform
- float[]: the new sample datapublic float get(int i)
i
- int: the index of the sample to returnpublic float value(float at)
public float[] getWaveform()
public void set(int i, float value)
value
. This is equivalent to:
getWaveform()[i] = value;
i
- int: the index of the sample to setvalue
- float: the new sample valuepublic int size()
getWaveform().length
public void scale(float scale)
scale
.scale
- float: the amount to scale the Wavetable withpublic void offset(float amount)
amount
to every sample.amount
- float: the amount to add to every sample in the tablepublic void normalize()
public void invert()
flip(0)
.flip(float)
public void flip(float in)
in
- float: the value to flip the table aroundpublic void addNoise(float sigma)
sigma
- float: the amount to scale the random values by, in effect how
"loud" the added noise will be.public void rectify()
public void smooth(int windowLength)
windowLength
- int: how many samples large the window should bepublic void warp(float warpPoint, float warpTarget)
warpPoint
- float: the point in the wave for to be moved, expressed as a
normalized value.warpTarget
- float: the point in the wave to move the warpPoint to,
expressed as a normalized value.