Package wellen.dsp
Class Envelope
java.lang.Object
wellen.dsp.Envelope
- All Implemented Interfaces:
DSPNodeOutput
envelope with multiple stages. the envelope is configured with value and duration defined in
Stage
. once
started the envelope interpolates linearly from current stage value to next stage value in current stage’s duration.
by definition the duration of the last stage is ignored.
a typical application of an envelope could look as follows:
Envelope mEnvelope = new Envelope();
mEnvelope.add_stage(0.0f, 2.0f);
mEnvelope.add_stage(1.0f, 5.0f);
mEnvelope.add_stage(0.0f);
the code above would read as follows:
- interpolate from
0.0
( value of 1st stage ) to1.0
( value of 2nd stage ) in2.0
seconds ( duration of 1st stage ) - interpolate from
1.0
to0.0
in5.0
seconds - envelope is done
the following example creates a simple ramp:
Envelope mEnvelope = new Envelope();
mEnvelope.add_stage(0.0f, 2.0f);
mEnvelope.add_stage(1.0f);
the code above would read as follows:
- interpolate from
0.0
to1.0
in2.0
seconds - envelope is done
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add_listener
(EnvelopeListener pEnvelopeListener) void
add_stage
(float pValue) void
add_stage
(float pValue, float pDuration) void
void
void
enable_loop
(boolean pLoop) enable looping of envelope.float
float
float
output()
advance envelope on stepvoid
ramp
(float pStartValue, float pEndValue, float pDuration) clears all current stages from the envelope and creates a ramp from start to end value in specified duration.void
ramp_to
(float pValue, float pDuration) clears all current stages from envelope and creates a ramp from the current value to specified value in specified duration.boolean
remove_listener
(EnvelopeListener pEnvelopeListener) void
set_current_value
(float pValue) void
set_time_scale
(float pTimeScale) stages()
void
start()
void
stop()
-
Constructor Details
-
Envelope
public Envelope(int pSamplingRate) - Parameters:
pSamplingRate
- sampling rate
-
Envelope
public Envelope()
-
-
Method Details
-
enable_loop
public void enable_loop(boolean pLoop) enable looping of envelope. once the last stage has completed the envelope is reset to the first stage and repeats.- Parameters:
pLoop
- flag to enable looping.
-
output
public float output()advance envelope on step- Specified by:
output
in interfaceDSPNodeOutput
- Returns:
- current value
-
ramp
public void ramp(float pStartValue, float pEndValue, float pDuration) clears all current stages from the envelope and creates a ramp from start to end value in specified duration.- Parameters:
pStartValue
- start value of ramppEndValue
- end value of ramppDuration
- duration of ramp
-
ramp_to
public void ramp_to(float pValue, float pDuration) clears all current stages from envelope and creates a ramp from the current value to specified value in specified duration. note, that the envelope might need to be restarted with `start()`.- Parameters:
pValue
- end value of ramppDuration
- duration of ramp
-
stages
- Returns:
- list of all stages
-
add_stage
public void add_stage(float pValue, float pDuration) - Parameters:
pValue
- value of stagepDuration
- duration of stage
-
add_stage
public void add_stage(float pValue) - Parameters:
pValue
- value of stage
-
clear_stages
public void clear_stages() -
start
public void start() -
stop
public void stop() -
get_time_scale
public float get_time_scale()- Returns:
- time scale in seconds
-
set_time_scale
public void set_time_scale(float pTimeScale) - Parameters:
pTimeScale
- time scale in seconds
-
get_current_value
public float get_current_value()- Returns:
- current value
-
set_current_value
public void set_current_value(float pValue) - Parameters:
pValue
- set current value
-
add_listener
- Parameters:
pEnvelopeListener
- envelope listener
-
remove_listener
- Parameters:
pEnvelopeListener
- envelope listener- Returns:
- true if envelope listener was removed
-
clear_listeners
public void clear_listeners() -
get_listeners
- Returns:
- list of all envelope listeners
-