Class ToneAudioBuffers

A data structure for holding multiple buffers in a Map-like datastructure.

Example

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();
});

Example

// 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/"
});

Hierarchy

  • Tone
    • ToneAudioBuffers

Constructors

Properties

baseUrl: string

A path which is prefixed before every url.

debug: boolean = false

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

name: string = "ToneAudioBuffers"
version: string = version

The version number semver

Accessors

  • get disposed(): 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.

    Returns boolean

Methods

  • Add a buffer by name and url to the Buffers

    Parameters

    • name: string | number

      A unique name to give the buffer

    • url: string | AudioBuffer | ToneAudioBuffer

      Either the url of the bufer, or a buffer which will be added with the given name.

    • callback: (() => void) = noOp

      The callback to invoke when the url is loaded.

        • (): void
        • Returns void

    • onerror: ((e) => void) = noOp

      Invoked if the buffer can't be loaded

        • (e): void
        • Parameters

          • e: Error

          Returns void

    Returns this

  • Convert the class to a string

    Returns string

    Example

    const osc = new Tone.Oscillator();
    console.log(osc.toString());