ToneOscillatorInterface
internal interface
The common interface of all Oscillators
Properties
Section titled “Properties”baseType
Section titled “baseType”baseType: OscillatorType | "pulse" | "pwm"The oscillator type without the partialsCount appended to the end
const osc = new Tone.Oscillator(); osc.type = "sine2"; console.log(osc.baseType); // "sine"
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);partialCount
Section titled “partialCount”optional
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 partials describes the relative amplitude of each of the harmonics of the oscillator. The first value in the array is the first harmonic (i.e. the fundamental frequency), the second harmonic is an octave up, the third harmonic is an octave and a fifth, etc. The resulting oscillator output is composed of a sine tone at the relative amplitude at each of the harmonic intervals.
Setting this value will automatically set the type to “custom”. The value is an empty array when the type is not “custom”.
const osc = new Tone.Oscillator("F3").toDestination().start();
setInterval(() => {
// generate 8 random partials
osc.partials = new Array(8).fill(0).map(() => Math.random());
}, 1000);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);The oscillator’s type. Also capable of setting the first x number of partials of the oscillator. For example: “sine4” would set be the first 4 partials of the sine wave and “triangle8” would set the first 8 partials of the triangle wave.
return Tone.Offline(() => {
const osc = new Tone.Oscillator().toDestination().start();
osc.type = "sine2";
}, 0.1, 1);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
numberThe length of the waveform to return
Returns Promise<Float32Array<ArrayBuffer>>