Wrapper around the OfflineAudioContext
The number of channels to render
the sample rate to render at
What the source of the clock is, either "worker" (default), "timeout", or "offline" (none).
Set this debug flag to log all events that happen in this class.
A reference to the Context's destination node.
Indicates if the instance was disposed. 'Disposing' an instance means that all of the Web Audio nodes that were created for the instance are disconnected and freed for garbage collection.
This is the Draw object for the context which is useful for synchronizing the draw frame with the Tone.js clock.
The type of playback, which affects tradeoffs between audio output latency and responsiveness. In addition to setting the value in seconds, the latencyHint also accepts the strings "interactive" (prioritizes low latency), "playback" (prioritizes sustained playback), "balanced" (balances latency and performance), and "fastest" (lowest latency, might glitch more often).
import * as Tone from "tone";
// set the latencyHint to prioritize smooth playback at the expensive of latency
Tone.context.latencyHint = "playback";
The listener
The amount of time into the future events are scheduled. Giving Web Audio a short amount of time into the future to schedule events can reduce clicks and improve performance. This value can be set to 0 to get the lowest latency.
The unwrapped AudioContext.
The current time in seconds of the AudioContext.
The current time in seconds of the AudioContext.
There is only one Transport per Context. It is created on initialization.
How often the interval callback is invoked. This number corresponds to how responsive the scheduling can be. context.updateInterval + context.lookAhead gives you the total latency between scheduling an event and hearing it.
The version number semver
Add an AudioWorkletProcessor module
The url of the module
The name of the module
Clear the function scheduled by setInterval
Clears a previously scheduled timeout with Tone.context.setTimeout
The ID returned from setTimeout
Create an audio worklet node from a name and options. The module must first be loaded using addAudioWorkletModule.
Clean up. Also closes the audio context.
Invoke all of the callbacks bound to the event with any arguments passed in.
The name of the event.
The arguments to pass to the functions listening.
Generate a looped buffer at some constant value.
Returns all of the default options belonging to the class.
The current audio context time without the lookAhead.
In most cases it is better to use now instead of immediate since
with now the lookAhead is applied equally to all components including internal components,
to making sure that everything is scheduled in sync. Mixing now and immediate
can cause some timing issues. If no lookAhead is desired, you can set the lookAhead to 0
.
Add Emitter functions (on/off/emit) to the object
Override the now method to point to the internal clock time
Remove the event listener.
The event to stop listening to.
The callback which was bound to the event with Emitter.on.If no callback is given, all callbacks events are removed.
Bind a callback to a specific event.
The name of the event to listen for.
The callback to invoke when the event is emitted
Bind a callback which is only invoked once
The name of the event to listen for.
The callback to invoke when the event is emitted
Render the output of the OfflineContext
If the clock should be rendered asynchronously, which will not block the main thread, but be slightly slower.
Starts the audio context from a suspended state. This is required to initially start the AudioContext.
Adds a repeating event to the context's callback clock
A setTimeout which is guaranteed by the clock source. Also runs in the offline context.
The callback to invoke
Convert the class to a string
import { Oscillator } from "tone";
const osc = new Oscillator();
console.log(osc.toString());