Lab

envelope-ramp

Envelope curves to gain automation: slicing an envelope at its sustain and scheduling its ramps on a GainNode's AudioParam, for synth voices

pnpm dlx shadcn@latest add @audio-ui/envelope-ramp
import { SUSTAIN_SPLIT_X, sliceEnvelope, scheduleEnvelopeRamp } from "@/lib/envelope-ramp";
Fileslib/envelope-ramp.ts
Depends onNothing
npmNothing
Used byspectrum-analyzer-demo, synth-voice, use-piano-roll-playback, use-synth-voices
ExportKindWhat it is
EnvelopePointinterface
SUSTAIN_SPLIT_XconstWhere an envelope's attack/decay phase ends and its release phase begins, as a fraction of the 0-1 curve.
sliceEnvelopefunctionExtracts the [fromX, toX] slice of an envelope curve, interpolating exact boundary values, and remaps it to its own local 0-1 x range.
scheduleEnvelopeRampfunctionSchedules a gain ramp through points (local 0-1 x) starting at startTime, stretched over durationSeconds, scaled by peakGain.

Usage

The ramps behind the voices, for your own sounds: scheduleEnvelopeRamp(param, points, startTime, seconds, peak, from) runs a gain through an envelope's points, and sliceEnvelope(points, fromX, toX) takes a part of one, such as the release after SUSTAIN_SPLIT_X. A ramp cancels what was scheduled on the param first, so starting a note again never clicks.

Built by Ouest Labs, the source code is available on GitHub.
RSS