Tone.Envelope

↳ EXTENDS Tone.AudioNode

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

CONSTRUCTOR

new Tone.Envelope ( [
attack
] , [
decay
] , [
sustain
] , [
release
] )
attack

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

type: Time
optional
decay

The period of time after the attack that it takes for the envelope to fall to the sustain value.

type: Time
optional
sustain

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

optional
release

The amount of time after the release is triggered it takes to reach 0.

type: Time
optional

DEFAULTS

{
attack : 0.01 ,
decay : 0.1 ,
sustain : 0.5 ,
release : 1 ,
attackCurve : linear ,
releaseCurve : exponential
}

EXAMPLE

//an amplitude envelope
var gainNode = Tone.context.createGain();
var env = new Tone.Envelope({
	"attack" : 0.1,
	"decay" : 0.2,
	"sustain" : 1,
	"release" : 0.8,
});
env.connect(gainNode.gain);

Members

.value

Number READONLY #

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

</>

.attackCurve

String or Array #

The shape of the attack. Can be any of these strings: <ul> <li>linear</li> <li>exponential</li> <li>sine</li> <li>cosine</li> <li>bounce</li> <li>ripple</li> <li>step</li> </ul> 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.

EXAMPLE

env.attackCurve = "linear";

EXAMPLE

//can also be an array
env.attackCurve = [0, 0.2, 0.3, 0.4, 1]
</>

.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.

</>

.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.

</>

.release

Time #

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

</>

.releaseCurve

String or Array #

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

EXAMPLE

env.releaseCurve = "linear";
</>

.sustain

NormalRange #

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

</>
inherited from Tone.AudioNode

.context

Tone.Context READONLY #

Get the audio context belonging to this instance.

</>

Methods

.cancel ( )

#
after
type: Time
↪ returns Tone.Envelope

this

Cancels all scheduled envelope changes after the given time.

</>

.triggerAttackRelease ( )

#
duration

The duration of the sustain.

type: Time
time

When the attack should be triggered.

type: Time
default: now
velocity

The velocity of the envelope.

type: number
default: 1
↪ returns Tone.Envelope

this

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

EXAMPLE

//trigger the attack and then the release after 0.6 seconds.
env.triggerAttackRelease(0.6);
</>

.triggerRelease ( )

#
time

When the release portion of the envelope should start.

type: Time
default: now
↪ returns Tone.Envelope

this

Triggers the release of the envelope.

EXAMPLE

//trigger release immediately
 env.triggerRelease();
</>

.dispose ( )

#
↪ returns Tone.Envelope

this

Disconnect and dispose.

</>

.getValueAtTime ( )

#
time

The time in seconds.

type: Number
↪ returns Number

The scheduled value at the given time.

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

</>

.triggerAttack ( )

#
time

When the attack should start.

type: Time
default: now
velocity

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

default: 1
↪ returns Tone.Envelope

this

Trigger the attack/decay portion of the ADSR envelope.

EXAMPLE

//trigger the attack 0.5 seconds from now with a velocity of 0.2
 env.triggerAttack("+0.5", 0.2);
</>
inherited from Tone.AudioNode

.disconnect ( )

#
output

Either the output index to disconnect if the output is an array, or the node to disconnect from.

↪ returns Tone.AudioNode

this

disconnect the output

</>
inherited from Tone.AudioNode

.toMaster ( )

#
↪ returns Tone.AudioNode

this

Connect ‘this’ to the master output. Shorthand for this.connect(Tone.Master)

EXAMPLE

//connect an oscillator to the master output
var osc = new Tone.Oscillator().toMaster();
</>
docs generated Sep 15 2019