A note isn't a steady tone — it's born, holds, and dies. The ADSR envelope draws that arc: Attack, Decay, Sustain, Release.
ampEnv = adsr 2ms 160ms 0 220ms reads: rise in 2ms (attack), fall over 160ms (decay) to a sustain level of 0, then fade over 220ms once the note ends (release).
Short attack + zero sustain = a percussive pluck. Long attack + full sustain = a pad that swells in and holds.
The envelope is where a patch's character lives — the same saw is a stab, a bell, or a string section depending only on these four numbers.
Two patches can share one file. Give each its own play line and they play together.
The starting point#
The lesson opens with this song in the editor. Every edit recompiles and plays.
-- The envelope: Attack, Decay, Sustain, Release shape every note's life.
pluck = patch {
source = saw (freq pitch),
-- A D S R
ampEnv = adsr 2ms 160ms 0 220ms,
gain = vel * 0.5
}
loop = play pluck !"c3 e3 g3 b3"
What to watch#
Watch the scope's height per note: it snaps up on the attack and tails off on the release. A long attack makes the wave swell in instead of starting full.
Goals#
The workbench checks these as you work; the solution is there when you want it.
- Let the pluck ring out — release at least 300ms
- Write a second, contrasting patch
- One patch should swell in slowly — attack 250ms or more
- Stretch: play both patches at once
Make it yours#
Design two opposite voices — a tight stab and a slow swell — and give each a pattern that suits its shape.
Further reading#
Language reference in the reference.