Skip to content
Tone.js

OmniOscillator

class Source ↳ extends Source<OmniOscillatorOptions>

OmniOscillator aggregates all of the oscillator types into one.

return Tone.Offline(() => {
	const omniOsc = new Tone.OmniOscillator("C#4", "pwm").toDestination().start();
}, 0.1, 1);
new OmniOscillator(frequency?: Frequency, type?: OmniOscillatorType)

Parameters

new OmniOscillator(options?: Partial<OmniOscillatorOptions>)

Parameters

read-only

detune: Signal<"cents">

The detune value in cents (100th of a semitone).

const osc = new Tone.PulseOscillator("F3").toDestination().start();
// pitch it 1 octave = 12 semitones = 1200 cents
osc.detune.setValueAtTime(-1200, Tone.now());
osc.detune.setValueAtTime(1200, Tone.now() + 0.5);
osc.detune.linearRampToValueAtTime(0, Tone.now() + 1);
osc.stop(Tone.now() + 1.5);

read-only

frequency: Signal<"frequency">

The frequency value of the oscillator

const osc = new Tone.FMOscillator("Bb4").toDestination().start();
osc.frequency.rampTo("D2", 3);

↳ inherited from Source

input: undefined

Sources have no inputs

Default: undefined

read-only

name: string

The name of the class

Default: "OmniOscillator"

↳ inherited from Source

The callback to invoke when the source is stopped.

↳ inherited from Source

output: OutputNode

The output node

↳ inherited from Source

volume: Param<"decibels">

The volume of the output in decibels.

const source = new Tone.PWMOscillator().toDestination();
source.volume.value = -6;
baseType: OscillatorType | "pulse" | "pwm"

The base type of the oscillator.

const omniOsc = new Tone.OmniOscillator(440, "fmsquare4");
console.log(omniOsc.sourceType, omniOsc.baseType, omniOsc.partialCount);

See also: Oscillator.baseType

count: IsFatOscillator<OscType, number>

The number of detuned oscillators when sourceType === “fat”.

See also: FatOscillator.count

read-only

harmonicity: IsAmOrFmOscillator<OscType, Signal<"positive">>

Harmonicity is the frequency ratio between the carrier and the modulator oscillators.

See also: AMOscillator or FMOscillator

read-only

modulationFrequency: IsPWMOscillator<OscType, Signal<"frequency">>

The modulationFrequency Signal of the oscillator when sourceType === “pwm” see PWMOscillator

Range: 0.1 to 5

read-only

modulationIndex: IsFMOscillator<OscType, Signal<"positive">>

The modulation index when the sourceType === “fm”

See also: FMOscillator.

modulationType: IsAmOrFmOscillator<OscType, ToneOscillatorType>

The type of the modulator oscillator. Only if the oscillator is set to “am” or “fm” types.

See also: AMOscillator or FMOscillator

↳ inherited from Source

mute: boolean

Mute the output.

const osc = new Tone.Oscillator().toDestination().start();
// mute the output
osc.mute = true;
partialCount: number

‘partialCount’ offers an alternative way to set the number of used partials. When partialCount is 0, the maximum number of partials are used when representing the waveform using the periodicWave. When ‘partials’ is set, this value is not settable, but equals the length of the partials array. A square wave wave is composed of only odd harmonics up through the harmonic series. Partial count can limit the number of harmonics which are used to generate the waveform.

const osc = new Tone.Oscillator("C3", "square").toDestination().start();
osc.partialCount = 1;
setInterval(() => {
	osc.partialCount++;
	console.log(osc.partialCount);
}, 500);
partials: number[]

The value is an empty array when the type is not “custom”. This is not available on “pwm” and “pulse” oscillator types.

See also: Oscillator.partials

phase: number

The phase is the starting position within the oscillator’s cycle. For example a phase of 180 would start halfway through the oscillator’s cycle.

return Tone.Offline(() => {
	const osc = new Tone.Oscillator({
		frequency: 20,
		phase: 90
	}).toDestination().start();
}, 0.1, 1);
sourceType: keyof OmniOscillatorSource

The source type of the oscillator.

const omniOsc = new Tone.OmniOscillator(440, "fmsquare");
console.log(omniOsc.sourceType); // 'fm'
spread: IsFatOscillator<OscType, number>

The detune spread between the oscillators when sourceType === “fat”.

See also: FatOscillator.count

read-only ↳ inherited from Source

Returns the playback state of the source, either “started” or “stopped”.

const player = new Tone.Player("https://tonejs.github.io/audio/berklee/ahntone_c3.mp3", () => {
	player.start();
	console.log(player.state);
}).toDestination();

The type of the oscillator. Can be any of the basic types: sine, square, triangle, sawtooth. Or prefix the basic types with “fm”, “am”, or “fat” to use the FMOscillator, AMOscillator or FatOscillator types. The oscillator could also be set to “pwm” or “pulse”. All of the parameters of the oscillator’s class are accessible when the oscillator is set to that type, but throws an error when it’s not.

const omniOsc = new Tone.OmniOscillator().toDestination().start();
omniOsc.type = "pwm";
// modulationFrequency is parameter which is available
// only when the type is "pwm".
omniOsc.modulationFrequency.value = 0.5;

read-only

width: IsPulseOscillator<OscType, Signal<"audioRange">>

The width of the oscillator when sourceType === “pulse”.

See also: PWMOscillator

asArray(length?: number): Promise<Float32Array<ArrayBuffer>>

Returns an array of values which represents the waveform.

Parameters

  • length number optional default 1024

    The length of the waveform to return

Returns Promise<Float32Array<ArrayBuffer>>

dispose(): this

Clean up.

Returns this

↳ inherited from Source

restart(time?: Time, offset?: Time, duration?: Time): this

Restart the source.

Parameters

  • time Time optional
  • offset Time optional
  • duration Time optional

Returns this

set(props: Partial<OmniOscillatorOptions>): this

Set multiple properties at once with an object.

const filter = new Tone.Filter().toDestination();
// set values using an object
filter.set({
	frequency: "C6",
	type: "highpass"
});
const player = new Tone.Player("https://tonejs.github.io/audio/berklee/Analogsynth_octaves_highmid.mp3").connect(filter);
player.autostart = true;

Parameters

Returns this

↳ inherited from Source

start(time?: Time, offset?: Time, duration?: Time): this

Start the source at the specified time. If no time is given, start the source now.

const source = new Tone.Oscillator().toDestination();
source.start("+0.5"); // starts the source 0.5 seconds from now

Parameters

  • time Time optional

    When the source should be started.

  • offset Time optional

  • duration Time optional

Returns this

↳ inherited from Source

stop(time?: Time): this

Stop the source at the specified time. If no time is given, stop the source now.

const source = new Tone.Oscillator().toDestination();
source.start();
source.stop("+0.5"); // stops the source 0.5 seconds from now

Parameters

  • time Time optional

    When the source should be stopped.

Returns this

↳ inherited from Source

sync(): this

Sync the source to the Transport so that all subsequent calls to start and stop are synced to the TransportTime instead of the AudioContext time.

const osc = new Tone.Oscillator().toDestination();
// sync the source so that it plays between 0 and 0.3 on the Transport's timeline
osc.sync().start(0).stop(0.3);
// start the transport.
Tone.Transport.start();
// set it to loop once a second
Tone.Transport.loop = true;
Tone.Transport.loopEnd = 1;

Returns this

↳ inherited from Source

unsync(): this

Unsync the source to the Transport.

See also: sync

Returns this

static

getDefaults(): OmniOscillatorOptions

Returns all of the default options belonging to the class.

Returns OmniOscillatorOptions