How to Change Tone.js Synth Oscillator Type

In Tone.js, the Tone.Synth instrument uses a basic oscillator to generate its sound source. This article provides a direct guide on how to customize the oscillator type of a Tone.Synth, covering both initialization setup and dynamic changes during runtime, as well as the various wave types available in the framework.

Customizing at Initialization

The most common way to set the oscillator type is by passing an options object when instantiating the Tone.Synth. Within this object, you define the oscillator property and specify the desired type.

// Create a synth with a square wave oscillator
const synth = new Tone.Synth({
  oscillator: {
    type: "square"
  }
}).toDestination();

Changing the Oscillator Dynamically

You can also change the oscillator type after the synth has been created. This is useful for interactive applications where the user can modify the sound in real-time. You access the oscillator property directly on the synth instance.

const synth = new Tone.Synth().toDestination();

// Change the oscillator type to sawtooth dynamically
synth.oscillator.type = "sawtooth";

Available Oscillator Types

Tone.js supports several standard and modified oscillator types: