Wrapper around the OfflineAudioContext
// generate a single channel, 0.5 second buffer
const context = new Tone.OfflineContext(1, 0.5, 44100);
const osc = new Tone.Oscillator({ context });
context.render().then(buffer => {
console.log(buffer.numberOfChannels, buffer.duration);
});
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).
// 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.
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. 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
Close the context
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.
Internal 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. See Tone.start
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
const osc = new Tone.Oscillator();
console.log(osc.toString());