Split Stereo to Left and Right in Tone.js

This article explains how to split a stereo audio signal into separate left and right mono channels using Tone.js. You will learn how to utilize the Tone.Split node to isolate each channel, route them independently through different audio effects, and understand the syntax required to target specific channel outputs.

Using the Tone.Split Node

In Tone.js, the Tone.Split node is used to separate a stereo (2-channel) input signal into two individual mono outputs. The first output (index 0) represents the left channel, and the second output (index 1) represents the right channel.

Step-by-Step Implementation

To split a stereo signal, you need to create a source, connect it to a Tone.Split instance, and then route the individual outputs of the splitter to your desired destinations.

Here is a practical code example:

// 1. Create a stereo source (e.g., a player with a stereo audio file)
const player = new Tone.Player("path/to/stereo-file.mp3");

// 2. Create the Split node
const splitter = new Tone.Split();

// 3. Connect the stereo source to the splitter
player.connect(splitter);

// 4. Route the left channel (output 0) to an effect or destination
const leftDelay = new Tone.FeedbackDelay("8n", 0.5).toDestination();
splitter.connect(leftDelay, 0, 0); 
// Arguments: (destinationNode, outputNumber, inputNumber)
// Output 0 of the splitter is the Left channel.

// 5. Route the right channel (output 1) to a different effect or destination
const rightReverb = new Tone.Reverb(3).toDestination();
splitter.connect(rightReverb, 1, 0);
// Output 1 of the splitter is the Right channel.

// Start the audio context and play the source
async function playAudio() {
  await Tone.start();
  player.start();
}

Connection Syntax Explained

The key to routing individual channels lies in the .connect() method parameters:

node.connect(destination, outputIndex, inputIndex)