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 AudioBufferRemarks
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
| Name | Description |
|---|---|
| AudioBuffer(AudioBufferOptions) | Creates a buffer of silence. |
AudioBuffer(AudioBufferOptions)
AudioBuffer.csCreates a buffer of silence.
public AudioBuffer(AudioBufferOptions options)Parameters
optionsAudioBufferOptions
Exceptions
DomException- An option is out of its supported range (a
NotSupportedError).
See also
Properties
| Name | Description |
|---|---|
| Duration | Gets the duration in seconds. |
| Length | Gets the length in sample frames. |
| NumberOfChannels | Gets the number of channels. |
| SampleRate | Gets the sample rate in Hz. |
Duration
AudioBuffer.csGets the duration in seconds.
public double Duration { get; }Length
AudioBuffer.csGets the length in sample frames.
public uint Length { get; }NumberOfChannels
AudioBuffer.csSampleRate
AudioBuffer.csGets the sample rate in Hz.
public float SampleRate { get; }Methods
| Name | Description |
|---|---|
| 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.csCopies the samples of a channel, from a frame, to an array.
Parameters
destinationSpan<byte>channelNumberuintbufferOffsetuint
Exceptions
DomException- The channel does not exist (an
IndexSizeError).
See also
CopyToChannel(ReadOnlySpan<byte>, uint, uint)
AudioBuffer.csCopies the samples of an array to a channel, from a frame.
public void CopyToChannel(ReadOnlySpan<byte> source, uint channelNumber, uint bufferOffset = 0U)Parameters
sourceReadOnlySpan<byte>channelNumberuintbufferOffsetuint
Exceptions
DomException- The channel does not exist (an
IndexSizeError).
See also
GetChannelData(int)
AudioBuffer.csGets the samples of a channel: the writes are visible to the scripts (until the content is acquired by a node).
GetChannelDataArray(uint)
AudioBuffer.csGets the Float32Array of the samples of a channel for the scripts: use AudioBuffer.GetChannelData in .NET code.
Parameters
channeluint
Returns
Exceptions
DomException- The channel does not exist (an
IndexSizeError).