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.

AudioBuffer接口的 copyFromChannel 方法将样本从 AudioBuffer 的指定通道复制到目标数组中

语法

myArrayBuffer.copyFromChannel(destination,channelNumber,startInChannel);

参数

destination

将通道数据复制到的Float32Array

channelNumber

当前 AudioBuffer 的通道号,用于复制通道数据。键入 channelNumber 大于或等于AudioBuffer.numberOfChannels,将会抛出INDEX_SIZE_ERR 的错误

startInChannel 可选

用于复制数据的可选偏移量。假如startInChannel 比AudioBuffer.length大,将会抛出INDEX_SIZE_ERR 的错误

例子

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

规范

Specification
Web Audio API
# dom-audiobuffer-copyfromchannel

浏览器兼容性

BCD tables only load in the browser

See also