Skip to content

ADSR

Tier: Primitives | ComponentType: 1 | Params: 5

Envelope generator with configurable curve shape for attack, decay, sustain, and release stages.

Overview

The ADSR generates a control signal envelope triggered by gate on/off events. It progresses through four stages: Attack (ramp to 1.0), Decay (ramp to sustain level), Sustain (hold), and Release (ramp to 0.0). A curve parameter controls whether transitions are linear, exponential (fast start), or logarithmic (slow start).

Used to shape the amplitude, filter cutoff, or any time-varying parameter of a sound. The envelope is a modulation source — it ignores audio input and generates its own signal from 0 to 1.

File Locations

Path
Header Sources/FolioDSP/include/FolioDSP/Primitives/ADSR.h
Implementation Sources/FolioDSP/src/Primitives/ADSR.cpp
Tests Tests/FolioDSPTests/ADSRTests.swift
Bridge Sources/FolioDSPBridge/src/FolioDSPBridge.mm (ADSRBridge)

Parameters

Index Name Description Min Max Default Min Default Max Default Unit
0 Attack Time to ramp from 0 to 1 0.1 30000.0 1.0 2000.0 10.0 ms
1 Decay Time to ramp from 1 to sustain level 0.1 30000.0 1.0 5000.0 100.0 ms
2 Sustain Level held while gate is on (after decay) 0.0 1.0 0.0 1.0 0.7
3 Release Time to ramp from current level to 0 after gate off 0.1 60000.0 10.0 10000.0 200.0 ms
4 Curve Shape of transitions: -1=log, 0=linear, +1=exponential -1.0 1.0 -1.0 1.0 0.0

Processing Algorithm

1. Stage State Machine

The envelope progresses through stages: Idle(0) → Attack(1) → Decay(2) → Sustain(3) → Release(4) → Idle.

2. Time Normalization

\[t = \frac{\text{stageTime}}{\text{stageDuration}}\]

where stageDuration = milliseconds × sampleRate × 0.001.

3. Curve Shaping

\[\text{shaped} = \begin{cases} t & |\text{curve}| < 0.001 \\ t^{1 + 4 \cdot \text{curve}} & \text{curve} > 0 \\ t^{1/(1 - 4 \cdot \text{curve})} & \text{curve} < 0 \end{cases}\]

4. Level Interpolation

\[y = \text{start} + (\text{end} - \text{start}) \cdot \text{shaped}\]

Snapshot Fields

Field Type Range Unit Description
Stage Uint8 0–4 Current envelope stage
Output Float 0–1 Current envelope value
Progress Float 0–1 Progress through current stage
Gate Bool 0–1 Whether gate is currently on

Implementation Notes

  • gate(true) triggers Attack; gate(false) triggers Release
  • retrigger() forces immediate re-entry to Attack
  • Stage transitions are seamless — interpolation maintains level continuity
  • No DC blocker needed — output is always in [0, 1]

Equation Summary

y = start + (end-start)·curve(t/dur)