public sealed class AudioRingBufferA fixed-size float queue with one writer and one reader, and no lock between them.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
The join between a thread that can block and a thread that must not. A decoder fills it from a disk or a network; the mixer drains it inside the audio callback. Neither takes a lock, so a decoder stalled on a slow read cannot stall the callback — the callback finds the buffer empty, writes silence, and counts it.
Monotonic counters rather than wrapped indices. The two cursors only ever increase, and the position in the array is the counter modulo the capacity. That makes "full" and "empty" different states without sacrificing a slot, and it means a torn read of a cursor is impossible on any platform .NET runs on: both are Int64 accessed through Volatile, and each is written by exactly one thread.
One writer and one reader is a requirement, not a nicety. Two writers race on the write cursor. The pump enforces it by owning each provider's buffer alone.
Fields and properties (3)
public int CapacityHow many floats it can hold.
public int CountHow many floats are waiting to be read.
public int FreeHow much room there is to write into.
Methods (4)
public AudioRingBuffer(int capacity)A buffer that holds a number of floats.
public int Write(ReadOnlySpan<float> source)Writes as much as will fit.
public int Read(Span<float> destination)Reads as much as is there.
public void Clear()Throws everything in it away.
Used by (5)
- AudioRingBufferTestsVixen.Audio.Tests
- LiveSampleProviderVixen.Audio
- NullAudioCaptureDeviceVixen.Audio
- OpenALCaptureDeviceVixen.Audio.Backend.OpenAL
- StreamingSampleProviderVixen.Audio