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.

const buffer = new Tone.ToneAudioBuffer("", () => {


  • Tone
    • ToneAudioBuffer


new ToneAudioBuffer (
url?:string | ToneAudioBuffer | AudioBuffer ,

The url to load, or the audio buffer to set.

onload?:undefined | (buffer) => void ,

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.

onerror?:undefined | (error) => void

The callback to invoke if there is an error

) => ToneAudioBuffer
new ToneAudioBuffer (
options?:Partial<ToneAudioBufferOptions >
) => ToneAudioBuffer


static baseUrl #


A path which is prefixed before every url.

debug #


Set this debug flag to log all events that happen in this class.

disposed #

readonly boolean

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.

static downloads #

Array<Promise<void > >

All of the downloads

duration #

readonly Seconds

The duration of the buffer in seconds.

length #

readonly Samples

The length of the buffer in samples

loaded #

readonly boolean

If the buffer is loaded or not

numberOfChannels #

readonly number

The number of discrete audio channels. Returns 0 if no buffer is loaded.

onload #

(buffer) => void

Callback when the buffer is loaded.

reverse #


Reverse the buffer.

sampleRate #

readonly number

The sample rate of the AudioBuffer

static version #


The version number semver


dispose #

clean up

dispose ( ) => this

fromArray #

Set the audio buffer from the array. To create a multichannel AudioBuffer, pass in a multidimensional array.

fromArray (
array:Float32Array | Float32Array []

The array to fill the audio buffer

) => this

static fromArray #

Create a ToneAudioBuffer from the array. To create a multichannel AudioBuffer, pass in a multidimensional array.

fromArray (
array:Float32Array | Float32Array []

The array to fill the audio buffer

) => ToneAudioBuffer
A ToneAudioBuffer created from the array

static fromUrl #

Creates a ToneAudioBuffer from a URL, returns a promise which resolves to a ToneAudioBuffer

fromUrl (

The url to load.

) => Promise<ToneAudioBuffer >
A promise which resolves to a ToneAudioBuffer

get #

The audio buffer stored in the object.

get ( ) => AudioBuffer | undefined

getChannelData #

Returns the Float32Array representing the PCM audio data for the specific channel.

getChannelData (

The channel number to return

) => Float32Array
The audio as a TypedArray

static getDefaults #

Returns all of the default options belonging to the class.

getDefaults ( ) => ToneAudioBufferOptions

load #

Makes an fetch request for the selected url then decodes the file as an audio buffer. Invokes the callback once the audio buffer loads.

load (

The url of the buffer to load. filetype support depends on the browser.

) => Promise<this >
A Promise which resolves with this ToneAudioBuffer

static load #

Loads a url using fetch and returns the AudioBuffer.

load (
) => Promise<AudioBuffer >

static loaded #

Returns a Promise which resolves when all of the buffers have loaded

loaded ( ) => Promise<void >

set #

Pass in an AudioBuffer or ToneAudioBuffer to set the value of this buffer.

set (
buffer:AudioBuffer | ToneAudioBuffer
) => this

slice #

Cut a subsection of the array and return a buffer of the subsection. Does not modify the original buffer

slice (
start:Seconds ,

The time to start the slice

end= this.duration:Seconds

The end time to slice. If none is given will default to the end of the buffer

) => ToneAudioBuffer

static supportsType #

Checks a url's extension to see if the current browser can play that file type.

Tone.ToneAudioBuffer.supportsType("wav"); // returns true
Tone.ToneAudioBuffer.supportsType("path/to/file.wav"); // returns true
supportsType (

The url/extension to test

) => boolean
If the file extension can be played

toArray #

Get the buffer as an array. Single channel buffers will return a 1-dimensional Float32Array, and multichannel buffers will return multidimensional arrays.

toArray (
channel?:undefined | number

Optionally only copy a single channel from the array.

) => Float32Array | Float32Array []

toMono #

Sums multiple channels into 1 channel

toMono (
chanNum?:undefined | number

Optionally only copy a single channel from the array.

) => this

toString #

Convert the class to a string

const osc = new Tone.Oscillator();
toString ( ) => string