Search guides and the APICtrl K
  1. API reference
  2. System, devices and network

audio_ring.h

The one lock-free ring both directions of audio use.

#include <sonore/audio_ring.h>
On this page

Design notes

It lived inside audio_input.h, in a standalone namespace, because a live capture device was the only thing that needed it. A recorder needs exactly the same object pointing the other way -- audio thread writes, another thread drains -- and including audio_input.h to get it would drag a WASAPI or ALSA backend into a plugin that only wants to write a file.

So it lives here, and audio_input.h keeps its old name for it. One ring, one set of index arithmetic, one place where "full" and "empty" are told apart.

Types 1

One writer, one reader, no locks, no allocation after construction.

Stereo interleaved, because that is what crosses the boundary: the DSP is handed two channels and a capture device with six has already been folded down by the time it gets here.

Capacity is rounded UP to a power of two so the wrap is a mask rather than a modulo, and one frame is left permanently unused so full and empty are distinguishable without a third variable that the two threads would then have to agree about.

↑↓ to move↵ to openEvery public name in the headers, and every guide