Skip to content
Tone.js

PulseOscillator

class Source ↳ extends Source<PulseOscillatorOptions>

PulseOscillator is an oscillator with control over pulse width, also known as the duty cycle. At 50% duty cycle (width = 0) the wave is a square wave. Read more.

width = -0.25 width = 0.0 width = 0.25
+-----+ +-------+ + +-------+ +-+
| | | | | | |
| | | | | | |
+-+ +-------+ + +-------+ +-----+
width = -0.5 width = 0.5
+---+ +-------+ +---+
| | | |
| | | |
+---+ +-------+ +---+
width = -0.75 width = 0.75
+-+ +-------+ +-----+
| | | |
| | | |
+-----+ +-------+ +-+
return Tone.Offline(() => {
	const pulse = new Tone.PulseOscillator(50, 0.4).toDestination().start();
}, 0.1, 1);
new PulseOscillator(frequency?: Frequency, width?: number)

Parameters

  • frequency Frequency optional

    The frequency of the oscillator

  • width number optional

    The width of the pulse

new PulseOscillator(options?: Partial<PulseOscillatorOptions>)

Parameters

read-only

detune: Signal<"cents">

The detune in cents.

read-only

frequency: Signal<"frequency">

The frequency control.

↳ inherited from Source

input: undefined

Sources have no inputs

Default: undefined

read-only

name: string

The name of the class

Default: "PulseOscillator"

↳ 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;

read-only

width: Signal<"audioRange">

The width of the pulse.

return Tone.Offline(() => {
	const pulse = new Tone.PulseOscillator(20, 0.8).toDestination().start();
}, 0.1, 1);

read-only

baseType: "pulse"

The baseType of the oscillator. Always returns “pulse”.

carrierType: "sine" | "triangle"

Internal use The carrier oscillator type is fed through the waveshaper node to create the pulse. Using different carrier oscillators changes oscillator’s behavior.

↳ inherited from Source

mute: boolean

Mute the output.

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

read-only

partialCount: number

No partials for this waveform type.

read-only

partials: number[]

The partials of the waveform. Cannot set partials for this waveform type

phase: number

The phase of the oscillator in degrees.

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();

read-only

type: "pulse"

The type of the oscillator. Always returns “pulse”.

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 method.

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

↳ 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(): PulseOscillatorOptions

Returns all of the default options belonging to the class.

Returns PulseOscillatorOptions