API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classEnvelope

@codexo/exojs / audio / stable

ADSR (Attack-Decay-Sustain-Release) envelope generator. Schedules a gain curve on a target `AudioParam`: attack: 0 → 1.0 (peak) over attack decay: 1.0 → sustainLevel over decay sustain: held at sustainLevel release: current → 0 over release (triggered by `release()`) Use `trigger()` to start the attack/decay/sustain phase, and `release()` to start the release phase. Multiple envelopes can target the same AudioParam; the latest schedule wins (cancel via `gain.cancelScheduledValues` if needed).

5
props
4
methods
0
events
Import
import { Envelope } from '@codexo/exojs'

ADSR (Attack-Decay-Sustain-Release) envelope generator. Schedules a gain curve on a target `AudioParam`:

attack: 0 → 1.0 (peak) over attack decay: 1.0 → sustainLevel over decay sustain: held at sustainLevel release: current → 0 over release (triggered by `release()`)

Use `trigger()` to start the attack/decay/sustain phase, and `release()` to start the release phase. Multiple envelopes can target the same AudioParam; the latest schedule wins (cancel via `gain.cancelScheduledValues` if needed).

Constructors1
new(options: EnvelopeOptions): Envelope
Methods4
destroy(): void
hold(gainParam: AudioParam, atTime: number): void
Freeze the running automation at its current value without releasing the note. Used when a voice is paused: the scheduled ramps must not keep advancing against audioContext.currentTime while nothing is audible. Unlike Envelope.release this keeps the trigger bookkeeping, so the envelope can be picked up again with trigger(param, now, elapsed).
releaseAt(gainParam: AudioParam, atTime: number): void
Schedule release → 0 starting at atTime. Call this when the note should stop (e.g., key release, sound dismissed). The release starts from wherever the envelope actually is, including mid-attack and mid-decay. A bare cancelScheduledValues would drop the in-flight ramp and snap the parameter back to the previous event's value (0 during attack) - an audible click.
Schedule attack → decay → sustain on the target gain parameter starting at atTime (audioContext.currentTime). elapsed resumes an envelope that had already run for that long when it was frozen (see Envelope.hold): the schedule is laid out as if the note had been triggered elapsed ago, so the parameter is pinned to the value the envelope had reached and only the stages still ahead are scheduled. A stage already behind the resume point is skipped rather than replayed - that is what keeps a paused voice from starting its attack over, and equally from finding the envelope run out against a clock that kept ticking while it was silent.
Properties5
sustainLevel: number
Sustain level, 0..1.
Source