Skip to main content

AudioBuffer

The AudioBuffer interface represents a short audio asset residing in memory, created from an audio file using the AudioContext.decodeAudioData() method, or from raw data using AudioContext.createBuffer(). Once put into an AudioBuffer, the audio can then be played by being passed into an AudioBufferSourceNode.

MDN Reference

Methods

copyFromChannel()

copyFromChannel(
destination,
channelNumber,
bufferOffset?
): void;

The copyFromChannel() method of the AudioBuffer interface copies the audio sample data from the specified channel of the AudioBuffer to a specified Float32Array.

MDN Reference

Parameters

ParameterType
destinationFloat32Array<ArrayBuffer>
channelNumbernumber
bufferOffset?number

Returns

void


copyToChannel()

copyToChannel(
source,
channelNumber,
bufferOffset?
): void;

The copyToChannel() method of the AudioBuffer interface copies the samples to the specified channel of the AudioBuffer, from the source array.

MDN Reference

Parameters

ParameterType
sourceFloat32Array<ArrayBuffer>
channelNumbernumber
bufferOffset?number

Returns

void


getChannelData()

getChannelData(channel): Float32Array<ArrayBuffer>;

The getChannelData() method of the AudioBuffer Interface returns a Float32Array containing the PCM data associated with the channel, defined by the channel parameter (with 0 representing the first channel).

MDN Reference

Parameters

ParameterType
channelnumber

Returns

Float32Array<ArrayBuffer>

Properties

duration

readonly duration: number;

The duration property of the AudioBuffer interface returns a double representing the duration, in seconds, of the PCM data stored in the buffer.

MDN Reference


length

readonly length: number;

The length property of the AudioBuffer interface returns an integer representing the length, in sample-frames, of the PCM data stored in the buffer.

MDN Reference


numberOfChannels

readonly numberOfChannels: number;

The numberOfChannels property of the AudioBuffer interface returns an integer representing the number of discrete audio channels described by the PCM data stored in the buffer.

MDN Reference


sampleRate

readonly sampleRate: number;

The sampleRate property of the AudioBuffer interface returns a float representing the sample rate, in samples per second, of the PCM data stored in the buffer.

MDN Reference