The number of channels to render
The duration to render in seconds
the sample rate to render at
Set this debug flag to log all events that happen in this class.
Readonly
isIndicates if the context is an OfflineAudioContext or an AudioContext
Readonly
nameStatic
versionThe version number semver
What the source of the clock is, either "worker" (default), "timeout", or "offline" (none).
Same as this.now()
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).
// prioritize sustained playback
const context = new Tone.Context({ latencyHint: "playback" });
// set this context as the global Context
Tone.setContext(context);
// the global context is gettable with Tone.getContext()
console.log(Tone.getContext().latencyHint);
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. Adjusting this value also affects the updateInterval.
The unwrapped AudioContext or OfflineAudioContext
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. Setting to 0 will result in the lowest practial interval based on context properties. context.updateInterval + context.lookAhead gives you the total latency between scheduling an event and hearing it.
Clear the function scheduled by setInterval
Create an audio worklet node from a name and options. The module must first be loaded using addAudioWorkletModule.
Optional
options: Partial<AudioWorkletNodeOptions>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
.
Remove the event listener.
The event to stop listening to.
Optional
callback: ((...args) => void)The callback which was bound to the event with Emitter.on. If no callback is given, all callbacks events are removed.
Rest
...args: any[]Render the output of the OfflineContext
If the clock should be rendered asynchronously, which will not block the main thread, but be slightly slower.
A setTimeout which is guaranteed by the clock source. Also runs in the offline context.
The callback to invoke
Rest
...args: any[]The timeout in seconds
ID to use when invoking Context.clearTimeout
Static
getReturns all of the default options belonging to the class.
Static
mixin
Wrapper around the OfflineAudioContext
Example