Documentation
    Preparing search index...

    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 (View Summary)

    • Tone
      • ToneAudioBuffer
    Index
    debug: boolean

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

    name: string

    The name of the class

    onload: (buffer: ToneAudioBuffer) => void

    Callback when the buffer is loaded.

    baseUrl: string

    A path which is prefixed before every url.

    downloads: Promise<void>[]

    All of the downloads

    version: string

    The version number semver

    • 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

    • get duration(): number

      The duration of the buffer in seconds.

      Returns number

    • get length(): number

      The length of the buffer in samples

      Returns number

    • get loaded(): boolean

      If the buffer is loaded or not

      Returns boolean

    • get numberOfChannels(): number

      The number of discrete audio channels. Returns 0 if no buffer is loaded.

      Returns number

    • get reverse(): boolean

      Reverse the buffer.

      Returns boolean

    • set reverse(rev: boolean): void

      Parameters

      • rev: boolean

      Returns void

    • get sampleRate(): number

      The sample rate of the AudioBuffer

      Returns number

    • clean up

      Returns this

    • Set the audio buffer from the array. To create a multichannel AudioBuffer, pass in a multidimensional array.

      Parameters

      Returns this

    • The audio buffer stored in the object.

      Returns AudioBuffer | undefined

    • Returns the Float32Array representing the PCM audio data for the specific channel.

      Parameters

      • channel: number

        The channel number to return

      Returns Float32Array

      The audio as a TypedArray

    • Makes an fetch request for the selected url then decodes the file as an audio buffer. Invokes the callback once the audio buffer loads.

      Parameters

      • url: string

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

      Returns Promise<ToneAudioBuffer>

      A Promise which resolves with this ToneAudioBuffer

    • Prints the outputs to the console log for debugging purposes. Prints the contents only if either the object has a property called debug set to true, or a variable called TONE_DEBUG_CLASS is set to the name of the class.

      Parameters

      • ...args: any[]

      Returns void

      const osc = new Tone.Oscillator();
      // prints all logs originating from this oscillator
      osc.debug = true;
      // calls to start/stop will print in the console
      osc.start();
    • Pass in an AudioBuffer or ToneAudioBuffer to set the value of this buffer.

      Parameters

      Returns this

    • Cut a subsection of the array and return a buffer of the subsection. Does not modify the original buffer

      Parameters

      • start: number

        The time to start the slice

      • Optionalend: number

        The end time to slice. If none is given will default to the end of the buffer

      Returns ToneAudioBuffer

    • Get the buffer as an array. Single channel buffers will return a 1-dimensional Float32Array, and multichannel buffers will return multidimensional arrays.

      Parameters

      • Optionalchannel: number

        Optionally only copy a single channel from the array.

      Returns Float32Array<ArrayBufferLike> | Float32Array<ArrayBufferLike>[]

    • Sums multiple channels into 1 channel

      Parameters

      • OptionalchanNum: number

        Optionally only copy a single channel from the array.

      Returns this

    • Convert the class to a string

      Returns string

      const osc = new Tone.Oscillator();
      console.log(osc.toString());
    • Create a ToneAudioBuffer from the array. To create a multichannel AudioBuffer, pass in a multidimensional array.

      Parameters

      Returns ToneAudioBuffer

      A ToneAudioBuffer created from the array

    • Creates a ToneAudioBuffer from a URL, returns a promise which resolves to a ToneAudioBuffer

      Parameters

      • url: string

        The url to load.

      Returns Promise<ToneAudioBuffer>

      A promise which resolves to a ToneAudioBuffer

    • Loads a url using fetch and returns the AudioBuffer.

      Parameters

      • url: string

      Returns Promise<AudioBuffer>

    • Returns a Promise which resolves when all of the buffers have loaded

      Returns Promise<void>

    • Checks a url's extension to see if the current browser can play that file type.

      Parameters

      • url: string

        The url/extension to test

      Returns boolean

      If the file extension can be played

      Tone.ToneAudioBuffer.supportsType("wav"); // returns true
      Tone.ToneAudioBuffer.supportsType("path/to/file.wav"); // returns true