AudioBuffer: copyToChannel() メソッド
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2021年4月.
copyToChannel() は AudioBuffer インターフェイスのメソッドで、元の配列から指定の AudioBuffer のチャンネルへとコピーします。
構文
js
copyToChannel(source, channelNumber)
copyToChannel(source, channelNumber, startInChannel)
引数
source-
コピー元となるチャンネルデータの
Float32Arrayです。 channelNumber-
チャンネルデータのコピー先となる現在の
AudioBufferのチャンネル番号です。 channelNumber がAudioBuffer.numberOfChannels以上の場合はINDEX_SIZE_ERR例外が発生します。 startInChannel省略可-
オプションで、データをコピーする先のオフセット位置です。 startInChannel が
AudioBuffer.lengthより大きければ、INDEX_SIZE_ERR例外が発生します。
返値
なし (undefined)。
例
js
const myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate);
const anotherArray = new Float32Array();
// myArrayBuffer の 2 番目のチャンネルからコピーする
myArrayBuffer.copyFromChannel(anotherArray, 1, 0);
// anotherArray から、 myArrayBuffer の 1 番目のチャンネルにコピーする。これで 2 つのチャンネルのデータは同じになる
myArrayBuffer.copyToChannel(anotherArray, 0, 0);
仕様書
| Specification |
|---|
| Web Audio API> # dom-audiobuffer-copytochannel> |
ブラウザーの互換性
Loading…