How to Scale Tone.LFO Output in Tone.js

This article explains how to scale and map the output range of a Tone.LFO (Low-Frequency Oscillator) in Tone.js. By default, a Tone.js LFO outputs values between -1 and 1. To control parameters like filter cutoffs, synth pitch, or volume, you must map this output to a custom range. We will cover the most efficient ways to achieve this using built-in LFO properties and helper nodes.

Using Built-in Min and Max Properties

The easiest way to scale a Tone.LFO is by setting its min and max properties during initialization. Tone.js automatically handles the scaling of the oscillator’s default waveform to your specified range.

// Create an LFO that modulates between 200Hz and 2000Hz
const lfo = new Tone.LFO({
  frequency: "4n", // Rate of modulation
  type: "sine",    // Waveform type
  min: 200,        // Minimum output value
  max: 2000        // Maximum output value
}).start();

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

Changing the Range Dynamically

If you need to adjust the scaling range of the LFO after it has been created, you can update the min and max properties directly on the LFO instance at any time.

// Update the range dynamically
lfo.min = 400;
lfo.max = 1200;

Mapping with Tone.Scale

If you have a single LFO that needs to control multiple parameters at different scales, you can keep the LFO at its default -1 to 1 range and route it through a Tone.Scale node for each destination.

// Create a standard LFO outputting -1 to 1
const sharedLfo = new Tone.LFO("2n").start();

// Scale the output to a 0 to 1 range for auto-panning
const panScale = new Tone.Scale(-1, 1, 0, 1);

// Connect LFO through the scale node to the panner
sharedLfo.connect(panScale);
panScale.connect(panner.pan);