Package wellen.dsp

Class Envelope

java.lang.Object
wellen.dsp.Envelope
All Implemented Interfaces:
DSPNodeOutput

public class Envelope extends Object implements 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 ) to 1.0 ( value of 2nd stage ) in 2.0 seconds ( duration of 1st stage )
  • interpolate from 1.0 to 0.0 in 5.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 to 1.0 in 2.0 seconds
  • envelope is done
  • 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 interface DSPNodeOutput
      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 ramp
      pEndValue - end value of ramp
      pDuration - 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 ramp
      pDuration - duration of ramp
    • stages

      public ArrayList<Envelope.Stage> stages()
      Returns:
      list of all stages
    • add_stage

      public void add_stage(float pValue, float pDuration)
      Parameters:
      pValue - value of stage
      pDuration - 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

      public void add_listener(EnvelopeListener pEnvelopeListener)
      Parameters:
      pEnvelopeListener - envelope listener
    • remove_listener

      public boolean remove_listener(EnvelopeListener pEnvelopeListener)
      Parameters:
      pEnvelopeListener - envelope listener
      Returns:
      true if envelope listener was removed
    • clear_listeners

      public void clear_listeners()
    • get_listeners

      public ArrayList<EnvelopeListener> get_listeners()
      Returns:
      list of all envelope listeners