Skip to content
Tone.js

Envelope

class Component ↳ extends ToneAudioNode<EnvelopeOptions>

Envelope is an ADSR envelope generator. Envelope outputs a signal which can be connected to an AudioParam or Tone.Signal.

/\
/ \
/ \
/ \
/ \___________
/ \
/ \
/ \
/ \
return Tone.Offline(() => {
	const env = new Tone.Envelope({
		attack: 0.1,
		decay: 0.2,
		sustain: 0.5,
		release: 0.8,
	}).toDestination();
	env.triggerAttackRelease(0.5);
}, 1.5, 1);
new Envelope(attack?: Time, decay?: Time, sustain?: number, release?: Time)

Parameters

  • attack Time optional

    The amount of time it takes for the envelope to go from 0 to it’s maximum value.

  • decay Time optional

    The period of time after the attack that it takes for the envelope to fall to the sustain value. Value must be greater than 0.

  • sustain number optional

    The percent of the maximum value that the envelope rests at until the release is triggered.

  • release Time optional

    The amount of time after the release is triggered it takes to reach 0. Value must be greater than 0.

new Envelope(options?: Partial<EnvelopeOptions>)

Parameters

attack: Time

When triggerAttack is called, the attack time is the amount of time it takes for the envelope to reach it’s maximum value.

/\
/X \
/XX \
/XXX \
/XXXX \___________
/XXXXX \
/XXXXXX \
/XXXXXXX \
/XXXXXXXX \

Range: 0 to 2

decay: Time

After the attack portion of the envelope, the value will fall over the duration of the decay time to it’s sustain value.

/\
/ X\
/ XX\
/ XXX\
/ XXXX\___________
/ XXXXX \
/ XXXXX \
/ XXXXX \
/ XXXXX \

Range: 0 to 2

input: InputNode | undefined

Envelope has no input

Default: undefined

read-only

name: string

The name of the class

Default: "Envelope"

output: OutputNode

The output signal of the envelope

release: Time

After triggerRelease is called, the envelope’s value will fall to it’s miminum value over the duration of the release time.

/\
/ \
/ \
/ \
/ \___________
/ X\
/ XX\
/ XXX\
/ XXXX\

Range: 0 to 5

sustain: number

The sustain value is the value which the envelope rests at after triggerAttack is called, but before triggerRelease is invoked.

/\
/ \
/ \
/ \
/ \___________
/ XXXXXXXXXXX\
/ XXXXXXXXXXX \
/ XXXXXXXXXXX \
/ XXXXXXXXXXX \
attackCurve: EnvelopeCurve

The shape of the attack. Can be any of these strings:

  • “linear”
  • “exponential”
  • “sine”
  • “cosine”
  • “bounce”
  • “ripple”
  • “step”

Can also be an array which describes the curve. Values in the array are evenly subdivided and linearly interpolated over the duration of the attack.

return Tone.Offline(() => {
	const env = new Tone.Envelope(0.4).toDestination();
	env.attackCurve = "linear";
	env.triggerAttack();
}, 1, 1);
decayCurve: EnvelopeCurve

The shape of the decay either “linear” or “exponential”

return Tone.Offline(() => {
	const env = new Tone.Envelope({
		sustain: 0.1,
		decay: 0.5
	}).toDestination();
	env.decayCurve = "linear";
	env.triggerAttack();
}, 1, 1);
releaseCurve: EnvelopeCurve

The shape of the release. See the attack curve types.

return Tone.Offline(() => {
	const env = new Tone.Envelope({
		release: 0.8
	}).toDestination();
	env.triggerAttack();
	// release curve could also be defined by an array
	env.releaseCurve = [1, 0.3, 0.4, 0.2, 0.7, 0];
	env.triggerRelease(0.2);
}, 1, 1);

read-only

value: number

Read the current value of the envelope. Useful for synchronizing visual output to the envelope.

asArray(length?: number): Promise<Float32Array<ArrayBuffer>>

Render the envelope curve to an array of the given length. Good for visualizing the envelope curve. Rescales the duration of the envelope to fit the length.

Parameters

  • length number optional default 1024

Returns Promise<Float32Array<ArrayBuffer>>

cancel(after?: Time): this

Cancels all scheduled envelope changes after the given time.

Parameters

  • after Time optional

Returns this

connect(destination: InputNode, outputNumber?: number, inputNumber?: number): this

Connect the envelope to a destination node.

Parameters

  • destination InputNode
  • outputNumber number optional default 0
  • inputNumber number optional default 0

Returns this

dispose(): this

Dispose and disconnect

Returns this

getValueAtTime(time: Time): number

Get the scheduled value at the given time. This will return the unconverted (raw) value.

const env = new Tone.Envelope(0.5, 1, 0.4, 2);
env.triggerAttackRelease(2);
setInterval(() => console.log(env.getValueAtTime(Tone.now())), 100);

Parameters

Returns number

triggerAttack(time?: Time, velocity?: number): this

Trigger the attack/decay portion of the ADSR envelope.

const env = new Tone.AmplitudeEnvelope().toDestination();
const osc = new Tone.Oscillator().connect(env).start();
// trigger the attack 0.5 seconds from now with a velocity of 0.2
env.triggerAttack("+0.5", 0.2);

Parameters

  • time Time optional

    When the attack should start.

  • velocity number optional default 1

    The velocity of the envelope scales the vales. number between 0-1

Returns this

triggerAttackRelease(duration: Time, time?: Time, velocity?: number): this

triggerAttackRelease is shorthand for triggerAttack, then waiting some duration, then triggerRelease.

const env = new Tone.AmplitudeEnvelope().toDestination();
const osc = new Tone.Oscillator().connect(env).start();
// trigger the release 0.5 seconds after the attack
env.triggerAttackRelease(0.5);

Parameters

  • duration Time

    The duration of the sustain.

  • time Time optional

    When the attack should be triggered.

  • velocity number optional default 1

    The velocity of the envelope.

Returns this

triggerRelease(time?: Time): this

Triggers the release of the envelope.

const env = new Tone.AmplitudeEnvelope().toDestination();
const osc = new Tone.Oscillator({
	type: "sawtooth"
}).connect(env).start();
env.triggerAttack();
// trigger the release half a second after the attack
env.triggerRelease("+0.5");

Parameters

  • time Time optional

    When the release portion of the envelope should start.

Returns this

static

getDefaults(): EnvelopeOptions

Returns all of the default options belonging to the class.

Returns EnvelopeOptions