Entropy Piano Tuner
1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
|
Template class for a circular buffer. More...
#include <circularbuffer.h>
Public Member Functions | |
CircularBuffer (std::size_t maximum_size=0) | |
Construct an empty buffer of maximal size zero. More... | |
void | clear () |
Clear the buffer, keeping its maximal size. More... | |
void | push_back (const data_type &data) |
Append a new data element to the buffer. More... | |
void | resize (std::size_t maximum_size) |
Resize the buffer, shrink oldest data if necessary. More... | |
std::vector< data_type > | getOrderedData () const |
Copy entire data in a time-ordered form. More... | |
std::vector< data_type > | readData (size_t n) |
Retrieve time-ordeded data with maximum size of n and remove if from the buffer. More... | |
std::size_t | size () const |
Return current buffer size. More... | |
std::size_t | maximum_size () const |
Return actual maximal size. More... | |
Private Attributes | |
std::size_t | mCurrentWritePosition |
Current read position. More... | |
std::size_t | mCurrentReadPosition |
Current write position. More... | |
std::size_t | mMaximumSize |
Maximal size of the buffer. More... | |
std::size_t | mCurrentSize |
Current size of the buffer. More... | |
std::vector< data_type > | mData |
Internal cyclic data buffer. More... | |
Template class for a circular buffer.
A circular buffer is a cyclic container with a fixed maximum size. When more data is written the oldest data is cyclicylly overwritten in order to keep the maximum size constant.
The current content of the buffer can be retrieved as a time-ordered vector by calling the function getOrderedData().
The circular buffer is used by the AudioRecorder and the SignalAnalyzer.
This class contains of a header file only. There is no corresponding implementation (cpp) file.
Definition at line 51 of file circularbuffer.h.
CircularBuffer< data_type >::CircularBuffer | ( | std::size_t | maximum_size = 0 | ) |
Construct an empty buffer of maximal size zero.
Default constructor, creating an empty buffer with maximal size zero.
Definition at line 88 of file circularbuffer.h.
void CircularBuffer< data_type >::clear | ( | ) |
Clear the buffer, keeping its maximal size.
Calling this function clears the buffer, setting the actual size to zero, but it does not change its maximum size.
Definition at line 109 of file circularbuffer.h.
std::vector< data_type > CircularBuffer< data_type >::getOrderedData | ( | ) | const |
Copy entire data in a time-ordered form.
Since the buffer is written cyclically, the newest data entry is somewhere but not necessarily at the phyical end of the buffer. This function therefore retrieves all data contained in the cyclic buffer in a temporally ordered form as a vector, i.e., the higher the index, the newer the data. The data will NOT be removed from the buffer
Definition at line 159 of file circularbuffer.h.
|
inline |
Return actual maximal size.
Definition at line 62 of file circularbuffer.h.
void CircularBuffer< data_type >::push_back | ( | const data_type & | data | ) |
Append a new data element to the buffer.
This function appends a new element. If the current size reaches the maximum size the oldest data is overwritten.
data | : New data element to be added. |
Definition at line 128 of file circularbuffer.h.
std::vector< data_type > CircularBuffer< data_type >::readData | ( | size_t | n | ) |
Retrieve time-ordeded data with maximum size of n and remove if from the buffer.
This function retrieves the existing data up to a given maximal size n in a time-ordered form and removes this data from the buffer.
Definition at line 186 of file circularbuffer.h.
void CircularBuffer< data_type >::resize | ( | std::size_t | maximum_size | ) |
Resize the buffer, shrink oldest data if necessary.
Set a new maximal buffer size. If the new maximal size is smaller than the actual data size only the newest data will be kept.
maximum_size | : The new maximal size of the circular buffer. |
Definition at line 213 of file circularbuffer.h.
|
inline |
Return current buffer size.
Definition at line 61 of file circularbuffer.h.
|
private |
Current write position.
Definition at line 67 of file circularbuffer.h.
|
private |
Current size of the buffer.
Definition at line 69 of file circularbuffer.h.
|
private |
Current read position.
Definition at line 66 of file circularbuffer.h.
|
private |
Internal cyclic data buffer.
Definition at line 70 of file circularbuffer.h.
|
private |
Maximal size of the buffer.
Definition at line 68 of file circularbuffer.h.