Class AudioBuffer
Represents a buffer of channel-interleaved audio samples.
Inheritance
Inherited Members
Namespace: Cosmos.HAL.Audio
Assembly: Cosmos.HAL2.dll
Syntax
public class AudioBuffer
Constructors
| Improve this Doc View SourceAudioBuffer(Int32, SampleFormat)
Creates an empty AudioBuffer.
Declaration
public AudioBuffer(int size, SampleFormat format)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | size | The size of the buffer. |
SampleFormat | format | The target format of the audio buffer. |
Fields
| Improve this Doc View SourceFormat
The audio format of the buffer.
Declaration
public readonly SampleFormat Format
Field Value
Type | Description |
---|---|
SampleFormat |
Properties
| Improve this Doc View SourceRawData
Provides access to the raw buffer data.
Declaration
public byte[] RawData { get; }
Property Value
Type | Description |
---|---|
System.Byte[] |
SampleAmount
The amount of sample values the buffer contains.
Declaration
public int SampleAmount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Size
The size of the audio buffer, in audio samples. Setting this property to a different value causes the audio buffer to flush.
Declaration
public int Size { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceFlush()
Flushes (empties) the audio buffer, setting all of its sample data to zero.
Declaration
public void Flush()
ReadSample(Int32, Byte*)
Reads a sample from the audio buffer to the target pointer in memory.
Declaration
public void ReadSample(int index, byte *dest)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the audio sample to read. |
System.Byte* | dest | The part of memory to write the sample to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown when attempting to write to a non-existent sample. |
ReadSample(Int32, Byte[], Int32)
Reads a sample from the audio buffer to the target array.
Declaration
public void ReadSample(int index, byte[] dest, int destOffset = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the audio sample to read. |
System.Byte[] | dest | The array to write the sample to. |
System.Int32 | destOffset | The offset in the array to write data to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when the provided destination array is not large enough to hold all of the bytes. |
System.ArgumentOutOfRangeException | Thrown when attempting to write to a non-existent sample. |
ReadSampleChannel(Int32, Int32, Byte*)
Reads a single channel of a sample to the target pointer in memory.
Declaration
public void ReadSampleChannel(int index, int channel, byte *dest)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the audio sample to read the channel of. |
System.Int32 | channel | The target channel to read. |
System.Byte* | dest | The part of memory to write the sample to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown when attempting to write to a non-existent channel or sample. |
ReadSampleChannel(Int32, Int32, Byte[], Int32)
Reads a single channel of a sample to the target array.
Declaration
public void ReadSampleChannel(int index, int channel, byte[] dest, int destOffset = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the audio sample to read the channel of. |
System.Int32 | channel | The target channel to read. |
System.Byte[] | dest | The array to write the sample to. |
System.Int32 | destOffset | The offset in the array to write data to. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when the provided source array is not large enough to hold all of the bytes. |
System.ArgumentOutOfRangeException | Thrown when attempting to write to a non-existent channel or sample. |
WriteSample(Int32, Byte*)
Writes a sample from the target pointer in memory to the buffer.
The amount of bytes that will be read is equal to
Declaration
public void WriteSample(int index, byte *src)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the audio sample to overwrite. |
System.Byte* | src | The part of memory to read the data from. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown when attempting to write to a non-existent sample. |
WriteSample(Int32, Byte[], Int32)
Writes a sample to the audio buffer, reading the sample data from
the specified array beginning at srcOffset
.
Declaration
public void WriteSample(int index, byte[] src, int srcOffset = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the audio sample to overwrite. |
System.Byte[] | src | The array to read the sample from. |
System.Int32 | srcOffset | The offset in the array to read data from. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when the provided source array is not large enough to provide all of the bytes. |
System.ArgumentOutOfRangeException | Thrown when attempting to write to a non-existent sample. |
WriteSampleChannel(Int32, Int32, Byte*)
Changes the value of a single channel of the specified sample to
the value that's located in memory at the specified pointer.
The amount of bytes that will be read is equal to the value of
Declaration
public void WriteSampleChannel(int index, int channel, byte *src)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the audio sample to overwrite the channel of. |
System.Int32 | channel | The channel to overwrite. |
System.Byte* | src | The part of memory to read the data from. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown when attempting to write to a non-existent channel or sample. |
WriteSampleChannel(Int32, Int32, Byte[], Int32)
Changes the value of a single channel of the specified sample to
the value that's located at index srcOffset
of the given
array. The amount of bytes that will be read is equal to the value of
Declaration
public void WriteSampleChannel(int index, int channel, byte[] src, int srcOffset = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the audio sample to overwrite the channel of. |
System.Int32 | channel | The channel to overwrite. |
System.Byte[] | src | The array to read the data from. |
System.Int32 | srcOffset | The starting index to read the data from |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when the provided source array is not large enough to provide all of the bytes. |
System.ArgumentOutOfRangeException | Thrown when attempting to write to a non-existent channel or sample. |