ToneAudioBuffer

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("https://tonejs.github.io/audio/casio/A1.mp3", () => {
	console.log("loaded");
});

Hierarchy

  • Tone
    • ToneAudioBuffer

Constructor

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

Properties

static baseUrl #

string

A path which is prefixed before every url.

debug #

boolean

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 #

boolean

Reverse the buffer.

sampleRate #

readonly number

The sample rate of the AudioBuffer

static version #

string

The version number semver

Methods

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 (
url:string

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 (
channel:number

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 (
url:string

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 (
url:string
) => 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 (
url:string

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();
console.log(osc.toString());
toString ( ) => string