12 #include "../contrib/pa_ringbuffer/pa_ringbuffer.h" 15 #include "../errors.hpp" 16 #include "../messages.h" 21 if (power <= 0)
throw InternalError(
"ringbuffer power must be positive");
22 if (size <= 0)
throw InternalError(
"ringbuffer element size must be positive");
24 this->
rb =
new PaUtilRingBuffer;
25 this->
buffer =
new char[(1 << power) * size];
27 if (PaUtil_InitializeRingBuffer(
28 this->
rb, size, static_cast<ring_buffer_size_t>(1 << power),
33 assert(this->
rb !=
nullptr);
34 assert(this->
buffer !=
nullptr);
39 assert(this->
rb !=
nullptr);
42 assert(this->
buffer !=
nullptr);
48 return CountCast(PaUtil_GetRingBufferWriteAvailable(this->
rb));
53 return CountCast(PaUtil_GetRingBufferReadAvailable(this->
rb));
58 if (count == 0)
throw InternalError(
"tried to store 0 items in ringbuffer");
62 this->
rb, start, static_cast<ring_buffer_size_t>(count)));
67 if (count == 0)
throw InternalError(
"tried to read 0 items from ringbuffer");
71 this->
rb, start, static_cast<ring_buffer_size_t>(count)));
76 PaUtil_FlushRingBuffer(this->
rb);
82 return static_cast<unsigned long>(count);
RingBuffer(int power, int size)
Constructs a RingBuffer.
char * buffer
The array used by the ringbuffer.
~RingBuffer()
Destructs a PaRingBuffer.
PaUtilRingBuffer * rb
The internal PortAudio ringbuffer.
unsigned long Read(char *start, unsigned long count)
Reads samples from the ring buffer into an array.
size_t WriteCapacity() const
The current write capacity.
The RingBuffer class template.
const std::string MSG_OUTPUT_RINGINIT
Message shown when there is an error initialising the ring buffer.
An Error signifying that playd has hit an internal snag.
size_t ReadCapacity() const
The current read capacity.
unsigned long Write(const char *start, unsigned long count)
Writes samples from an array into the ring buffer.
void Flush()
Empties the ring buffer.
static unsigned long CountCast(ring_buffer_size_t count)
Converts a ring buffer size into an external size.