Tone.js
    Preparing search index...

    Class FrequencyEnvelope

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

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    attack: Unit.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 \

    0

    2

    context: BaseContext

    The context belonging to the node.

    debug: boolean = false

    Set this debug flag to log all events that happen in this class.

    decay: Unit.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 \

    0

    2

    input: undefined | InputNode = undefined

    Envelope has no input

    name: string = "FrequencyEnvelope"

    The name of the class

    output: OutputNode = ...

    The output signal of the envelope

    release: Unit.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\

    0

    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 \
    version: string = version

    The version number semver

    Accessors

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

      Returns EnvelopeCurve

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

      Parameters

      Returns void

    • get blockTime(): number

      The number of seconds of 1 processing block (128 samples)

      Returns number

      console.log(Tone.Destination.blockTime);
      
    • get channelCount(): number

      channelCount is the number of channels used when up-mixing and down-mixing connections to any inputs to the node. The default value is 2 except for specific nodes where its value is specially determined.

      Returns number

    • set channelCount(channelCount: number): void

      Parameters

      • channelCount: number

      Returns void

    • get channelCountMode(): ChannelCountMode

      channelCountMode determines how channels will be counted when up-mixing and down-mixing connections to any inputs to the node. The default value is "max". This attribute has no effect for nodes with no inputs.

      • "max" - computedNumberOfChannels is the maximum of the number of channels of all connections to an input. In this mode channelCount is ignored.
      • "clamped-max" - computedNumberOfChannels is determined as for "max" and then clamped to a maximum value of the given channelCount.
      • "explicit" - computedNumberOfChannels is the exact value as specified by the channelCount.

      Returns ChannelCountMode

    • set channelCountMode(channelCountMode: ChannelCountMode): void

      Parameters

      • channelCountMode: ChannelCountMode

      Returns void

    • get channelInterpretation(): ChannelInterpretation

      channelInterpretation determines how individual channels will be treated when up-mixing and down-mixing connections to any inputs to the node. The default value is "speakers".

      Returns ChannelInterpretation

    • set channelInterpretation(channelInterpretation: ChannelInterpretation): void

      Parameters

      • channelInterpretation: ChannelInterpretation

      Returns void

    • get disposed(): boolean

      Indicates if the instance was disposed. 'Disposing' an instance means that all of the Web Audio nodes that were created for the instance are disconnected and freed for garbage collection.

      Returns boolean

    • get numberOfInputs(): number

      The number of inputs feeding into the AudioNode. For source nodes, this will be 0.

      Returns number

      const node = new Tone.Gain();
      console.log(node.numberOfInputs);
    • get numberOfOutputs(): number

      The number of outputs of the AudioNode.

      Returns number

      const node = new Tone.Gain();
      console.log(node.numberOfOutputs);
    • get value(): number

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

      Returns number

    Methods

    • 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 = 1024

      Returns Promise<Float32Array>

    • Connect the output of this node to the rest of the nodes in series.

      Parameters

      Returns this

      const player = new Tone.Player("https://tonejs.github.io/audio/drum-samples/handdrum-loop.mp3");
      player.autostart = true;
      const filter = new Tone.AutoFilter(4).start();
      const distortion = new Tone.Distortion(0.5);
      // connect the player to the filter, distortion and then to the master output
      player.chain(filter, distortion, Tone.Destination);
    • connect the output of this node to the rest of the nodes in parallel.

      Parameters

      Returns this

      const player = new Tone.Player("https://tonejs.github.io/audio/drum-samples/conga-rhythm.mp3");
      player.autostart = true;
      const pitchShift = new Tone.PitchShift(4).toDestination();
      const filter = new Tone.Filter("G5").toDestination();
      // connect a node to the pitch shift and filter in parallel
      player.fan(pitchShift, filter);
    • Get the scheduled value at the given time. This will return the unconverted (raw) value.

      Parameters

      Returns number

      const env = new Tone.Envelope(0.5, 1, 0.4, 2);
      env.triggerAttackRelease(2);
      setInterval(() => console.log(env.getValueAtTime(Tone.now())), 100);
    • Set multiple properties at once with an object.

      Parameters

      • props: RecursivePartial<Options>

      Returns this

      const filter = new Tone.Filter().toDestination();
      // set values using an object
      filter.set({
      frequency: "C6",
      type: "highpass"
      });
      const player = new Tone.Player("https://tonejs.github.io/audio/berklee/Analogsynth_octaves_highmid.mp3").connect(filter);
      player.autostart = true;
    • Convert the class to a string

      Returns string

      const osc = new Tone.Oscillator();
      console.log(osc.toString());
    • Trigger the attack/decay portion of the ADSR envelope.

      Parameters

      • Optionaltime: Unit.Time

        When the attack should start.

      • velocity: number = 1

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

      Returns this

      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);
    • triggerAttackRelease is shorthand for triggerAttack, then waiting some duration, then triggerRelease.

      Parameters

      • duration: Unit.Time

        The duration of the sustain.

      • Optionaltime: Unit.Time

        When the attack should be triggered.

      • velocity: number = 1

        The velocity of the envelope.

      Returns this

      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);
    • Triggers the release of the envelope.

      Parameters

      • Optionaltime: Unit.Time

        When the release portion of the envelope should start.

      Returns this

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