Tone.Buffer

↳ EXTENDS Tone

Buffer loading and storage. Tone.Buffer 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, Tone.Buffer provides static methods which keep track of the loading progress of all of the buffers. These methods are Tone.Buffer.onload, Tone.Buffer.onprogress, and Tone.Buffer.onerror.

CONSTRUCTOR

new Tone.Buffer (
url
, [
onload
] )
url

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

type: AudioBuffer or string
onload

A callback which is invoked after the buffer is loaded. It’s recommended to use Tone.Buffer.onload instead since it will give you a callback when ALL buffers are loaded.

type: function
optional

DEFAULTS

{
url : undefined ,
onload : Tone.noOp ,
reverse : false
}

EXAMPLE

var buffer = new Tone.Buffer("path/to/sound.mp3", function(){
	//the buffer is now available.
	var buff = buffer.get();
});

Members

.duration

↝ number READONLY #

The duration of the buffer.

</>

.loaded

↝ boolean READONLY #

Indicates if the buffer is loaded or not.

</>

.onload

↝ function #

The callback to invoke when everything is loaded.

</>

.reverse

↝ boolean #

Reverse the buffer.

</>

.url

↝ string READONLY #

The url of the buffer. undefined if it was constructed with a buffer

</>

Methods

.dispose ( )

#
↪ returns Tone.Buffer

this

dispose and disconnect

</>

.get ( )

#
↪ returns AudioBuffer

The audio buffer stored in the object.

</>

.load ( )

#
url

The url to load

type: String
callback

The callback to invoke on load. don’t need to set if onload is already set.

type: function
optional
↪ returns Tone.Buffer

this

Load url into the buffer.

</>

.set ( )

#
buffer

the buffer

type: AudioBuffer or Tone.Buffer
↪ returns Tone.Buffer

this

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

</>

Static Methods

.load ( )

#
url

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

type: string
callback

The function to invoke when the url is loaded.

type: function
↪ returns XMLHttpRequest

returns the XHR

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

</>
docs generated Sep 15 2019