Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

AudioBuffer — audio samples in memory

AudioBuffer stores channels of PCM samples in memory; it neither plays sound itself nor represents an audio file.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

new AudioBuffer({ length, sampleRate, numberOfChannels: 1 })

AudioBuffer belongs to Web Audio, not ECMAScript. It stores channels of 32-bit floating-point PCM samples. length counts frames, not bytes; duration = length / sampleRate gives seconds. A new buffer contains zeros.

getChannelData(0) exposes the first channel as a readable, writable Float32Array. copyToChannel() copies samples in; copyFromChannel() copies them out. An invalid channel index causes IndexSizeError. Playback uses AudioBufferSourceNode. Check availability in the target browser; Node 24 does not establish support.

Examples

const buffer = new AudioBuffer({ length: 4, sampleRate: 8000 });
buffer.copyToChannel(new Float32Array([0, 0.5, -0.5, 0]), 0);
console.log(buffer.length, buffer.numberOfChannels);
console.log(Array.from(buffer.getChannelData(0)).join(','));

Result

4 1
0,0.5,-0.5,0

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources