Path: blob/main/files/en-us/web/api/audiodata/copyto/index.md
6561 views
------{{APIRef("WebCodecs API")}}{{SeeCompatTable}}
The copyTo() method of the {{domxref("AudioData")}} interface copies a plane of an AudioData object to a destination buffer.
Syntax
Parameters
destination: An {{jsxref("ArrayBuffer")}}, a {{jsxref("TypedArray")}}, or a {{jsxref("DataView")}} to copy the plane to.
options: An object containing the following:
planeIndex: The index of the plane to copy from.
frameOffset{{optional_inline}}: An integer giving an offset into the plane data indicating which plane to begin copying from. Defaults to
0.
frameCount{{optional_inline}}: An integer giving the number of frames to copy. If omitted then all frames in the plane will be copied, beginning with the frame specified in
frameOffset.
Return value
Undefined.
Exceptions
InvalidStateError{{domxref("DOMException")}}: Thrown if the
AudioDataobject has been transferred.
{{jsxref("RangeError")}}
: Thrown if one of the following conditions is met:
The length of the sample is longer than the destination length.
The format of the
AudioDataobject describes a planar format, butoptions.planeIndexis outside of the number of planes available.The format of the
AudioDataobject describes an interleaved format, butoptions.planeIndexis greater than0.
Examples
The following example copies the plane at index 1 to a destination buffer.
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}