Guide to Tone.Phaser and Phase Cancellation in Tone.js

This article explores Tone.Phaser, a powerful audio effect in the Tone.js framework, by explaining how it utilizes phase cancellation to create its signature sweeping sound. You will learn the underlying mechanics of phase modulation, the key parameters of the Tone.Phaser class, and how to implement this effect in your Web Audio API projects.

What is Tone.Phaser?

Tone.Phaser is an effect class in Tone.js that wraps a phase shifter. It creates a sweeping, swooshing sound often heard on electric guitars, electric pianos, and synthesizers. The effect is achieved by splitting an audio signal into two paths, altering the phase of one path, and mixing it back with the original, unaltered signal.

How Tone.Phaser Manipulates Phase Cancellation

The core mechanic behind a phaser is phase cancellation. When two identical sound waves are perfectly in phase, they combine to double in volume (constructive interference). However, if one wave is shifted by 180 degrees (completely out of phase) relative to the other, they cancel each other out, resulting in silence (destructive interference).

Tone.Phaser exploits this behavior using the following components:

  1. Allpass Filters: Unlike highpass or lowpass filters that cut out specific frequency ranges, an allpass filter allows all frequencies to pass through but alters their phase relationship. Tone.Phaser chains multiple allpass filters together.
  2. Frequency Notches: At specific frequencies, the allpass filters shift the phase of the wet signal by exactly 180 degrees relative to the dry signal. When the dry and wet signals are mixed, these specific frequencies cancel each other out, creating “notches” or dips in the frequency spectrum.
  3. LFO Modulation: To make the effect dynamic, Tone.Phaser uses an internal Low-Frequency Oscillator (LFO). This LFO continuously modulates the center frequency of the allpass filters. As the center frequency moves up and down, the notches sweep across the frequency spectrum, creating the classic swirling phaser sound.

Key Parameters of Tone.Phaser

To customize how Tone.Phaser manipulates phase cancellation, you can adjust several key properties:

Implementation Example

Below is a basic implementation of Tone.Phaser applied to a synthesizer in Tone.js:

// Create a new phaser effect
const phaser = new Tone.Phaser({
  frequency: 0.5,  // LFO speed of 0.5 Hz (one sweep every 2 seconds)
  octaves: 5,      // Sweep across 5 octaves
  stages: 4,       // 4 allpass filters (creates 2 phase notches)
  Q: 10,           // High resonance for a sharp effect
  wet: 0.5         // 50/50 mix for maximum phase cancellation
}).toDestination();

// Create a synth and connect it to the phaser
const synth = new Tone.Synth().connect(phaser);

// Trigger a note to hear the sweeping phaser effect
synth.triggerAttackRelease("C4", "2n");