AudioData Class
Audio samples (https://w3c.github.io/webcodecs/#audiodata): the decoded audio of an AudioDecoder, the input of an AudioEncoder, or the audio created by the scripts from a buffer. The samples are immutable and shared by the clones; they can be copied to a buffer in any sample format, and posted to a worker (serialized or transferred).
public sealed class AudioDataConstructors
| Name | Description |
|---|---|
| AudioData(AudioDataInit) | Creates audio samples from a buffer (https://w3c.github.io/webcodecs/#dom-audiodata-audiodata): the samples are copied. |
AudioData(AudioDataInit)
AudioData.csCreates audio samples from a buffer (https://w3c.github.io/webcodecs/#dom-audiodata-audiodata): the samples are copied.
public AudioData(AudioDataInit init)Parameters
initAudioDataInit- The description of the samples.
Exceptions
TypeErrorException- The description is invalid, or the buffer is too small.
DomException- A
DataCloneErrorwhen the transfer list has a detached buffer or a buffer twice.
See also
Properties
| Name | Description |
|---|---|
| Duration | Gets the duration in microseconds (0 when the data is closed). |
| Format | Gets the format of the samples, or null when the data is closed. |
| NumberOfChannels | Gets the number of channels (0 when the data is closed). |
| NumberOfFrames | Gets the number of frames (samples per channel; 0 when the data is closed). |
| SampleRate | Gets the sample rate in Hz (0 when the data is closed). |
| Timestamp | Gets the presentation timestamp in microseconds. |
Duration
AudioData.csGets the duration in microseconds (0 when the data is closed).
public ulong Duration { get; }Format
AudioData.csGets the format of the samples, or null when the data is closed.
public AudioSampleFormat? Format { get; }NumberOfChannels
AudioData.csGets the number of channels (0 when the data is closed).
public uint NumberOfChannels { get; }NumberOfFrames
AudioData.csGets the number of frames (samples per channel; 0 when the data is closed).
public uint NumberOfFrames { get; }SampleRate
AudioData.csGets the sample rate in Hz (0 when the data is closed).
public float SampleRate { get; }Timestamp
AudioData.csGets the presentation timestamp in microseconds.
public long Timestamp { get; }Methods
| Name | Description |
|---|---|
| AllocationSize(AudioDataCopyToOptions) | Returns the number of bytes AudioData.CopyTo writes with the options (https://w3c.github.io/webcodecs/#dom-audiodata-allocationsize). |
| Clone() | Creates audio data that references the same samples (https://w3c.github.io/webcodecs/#dom-audiodata-clone). |
| Close() | Releases the reference to the samples (https://w3c.github.io/webcodecs/#close-audiodata): the data cannot be used anymore. |
| CopyTo(Span<byte>, AudioDataCopyToOptions) | Copies the samples of a plane into a buffer (https://w3c.github.io/webcodecs/#dom-audiodata-copyto), converted to the format of the options. Any format can be converted to any format. |
AllocationSize(AudioDataCopyToOptions)
AudioData.csReturns the number of bytes AudioData.CopyTo writes with the options (https://w3c.github.io/webcodecs/#dom-audiodata-allocationsize).
public uint AllocationSize(AudioDataCopyToOptions options)Parameters
optionsAudioDataCopyToOptions
Returns
Exceptions
DomException- An
InvalidStateErrorwhen the data is closed, aNotSupportedErrorfor an unsupported conversion. RangeErrorException- The plane or the frames do not exist.
See also
Clone()
AudioData.csCreates audio data that references the same samples (https://w3c.github.io/webcodecs/#dom-audiodata-clone).
public AudioData Clone()Close()
AudioData.csReleases the reference to the samples (https://w3c.github.io/webcodecs/#close-audiodata): the data cannot be used anymore.
public void Close()CopyTo(Span<byte>, AudioDataCopyToOptions)
AudioData.csCopies the samples of a plane into a buffer (https://w3c.github.io/webcodecs/#dom-audiodata-copyto), converted to the format of the options. Any format can be converted to any format.
public void CopyTo(Span<byte> destination, AudioDataCopyToOptions options)Parameters
destinationSpan<byte>- The buffer.
optionsAudioDataCopyToOptions- The plane, the frames and the format.
Exceptions
DomException- An
InvalidStateErrorwhen the data is closed. RangeErrorException- The plane or the frames do not exist, or the buffer is too small.