createBuffer method

AudioBuffer createBuffer(
  1. int numberOfChannels,
  2. int length,
  3. num sampleRate
)

The createBuffer() method of the BaseAudioContext Interface is used to create a new, empty AudioBuffer object, which can then be populated by data, and played via an AudioBufferSourceNode.

For more details about audio buffers, check out the AudioBuffer reference page.

Note: createBuffer() used to be able to take compressed data and give back decoded samples, but this ability was removed from the specification, because all the decoding was done on the main thread, so createBuffer() was blocking other code execution. The asynchronous method decodeAudioData() does the same thing — takes compressed audio, such as an MP3 file, and directly gives you back an AudioBuffer that you can then play via an AudioBufferSourceNode. For simple use cases like playing an MP3, decodeAudioData() is what you should be using.

Implementation

external AudioBuffer createBuffer(
  int numberOfChannels,
  int length,
  num sampleRate,
);