Skip to main content

Crate rlx_ring

Crate rlx_ring 

Source
Expand description

A lock-free single-producer/single-consumer ring of interleaved f32 samples — the one piece of pure-Rust unsafe in the project.

The producer side lives on an audio thread (WASAPI capture, foobar’s visualisation_stream, …) and must stay real-time safe: push_samples performs no allocation, no locks, no logging, no I/O (NFR section 5).

Samples are interleaved f32 frames. If the ring is full the producer drops the excess (never blocks); the consumer is expected to drain every render frame so reads stay near the write head (NFR section 3).

This crate is deliberately dependency-free (no wgpu, no audio-source, no platform types) so cargo +nightly miri test -p rlx-ring compiles and runs the SPSC unit tests under Miri in seconds — the fast UB gate the extraction exists for (Plan 0005). Format validation and the audio-facing intake wrapper live in rlx-core’s audio module, which re-exports these types.

Structs§

SampleConsumer
Render/DSP-thread half.
SampleProducer
Audio-thread half. Real-time safe: push_samples never allocates, locks, or blocks.

Functions§

spsc
Create an SPSC pair over a ring sized to hold at least capacity_samples interleaved samples (rounded up to a power of two so the index mask is valid). channels is the interleaving width the producer rounds pushes to so a partial write never splits a frame; the caller (rlx-core’s intake) has already validated it.