public class Waves
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static Wavetable |
PHASOR
A perfect phasor wave going from 0 to 1.
|
static Wavetable |
QUARTERPULSE
A perfect square wave with a 25% duty cycle.
|
static Wavetable |
SAW
A perfect sawtooth wave.
|
static Wavetable |
SINE
A pure sine wave.
|
static Wavetable |
SQUARE
A perfect square wave with a 50% duty cycle.
|
static Wavetable |
TRIANGLE
A perfect triangle wave.
|
Modifier and Type | Method and Description |
---|---|
static Wavetable |
add(float[] amps,
Waveform... waves)
Generates a Wavetable by adding any number of Waveforms, each scaled by an amplitude.
|
static Wavetable |
pulse(float dutyCycle)
Constructs a perfect square wave with the specified duty cycle.
|
static Wavetable |
randomNHarms(int numberOfHarmonics)
Constructs a waveform by summing together the first numberOfHarmonics
in the harmonic series with randomly chosen amplitudes.
|
static Wavetable |
randomNOddHarms(int numberOfHarmonics)
Constructs a waveform by summing together the first odd numberOfHarmonics
in the harmonic series (1, 3, 5, etc) with randomly chosen amplitudes.
|
static Wavetable |
randomNoise()
Constructs a Wavetable of randomly generated noise.
|
static Wavetable |
saw(float dutyCycle)
Constructs a perfect sawtooth wave with the specified duty cycle.
|
static Wavetable |
sawh(int numberOfHarmonics)
Builds an approximation of a perfect sawtooth wave by summing together
harmonically related sine waves.
|
static Wavetable |
square(float dutyCycle)
Constructs a perfect square wave with the specified duty cycle.
|
static Wavetable |
squareh(int numberOfHarmonics)
Builds an approximation of a perfect square wave by summing together
harmonically related sine waves.
|
static Wavetable |
triangle(float dutyCycle)
Constructs a perfect triangle wave with the specified duty cycle.
|
static Wavetable |
triangleh(int numberOfHarmonics)
Builds an approximation of a perfect triangle wave by summing together
harmonically related sine waves.
|
public static final Wavetable SINE
public static final Wavetable SAW
public static final Wavetable PHASOR
public static final Wavetable SQUARE
public static final Wavetable TRIANGLE
public static final Wavetable QUARTERPULSE
public static Wavetable sawh(int numberOfHarmonics)
numberOfHarmonics
- int: the number of harmonics to use in the approximation. 1 harmonic
will simply generate a sine wave. The greater the number of
harmonics used, the closer to a pure saw wave the approximation will be.public static Wavetable saw(float dutyCycle)
dutyCycle
- float: a sawtooth wave with a duty cycle of 0.5 will be
a perfect sawtooth wave that smoothly changes from 1 to -1
with a zero-crossing in the middle. By changing the duty
cycle, you change how much of the sawtooth is below zero.
So, a duty cycle of 0.2 would result in 20 percent of the
sawtooth below zero and the rest above. Duty cycle will
be clamped to [0,1].public static Wavetable squareh(int numberOfHarmonics)
numberOfHarmonics
- int: the number of harmonics to use in the approximation. 1 harmonic
will simply generate a sine wave. The greater the number of
harmonics used, the closer to a pure saw wave the approximation will be.public static Wavetable square(float dutyCycle)
dutyCycle
- float: a square wave with a duty cycle of 0.5 will be
a perfect square wave that is 1 half the time and -1 the other half.
By changing the duty cycle, you change how much of the square
is below zero. So, a duty cycle of 0.2 would result in 20 percent of the
square below zero and the rest above. Duty cycle will
be clamped to [0,1].public static Wavetable pulse(float dutyCycle)
dutyCycle
- float: a square wave with a duty cycle of 0.5 will be
a perfect square wave that is 1 half the time and -1 the other half.
By changing the duty cycle, you change how much of the square
is below zero. So, a duty cycle of 0.2 would result in 20 percent of the
square below zero and the rest above. Duty cycle will
be clamped to [0,1].public static Wavetable triangleh(int numberOfHarmonics)
numberOfHarmonics
- int: the number of harmonics to use in the approximation. 1 harmonic
will simply generate a sine wave. The greater the number of
harmonics used, the closer to a pure saw wave the approximation will be.public static Wavetable triangle(float dutyCycle)
dutyCycle
- float: a triangle wave with a duty cycle of 0.5 will be
a perfect triangle wave that is 1 half the time and -1 the other half.
By changing the duty cycle, you change how much of the triangle
is below zero. So, a duty cycle of 0.2 would result in 20 percent of the
triangle below zero and the rest above. Duty cycle will
be clamped to [0,1].public static Wavetable randomNHarms(int numberOfHarmonics)
numberOfHarmonics
- int: the number of harmonics to use when generating the wavepublic static Wavetable randomNOddHarms(int numberOfHarmonics)
numberOfHarmonics
- int: the number of odd harmonics to use when generating the wavepublic static Wavetable randomNoise()
public static Wavetable add(float[] amps, Waveform... waves)
Wavetable wave = Wavetable.add( new float[] { 0.8f, 0.2f }, Waves.SINE, Waves.SAW );
or:
Wavetable wave = Wavetable.add( new float[] { 0.2f, 0.3f, 0.5f }, Waves.SINE, Waves.SQUARE, Waves.sawh( 6 ) );
In other words, the number of elements in the amplitude array
must match the number of Waveform arguments provided.amps
- float[]: an array of amplitudes used to scale the matching Waveform argument
when adding it into the final Wavetable.waves
- Waveform vararg: The Waveforms to be added together. The number of Waveforms
passed in as arguments much match the length of the amps array.