Package net.paulhertz.pixelaudio.sampler
Class SimpleADSR
java.lang.Object
net.paulhertz.pixelaudio.sampler.SimpleADSR
SimpleADSR - software envelope generator with optional exponential curves.
Features:
- Sample-rate-based time scaling
- Per-stage exponential curvature
- Sustain-level clamping
noteOn(),noteOff(),tick(), andisFinished()
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate floatprivate floatprivate floatprivate floatprivate floatprivate floatprivate floatprivate floatprivate intprivate SimpleADSR.Stageprivate intprivate floatprivate float -
Constructor Summary
ConstructorsConstructorDescriptionSimpleADSR(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 TypeMethodDescriptionprivate static floatexponentialInterp(int step, int total, float start, float end, float curve) floatgetValue()Returns the current envelope value.booleanReports whether the envelope is idle or has completed its release stage.voidnoteOff()Starts the release stage from the current envelope value.voidnoteOn()Starts the envelope at the attack stage.voidsetCurves(float attackC, float decayC, float releaseC) Sets curvature values for attack, decay, and release stages.voidsetSampleRate(float sr) Sets the sample rate used to convert envelope stage times to samples.voidsetTimes(float a, float d, float s, float r) Sets envelope stage times and sustain level.floattick()Advances the envelope by one sample.
-
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
-
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 secondsdecay- decay time in secondssustain- sustain level in the range 0..1release- 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 secondsdecay- decay time in secondssustain- sustain level in the range 0..1release- release time in secondsattackCurve- curvature for the attack stagedecayCurve- curvature for the decay stagereleaseCurve- 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 curvaturedecayC- decay-stage curvaturereleaseC- 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 secondsd- decay time in secondss- sustain levelr- release time in seconds
-