What is Tone.LFO and its Wave Shapes in Tone.js

This article explains what the Tone.LFO (Low-Frequency Oscillator) class is in the Tone.js web audio library and details the various oscillator wave shapes it supports. You will learn how to configure an LFO to modulate audio parameters and explore the specific waveforms available for creating dynamic sound synthesis effects.

Understanding Tone.LFO

In Tone.js, Tone.LFO is an oscillator designed to operate at low frequencies, typically below the audible range (less than 20 Hz). Instead of being heard directly as sound, an LFO is used to modulate other audio parameters over time. For example, you can connect an LFO to the frequency of a synthesizer to create vibrato, or to the volume of an amplifier to create tremolo.

The Tone.LFO class outputs a signal that alternates between a designated minimum and maximum value at a speed determined by its frequency.

Basic Usage Example

// Create an LFO oscillating between 100Hz and 1000Hz at a rate of 2Hz
const lfo = new Tone.LFO("2hz", 100, 1000);

// Connect the LFO to a filter's frequency parameter
const filter = new Tone.Filter(200, "lowpass").toDestination();
lfo.connect(filter.frequency);

// Start the LFO
lfo.start();

Supported Wave Shapes in Tone.LFO

The wave shape (or type) of the LFO determines the pattern of the modulation. Tone.LFO inherits its oscillator behaviors from Tone.Oscillator, supporting several standard wave shapes:

1. Sine (sine)

The sine wave is the default wave shape. It provides a smooth, continuous, and natural-sounding transition between the minimum and maximum values. It is ideal for gentle vibrato, tremolo, or subtle filter sweeps.

2. Triangle (triangle)

The triangle wave rises and falls in a linear, straight-line ramp. This creates a highly predictable, constant-speed modulation that changes direction sharply at the peaks and troughs.

3. Sawtooth (sawtooth)

The sawtooth wave rises linearly from its minimum value to its maximum value, then drops instantly back to the minimum. This ramp-up shape is useful for rhythmic, building modulation effects that reset abruptly.

4. Square (square)

The square wave switches instantly between the maximum and minimum values without any transition states. It spends 50% of its cycle at the maximum value and 50% at the minimum. This creates a rhythmic, gating, or hard-switching effect (such as an octave jump or abrupt on/off modulation).


Advanced Waveform Types

In addition to the four basic shapes, Tone.js allows you to customize the harmonic content of these waveforms by appending a number representing the number of partials, or by using specific variations: