AudioBuffer: Methode copyToChannel()

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.

Die Methode copyToChannel() des AudioBuffer-Interfaces kopiert die Samples aus dem Quellarray in den angegebenen Kanal des AudioBuffer.

Syntax

js
copyToChannel(source, channelNumber)
copyToChannel(source, channelNumber, startInChannel)

Parameter

source

Ein Float32Array, aus dem die Kanaldaten kopiert werden.

channelNumber

Die Kanalnummer des aktuellen AudioBuffer, in die die Kanaldaten kopiert werden sollen. Wenn channelNumber größer oder gleich AudioBuffer.numberOfChannels ist, wird ein INDEX_SIZE_ERR ausgelöst.

startInChannel Optional

Ein optionaler Offset, zu dem die Daten kopiert werden sollen. Wenn startInChannel größer als AudioBuffer.length ist, wird ein INDEX_SIZE_ERR ausgelöst.

Rückgabewert

Keiner (undefined).

Beispiele

js
const myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate);
const anotherArray = new Float32Array();
// Copy channel data from second channel of myArrayBuffer.
myArrayBuffer.copyFromChannel(anotherArray, 1, 0);
// Copy data from anotherArray to first channel of myArrayBuffer. Both channels have the same data now.
myArrayBuffer.copyToChannel(anotherArray, 0, 0);

Spezifikationen

Specification
Web Audio API
# dom-audiobuffer-copytochannel

Browser-Kompatibilität

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
copyToChannel

Legend

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

Full support
Full support

Siehe auch