Tone.Buffer
↳ EXTENDS ToneBuffer 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 events which keep track of the loading progress of all of the buffers. These are Tone.Buffer.on(“load” / “progress” / “error”)
CONSTRUCTOR
new Tone.Buffer (The url to load, or the audio buffer to set.
A callback which is invoked after the buffer is loaded. It’s recommended to use Tone.Buffer.on('load', callback)
instead since it will give you a callback when all buffers are loaded.
The callback to invoke if there is an error
DEFAULTS
EXAMPLE
EXAMPLE
Members
.numberOfChannels
↝ Number READONLY #The number of discrete audio channels. Returns 0 if no buffer is loaded.
Methods
.toMono ( )
#Optionally only copy a single channel from the array.
Sums muliple channels into 1 channel
.fromArray ( )
#The array to fill the audio buffer
this
Set the audio buffer from the array. To create a multichannel AudioBuffer, pass in a multidimensional array.
.getChannelData ( )
#The channel number to return
The audio as a TypedArray
Returns the Float32Array representing the PCM audio data for the specific channel.
.load ( )
#The url of the buffer to load. filetype support depends on the browser.
returns a Promise which resolves with the Tone.Buffer
Makes an xhr reqest for the selected url then decodes the file as an audio buffer. Invokes the callback once the audio buffer loads.
.set ( )
#the buffer
this
Pass in an AudioBuffer or Tone.Buffer to set the value of this buffer.
.slice ( )
#The time to start the slice
The end time to slice. If none is given will default to the end of the buffer
this
Cut a subsection of the array and return a buffer of the subsection. Does not modify the original buffer
.toArray ( )
#Get the buffer as an array. Single channel buffers will return a 1-dimensional Float32Array, and multichannel buffers will return multidimensional arrays.
Static Methods
.fromArray ( )
#The array to fill the audio buffer
A Tone.Buffer created from the array
Create a Tone.Buffer from the array. To create a multichannel AudioBuffer, pass in a multidimensional array.
.load ( )
#Loads a url using XMLHttpRequest.
.supportsType ( )
#Checks a url’s extension to see if the current browser can play that file type.