AudioBuffer: copyFromChannel() メソッド

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.

copyFromChannel()AudioBuffer インターフェイスのメソッドで、 AudioBuffer の指定されたチャンネルから音声サンプルデータを指定された Float32Array へコピーします。

構文

js
copyFromChannel(destination, channelNumber, startInChannel)

引数

destination

チャンネルのサンプルのコピー先となる Float32Array です。

channelNumber

チャンネルデータをコピーする現在の AudioBuffer のチャンネル数です。

startInChannel 省略可

オプションで、ソースチャンネルバッファー内でサンプルのコピーを始める位置のオフセットです。指定されていない場合は、既定で 0 の値(バッファーの先頭)とみなされます。

返値

なし (undefined)。

例外

indexSizeError

入力引数のうちの一つが、受付可能な範囲の外にある場合。

  • channelNumber の値が存在しないチャンネル番号を指定している場合(つまり、チャンネルの numberOfChannels 以上である場合)。
  • startInChannel の値がソースバッファーの中に既に存在するサンプルの現在の範囲の外にある場合。つまり、現在の length より大きい場合。

この例では新しい音声バッファーを生成し、他のチャンネルからサンプルをコピーします。

js
const myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate);
const anotherArray = new Float32Array(length);
myArrayBuffer.copyFromChannel(anotherArray, 1, 0);

仕様書

Specification
Web Audio API
# dom-audiobuffer-copyfromchannel

ブラウザーの互換性

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
copyFromChannel

Legend

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

Full support
Full support

関連情報