AuxPort 0.2
Modules for Audio Software Development
Loading...
Searching...
No Matches
AuxPort::CircularBuffer< sample > Class Template Reference

Represents a circular buffer data structure. More...

#include <AuxCircularBuffer.h>

Inheritance diagram for AuxPort::CircularBuffer< sample >:
AuxPort::ILog

Public Member Functions

 CircularBuffer ()
 Default Constructor.
 
 CircularBuffer (const size_t &capacity)
 Initializes a CircularBuffer Object with the given capacity.
 
 CircularBuffer (const std::vector< sample > &buffer)
 Initializes a CircularBuffer Object using contents of a given vector.
 
 CircularBuffer (const sample *data, const size_t dataSize)
 Initializes a CircularBuffer Object using pointer to an array of elements.
 
 CircularBuffer (const CircularBuffer< sample > &obj)=default
 Default copy constructor.
 
virtual ~CircularBuffer ()=default
 Default destructor.
 
void push (const sample &val)
 Pushes an element onto the circular buffer.
 
sample pop ()
 Pops an element from the circular buffer. The buffer should not be empty.
 
void Log () override
 Logs the details of the circular buffer.
 
void reset ()
 Resets the circular buffer. This reduces size to zero.
 
void meanRemoval ()
 Subtracts the mean of the buffer from each element in the buffer.
 
uint32_t getSize ()
 Returns the size of the buffer.
 
void resize (size_t newCapacity)
 Resizes the buffer capacity but also resets the current buffer.
 
sample getShiftedElement (int index)
 Return the element at the given shifted index. (Read Head has index 0, and so on...).
 

Protected Member Functions

void incrementIndex (size_t &index)
 Increments the given index in a circular manner.
 
- Protected Member Functions inherited from AuxPort::ILog
void setColour (const ColourType &colourType)
 This function allows you to set text colour for the text to be printed onto the console.
 

Protected Attributes

std::vector< sample > buffer
 
size_t capacity
 
size_t size
 
size_t readIndex
 
size_t writeIndex
 

Detailed Description

template<class sample>
class AuxPort::CircularBuffer< sample >

Represents a circular buffer data structure.

Definition at line 50 of file AuxCircularBuffer.h.

Constructor & Destructor Documentation

◆ CircularBuffer() [1/4]

template<class sample >
AuxPort::CircularBuffer< sample >::CircularBuffer ( )
inline

Default Constructor.

Definition at line 56 of file AuxCircularBuffer.h.

◆ CircularBuffer() [2/4]

template<class sample >
AuxPort::CircularBuffer< sample >::CircularBuffer ( const size_t & capacity)
inline

Initializes a CircularBuffer Object with the given capacity.

Definition at line 67 of file AuxCircularBuffer.h.

◆ CircularBuffer() [3/4]

template<class sample >
AuxPort::CircularBuffer< sample >::CircularBuffer ( const std::vector< sample > & buffer)
inline

Initializes a CircularBuffer Object using contents of a given vector.

Note
The CircularBuffer will have same size and capacity as the vector.
First element of the given vector will be the first element of the buffer.

Definition at line 80 of file AuxCircularBuffer.h.

◆ CircularBuffer() [4/4]

template<class sample >
AuxPort::CircularBuffer< sample >::CircularBuffer ( const sample * data,
const size_t dataSize )
inline

Initializes a CircularBuffer Object using pointer to an array of elements.

Note
The CircularBuffer will have same size and capacity as the number of elements.
Initial element of the array will be the first element of the buffer.

Definition at line 93 of file AuxCircularBuffer.h.

Member Function Documentation

◆ getShiftedElement()

template<class sample >
sample AuxPort::CircularBuffer< sample >::getShiftedElement ( int index)
inline

Return the element at the given shifted index. (Read Head has index 0, and so on...).

Note
Make Sure that index is less than the number of elements actively in buffer. Otherwise, old elements might be returned from the buffer.
Negative Indexing is also supported.

Definition at line 211 of file AuxCircularBuffer.h.

◆ getSize()

template<class sample >
uint32_t AuxPort::CircularBuffer< sample >::getSize ( )
inline

Returns the size of the buffer.

Definition at line 191 of file AuxCircularBuffer.h.

◆ incrementIndex()

template<class sample >
void AuxPort::CircularBuffer< sample >::incrementIndex ( size_t & index)
inlineprotected

Increments the given index in a circular manner.

Definition at line 226 of file AuxCircularBuffer.h.

◆ Log()

template<class sample >
void AuxPort::CircularBuffer< sample >::Log ( )
inlineoverridevirtual

Logs the details of the circular buffer.

Reimplemented from AuxPort::ILog.

Definition at line 149 of file AuxCircularBuffer.h.

◆ meanRemoval()

template<class sample >
void AuxPort::CircularBuffer< sample >::meanRemoval ( )
inline

Subtracts the mean of the buffer from each element in the buffer.

Definition at line 181 of file AuxCircularBuffer.h.

◆ pop()

template<class sample >
sample AuxPort::CircularBuffer< sample >::pop ( )
inline

Pops an element from the circular buffer. The buffer should not be empty.

Definition at line 137 of file AuxCircularBuffer.h.

◆ push()

template<class sample >
void AuxPort::CircularBuffer< sample >::push ( const sample & val)
inline

Pushes an element onto the circular buffer.

Note
If the buffer is already full, then the oldest element is removed and the new element is inserted.

Definition at line 120 of file AuxCircularBuffer.h.

◆ reset()

template<class sample >
void AuxPort::CircularBuffer< sample >::reset ( )
inline

Resets the circular buffer. This reduces size to zero.

Definition at line 173 of file AuxCircularBuffer.h.

◆ resize()

template<class sample >
void AuxPort::CircularBuffer< sample >::resize ( size_t newCapacity)
inline

Resizes the buffer capacity but also resets the current buffer.

Definition at line 199 of file AuxCircularBuffer.h.

Member Data Documentation

◆ buffer

template<class sample >
std::vector<sample> AuxPort::CircularBuffer< sample >::buffer
protected

Definition at line 217 of file AuxCircularBuffer.h.

◆ capacity

template<class sample >
size_t AuxPort::CircularBuffer< sample >::capacity
protected

Definition at line 218 of file AuxCircularBuffer.h.

◆ readIndex

template<class sample >
size_t AuxPort::CircularBuffer< sample >::readIndex
protected

Definition at line 220 of file AuxCircularBuffer.h.

◆ size

template<class sample >
size_t AuxPort::CircularBuffer< sample >::size
protected

Definition at line 219 of file AuxCircularBuffer.h.

◆ writeIndex

template<class sample >
size_t AuxPort::CircularBuffer< sample >::writeIndex
protected

Definition at line 221 of file AuxCircularBuffer.h.


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