Loading...
Searching...
No Matches
Process::SampleRing Class Reference

Detailed Description

The most recent samples of a multichannel signal, written by the execution thread and read by the GUI without lock or allocation on the writing side.

The writer never waits: it overwrites the oldest samples. It announces the end of the block it is about to write before writing it, and publishes it once written; the reader copies the span it wants and checks afterwards that no block announced meanwhile reached it, as in a seqlock. A copy the writer may have overwritten is reported as unavailable rather than returned torn.

Only what was written as one continuous stream is returned: the frames of a channel from before its buffer existed or from before the writer skipped it, and the frames from before a pause of the writer (see restart()), are reported as unavailable.

Channel buffers are allocated by the reader (provision()) when the writer reports more channels than are allocated; until then the writer skips the extra channels. Buffers are freed only with the ring.

Public Member Functions

 SampleRing (int capacity=1<< 16)
 
 SampleRing (const SampleRing &)=delete
 
SampleRing & operator= (const SampleRing &)=delete
 
uint64_t capacity () const noexcept
 
template<typename F >
void write (int channel_count, int frames, F &&channel) noexcept
 
void restart () noexcept
 Writer: what was written so far is not continuous with what comes next.
 
void set_rate (double rate) noexcept
 
void provision ()
 Reader: allocates the buffers of the channels the writer reported.
 
int channels () const noexcept
 
double rate () const noexcept
 
uint64_t written () const noexcept
 Absolute index one past the last frame written so far.
 
bool read (int c, uint64_t start, std::span< float > dst) const noexcept
 
bool read_latest (int c, std::span< float > dst, uint64_t &first) const noexcept
 

Static Public Attributes

static constexpr int max_channels = 64
 

Member Function Documentation

◆ read()

bool Process::SampleRing::read ( int  c,
uint64_t  start,
std::span< float >  dst 
) const
inlinenoexcept

Copies the frames [start, start + dst.size()) of channel c into dst. False when they are not written yet, already overwritten, not part of the current stream of the channel, or the channel has no buffer yet.

◆ read_latest()

bool Process::SampleRing::read_latest ( int  c,
std::span< float >  dst,
uint64_t &  first 
) const
inlinenoexcept

Copies the latest dst.size() frames of channel c; returns the absolute index of the first one, or nothing.

◆ write()

template<typename F >
void Process::SampleRing::write ( int  channel_count,
int  frames,
F &&  channel 
)
inlinenoexcept

Writer: appends frames frames; channel(c) gives channel c's samples. When the previous block is older than a few blocks, the writer was paused (it writes only while a view watches) and restart() is implied.


The documentation for this class was generated from the following file: