ToneAudioBuffers
class Core ↳ extends Tone
A data structure for holding multiple buffers in a Map-like datastructure.
const pianoSamples = new Tone.ToneAudioBuffers({
A1: "https://tonejs.github.io/audio/casio/A1.mp3",
A2: "https://tonejs.github.io/audio/casio/A2.mp3",
}, () => {
const player = new Tone.Player().toDestination();
// play one of the samples when they all load
player.buffer = pianoSamples.get("A2");
player.start();
});// To pass in additional parameters in the second parameter
const buffers = new Tone.ToneAudioBuffers({
urls: {
A1: "A1.mp3",
A2: "A2.mp3",
},
onload: () => console.log("loaded"),
baseUrl: "https://tonejs.github.io/audio/casio/"
});Constructor
Section titled “Constructor”new ToneAudioBuffers(urls?: ToneAudioBuffersUrlMap, onload?: () => void, baseUrl?: string)Parameters
-
urls
ToneAudioBuffersUrlMapoptionalAn object literal or array of urls to load.
-
onload
() => voidoptionalThe callback to invoke when the buffers are loaded.
-
baseUrl
stringoptionalA prefix url to add before all the urls
new ToneAudioBuffers(options?: Partial<ToneAudioBuffersOptions>)Parameters
- options
Partial<ToneAudioBuffersOptions>optional
Properties
Section titled “Properties”Methods
Section titled “Methods”add(name: string | number, url: string | ToneAudioBuffer | AudioBuffer, callback?: () => void, onerror?: (e: Error) => void): thisAdd a buffer by name and url to the Buffers
Parameters
-
name
string | numberA unique name to give the buffer
-
url
string | ToneAudioBuffer | AudioBufferEither the url of the bufer, or a buffer which will be added with the given name.
-
callback
() => voidoptional defaultnoOpThe callback to invoke when the url is loaded.
-
onerror
(e: Error) => voidoptional defaultnoOpInvoked if the buffer can’t be loaded
Returns this
get(name: string | number): ToneAudioBufferGet a buffer by name. If an array was loaded, then use the array index.
Parameters
-
name
string | numberThe key or index of the buffer.
Returns ToneAudioBuffer
has(name: string | number): booleanTrue if the buffers object has a buffer by that name.
Parameters
-
name
string | numberThe key or index of the buffer.
Returns boolean
getDefaults()
Section titled “getDefaults()”static
getDefaults(): ToneAudioBuffersOptionsReturns all of the default options belonging to the class.
Returns ToneAudioBuffersOptions
Inherited members
Section titled “Inherited members”- From
Tone: debug, version, disposed, toString()