Essentia
2.1-beta6-dev
|
#include <phantombuffer.h>
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 |
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
|
inline |
References PhantomBuffer< T >::_parent, and PhantomBuffer< T >::setBufferType().
|
inline |
|
inline |
|
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.
|
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.
|
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.
|
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 >.
|
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().
|
inlinevirtual |
Implements MultiRateBuffer< T >.
References PhantomBuffer< T >::_bufferSize, PhantomBuffer< T >::_phantomSize, BufferInfo::maxContiguousElements, and BufferInfo::size.
|
inlinevirtual |
|
virtual |
Implements MultiRateBuffer< T >.
|
virtual |
Implements MultiRateBuffer< T >.
|
virtual |
Implements MultiRateBuffer< T >.
References Window::begin, Window::end, and NOWARN_UNUSED.
|
virtual |
Implements MultiRateBuffer< T >.
References essentia::fastcopy(), and NOWARN_UNUSED.
|
protected |
References Window::begin, Window::end, and Window::turn.
|
protected |
|
virtual |
Implements MultiRateBuffer< T >.
|
virtual |
Implements MultiRateBuffer< T >.
|
inlineprotected |
|
inlinevirtual |
WARNING: do only before starting to use buffer, for initial configuration
Implements MultiRateBuffer< T >.
References PhantomBuffer< T >::_buffer, PhantomBuffer< T >::_bufferSize, and PhantomBuffer< T >::_phantomSize.
|
inlinevirtual |
Implements MultiRateBuffer< T >.
References PhantomBuffer< T >::_buffer, PhantomBuffer< T >::_bufferSize, PhantomBuffer< T >::_phantomSize, BufferInfo::maxContiguousElements, and BufferInfo::size.
Referenced by PhantomBuffer< T >::setBufferType().
|
inlinevirtual |
Implements MultiRateBuffer< T >.
References essentia::streaming::BufferUsage::forAudioStream, essentia::streaming::BufferUsage::forLargeAudioStream, essentia::streaming::BufferUsage::forMultipleFrames, essentia::streaming::BufferUsage::forSingleFrames, BufferInfo::maxContiguousElements, PhantomBuffer< T >::setBufferInfo(), and BufferInfo::size.
Referenced by PhantomBuffer< T >::PhantomBuffer().
|
inlinevirtual |
Implements MultiRateBuffer< T >.
References PhantomBuffer< T >::_bufferSize, PhantomBuffer< T >::_readWindow, PhantomBuffer< T >::mutex, and NOWARN_UNUSED.
|
inlinevirtual |
Implements MultiRateBuffer< T >.
References PhantomBuffer< T >::_bufferSize, PhantomBuffer< T >::_writeWindow, PhantomBuffer< T >::mutex, NOWARN_UNUSED, and Window::total().
|
inlineprotected |
References RogueVector< T >::setData(), and RogueVector< T >::setSize().
|
inlineprotected |
|
inlinevirtual |
Implements MultiRateBuffer< T >.
References PhantomBuffer< T >::_writeView.
|
protected |
|
protected |
|
protected |
Referenced by PhantomBuffer< T >::lastTokenProduced(), and PhantomBuffer< T >::PhantomBuffer().
|
protected |
|
protected |
|
protected |
Referenced by PhantomBuffer< T >::totalTokensRead().
|
protected |
Referenced by PhantomBuffer< T >::writeView().
|
protected |
Referenced by PhantomBuffer< T >::lastTokenProduced(), and PhantomBuffer< T >::totalTokensWritten().
|
mutableprotected |