AudioBuffer Class

An audio asset in memory (https://webaudio.github.io/web-audio-api/#AudioBuffer): one or more channels of linear PCM samples (32-bit floats, nominally between -1 and 1), at a sample rate.

public sealed class AudioBuffer

Remarks

The arrays returned to the scripts by getChannelData() share their memory with the buffer, until its content is acquired by a node (https://webaudio.github.io/web-audio-api/#acquire-the-content, e.g. when an AudioBufferSourceNode starts): the node then plays a copy, and the next calls of getChannelData() return new arrays.

See also

Constructors

NameDescription
AudioBuffer(AudioBufferOptions)Creates a buffer of silence.

AudioBuffer(AudioBufferOptions)

AudioBuffer.cs

Creates a buffer of silence.

public AudioBuffer(AudioBufferOptions options)

Parameters

options AudioBufferOptions

Exceptions

DomException
An option is out of its supported range (a NotSupportedError).

See also

Properties

NameDescription
DurationGets the duration in seconds.
LengthGets the length in sample frames.
NumberOfChannelsGets the number of channels.
SampleRateGets the sample rate in Hz.

Gets the duration in seconds.

public double Duration { get; }

Gets the length in sample frames.

public uint Length { get; }

NumberOfChannels

AudioBuffer.cs

Gets the number of channels.

public uint NumberOfChannels { get; }

SampleRate

AudioBuffer.cs

Gets the sample rate in Hz.

public float SampleRate { get; }

Methods

NameDescription
CopyFromChannel(Span<byte>, uint, uint)Copies the samples of a channel, from a frame, to an array.
CopyToChannel(ReadOnlySpan<byte>, uint, uint)Copies the samples of an array to a channel, from a frame.
GetChannelData(int)Gets the samples of a channel: the writes are visible to the scripts (until the content is acquired by a node).
GetChannelDataArray(uint)Gets the Float32Array of the samples of a channel for the scripts: use AudioBuffer.GetChannelData in .NET code.

CopyFromChannel(Span<byte>, uint, uint)

AudioBuffer.cs

Copies the samples of a channel, from a frame, to an array.

public void CopyFromChannel(Span<byte> destination, uint channelNumber, uint bufferOffset = 0U)

Parameters

destination Span<byte>
channelNumber uint
bufferOffset uint

Exceptions

DomException
The channel does not exist (an IndexSizeError).

See also

CopyToChannel(ReadOnlySpan<byte>, uint, uint)

AudioBuffer.cs

Copies the samples of an array to a channel, from a frame.

public void CopyToChannel(ReadOnlySpan<byte> source, uint channelNumber, uint bufferOffset = 0U)

Parameters

source ReadOnlySpan<byte>
channelNumber uint
bufferOffset uint

Exceptions

DomException
The channel does not exist (an IndexSizeError).

See also

GetChannelData(int)

AudioBuffer.cs

Gets the samples of a channel: the writes are visible to the scripts (until the content is acquired by a node).

public Span<float> GetChannelData(int channel)

Parameters

channel int

Returns

Span<float>

Exceptions

DomException
The channel does not exist (an IndexSizeError).

GetChannelDataArray(uint)

AudioBuffer.cs

Gets the Float32Array of the samples of a channel for the scripts: use AudioBuffer.GetChannelData in .NET code.

public object GetChannelDataArray(uint channel)

Parameters

channel uint

Returns

object

Exceptions

DomException
The channel does not exist (an IndexSizeError).

See also