Package toxi.math.waves
Class AbstractWave
java.lang.Object
toxi.math.waves.AbstractWave
- Direct Known Subclasses:
AMFMSineWave,ConstantWave,FMHarmonicSquareWave,FMSawtoothWave,FMSineWave,FMSquareWave,FMTriangleWave,SineWave
Abstract wave oscillator type which needs to be subclassed to implement
different waveforms. Please note that the frequency unit is radians, but
conversion methods to & from Hertz (
hertzToRadians(float, float))
are included in this base class.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractWave(float phase) AbstractWave(float phase, float freq) AbstractWave(float phase, float freq, float amp, float offset) -
Method Summary
Modifier and TypeMethodDescriptionfinal floatEnsures phase remains in the 0...TWO_PI interval.final floatcyclePhase(float freq) Progresses phase and ensures it remains in the 0...TWO_PI interval.static final floathertzToRadians(float hz, float sampleRate) Converts a frequency in Hertz into radians.voidpop()voidpush()static final floatradiansToHertz(float f, float sampleRate) Converts a frequency from radians to Hertz.voidreset()Resets the wave phase to the last set phase value (viasetPhase(float).voidsetPhase(float phase) Starts the wave from a new phase.toString()abstract floatupdate()Updates the wave and returns new value.
-
Field Details
-
PI
public static final float PI- See Also:
-
TWO_PI
public static final float TWO_PI- See Also:
-
phase
public float phaseCurrent wave phase -
frequency
public float frequency -
amp
public float amp -
offset
public float offset -
value
public float value
-
-
Constructor Details
-
AbstractWave
public AbstractWave() -
AbstractWave
public AbstractWave(float phase) - Parameters:
phase-
-
AbstractWave
public AbstractWave(float phase, float freq) - Parameters:
phase-freq-
-
AbstractWave
public AbstractWave(float phase, float freq, float amp, float offset) - Parameters:
phase-freq-amp-offset-
-
-
Method Details
-
hertzToRadians
public static final float hertzToRadians(float hz, float sampleRate) Converts a frequency in Hertz into radians.- Parameters:
hz- frequency to convert (in Hz)sampleRate- sampling rate in Hz (equals period length @ 1 Hz)- Returns:
- frequency in radians
-
radiansToHertz
public static final float radiansToHertz(float f, float sampleRate) Converts a frequency from radians to Hertz.- Parameters:
f- frequency in radianssampleRate- sampling rate in Hz (equals period length @ 1 Hz)- Returns:
- freq in Hz
-
cyclePhase
public final float cyclePhase()Ensures phase remains in the 0...TWO_PI interval.- Returns:
- current phase
-
cyclePhase
public final float cyclePhase(float freq) Progresses phase and ensures it remains in the 0...TWO_PI interval.- Parameters:
freq- normalized progress frequency- Returns:
- update phase value
-
pop
public void pop() -
push
public void push() -
reset
public void reset()Resets the wave phase to the last set phase value (viasetPhase(float). -
setPhase
public void setPhase(float phase) Starts the wave from a new phase. The new phase position will also be used for any later call to {reset()- Parameters:
phase- new phase
-
toString
-
update
public abstract float update()Updates the wave and returns new value. Implementing classes should manually ensure the phase remains in the 0...TWO_PI interval or by callingcyclePhase().- Returns:
- current (newly calculated) wave value
-