--- title: AudioBuffer.copyFromChannel() slug: Web/API/AudioBuffer/copyFromChannel translation_of: Web/API/AudioBuffer/copyFromChannel ---

{{ APIRef("Web Audio API") }}

{{ domxref("AudioBuffer") }}接口的copyFromChannel方法将样本从AudioBuffer的指定通道复制到目标数组中

语法

myArrayBuffer.copyFromChannel(destination,channelNumber,startInChannel);

参数

destination
将通道数据复制到的{{domxref("Float32Array")}}
channelNumber
当前AudioBuffer的通道号,用于复制通道数据。键入channelNumber大于或等于{{domxref("AudioBuffer.numberOfChannels")}},将会抛出INDEX_SIZE_ERR 的错误
startInChannel {{optional_inline}}
用于复制数据的可选偏移量。假如startInChannel比{{domxref("AudioBuffer.length")}}大,将会抛出INDEX_SIZE_ERR 的错误

例子

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

规范

Specification Status Comment
{{SpecName('Web Audio API', '#widl-AudioBuffer-copyFromChannel-void-Float32Array-destination-long-channelNumber-unsigned-long-startInChannel', 'copyFromChannel')}} {{Spec2('Web Audio API')}}  

浏览器兼容性

{{CompatibilityTable}}
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(14.0)}} {{property_prefix("webkit")}} {{CompatVersionUnknown}} {{CompatGeckoDesktop(27)}} {{CompatNo}} 15 {{property_prefix("webkit")}}
22 (unprefixed)
{{CompatNo}}
Unprefixed {{CompatChrome(43.0)}} {{CompatVersionUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatNo}}
Feature Android Android Webview Edge Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support {{CompatNo}} {{CompatUnknown}} {{CompatVersionUnknown}} {{CompatGeckoMobile(27)}} 1.2 {{CompatNo}} {{CompatNo}} {{CompatNo}} {{CompatChrome(28.0)}} {{property_prefix("webkit")}}
Unprefixed {{CompatNo}} {{CompatNo}} {{CompatVersionUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatNo}} {{CompatChrome(43.0)}}

See also