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();Constructor
Section titled “Constructor”Parameters
new FrequencyEnvelope(options?: Partial<FrequencyEnvelopeOptions>)Parameters
- options
Partial<FrequencyEnvelopeOptions>optional
Properties
Section titled “Properties”attack
Section titled “attack”↳ inherited from Envelope
attack: TimeWhen 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: TimeAfter 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
output
Section titled “output”↳ inherited from Envelope
output: OutputNodeThe output signal of the envelope
release
Section titled “release”↳ inherited from Envelope
release: TimeAfter 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
Section titled “sustain”↳ inherited from Envelope
sustain: numberThe sustain value is the value which the envelope rests at after triggerAttack is called, but before triggerRelease is invoked.
/\ / \ / \ / \ / \___________ / XXXXXXXXXXX\ / XXXXXXXXXXX \ / XXXXXXXXXXX \ / XXXXXXXXXXX \attackCurve
Section titled “attackCurve”↳ inherited from Envelope
attackCurve: EnvelopeCurveThe 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
Section titled “baseFrequency”baseFrequency: FrequencyThe envelope’s minimum output value. This is the value which it starts at.
decayCurve
Section titled “decayCurve”↳ inherited from Envelope
decayCurve: EnvelopeCurveThe 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);octaves
Section titled “octaves”octaves: numberThe number of octaves above the baseFrequency that the envelope will scale to.
releaseCurve
Section titled “releaseCurve”↳ inherited from Envelope
releaseCurve: EnvelopeCurveThe 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: numberRead the current value of the envelope. Useful for synchronizing visual output to the envelope.
Methods
Section titled “Methods”asArray()
Section titled “asArray()”↳ 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
numberoptional default1024
Returns Promise<Float32Array<ArrayBuffer>>
cancel()
Section titled “cancel()”↳ inherited from Envelope
cancel(after?: Time): thisCancels all scheduled envelope changes after the given time.
Parameters
- after
Timeoptional
Returns this
connect()
Section titled “connect()”↳ inherited from Envelope
connect(destination: InputNode, outputNumber?: number, inputNumber?: number): thisConnect the envelope to a destination node.
Parameters
- destination
InputNode - outputNumber
numberoptional default0 - inputNumber
numberoptional default0
Returns this
getValueAtTime()
Section titled “getValueAtTime()”↳ inherited from Envelope
getValueAtTime(time: Time): numberGet 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
- time
Time
Returns number
triggerAttack()
Section titled “triggerAttack()”↳ inherited from Envelope
triggerAttack(time?: Time, velocity?: number): thisTrigger 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
TimeoptionalWhen the attack should start.
-
velocity
numberoptional default1The velocity of the envelope scales the vales. number between 0-1
Returns this
triggerAttackRelease()
Section titled “triggerAttackRelease()”↳ inherited from Envelope
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
Returns this
triggerRelease()
Section titled “triggerRelease()”↳ inherited from Envelope
triggerRelease(time?: Time): thisTriggers 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
TimeoptionalWhen the release portion of the envelope should start.
Returns this
getDefaults()
Section titled “getDefaults()”static
getDefaults(): FrequencyEnvelopeOptionsReturns all of the default options belonging to the class.
Returns FrequencyEnvelopeOptions
Inherited members
Section titled “Inherited members”- From
ToneWithContext: context, blockTime, sampleTime, get(), immediate(), now(), set(), toFrequency(), toSeconds(), toTicks() - From
Tone: debug, version, disposed, toString() - From
ToneAudioNode: channelCount, channelCountMode, channelInterpretation, numberOfInputs, numberOfOutputs, chain(), disconnect(), fan(), toDestination(), toMaster()