|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
Classic ADSR envelope generator with exponential curves. More...
#include <EnvelopeGenerator.h>
Public Types | |
| enum class | State { Idle , Attack , Decay , Sustain , Release } |
Public Member Functions | |
| ADSREnvelope () noexcept | |
| void | prepare (double sampleRate) noexcept |
| Prepares the envelope for the given sample rate. | |
| void | prepare (const AudioSpec &spec) noexcept |
| Prepares from AudioSpec (unified API). | |
| void | setAttack (T ms) noexcept |
| Sets attack time in milliseconds (0 -> 1). | |
| void | setDecay (T ms) noexcept |
| Sets decay time in milliseconds (1 -> sustain). | |
| void | setSustain (T level) noexcept |
| Sets sustain level (0.0 to 1.0). | |
| void | setRelease (T ms) noexcept |
| Sets release time in milliseconds (full scale -> silence). | |
| void | setParameters (T attackMs, T decayMs, T sustain, T releaseMs) noexcept |
| Sets all ADSR parameters at once. | |
| void | setCurvature (T curve) noexcept |
| Sets the curvature of all exponential stages at once. | |
| void | setCurvature (T attackCurve, T decayCurve, T releaseCurve) noexcept |
| Sets independent curvatures per stage. | |
| void | noteOn () noexcept |
| Triggers the attack phase (note on). Legato: continues from the current value. | |
| void | noteOff () noexcept |
| Triggers the release phase (note off). | |
| void | reset () noexcept |
| Resets the envelope to idle with zero output. | |
| T | getNextValue () noexcept |
| Returns the next envelope value and advances the state machine. | |
| void | processBlock (T *output, int numSamples) noexcept |
| Fills a buffer with envelope values. | |
| T | getCurrentValue () const noexcept |
| Returns the current envelope value. | |
| State | getState () const noexcept |
| Returns the current state. | |
| bool | isActive () const noexcept |
| Returns true if the envelope is actively producing output. | |
Classic ADSR envelope generator with exponential curves.
Each stage runs an asymptotic RC-style one-pole toward a target that overshoots the stage endpoint, so the stage completes in finite time with the exact duration set by its parameter:
Curvature shapes each stage: high values are strongly exponential, 0.1 is near-linear. Stage durations stay exact across the whole curvature range.
State machine: Idle -> Attack -> Decay -> Sustain -> Release -> Idle. The recursion state is double regardless of T (the framework rule for recursive state): in float, very long stages stall short of their target when the per-sample increment rounds to zero.
Threading is owner-managed: call setters, triggers and processing from the owning (audio) thread, the pattern of a synth voice. A default-constructed envelope is functional at 48 kHz; prepare() adapts it to the real rate.
| T | Output type (float or double). Constrained to IEEE 754 floats. |
Definition at line 56 of file EnvelopeGenerator.h.
|
strong |
| Enumerator | |
|---|---|
| Idle | |
| Attack | |
| Decay | |
| Sustain | |
| Release | |
Definition at line 59 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Definition at line 61 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Returns the current envelope value.
Definition at line 328 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Returns the next envelope value and advances the state machine.
Definition at line 167 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Returns the current state.
Definition at line 331 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Returns true if the envelope is actively producing output.
Definition at line 334 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Triggers the release phase (note off).
Definition at line 148 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Triggers the attack phase (note on). Legato: continues from the current value.
Definition at line 142 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Prepares from AudioSpec (unified API).
| spec | Audio specification containing the sample rate. |
Definition at line 78 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Prepares the envelope for the given sample rate.
| sampleRate | The operating sample rate in Hz. |
Definition at line 67 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Fills a buffer with envelope values.
Runs each stage as a tight loop with its constants hoisted (no state dispatch per sample). Sample-exact match with getNextValue().
| output | Buffer to fill with envelope values. |
| numSamples | Number of samples to generate. |
Definition at line 227 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Resets the envelope to idle with zero output.
Definition at line 155 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Sets attack time in milliseconds (0 -> 1).
Definition at line 83 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Sets independent curvatures per stage.
Classic analog envelopes shape each stage differently (near-linear attack, strongly exponential release). Higher values = more curved.
| attackCurve | Attack curvature (0.1 to 10.0; low = near-linear). |
| decayCurve | Decay curvature. |
| releaseCurve | Release curvature. |
Definition at line 131 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Sets the curvature of all exponential stages at once.
| curve | Curvature factor (default: 3.0, range: 0.1 to 10.0). |
Definition at line 114 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Sets decay time in milliseconds (1 -> sustain).
Definition at line 86 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Sets all ADSR parameters at once.
| attackMs | Attack time in ms. |
| decayMs | Decay time in ms. |
| sustain | Sustain level (0-1). |
| releaseMs | Release time in ms. |
Definition at line 101 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Sets release time in milliseconds (full scale -> silence).
Definition at line 92 of file EnvelopeGenerator.h.
|
inlinenoexcept |
Sets sustain level (0.0 to 1.0).
Definition at line 89 of file EnvelopeGenerator.h.