Cinder  0.9.1
Public Member Functions | List of all members
cinder::audio::dsp::RingBufferT< T > Class Template Reference

#include <RingBuffer.h>

Public Member Functions

 RingBufferT ()
 
 RingBufferT (size_t count)
 
 RingBufferT (RingBufferT &&other)
 
 ~RingBufferT ()
 
void resize (size_t count)
 
void clear ()
 
size_t getSize () const
 
size_t getAvailableWrite () const
 
size_t getAvailableRead () const
 
bool write (const T *array, size_t count)
 
bool read (T *array, size_t count)
 

Detailed Description

template<typename T>
class cinder::audio::dsp::RingBufferT< T >

Ringbuffer (aka circular buffer) data structure for use in concurrent audio scenarios.

Other than minor modifications, this ringbuffer is a copy of Tim Blechmann's fine work, found as the base structure of boost::lockfree::spsc_queue (ringbuffer_base). Whereas the boost::lockfree data structures are meant for a wide range of applications / archs, this version specifically caters to audio processing.

The implementation remains lock-free and thread-safe within a single write thread / single read thread context.

Note
T must be POD.

Constructor & Destructor Documentation

template<typename T >
cinder::audio::dsp::RingBufferT< T >::RingBufferT ( )

Constructs a RingBufferT with size = 0.

template<typename T >
cinder::audio::dsp::RingBufferT< T >::RingBufferT ( size_t  count)

Constructs a RingBufferT with count maximum elements.

template<typename T >
cinder::audio::dsp::RingBufferT< T >::RingBufferT ( RingBufferT< T > &&  other)
template<typename T >
cinder::audio::dsp::RingBufferT< T >::~RingBufferT ( )

Member Function Documentation

template<typename T >
void cinder::audio::dsp::RingBufferT< T >::resize ( size_t  count)

Resizes the container to contain count maximum elements. Invalidates the internal buffer and resets read / write indices to 0.

Note
Must be synchronized with both read and write threads.
template<typename T >
void cinder::audio::dsp::RingBufferT< T >::clear ( )

Invalidates the internal buffer and resets read / write indices to 0.

Note
Must be synchronized with both read and write threads.
template<typename T >
size_t cinder::audio::dsp::RingBufferT< T >::getSize ( ) const

Returns the maximum number of elements.

template<typename T >
size_t cinder::audio::dsp::RingBufferT< T >::getAvailableWrite ( ) const

Returns the number of elements available for wrtiing.

Note
Only safe to call from the write thread.
template<typename T >
size_t cinder::audio::dsp::RingBufferT< T >::getAvailableRead ( ) const

Returns the number of elements available for wrtiing.

Note
Only safe to call from the read thread.
template<typename T >
bool cinder::audio::dsp::RingBufferT< T >::write ( const T *  array,
size_t  count 
)

Writes count elements into the internal buffer from array.

Returns
true if all elements were successfully written, or false otherwise.
Note
only safe to call from the write thread. TODO: consider renaming this to writeAll / readAll, and having generic read / write that just does as much as it can
template<typename T >
bool cinder::audio::dsp::RingBufferT< T >::read ( T *  array,
size_t  count 
)

Reads count elements from the internal buffer into array.

Returns
true if all elements were successfully read, or false otherwise.
Note
only safe to call from the read thread.

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