AudioBuffer loading and storage. ToneAudioBuffer is used internally by all classes that make requests for audio files such as Tone.Player, Tone.Sampler and Tone.Convolver. Aside from load callbacks from individual buffers, ToneAudioBuffer provides events which keep track of the loading progress of all of the buffers. These are ToneAudioBuffer.on("load" / "progress" / "error")
import { ToneAudioBuffer } from "tone";
const buffer = new ToneAudioBuffer("https://tonejs.github.io/examples/audio/FWDL.mp3", () => {
console.log("loaded");
});
A callback which is invoked after the buffer is loaded.It's recommended to use ToneAudioBuffer.on('load', callback)
insteadsince it will give you a callback when all buffers are loaded.
The callback to invoke if there is an error
A path which is prefixed before every url.
Set this debug flag to log all events that happen in this class.
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.
All of the downloads
The duration of the buffer in seconds.
The length of the buffer in samples
If the buffer is loaded or not
The number of discrete audio channels. Returns 0 if no buffer is loaded.
Callback when the buffer is loaded.
The sample rate of the AudioBuffer
The version number semver
Set the audio buffer from the array. To create a multichannel AudioBuffer, pass in a multidimensional array.
The array to fill the audio buffer
Create a ToneAudioBuffer from the array. To create a multichannel AudioBuffer, pass in a multidimensional array.
The array to fill the audio buffer
Creates a ToneAudioBuffer from a URL, returns a promise which resolves to a ToneAudioBuffer
The url to load.
The audio buffer stored in the object.
Returns the Float32Array representing the PCM audio data for the specific channel.
The channel number to return
Returns all of the default options belonging to the class.
Makes an fetch request for the selected url then decodes the file as an audio buffer. Invokes the callback once the audio buffer loads.
The url of the buffer to load. filetype support depends on the browser.
Loads a url using fetch and returns the AudioBuffer.
Returns a Promise which resolves when all of the buffers have loaded
Pass in an AudioBuffer or ToneAudioBuffer to set the value of this buffer.
Cut a subsection of the array and return a buffer of the subsection. Does not modify the original buffer
The end time to slice. If none is given will default to the end of the buffer
Checks a url's extension to see if the current browser can play that file type.
import { ToneAudioBuffer } from "tone";
ToneAudioBuffer.supportsType("wav"); // returns true
ToneAudioBuffer.supportsType("path/to/file.wav"); // returns true
The url/extension to test
Get the buffer as an array. Single channel buffers will return a 1-dimensional Float32Array, and multichannel buffers will return multidimensional arrays.
Optionally only copy a single channel from the array.
Sums multiple channels into 1 channel
Optionally only copy a single channel from the array.
Convert the class to a string
import { Oscillator } from "tone";
const osc = new Oscillator();
console.log(osc.toString());