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:
- Standard Waves:
"sine","square","triangle", and"sawtooth". - Partials (Add numbers to the wave name): You can
specify the number of partials to generate a brighter or darker sound
(e.g.,
"sine4","square8","sawtooth2"). - Fat Oscillators: These stack multiple detuned
oscillators for a thicker sound. Prefix the wave name with “fat” (e.g.,
"fatsawtooth","fatsquare"). - AM/FM Oscillators: Modulate the amplitude or
frequency using another oscillator (e.g.,
"fmsine","amsine").