arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BufferBlocking< T > Class Template Reference

Buffer implementation which provides the same blocking, thread-safe semantics as BufferRTOS (ESP32/STM32) and BufferZephyr, for platforms that have no native blocking stream buffer primitive - built on a SpinLock-protected RingBuffer plus a delay(1) polling wait loop. More...

#include <BufferBlocking.h>

Inheritance diagram for BufferBlocking< T >:
BaseBuffer< T >

Public Member Functions

 BufferBlocking (size_t streamBufferSize, size_t xTriggerLevel=1, TickType_t writeMaxWait=UINT32_MAX, TickType_t readMaxWait=UINT32_MAX, Allocator &allocator=DefaultAllocator)
 
T * address () override
 returns the address of the start of the physical read buffer
 
int available () override
 provides the number of entries that are available to read
 
int availableForWrite () override
 provides the number of entries that are available to write
 
virtual int bufferCountEmpty ()
 Provides the number of entries that are available to write: -1 does not apply.
 
virtual int bufferCountFilled ()
 Provides the number of entries that are available to read: -1 does not apply.
 
void clear ()
 same as reset
 
virtual int clearArray (int len)
 Removes the next len entries.
 
virtual void flush ()
 
virtual float freePercent ()
 Returns the free space of the buffer in %.
 
bool isEmpty ()
 
bool isFull () override
 checks if the buffer is full
 
virtual float levelPercent ()
 Returns the level of the buffer in %.
 
 operator bool ()
 
bool peek (T &result) override
 peeks the actual entry from the buffer
 
bool read (T &result) override
 reads a single value
 
int readArray (T data[], int len)
 reads multiple values
 
void reset () override
 clears the buffer
 
bool resize (size_t size)
 Re-Allocates the memory of the ring buffer.
 
virtual bool resize (size_t size, int count)
 Resize the buffer by indicating the size and count (allocated bytes = size * count)
 
void setReadFromISR (bool active)
 
void setReadMaxWait (TickType_t ticks)
 
void setWriteFromISR (bool active)
 
void setWriteMaxWait (TickType_t ticks)
 
size_t size ()
 
bool write (T data) override
 write add an entry to the buffer
 
int writeArray (const T data[], int len)
 Fills the buffer data.
 
virtual int writeArrayOverwrite (const T data[], int len)
 Fills the buffer data and overwrites the oldest data if the buffer is full.
 

Protected Member Functions

bool isTimeLeft (uint32_t start, TickType_t maxWait)
 

Protected Attributes

RingBuffer< T > buffer
 
SpinLock mutex
 
TickType_t readWait = UINT32_MAX
 
TickType_t writeWait = UINT32_MAX
 

Detailed Description

template<typename T>
class audio_tools::BufferBlocking< T >

Buffer implementation which provides the same blocking, thread-safe semantics as BufferRTOS (ESP32/STM32) and BufferZephyr, for platforms that have no native blocking stream buffer primitive - built on a SpinLock-protected RingBuffer plus a delay(1) polling wait loop.

Note
Supported on any platform providing MutexBase, delay() and millis() (e.g. Desktop, RP2040 without FreeRTOS)
Author
Phil Schatzmann
Template Parameters
T

Constructor & Destructor Documentation

◆ BufferBlocking()

template<typename T >
BufferBlocking ( size_t  streamBufferSize,
size_t  xTriggerLevel = 1,
TickType_t  writeMaxWait = UINT32_MAX,
TickType_t  readMaxWait = UINT32_MAX,
Allocator allocator = DefaultAllocator 
)
inline

Member Function Documentation

◆ address()

template<typename T >
T * address ( )
inlineoverridevirtual

returns the address of the start of the physical read buffer

Implements BaseBuffer< T >.

◆ available()

template<typename T >
int available ( )
inlineoverridevirtual

provides the number of entries that are available to read

Implements BaseBuffer< T >.

◆ availableForWrite()

template<typename T >
int availableForWrite ( )
inlineoverridevirtual

provides the number of entries that are available to write

Implements BaseBuffer< T >.

◆ bufferCountEmpty()

virtual int bufferCountEmpty ( )
inlinevirtualinherited

Provides the number of entries that are available to write: -1 does not apply.

