Note: This feature is available in Dedicated Web Workers.
The copyTo() method of the AudioData interface copies a plane of an AudioData object to a destination buffer.
copyTo(destination, options)destinationAn ArrayBuffer, a TypedArray, or a DataView to copy the plane to.
optionsAn object containing the following:
planeIndexThe index of the plane to copy from.
frameOffset OptionalAn integer giving the offset of the first frame to copy within the plane. Defaults to 0.
frameCount OptionalAn integer giving the number of frames to copy. If omitted, all frames from frameOffset to the end of the plane are copied.
format OptionalA string indicating the audio format that the source samples should be converted to when copied to the destination. This can be any of the values: "u8", "s16", "s32", "f32", "u8-planar", "s16-planar", "s32-planar", and "f32-planar" (see AudioData.format for more information). Note that "f32-planar" must be supported. If omitted, the samples are copied in the AudioData's own format.
Undefined.
InvalidStateError DOMExceptionThrown if the AudioData object has been transferred.
RangeErrorThrown if one of the following conditions is met:
AudioData object describes a planar format, but options.planeIndex is outside of the number of planes available.AudioData object describes an interleaved format, but options.planeIndex is greater than 0.NotSupportedError DOMExceptionThrown if the specified format to convert the data to is not supported.
The following example copies the plane at index 1 to a destination buffer.
AudioData.copyTo(AudioBuffer, { planeIndex: 1 });