Essentia  2.1-beta5-dev
PhantomBuffer< T > Class Template Reference

#include <phantombuffer.h>

Inheritance diagram for PhantomBuffer< T >:
MultiRateBuffer< T >

Public Member Functions

 PhantomBuffer (SourceBase *parent, BufferUsage::BufferUsageType type)
 
void setBufferType (BufferUsage::BufferUsageType type)
 
BufferInfo bufferInfo () const
 
void setBufferInfo (const BufferInfo &info)
 
 PhantomBuffer (SourceBase *parent, int size, int phantomSize)
 
 ~PhantomBuffer ()
 
const std::vector< T > & readView (ReaderID id) const
 
std::vector< T > & writeView ()
 
bool acquireForRead (ReaderID id, int requested)
 
bool acquireForWrite (int requested)
 
void releaseForWrite (int released)
 
void releaseForRead (ReaderID id, int released)
 
ReaderID addReader (bool startFromZero=false)
 
void removeReader (ReaderID id)
 
int numberReaders () const
 
void resize (int size, int phantomSize)
 
int totalTokensWritten () const
 
int totalTokensRead (ReaderID id) const
 
const T & lastTokenProduced () const
 
void reset ()
 
- Public Member Functions inherited from MultiRateBuffer< T >
virtual ~MultiRateBuffer ()
 
void readerConsume (ReaderID id, int requested)
 
void readerProduce (ReaderID id, int released)
 
void writerConsume (int requested)
 
void writerProduce (int released)
 

Protected Member Functions

void resetTurns ()
 
void updateReadView (ReaderID id)
 
void updateWriteView ()
 
int availableForRead (ReaderID id) const
 
int availableForWrite (bool contiguous=true) const
 
void relocateReadWindow (ReaderID id)
 
void relocateWriteWindow ()
 

Protected Attributes

SourceBase_parent
 
int _bufferSize
 
int _phantomSize
 
std::vector< T > _buffer
 
Window _writeWindow
 
std::vector< Window_readWindow
 
RogueVector< T > _writeView
 
std::vector< RogueVector< T > > _readView
 
Mutex mutex
 

Detailed Description

template<typename T>
class essentia::streaming::PhantomBuffer< T >

The PhantomBuffer class is an implementation of the MultiRateBuffer interface that has a special zone at its end, called the phantom zone, which is also replicated at the beginning of the buffer, so that we can always guarantee that retrieving any number of samples lower than the phantom size can be done on a contiguous zone in memory.

NB: we can only guarantee that availableFor* returns a least the size of the phantom buffer, not more we have to choose the size of the phantom zone carefully, or make it dynamically resizable

Constructor & Destructor Documentation

◆ PhantomBuffer() [1/2]

PhantomBuffer ( SourceBase parent,
BufferUsage::BufferUsageType  type 
)
inline

◆ PhantomBuffer() [2/2]

PhantomBuffer ( SourceBase parent,
int  size,
int  phantomSize 
)
inline

◆ ~PhantomBuffer()

~PhantomBuffer ( )
inline

Member Function Documentation

◆ acquireForRead()

bool acquireForRead ( ReaderID  id,
int  requested 
)
virtual

This method tries to acquire the requested number of tokens. It returns true on success, or false if there were not enough tokens available.

Implements MultiRateBuffer< T >.

References NOWARN_UNUSED.

◆ acquireForWrite()

bool acquireForWrite ( int  requested)
virtual

This method tries to acquire the requested number of tokens. It returns true on success, or false if there were not enough tokens available.

This method acquires (reserves) the requested number of tokens for the Writer (Source). If not enough tokens were available, it puts the thread to sleep and waits until the freeSpaceAvailable condition has been signalled, or until it times out.

Implements MultiRateBuffer< T >.

References NOWARN_UNUSED.

◆ addReader()

ReaderID addReader ( bool  startFromZero = false)
virtual

Add a new reader and return its ID. The reader will start at the point where the write window is currently located. If startFromZero is true, the reader will then start at t = 0, meaning that a reader that is connected after some tokens are produced will still get those tokens.

Implements MultiRateBuffer< T >.

References Window::begin, and Window::end.

◆ availableForRead()

int availableForRead ( ReaderID  id) const
protectedvirtual

This method computes the maximum number of contiguous tokens that can be acquired by the Reader at this moment. It is computed as the minimum between the theoretical number of tokens available (without the contiguous condition) and the number of contiguous tokens from the place where we are inside the buffer.

Implements MultiRateBuffer< T >.

◆ availableForWrite()

int availableForWrite ( bool  contiguous = true) const
protectedvirtual

This method computes the maximum number of contiguous tokens that can be acquired by the Writer at this moment. It is computed as the minimum between the theoretical number of tokens available (without the contiguous condition) and the number of contiguous tokens from the place where we are inside the buffer.

Implements MultiRateBuffer< T >.

References Window::total().

◆ bufferInfo()

BufferInfo bufferInfo ( ) const
inlinevirtual

◆ lastTokenProduced()

const T& lastTokenProduced ( ) const
inlinevirtual

Implements MultiRateBuffer< T >.

References NOWARN_UNUSED.

◆ numberReaders()

int numberReaders ( ) const
virtual

Implements MultiRateBuffer< T >.

◆ readView()

const std::vector< T > & readView ( ReaderID  id) const
virtual

Implements MultiRateBuffer< T >.

◆ releaseForRead()

void releaseForRead ( ReaderID  id,
int  released 
)
virtual

◆ releaseForWrite()

void releaseForWrite ( int  released)
virtual

◆ relocateReadWindow()

void relocateReadWindow ( ReaderID  id)
protected

◆ relocateWriteWindow()

void relocateWriteWindow ( )
protected

◆ removeReader()

void removeReader ( ReaderID  id)
virtual

Implements MultiRateBuffer< T >.

◆ reset()

void reset ( )
virtual

Implements MultiRateBuffer< T >.

◆ resetTurns()

void resetTurns ( )
inlineprotected

◆ resize()

void resize ( int  size,
int  phantomSize 
)
inlinevirtual

WARNING: do only before starting to use buffer, for initial configuration

Implements MultiRateBuffer< T >.

◆ setBufferInfo()

void setBufferInfo ( const BufferInfo info)
inlinevirtual

◆ setBufferType()

◆ totalTokensRead()

int totalTokensRead ( ReaderID  id) const
inlinevirtual

Implements MultiRateBuffer< T >.

References NOWARN_UNUSED.

◆ totalTokensWritten()

int totalTokensWritten ( ) const
inlinevirtual

Implements MultiRateBuffer< T >.

References NOWARN_UNUSED.

◆ updateReadView()

void updateReadView ( ReaderID  id)
inlineprotected

◆ updateWriteView()

void updateWriteView ( )
inlineprotected

◆ writeView()

std::vector<T>& writeView ( )
inlinevirtual

Implements MultiRateBuffer< T >.

Member Data Documentation

◆ _buffer

std::vector<T> _buffer
protected

◆ _bufferSize

int _bufferSize
protected

◆ _parent

SourceBase* _parent
protected

◆ _phantomSize

int _phantomSize
protected

◆ _readView

std::vector<RogueVector<T> > _readView
protected

◆ _readWindow

std::vector<Window> _readWindow
protected

◆ _writeView

RogueVector<T> _writeView
protected

◆ _writeWindow

Window _writeWindow
protected

◆ mutex

Mutex mutex
mutableprotected

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