Class SimpleADSR

java.lang.Object
net.paulhertz.pixelaudio.sampler.SimpleADSR

public class SimpleADSR extends Object
SimpleADSR - software envelope generator with optional exponential curves.

Features:

  • Sample-rate-based time scaling
  • Per-stage exponential curvature
  • Sustain-level clamping
  • noteOn(), noteOff(), tick(), and isFinished()
TODO coding examples using shape curvature.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static enum 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private float
     
    private float
     
    private float
     
    private float
     
    private float
     
    private float
     
    private float
     
    private float
     
    private int
     
     
    private int
     
    private float
     
    private float
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SimpleADSR(float attack, float decay, float sustain, float release)
    Constructs an envelope with default exponential curvature.
    SimpleADSR(float attack, float decay, float sustain, float release, float attackCurve, float decayCurve, float releaseCurve)
    Constructs an envelope with explicit stage curvature.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static float
    exponentialInterp(int step, int total, float start, float end, float curve)
     
    float
    Returns the current envelope value.
    boolean
    Reports whether the envelope is idle or has completed its release stage.
    void
    Starts the release stage from the current envelope value.
    void
    Starts the envelope at the attack stage.
    void
    setCurves(float attackC, float decayC, float releaseC)
    Sets curvature values for attack, decay, and release stages.
    void
    setSampleRate(float sr)
    Sets the sample rate used to convert envelope stage times to samples.
    void
    setTimes(float a, float d, float s, float r)
    Sets envelope stage times and sustain level.
    float
    Advances the envelope by one sample.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • attackTime

      private float attackTime
    • decayTime

      private float decayTime
    • sustainLevel

      private float sustainLevel
    • releaseTime

      private float releaseTime
    • sampleRate

      private float sampleRate
    • attackCurve

      private float attackCurve
    • decayCurve

      private float decayCurve
    • releaseCurve

      private float releaseCurve
    • stage

      private SimpleADSR.Stage stage
    • value

      private float value
    • releaseStart

      private float releaseStart
    • samplesInStage

      private int samplesInStage
    • stageSamples

      private int stageSamples
  • Constructor Details

    • SimpleADSR

      public SimpleADSR(float attack, float decay, float sustain, float release)
      Constructs an envelope with default exponential curvature.
      Parameters:
      attack - attack time in seconds
      decay - decay time in seconds
      sustain - sustain level in the range 0..1
      release - release time in seconds
    • SimpleADSR

      public SimpleADSR(float attack, float decay, float sustain, float release, float attackCurve, float decayCurve, float releaseCurve)
      Constructs an envelope with explicit stage curvature.
      Parameters:
      attack - attack time in seconds
      decay - decay time in seconds
      sustain - sustain level in the range 0..1
      release - release time in seconds
      attackCurve - curvature for the attack stage
      decayCurve - curvature for the decay stage
      releaseCurve - curvature for the release stage
  • Method Details

    • setSampleRate

      public void setSampleRate(float sr)
      Sets the sample rate used to convert envelope stage times to samples.
      Parameters:
      sr - sample rate in Hz
    • noteOn

      public void noteOn()
      Starts the envelope at the attack stage.
    • noteOff

      public void noteOff()
      Starts the release stage from the current envelope value.
    • isFinished

      public boolean isFinished()
      Reports whether the envelope is idle or has completed its release stage.
      Returns:
      true when no active envelope value remains
    • tick

      public float tick()
      Advances the envelope by one sample.
      Returns:
      the current envelope value after advancing
    • exponentialInterp

      private static float exponentialInterp(int step, int total, float start, float end, float curve)
    • getValue

      public float getValue()
      Returns the current envelope value.
      Returns:
      current envelope value
    • setCurves

      public void setCurves(float attackC, float decayC, float releaseC)
      Sets curvature values for attack, decay, and release stages.
      Parameters:
      attackC - attack-stage curvature
      decayC - decay-stage curvature
      releaseC - release-stage curvature
    • setTimes

      public void setTimes(float a, float d, float s, float r)
      Sets envelope stage times and sustain level.
      Parameters:
      a - attack time in seconds
      d - decay time in seconds
      s - sustain level
      r - release time in seconds