Sanic Boom

Envelopes

ADSR envelope shaping

Envelopes shape how notes evolve over time. Without an envelope, notes start and stop abruptly. With an envelope, they can fade in, sustain, and fade out naturally.

ADSR Envelope

The adsr() function adds an ADSR (Attack, Decay, Sustain, Release) envelope to your sound.

play [C4 E4 G4] |> saw |> adsr(0.1, 0.2, 0.7, 0.3)

Parameters

ParameterDescriptionRangeDefault
attackTime to reach full volume0.001 - 10 seconds0.01
decayTime to fall to sustain level0.001 - 10 seconds0.1
sustainVolume level while held0.0 - 1.00.7
releaseTime to fade to silence after note ends0.001 - 10 seconds0.3

Syntax

|> adsr(10ms, 100ms, 0.7, 200ms)                    // Milliseconds
|> adsr(0.01s, 0.1s, 0.7, 0.2s)                     // Seconds
|> adsr(attack: 10ms, decay: 100ms, sustain: 0.7, release: 200ms)

Time parameters (attack, decay, release) accept:

  • Seconds: 0.1s
  • Milliseconds: 100ms
  • Plain numbers (interpreted as seconds): 0.1
// Positional arguments (attack, decay, sustain, release)
[C4] |> saw |> adsr(0.1, 0.2, 0.7, 0.3)

// Named arguments
[C4] |> saw |> adsr(attack: 0.1, decay: 0.2, sustain: 0.7, release: 0.3)

// Mix positional and named
[C4] |> saw |> adsr(0.1, 0.2, sustain: 0.5)

// Use defaults
[C4] |> saw |> adsr

How ADSR Works

Volume
  ^
1 |    /\
  |   /  \___________
S |  /              \
  | /                \
0 +--A--D-----S------R--> Time
  1. Attack: Volume ramps from 0 to maximum (1.0)
  2. Decay: Volume falls from maximum to sustain level
  3. Sustain: Volume holds at sustain level while note is held
  4. Release: When note ends, volume fades to silence

Common Envelope Shapes

Pad (slow, atmospheric)

play [C4 E4 G4] |> supersaw |> adsr(0.8, 0.3, 0.6, 1.5) |> reverb(0.7)

Long attack for fade-in, high sustain, long release for wash.

Pluck (short, percussive)

play [C4 E4 G4] |> saw |> adsr(0.001, 0.1, 0.0, 0.1)

Instant attack, quick decay to silence, no sustain.

Bass (punchy)

play [C2 _ C2 _] |> saw |> adsr(0.01, 0.1, 0.3, 0.1)

Very fast attack for punch, short decay, low sustain for body.

Strings (smooth)

play [C4 E4 G4 B4] |> saw |> adsr(0.3, 0.1, 0.8, 0.5)

Moderate attack for bow-like feel, high sustain.

Bell (ringing)

play [C5 E5 G5] |> fm(ratio: 3.5, index: 5.0) |> adsr(0.001, 0.5, 0.2, 2.0)

Instant attack, long decay, low sustain, very long release.

Placement in Pipe Chain

adsr() goes after the instrument, before other effects:

pattern → transforms → instrument → adsr → effects

Correct:

play [C4 E4 G4]
    |> arp(up)                       // transform
    |> saw                           // instrument
    |> adsr(0.1, 0.2, 0.7, 0.3)      // envelope
    |> lowpass(800)                  // effect
    |> reverb(0.5)                   // effect

Tips

  • Attack = 0 can cause clicks. Use at least 0.001 for a clean start.
  • Sustain = 0 with long decay creates pluck/bell sounds.
  • Long release works well with reverb for atmospheric sounds.
  • Short everything gives percussive, rhythmic sounds.
  • Match envelope to tempo: faster tempos need shorter envelopes.

On this page