A ring buffer. More...
#include <ringbuffer.hpp>
Public Member Functions | |
RingBuffer (int power, int size) | |
Constructs a RingBuffer. More... | |
~RingBuffer () | |
Destructs a PaRingBuffer. | |
RingBuffer (const RingBuffer &)=delete | |
Deleted copy constructor. | |
RingBuffer & | operator= (const RingBuffer &)=delete |
Deleted copy-assignment. | |
size_t | WriteCapacity () const |
The current write capacity. More... | |
size_t | ReadCapacity () const |
The current read capacity. More... | |
unsigned long | Write (const char *start, unsigned long count) |
Writes samples from an array into the ring buffer. More... | |
unsigned long | Read (char *start, unsigned long count) |
Reads samples from the ring buffer into an array. More... | |
void | Flush () |
Empties the ring buffer. | |
Static Private Member Functions | |
static unsigned long | CountCast (ring_buffer_size_t count) |
Converts a ring buffer size into an external size. More... | |
Private Attributes | |
char * | buffer |
The array used by the ringbuffer. | |
PaUtilRingBuffer * | rb |
The internal PortAudio ringbuffer. | |
A ring buffer.
This ring buffer is based on the PortAudio ring buffer, provided in the contrib/ directory. This is stable and performs well, but, as it is C code, necessitates some hoop jumping to integrate and could do with being replaced with a native solution.
Definition at line 24 of file ringbuffer.hpp.
RingBuffer::RingBuffer | ( | int | power, |
int | size | ||
) |
Constructs a RingBuffer.
power | n, where 2^n is the number of elements in the ring buffer. |
size | The size of one element in the ring buffer. |
Definition at line 19 of file ringbuffer.cpp.
References buffer, MSG_OUTPUT_RINGINIT, and rb.
|
staticprivate |
Converts a ring buffer size into an external size.
count | The size/count in PortAudio form. |
Definition at line 80 of file ringbuffer.cpp.
Referenced by Read(), ReadCapacity(), Write(), and WriteCapacity().
unsigned long RingBuffer::Read | ( | char * | start, |
unsigned long | count | ||
) |
Reads samples from the ring buffer into an array.
To read one sample, pass a count of 1 and take a pointer to the sample variable.
start | The start of the array buffer to which we write samples. Must not be nullptr. |
count | The number of samples to read. This must not exceed the minimum of ReadCapacity() and the length of the array. |
Definition at line 65 of file ringbuffer.cpp.
References CountCast(), rb, and ReadCapacity().
Referenced by SdlAudioSink::Callback().
size_t RingBuffer::ReadCapacity | ( | ) | const |
The current read capacity.
Definition at line 51 of file ringbuffer.cpp.
References CountCast(), and rb.
Referenced by SdlAudioSink::Callback(), Flush(), and Read().
unsigned long RingBuffer::Write | ( | const char * | start, |
unsigned long | count | ||
) |
Writes samples from an array into the ring buffer.
To write one sample, pass a count of 1 and take a pointer to the sample variable. Note that start pointer is not constant. This is because the underlying implementation of the ring buffer might not guarantee that the array is left untouched.
start | The start of the array buffer from which we read samples. Must not be nullptr. |
count | The number of samples to write. This must not exceed the minimum of WriteCapacity() and the length of the array. |
Definition at line 56 of file ringbuffer.cpp.
References CountCast(), rb, and WriteCapacity().
Referenced by SdlAudioSink::Transfer().
size_t RingBuffer::WriteCapacity | ( | ) | const |
The current write capacity.
Definition at line 46 of file ringbuffer.cpp.
References CountCast(), and rb.
Referenced by SdlAudioSink::Transfer(), and Write().