AudioBuffer
readonly struct NatML.Devices.AudioBuffer
Audio buffers contain audio data, along with corresponding information about aforementioned data. These buffers are produced by AudioDevice
instances while streaming, but can also be created with client-owned data.
Creating an Audio Buffer
While clients will usually interact with audio buffers produced by audio devices, clients can also create audio buffers for use with audio device outputs. Audio buffers can be created in several different ways:
From a Sample Buffer
Audio buffers can be created by clients for use with existing audio outputs. The sampleBuffer
should contain linear PCM audio data interleaved by channel (when channelCount > 1
).
From a Native Array
The audio buffer constructor has an overload that accepts a NativeArray<float>
in place of a managed float[]
.
From a Native Buffer
The audio buffer constructor has an overload that accepts a raw float*
buffer. The sampleCount
refers to the total number of samples within the buffer.
The sampleBuffer
must remain valid for the duration of the audio buffer.
Inspecting the Buffer Format
Audio buffers declare the format of the audio data contained within them:
Sample Rate
The sampleRate
is defined in Hertz.
Channel Count
The channelCount
defines the number of interleaved channels within the audio data.
Inspecting the Buffer Timestamp
The timestamp
defines the buffer timestamp in nanoseconds.
For audio buffers generated by AudioDevice
instances, the timestamp is based on the system media clock.
Accessing the Sample Buffer
The sampleBuffer
contains linear PCM audio samples, interleaved by channel.
Inspecting the Audio Device
The device
identifies the audio device that the buffer was generated from.
Last updated