web api instance method
AudioData: copyTo() method
Available in workers
The copyTo() method of the AudioData interface copies a plane of an AudioData object to a destination buffer.
Syntax
copyTo(destination, options)
Parameters
destination- : An
ArrayBuffer, aTypedArray, or aDataViewto copy the plane to.
- : An
options- : An object containing the following:
planeIndex- : The index of the plane to copy from.
frameOffsetOptional- : An integer giving the offset of the first frame to copy within the plane. Defaults to
0.
- : An integer giving the offset of the first frame to copy within the plane. Defaults to
frameCountOptional- : An integer giving the number of frames to copy. If omitted, all frames from
frameOffsetto the end of the plane are copied.
- : An integer giving the number of frames to copy. If omitted, all frames from
formatOptional- : A 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"(seeformatfor more information). Note that"f32-planar"must be supported. If omitted, the samples are copied in theAudioData’s own format.
- : A 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:
- : An object containing the following:
Return value
Undefined.
Exceptions
InvalidStateErrorDOMException- : Thrown if the
AudioDataobject has been transferred.
- : Thrown if the
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.
- : Thrown if one of the following conditions is met:
NotSupportedErrorDOMException- : Thrown if the specified
formatto convert the data to is not supported.
- : Thrown if the specified
Examples
The following example copies the plane at index 1 to a destination buffer.
AudioData.copyTo(AudioBuffer, { planeIndex: 1 });
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.