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:
- 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.Phaserchains multiple allpass filters together. - 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.
- LFO Modulation: To make the effect dynamic,
Tone.Phaseruses 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:
frequency: Controls the speed of the LFO sweep in Hertz (Hz). A lower frequency results in a slow, subtle sweep, while a higher frequency creates a rapid, vibrating modulation.octaves: Determines the range of the frequency sweep. A higher octave value spreads the phase cancellation notches across a wider frequency range.stages: The number of allpass filters in the chain. Each pair of stages typically creates one notch in the frequency spectrum. More stages result in more notches, leading to a denser and more complex phase cancellation pattern.Q: Represents the quality factor of the filters. Higher values sharpen the notches, making the phase cancellation more pronounced and resonant.wet: Controls the mix between the dry (unaffected) and wet (phase-shifted) signals. For the maximum phase cancellation effect, this should be set to0.5(an equal 50/50 mix).
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");