Skip to content
Tone.js

AmplitudeEnvelope

class Component ↳ extends Envelope

AmplitudeEnvelope is a Tone.Envelope connected to a gain node. Unlike Tone.Envelope, which outputs the envelope’s value, AmplitudeEnvelope accepts an audio signal as the input and will apply the envelope to the amplitude of the signal. Read more about ADSR Envelopes on Wikipedia.

return Tone.Offline(() => {
	const ampEnv = new Tone.AmplitudeEnvelope({
		attack: 0.1,
		decay: 0.2,
		sustain: 1.0,
		release: 0.8
	}).toDestination();
	// create an oscillator and connect it
	const osc = new Tone.Oscillator().connect(ampEnv).start();
	// trigger the envelopes attack and release "8t" apart
	ampEnv.triggerAttackRelease("8t");
}, 1.5, 1);
new AmplitudeEnvelope(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 AmplitudeEnvelope(options?: Partial<EnvelopeOptions>)

Parameters

↳ inherited from Envelope

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

↳ inherited from Envelope

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: Gain

Envelope has no input

read-only

name: string

The name of the class

Default: "AmplitudeEnvelope"

output: Gain

The output signal of the envelope

↳ inherited from 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

↳ inherited from Envelope

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 \

↳ inherited from Envelope

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);

↳ inherited from Envelope

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);

↳ inherited from Envelope

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 ↳ inherited from Envelope

value: number

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

↳ inherited from 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>>

↳ inherited from Envelope

cancel(after?: Time): this

Cancels all scheduled envelope changes after the given time.

Parameters

  • after Time optional

Returns this

↳ inherited from Envelope

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

Clean up

Returns this

↳ inherited from Envelope

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

↳ inherited from Envelope

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

↳ inherited from Envelope

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

↳ inherited from Envelope

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 ↳ inherited from Envelope

getDefaults(): EnvelopeOptions

Returns all of the default options belonging to the class.

Returns EnvelopeOptions