Skip to content
Tone.js

FrequencyEnvelope

class Component ↳ extends Envelope

FrequencyEnvelope is an Envelope which ramps between baseFrequency and octaves. It can also have an optional exponent to adjust the curve which it ramps.

const oscillator = new Tone.Oscillator().toDestination().start();
const freqEnv = new Tone.FrequencyEnvelope({
	attack: 0.2,
	baseFrequency: "C2",
	octaves: 4
});
freqEnv.connect(oscillator.frequency);
freqEnv.triggerAttack();
new FrequencyEnvelope(attack?: Time, decay?: Time, sustain?: number, release?: Time)

Parameters

  • attack Time optional

    the attack time in seconds

  • decay Time optional

    the decay time in seconds

  • sustain number optional

    a percentage (0-1) of the full amplitude

  • release Time optional

    the release time in seconds

new FrequencyEnvelope(options?: Partial<FrequencyEnvelopeOptions>)

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 its 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 its sustain value.

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

Range: 0 to 2

↳ inherited from Envelope

input: InputNode | undefined

Envelope has no input

Default: undefined

read-only

name: string

The name of the class

Default: "FrequencyEnvelope"

↳ inherited from Envelope

output: OutputNode

The output signal of the envelope

↳ inherited from Envelope

release: Time

After triggerRelease is called, the envelope’s value will fall to its minimum 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);
baseFrequency: Frequency

The envelope’s minimum output value. This is the value which it starts at.

↳ 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);
exponent: number

The envelope’s exponent value.

octaves: number

The number of octaves above the baseFrequency that the envelope will scale to.

↳ 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

↳ inherited from Envelope

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

disconnect the output

Parameters

  • destination InputNode optional
  • 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

Returns all of the default options belonging to the class.

Returns FrequencyEnvelopeOptions