Reimplemented in SynchronizedNBufferRTOST< T >, SynchronizedNBufferZephyrT< T >, and NBuffer< T >.

◆ bufferCountFilled()

virtual int bufferCountFilled ( )
inlinevirtualinherited

Provides the number of entries that are available to read: -1 does not apply.

Reimplemented in SynchronizedNBufferRTOST< T >, SynchronizedNBufferZephyrT< T >, and NBuffer< T >.

◆ clear()

void clear ( )
inlineinherited

same as reset

◆ clearArray()

virtual int clearArray ( int  len)
inlinevirtualinherited

Removes the next len entries.

Reimplemented in SingleBuffer< T >.

◆ flush()

virtual void flush ( )
inlinevirtualinherited

Submit any partially-filled write buffer so the reader can access it. Only meaningful for NBuffer-style block pools; no-op for ring buffers.

Reimplemented in NBuffer< T >.

◆ freePercent()

virtual float freePercent ( )
inlinevirtualinherited

Returns the free space of the buffer in %.

◆ isEmpty()

template<typename T >
bool isEmpty ( )
inline

◆ isFull()

template<typename T >
bool isFull ( )
inlineoverridevirtual

checks if the buffer is full

Reimplemented from BaseBuffer< T >.

◆ isTimeLeft()

template<typename T >
bool isTimeLeft ( uint32_t  start,
TickType_t  maxWait 
)
inlineprotected

◆ levelPercent()

virtual float levelPercent ( )
inlinevirtualinherited

Returns the level of the buffer in %.

◆ operator bool()

template<typename T >
operator bool ( )
inline

◆ peek()

template<typename T >
bool peek ( T &  result)
inlineoverridevirtual

peeks the actual entry from the buffer

Implements BaseBuffer< T >.

◆ read()

template<typename T >
bool read ( T &  result)
inlineoverridevirtual

reads a single value

Implements BaseBuffer< T >.

◆ readArray()

template<typename T >
int readArray ( data[],
int  len 
)
inlinevirtual

reads multiple values

Reimplemented from BaseBuffer< T >.

◆ reset()

template<typename T >
void reset ( )
inlineoverridevirtual

clears the buffer

Implements BaseBuffer< T >.

◆ resize() [1/2]

template<typename T >
bool resize ( size_t  size)
inlinevirtual

Re-Allocates the memory of the ring buffer.

Reimplemented from BaseBuffer< T >.

◆ resize() [2/2]

virtual bool resize ( size_t  size,
int  count 
)
inlinevirtualinherited

Resize the buffer by indicating the size and count (allocated bytes = size * count)

Reimplemented in SynchronizedNBufferRTOST< T >, SynchronizedNBufferZephyrT< T >, and NBuffer< T >.

◆ setReadFromISR()

template<typename T >
void setReadFromISR ( bool  active)
inline

◆ setReadMaxWait()

template<typename T >
void setReadMaxWait ( TickType_t  ticks)
inline

◆ setWriteFromISR()

template<typename T >
void setWriteFromISR ( bool  active)
inline

◆ setWriteMaxWait()

template<typename T >
void setWriteMaxWait ( TickType_t  ticks)
inline

◆ size()

template<typename T >
size_t size ( )
inlinevirtual

Implements BaseBuffer< T >.

◆ write()

template<typename T >
bool write ( data)
inlineoverridevirtual

write add an entry to the buffer

Implements BaseBuffer< T >.

◆ writeArray()

template<typename T >
int writeArray ( const T  data[],
int  len 
)
inlinevirtual

Fills the buffer data.

Reimplemented from BaseBuffer< T >.

◆ writeArrayOverwrite()

virtual int writeArrayOverwrite ( const T  data[],
int  len 
)
inlinevirtualinherited

Fills the buffer data and overwrites the oldest data if the buffer is full.

Member Data Documentation

◆ buffer

template<typename T >
RingBuffer<T> buffer
protected

◆ mutex

template<typename T >
SpinLock mutex
protected

◆ readWait

template<typename T >
TickType_t readWait = UINT32_MAX
protected

◆ writeWait

template<typename T >
TickType_t writeWait = UINT32_MAX
protected

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