bpmdetect 0.8.11
Automatic BPM detection tool
Loading...
Searching...
No Matches
SampleRingBuffer Class Reference

#include <sampleringbuffer.h>

Public Member Functions

 SampleRingBuffer (std::size_t capacity)
std::size_t write (std::span< const float > samples)
std::size_t read (std::span< float > destination)
void discardAll ()

Detailed Description

Lock-free single-producer, single-consumer ring buffer for audio samples.

The producer (real-time audio thread) only calls write(), and the consumer (worker thread) only calls read() and discardAll(). Writes are all-or-nothing so interleaved frames are never split.

Constructor & Destructor Documentation

◆ SampleRingBuffer()

SampleRingBuffer::SampleRingBuffer ( std::size_t capacity)
explicit

Constructs a ring buffer holding at least capacity samples (rounded up to a power of two).

Member Function Documentation

◆ discardAll()

void SampleRingBuffer::discardAll ( )

Discards all buffered samples. Consumer only.

◆ read()

std::size_t SampleRingBuffer::read ( std::span< float > destination)

Reads up to destination.size() samples. Returns the number of samples read. Consumer only.

◆ write()

std::size_t SampleRingBuffer::write ( std::span< const float > samples)

Writes all samples or none if there is not enough space. Returns the number of samples written. Producer only. Real-time safe.


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