AudioBufferSourceNode: buffer プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.

bufferAudioBufferSourceNode インターフェイスのプロパティで、音声データのソースとして AudioBuffer を使用して音声を再生する機能を提供します。

buffer プロパティに null という値を設定すると、ノードは無音を含む単一のチャンネルを生成します(つまり、すべてのサンプルが 0 になります)。

ノードが再生する音を表すデータを格納した AudioBuffer

メモ: 動作する完全な例は、このコードをライブ実行またはソースを閲覧してください。

js
const myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate);

button.onclick = () => {
  // Fill the buffer with white noise;
  //just random values between -1.0 and 1.0
  for (let channel = 0; channel < channels; channel++) {
    // This gives us the actual ArrayBuffer that contains the data
    const nowBuffering = myArrayBuffer.getChannelData(channel);
    for (let i = 0; i < frameCount; i++) {
      // Math.random() is in [0; 1.0]
      // audio needs to be in [-1.0; 1.0]
      nowBuffering[i] = Math.random() * 2 - 1;
    }
  }

  // Get an AudioBufferSourceNode.
  // This is the AudioNode to use when we want to play an AudioBuffer
  const source = audioCtx.createBufferSource();
  // set the buffer in the AudioBufferSourceNode
  source.buffer = myArrayBuffer;
};

仕様書

Specification
Web Audio API
# dom-audiobuffersourcenode-buffer

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
buffer

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

関連情報