URY playd
C++ minimalist audio player
ringbuffer.hpp
Go to the documentation of this file.
1 // This file is part of playd.
2 // playd is licensed under the MIT licence: see LICENSE.txt.
3 
9 #ifndef PLAYD_RINGBUFFER_HPP
10 #define PLAYD_RINGBUFFER_HPP
11 
12 extern "C" {
13 #include "../contrib/pa_ringbuffer/pa_ringbuffer.h"
14 }
15 
25 {
26 public:
37  RingBuffer(int power, int size);
38 
40  ~RingBuffer();
41 
43  RingBuffer(const RingBuffer &) = delete;
44 
46  RingBuffer &operator=(const RingBuffer &) = delete;
47 
53  size_t WriteCapacity() const;
54 
60  size_t ReadCapacity() const;
61 
84  unsigned long Write(const char *start, unsigned long count);
85 
105  unsigned long Read(char *start, unsigned long count);
106 
108  void Flush();
109 
110 private:
111  char *buffer;
112  PaUtilRingBuffer *rb;
113 
119  static unsigned long CountCast(ring_buffer_size_t count);
120 };
121 
122 #endif // PLAYD_RINGBUFFER_HPP
RingBuffer(int power, int size)
Constructs a RingBuffer.
Definition: ringbuffer.cpp:19
char * buffer
The array used by the ringbuffer.
Definition: ringbuffer.hpp:111
~RingBuffer()
Destructs a PaRingBuffer.
Definition: ringbuffer.cpp:37
PaUtilRingBuffer * rb
The internal PortAudio ringbuffer.
Definition: ringbuffer.hpp:112
RingBuffer & operator=(const RingBuffer &)=delete
Deleted copy-assignment.
unsigned long Read(char *start, unsigned long count)
Reads samples from the ring buffer into an array.
Definition: ringbuffer.cpp:65
size_t WriteCapacity() const
The current write capacity.
Definition: ringbuffer.cpp:46
size_t ReadCapacity() const
The current read capacity.
Definition: ringbuffer.cpp:51
unsigned long Write(const char *start, unsigned long count)
Writes samples from an array into the ring buffer.
Definition: ringbuffer.cpp:56
A ring buffer.
Definition: ringbuffer.hpp:24
void Flush()
Empties the ring buffer.
Definition: ringbuffer.cpp:74
static unsigned long CountCast(ring_buffer_size_t count)
Converts a ring buffer size into an external size.
Definition: ringbuffer.cpp:80