Class ADSRParams

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

public class ADSRParams extends Object
Value object describing an ADSR envelope. Minim's implementation of a typical ADSR (attack, decay, sustain, release) envelope doesn't allow us to retrieve the values of its parameters after it's been created. This class makes those values available and also stores the per-stage curves used by SimpleADSR.
  • Field Details

    • DEFAULT_CURVE

      public static final float DEFAULT_CURVE
      Default curve used by SimpleADSR; 1.0f is linear.
      See Also:
    • maxAmp

      private final float maxAmp
    • attack

      private final float attack
    • decay

      private final float decay
    • sustain

      private final float sustain
    • release

      private final float release
    • attackCurve

      private final float attackCurve
    • decayCurve

      private final float decayCurve
    • releaseCurve

      private final float releaseCurve
  • Constructor Details

    • ADSRParams

      public ADSRParams(float maxAmp, float attack, float decay, float sustain, float release)
      Construct an ADSRParams object - note that duration of the envelope is calculated up to but not including release time.
      Parameters:
      maxAmp - maximum amplitude (0..1)
      attack - attack time in seconds
      decay - decay time in seconds
      sustain - sustain amplitude (0..1)
      release - release time in seconds
    • ADSRParams

      public ADSRParams(float maxAmp, float attack, float decay, float sustain, float release, float attackCurve, float decayCurve, float releaseCurve)
      Constructs an ADSRParams object with explicit stage curves.

      A curve of 1.0f is linear. Values greater than 1.0f rise slowly at first and more quickly near the end; values between 0.0f and 1.0f do the reverse. Curve values are clamped to the minimum supported by SimpleADSR.

      Parameters:
      maxAmp - maximum amplitude (0..1)
      attack - attack time in seconds
      decay - decay time in seconds
      sustain - sustain amplitude (0..1)
      release - release time in seconds
      attackCurve - attack-stage curve
      decayCurve - decay-stage curve
      releaseCurve - release-stage curve
  • Method Details

    • getMaxAmp

      public float getMaxAmp()
      Returns:
      maximum amplitude
    • getAttack

      public float getAttack()
      Returns:
      attack time in seconds
    • getDecay

      public float getDecay()
      Returns:
      decay time in seconds
    • getSustain

      public float getSustain()
      Returns:
      sustain level in the range 0..1
    • getRelease

      public float getRelease()
      Returns:
      release time in seconds
    • getAttackCurve

      public float getAttackCurve()
      Returns:
      attack-stage curve; 1.0f is linear
    • getDecayCurve

      public float getDecayCurve()
      Returns:
      decay-stage curve; 1.0f is linear
    • getReleaseCurve

      public float getReleaseCurve()
      Returns:
      release-stage curve; 1.0f is linear
    • copy

      public ADSRParams copy()
      Returns:
      a copy of this ADSRParams object
    • withCurves

      public ADSRParams withCurves(float attackCurve, float decayCurve, float releaseCurve)
      Returns a copy with new attack, decay, and release curves.
      Parameters:
      attackCurve - attack-stage curve
      decayCurve - decay-stage curve
      releaseCurve - release-stage curve
      Returns:
      a new ADSRParams with the requested curves
    • toADSR

      public ddf.minim.ugens.ADSR toADSR()
      Build a fresh Minim ADSR from these parameters.
      Returns:
      a Minim ADSR constructed with the instance variables stored in ADSRParams
    • toSimpleADSR

      public SimpleADSR toSimpleADSR(float sampleRate)
      Builds a fresh SimpleADSR from this complete envelope description.

      The returned envelope has not been triggered; call SimpleADSR.noteOn() when it should begin.

      Parameters:
      sampleRate - sample rate in Hz
      Returns:
      a SimpleADSR configured with this instance's times, level, and curves
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      a String representation of the ADSRParams data
    • clampCurve

      private static float clampCurve(float curve)