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);Constructor
Section titled “Constructor”new OmniOscillator(frequency?: Frequency, type?: OmniOscillatorType)Parameters
-
frequency
FrequencyoptionalThe initial frequency of the oscillator.
-
type
OmniOscillatorTypeoptionalThe type of the oscillator.
new OmniOscillator(options?: Partial<OmniOscillatorOptions>)Parameters
- options
Partial<OmniOscillatorOptions>optional
Properties
Section titled “Properties”detune
Section titled “detune”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);frequency
Section titled “frequency”read-only
frequency: Signal<"frequency">The frequency value of the oscillator
const osc = new Tone.FMOscillator("Bb4").toDestination().start();
osc.frequency.rampTo("D2", 3);onstop
Section titled “onstop”↳ inherited from Source
onstop: onStopCallbackThe callback to invoke when the source is stopped.
volume
Section titled “volume”↳ inherited from Source
volume: Param<"decibels">The volume of the output in decibels.
const source = new Tone.PWMOscillator().toDestination(); source.volume.value = -6;
baseType
Section titled “baseType”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
harmonicity
Section titled “harmonicity”read-only
harmonicity: IsAmOrFmOscillator<OscType, Signal<"positive">>Harmonicity is the frequency ratio between the carrier and the modulator oscillators.
See also: AMOscillator or FMOscillator
modulationFrequency
Section titled “modulationFrequency”read-only
modulationFrequency: IsPWMOscillator<OscType, Signal<"frequency">>The modulationFrequency Signal of the oscillator when sourceType === “pwm” see PWMOscillator
Range: 0.1 to 5
modulationIndex
Section titled “modulationIndex”read-only
modulationIndex: IsFMOscillator<OscType, Signal<"positive">>The modulation index when the sourceType === “fm”
See also: FMOscillator.
modulationType
Section titled “modulationType”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: booleanMute the output.
const osc = new Tone.Oscillator().toDestination().start(); // mute the output osc.mute = true;
partialCount
Section titled “partialCount”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
Section titled “partials”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: numberThe 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
Section titled “sourceType”sourceType: keyof OmniOscillatorSourceThe source type of the oscillator.
const omniOsc = new Tone.OmniOscillator(440, "fmsquare"); console.log(omniOsc.sourceType); // 'fm'
spread
Section titled “spread”spread: IsFatOscillator<OscType, number>The detune spread between the oscillators when sourceType === “fat”.
See also: FatOscillator.count
read-only ↳ inherited from Source
state: BasicPlaybackStateReturns 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();type: OmniOscillatorTypeThe 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
Methods
Section titled “Methods”asArray()
Section titled “asArray()”asArray(length?: number): Promise<Float32Array<ArrayBuffer>>Returns an array of values which represents the waveform.
Parameters
-
length
numberoptional default1024The length of the waveform to return
Returns Promise<Float32Array<ArrayBuffer>>
set(props: Partial<OmniOscillatorOptions>): thisSet 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
- props
Partial<OmniOscillatorOptions>
Returns this
start()
Section titled “start()”↳ inherited from Source
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 nowParameters
Returns this
stop()
Section titled “stop()”↳ inherited from Source
stop(time?: Time): thisStop 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 nowParameters
-
time
TimeoptionalWhen the source should be stopped.
Returns this
sync()
Section titled “sync()”↳ inherited from Source
sync(): thisSync 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
unsync()
Section titled “unsync()”↳ inherited from Source
unsync(): thisUnsync the source to the Transport.
See also: sync
Returns this
getDefaults()
Section titled “getDefaults()”static
getDefaults(): OmniOscillatorOptionsReturns all of the default options belonging to the class.
Returns OmniOscillatorOptions
Inherited members
Section titled “Inherited members”- From
ToneWithContext: context, blockTime, sampleTime, get(), immediate(), now(), toFrequency(), toSeconds(), toTicks() - From
Tone: debug, version, disposed, toString() - From
ToneAudioNode: channelCount, channelCountMode, channelInterpretation, numberOfInputs, numberOfOutputs, chain(), connect(), disconnect(), fan(), toDestination(), toMaster()