Skip to content
Tone.js

Connections

source.connect(sink);

connect is used to specify how audio data should flow from one node to the next. It’s analogous to “connecting a cable” from the output of one thing to the input of another. You will see the method used all over Tone.js and the Web Audio API.

Signal flows from the output of the connect-er node (aka “source”) to the input of the connect-ee (“sink”). For example, this code snippet: source.connect(sink) could be visualized like this:

source sink

Connecting a node more than once doesn’t replace its earlier connections, it adds to them. Each destination gets its own copy of the signal:

a.connect(b);
a.connect(c);
a b c

When several nodes connect to the same input, their signals are added together. This is how sounds are mixed:

a.connect(c);
b.connect(c);
a c b

The connection is made at a low level within the underlying API. Neither Tone.js nor the Web Audio API explicitly retain connection data so there is no query mechanism enabling you to determine something like “Is A connected to B?”.

You can connect different inputs and outputs

Section titled “You can connect different inputs and outputs”

For nodes that have multiple inputs or outputs, connect can accept two additional arguments: the output number of the connect-er and the input number of the connect-ee.

To connect the left (0th) output of a splitter node to the right (1st) input of a merger node: split.connect(merge, 0, 1).

split merge Stereo L R R L Stereo

Tone.js gives you a few convenience methods for connecting up nodes.

Use chain to connect a group of nodes in series.

source.chain(filter, pan, volume, Tone.getDestination());
source filter pan volume destination

fan connects the output of a node to the inputs of all of the arguments:

source.fan(reverb, chorus);
source reverb chorus

toDestination is shorthand for connecting a node to the Destination (the speakers). It returns the node so it can be chained onto the constructor:

const synth = new Tone.Synth().toDestination();
synth destination

disconnect removes connections. With no arguments it removes all of a node’s outgoing connections, or pass a node to remove just that one:

source.disconnect(reverb);