Package net.paulhertz.pixelaudio.sampler
Class ADSRParams
java.lang.Object
net.paulhertz.pixelaudio.sampler.ADSRParams
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final floatprivate final floatprivate final floatprivate final floatstatic final floatDefault curve used bySimpleADSR;1.0fis linear.private final floatprivate final floatprivate final floatprivate final float -
Constructor Summary
ConstructorsConstructorDescriptionADSRParams(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.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. -
Method Summary
Modifier and TypeMethodDescriptionprivate static floatclampCurve(float curve) copy()floatfloatfloatgetDecay()floatfloatfloatfloatfloatddf.minim.ugens.ADSRtoADSR()Build a fresh Minim ADSR from these parameters.toSimpleADSR(float sampleRate) Builds a fresh SimpleADSR from this complete envelope description.toString()withCurves(float attackCurve, float decayCurve, float releaseCurve) Returns a copy with new attack, decay, and release curves.
-
Field Details
-
DEFAULT_CURVE
public static final float DEFAULT_CURVEDefault curve used bySimpleADSR;1.0fis 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 secondsdecay- decay time in secondssustain- 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.0fis linear. Values greater than1.0frise slowly at first and more quickly near the end; values between0.0fand1.0fdo the reverse. Curve values are clamped to the minimum supported bySimpleADSR.- Parameters:
maxAmp- maximum amplitude (0..1)attack- attack time in secondsdecay- decay time in secondssustain- sustain amplitude (0..1)release- release time in secondsattackCurve- attack-stage curvedecayCurve- decay-stage curvereleaseCurve- 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.0fis linear
-
getDecayCurve
public float getDecayCurve()- Returns:
- decay-stage curve;
1.0fis linear
-
getReleaseCurve
public float getReleaseCurve()- Returns:
- release-stage curve;
1.0fis linear
-
copy
- Returns:
- a copy of this ADSRParams object
-
withCurves
Returns a copy with new attack, decay, and release curves.- Parameters:
attackCurve- attack-stage curvedecayCurve- decay-stage curvereleaseCurve- 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
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
-
clampCurve
private static float clampCurve(float curve)
-