Class thl::core::RingBuffer#
-
template<typename T>
class RingBuffer# Multi-channel ring buffer over an arbitrary element type.
Push semantics are delay-line friendly: pushing into a full channel silently overwrites the oldest sample (the read position advances), so the buffer can be driven continuously as a history/delay line. Popping an empty channel returns a value-initialized element (T{}).
The element type only needs to be copyable and value-initializable; float for audio, integer types for token/index streams, etc.
Index arithmetic wraps with a compare-and-subtract instead of
%: the capacity is a runtime value, so a modulo would be a real integer division on every push/pop – and anira-style consumers push per sample on targets without a hardware divider (armv7l).Public Functions
-
RingBuffer() = default#
-
inline void initialise_with_positions(size_t num_channels, size_t num_samples)#
-
inline void initialize_with_positions(size_t num_channels, size_t num_samples)#
American-spelling alias (anira-compatible surface).
-
inline void clear_with_positions()#
-
inline void push_block(size_t channel, const T *data, size_t count)#
Push
countsamples.Equivalent to
countcalls of push_sample(), but copies in at most two contiguous chunks. Ifcountexceeds the capacity only the lastcapacitysamples are retained.
-
inline void push_block(size_t channel, const T *data, size_t count, size_t stride)#
Strided push: reads
countsamples from data[0], data[stride], data[2 * stride], … Equivalent tocountcalls of push_sample(channel, data[i * stride]), so one channel of an interleaved host buffer (data = interleaved + c,stride = num_channels) goes into the ring without a de-interleaved copy in between.strideis in elements and at least 1;stride == 1is push_block(channel, data,
count). An oversized block keeps its last
capacitysamples, like the unit-stride form. Never allocates.
-
inline void pop_block(size_t channel, T *data, size_t count)#
Pop
countsamples.Equivalent to
countcalls of pop_sample(): any samples beyond what is available are value-initialised (T{}).
-
inline void pop_block(size_t channel, T *data, size_t count, size_t stride)#
Strided pop: writes
countsamples to data[0], data[stride], data[2 * stride], … Equivalent to data[i * stride] = pop_sample(channel) for i in [0, count): samples beyond what is available are value-initialised (T{}), and the elements between the strided ones are not touched.strideis in elements and at least 1;stride == 1is pop_block(channel, data, count). Never allocates.
-
inline void push_fill(size_t channel, T value, size_t count)#
Push
countcopies ofvalue.Equivalent to
countcalls of push_sample(value) (e.g. priming a latency with silence) without touching the elements one at a time.
-
inline size_t discard(size_t channel, size_t count)#
Drop up to
countunread samples.Equivalent to
countcalls of pop_sample() with the results ignored. Returns how many were dropped.
-
inline void peek_past_block(size_t channel, T *data, size_t count) const#
Copy the
countmost recently consumed samples (history) intodata, oldest first, so data[count - 1] is the sample popped last.Equivalent to get_past_sample(channel, count - k) for k in [0, count). Like get_past_sample() the range is not checked against the retained history, and a count beyond the capacity wraps the same way.
-
inline void peek_past_block(size_t channel, T *data, size_t count, size_t stride) const#
Strided peek_past_block: the
countmost recently consumed samples, oldest first, written to data[0], data[stride], … so that data[(count - 1) * stride] is the sample popped last.Same range rules as the unit-stride form;
strideis in elements and at least 1. Never allocates.
-
inline size_t get_available_samples(size_t channel) const#
-
inline size_t get_available_past_samples(size_t channel) const#
-
inline size_t get_num_channels() const#
-
inline size_t get_num_samples() const#
-
RingBuffer() = default#