How to Control Synth Envelopes in Tone.js

In web audio development, shaping the character of a synthesizer’s sound is crucial for creating dynamic, expressive instruments. This article explores the specific parameters Tone.js provides to control a synthesizer’s amplitude envelope, focusing on the classic ADSR (Attack, Decay, Sustain, Release) model and the curve shaping options that allow developers to programmatically customize how a sound evolves over time.

The Core ADSR Parameters

Tone.js synthesizers, such as Tone.Synth and Tone.MonoSynth, utilize an internal Tone.Envelope to shape the volume of a sound from the moment a note is triggered to the moment it decays to silence. The envelope is defined by four primary temporal and level parameters:

Envelope Curve Parameters

To provide more organic and natural-sounding instruments, Tone.js allows you to adjust the interpolation mathematical curves of the attack, decay, and release phases.

Configuring Envelopes in Code

In Tone.js, you can define these parameters directly inside the constructor options when instantiating a synthesizer, or update them dynamically after instantiation.

Inline Configuration

const synth = new Tone.Synth({
  envelope: {
    attack: 0.1,
    decay: 0.2,
    sustain: 0.5,
    release: 0.8,
    attackCurve: "exponential",
    releaseCurve: "linear"
  }
}).toDestination();

Dynamic Updating

You can also modify these parameters on the fly, allowing for interactive user interfaces like sliders or knobs to control the synthesizer in real-time.

// Change the attack time to 0.5 seconds
synth.envelope.attack = 0.5;

// Change the release curve type
synth.envelope.releaseCurve = "exponential";