Search Results for

    Show / Hide Table of Contents

    Class FloatRingBuffer

    • Lock-free single-producer/single-consumer ring buffer for float PCM samples.
    • Overwrite policy: when full, drops the oldest samples by advancing a producer-owned drop floor.
    • ReadOrSilence() always fills the requested output length (pads with zeros) to avoid audio underruns.
    • TryRead() reads up to output length and returns how many samples were copied.
    • SPSC only: exactly one producer thread and exactly one consumer thread.
    Inheritance
    object
    FloatRingBuffer
    Implements
    IDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Glitch9.IO.Audio
    Assembly: Glitch9.IO.dll
    Syntax
    public sealed class FloatRingBuffer : IDisposable

    Constructors

    | Edit this page View Source

    FloatRingBuffer(int)

    Declaration
    public FloatRingBuffer(int capacity)
    Parameters
    Type Name Description
    int capacity

    Properties

    | Edit this page View Source

    AvailableRead

    • Approximate readable sample count (clamped to int range).
    Declaration
    public int AvailableRead { get; }
    Property Value
    Type Description
    int
    | Edit this page View Source

    Capacity

    • Ring buffer capacity in samples (power of two).
    Declaration
    public int Capacity { get; }
    Property Value
    Type Description
    int
    | Edit this page View Source

    DroppedSamples

    • Total number of samples logically dropped due to overwrite.
    Declaration
    public long DroppedSamples { get; }
    Property Value
    Type Description
    long

    Methods

    | Edit this page View Source

    Clear()

    • Clears cursors and drop counters.
    • Safe only when streaming is stopped (no concurrent Read/Write expected).
    Declaration
    public void Clear()
    | Edit this page View Source

    Dispose()

    • Disposes the ring buffer by clearing all cursors and counters.
    • Note: This class uses only managed memory; Dispose is provided for explicit cleanup semantics.
    Declaration
    public void Dispose()
    | Edit this page View Source

    GetCursors()

    Declaration
    public (long Read, long Write, long Floor) GetCursors()
    Returns
    Type Description
    (long Read, long Write, long Floor)
    | Edit this page View Source

    ReadOrSilence(Span<float>)

    • Reads exactly output.Length samples if possible; otherwise reads what is available and zero-fills the rest.
    • This is the recommended method for audio callbacks to avoid underruns.
    • Returns how many samples came from the buffer (0..output.Length).
    Declaration
    public int ReadOrSilence(Span<float> output)
    Parameters
    Type Name Description
    Span<float> output
    Returns
    Type Description
    int
    | Edit this page View Source

    TryRead(Span<float>)

    • Tries to read up to output.Length samples.
    • Returns the number of samples copied (may be 0).
    • If overwrite is detected (drop floor advanced past our cursor), it catches up and returns 0.
    Declaration
    public int TryRead(Span<float> output)
    Parameters
    Type Name Description
    Span<float> output
    Returns
    Type Description
    int
    | Edit this page View Source

    Write(ReadOnlySpan<float>)

    • Writes samples to the buffer.
    • If the write would exceed capacity, drops the oldest samples by advancing the drop floor.
    • Returns the number of samples accepted (equals input length).
    Declaration
    public int Write(ReadOnlySpan<float> input)
    Parameters
    Type Name Description
    ReadOnlySpan<float> input
    Returns
    Type Description
    int

    Implements

    IDisposable

    Extension Methods

    ArrayExtensions.ToArrayOrEmpty<T>(T)
    ArrayExtensions.ToArrayOrNull<T>(T)
    EventExtensions.ToDelta<T>(T, string, int, string, bool)
    EventExtensions.ToDone<T>(T, string, int, string)
    EventExtensions.ToEvent<T>(T)
    EventExtensions.UpcastDelta<T1, T2>(T1, string, int, string, bool)
    FallbackExtensions.IsOr<TParent, TChild>(TParent, TChild)
    ResponseCastingExtensions.GetResult<T>(T)
    SystemExtensions.TryDispose(IDisposable)
    SystemExtensions.GetName(object)
    • Edit this page
    • View Source
    In this article
    Back to top AI DevKit Documentation