Understanding Tone.Destination in Tone.js

This article explains the purpose and functionality of Tone.Destination within a Tone.js audio graph. You will learn how this crucial node acts as the final output for your web audio projects, how to route audio to it, and how to use it to manage master audio properties like volume, muting, and global effects.

In Tone.js, Tone.Destination represents the master audio output node of your audio graph. It is a direct wrapper around the Web Audio API’s native AudioContext.destination, acting as the final gateway through which all sound must pass before it can be heard through the user’s speakers or headphones. Without connecting your sound sources to this node, your synthesis and audio playback will remain silent.

Audio Routing and Connection

To make any sound source audible in Tone.js—whether it is a synthesizer, an audio player, or an oscillator—you must route its output to Tone.Destination. This can be done in two ways:

  1. The .toDestination() Shorthand: Most nodes in Tone.js feature a convenient .toDestination() method. This automatically connects the output of that specific node directly to the master output.

    const synth = new Tone.Synth().toDestination();
    synth.triggerAttackRelease("C4", "8n");
  2. The .connect() Method: You can manually connect any node to the destination using the standard connection syntax.

    const player = new Tone.Player("audio.mp3");
    player.connect(Tone.Destination);

In a complex audio graph, you will often route sources through multiple effects processors (like delays, reverbs, or filters) before finally connecting the end of the effect chain to Tone.Destination.

Global Audio Control

Because all audio signals eventually converge at Tone.Destination, it serves as the perfect point for global audio control. It inherits from the Tone.Volume class, allowing you to manipulate the master output of your entire application easily.

Applying Master Effects

Tone.Destination can also be used to apply master effects to your entire mix, such as a limiter to prevent clipping or a global reverb. By utilizing the chain method, you can insert effects right before the final physical output.

const limiter = new Tone.Limiter(-2);
const lowpass = new Tone.Filter(800, "lowpass");

// Route all incoming audio through the filter and limiter before outputting to speakers
Tone.Destination.chain(lowpass, limiter);