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 AudioData

Constructors

NameDescription
AudioData(AudioDataInit)Creates audio samples from a buffer (https://w3c.github.io/webcodecs/#dom-audiodata-audiodata): the samples are copied.

AudioData(AudioDataInit)

AudioData.cs

Creates audio samples from a buffer (https://w3c.github.io/webcodecs/#dom-audiodata-audiodata): the samples are copied.

public AudioData(AudioDataInit init)

Parameters

init AudioDataInit
The description of the samples.

Exceptions

TypeErrorException
The description is invalid, or the buffer is too small.
DomException
A DataCloneError when the transfer list has a detached buffer or a buffer twice.

See also

Properties

NameDescription
DurationGets the duration in microseconds (0 when the data is closed).
FormatGets the format of the samples, or null when the data is closed.
NumberOfChannelsGets the number of channels (0 when the data is closed).
NumberOfFramesGets the number of frames (samples per channel; 0 when the data is closed).
SampleRateGets the sample rate in Hz (0 when the data is closed).
TimestampGets the presentation timestamp in microseconds.

Duration

AudioData.cs

Gets the duration in microseconds (0 when the data is closed).

public ulong Duration { get; }

Gets the format of the samples, or null when the data is closed.

public AudioSampleFormat? Format { get; }

NumberOfChannels

AudioData.cs

Gets the number of channels (0 when the data is closed).

public uint NumberOfChannels { get; }

NumberOfFrames

AudioData.cs

Gets the number of frames (samples per channel; 0 when the data is closed).

public uint NumberOfFrames { get; }

SampleRate

AudioData.cs

Gets the sample rate in Hz (0 when the data is closed).

public float SampleRate { get; }

Timestamp

AudioData.cs

Gets the presentation timestamp in microseconds.

public long Timestamp { get; }

Methods

NameDescription
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.cs

Returns the number of bytes AudioData.CopyTo writes with the options (https://w3c.github.io/webcodecs/#dom-audiodata-allocationsize).

public uint AllocationSize(AudioDataCopyToOptions options)

Parameters

options AudioDataCopyToOptions

Returns

uint

Exceptions

DomException
An InvalidStateError when the data is closed, a NotSupportedError for an unsupported conversion.
RangeErrorException
The plane or the frames do not exist.

See also

Creates audio data that references the same samples (https://w3c.github.io/webcodecs/#dom-audiodata-clone).

public AudioData Clone()

Returns

AudioData

Exceptions

DomException
An InvalidStateError when the data is closed.

See also

Releases 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.cs

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.

public void CopyTo(Span<byte> destination, AudioDataCopyToOptions options)

Parameters

destination Span<byte>
The buffer.
options AudioDataCopyToOptions
The plane, the frames and the format.

Exceptions

DomException
An InvalidStateError when the data is closed.
RangeErrorException
The plane or the frames do not exist, or the buffer is too small.

See also