Add real-time-safe SPSC ring buffer and denormal-aware delay line#18
Merged
Conversation
Adds two real-time-safe container types in support of the .NET VST3 effects host plan (upstream roadmap item #3): - SpscRingBuffer<T>: a lock-free, wait-free, fixed-capacity single-producer/single-consumer ring buffer. Allocation-free and non-blocking on both push and pop, with acquire/release ordering and cache-line padding to avoid false sharing. Intended for pushing meter/scope telemetry from an audio callback to the UI thread. - DelayLine: a fixed-capacity circular delay line for audio-rate float samples with integer and linear-interpolated taps. Denormals are flushed to zero on write to avoid CPU spikes in decaying feedback paths. Read(d) returns x[n-d] with d in [0, Capacity]. Both pre-allocate their backing store and never allocate, lock, or block on the hot path. Includes MSTest coverage, including a concurrent producer/consumer soak test for the ring buffer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements upstream roadmap item #3 from the .NET VST3 effects host plan: real-time-safe buffers for the audio↔UI boundary and for delay-based DSP. Both types are additive and pre-allocate their backing store so they never allocate, lock, or block on the hot path.
SpscRingBuffer<T>A lock-free, wait-free, fixed-capacity single-producer/single-consumer ring buffer.
TryEnqueue/TryDequeue/TryPeek— safe to call from an audio/render thread (producer) with a UI/worker thread (consumer).Volatile.Read/Volatile.Write); one reserved slot disambiguates full vs empty.[StructLayout(Explicit)]struct) to avoid false sharing.DelayLineA fixed-capacity circular delay line for audio-rate
floatsamples.Read) and linear-interpolated (ReadInterpolated) taps;Process(input, delay)is the common write-then-tap idiom.Read(d)returnsx[n-d]withdin[0, Capacity](delay 0 = most recently written sample), soProcess(x, D)outputs the input from exactlyDsamples earlier.Testing
Added MSTest coverage for both types (
SpscRingBufferTests,DelayLineTests), including FIFO ordering, full/empty edges, wraparound, denormal flushing, interpolation, argument validation, and a 1M-item concurrent producer/consumer soak test. Full suite: 351/351 passing locally (net10.0).🤖 Part of the ktsu VST plugin upstream-enablement work.
https://claude.ai/code/session_01JQ3bQMuSYuumAnQZaYUKP7
Generated by Claude Code