Tone.js
    Preparing search index...

    Class ToneAudioBuffer

    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

    • Tone
      • ToneAudioBuffer
    Index

    Constructors

    Properties

    debug: boolean = false

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

    name: string = "ToneAudioBuffer"

    The name of the class

    onload: (buffer: ToneAudioBuffer) => void = noOp

    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 = 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

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

      Parameters

      • array: Float32Array | Float32Array[]

        The array to fill the audio buffer

      Returns this

    • 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

    • 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

      • end: 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 | Float32Array[]

    • 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

      • array: Float32Array | Float32Array[]

        The array to fill the audio buffer

      Returns ToneAudioBuffer

      A ToneAudioBuffer created from the array

    • Returns all of the default options belonging to the class.

      Returns ToneAudioBufferOptions

    • 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