arduino-audio-tools
Loading...
Searching...
No Matches
SingleBuffer< T > Class Template Referenceabstract

A simple Buffer implementation which just uses a (dynamically sized) array. More...

#include <CodecOpusOgg.h>

Inheritance diagram for SingleBuffer< T >:
BaseBuffer< uint8_t > BaseBuffer< uint8_t >

Public Member Functions

 SingleBuffer ()
 Construct a new Single Buffer w/o allocating any memory.
 SingleBuffer ()
 Construct a new Single Buffer w/o allocating any memory.
 SingleBuffer (const SingleBuffer &)=default
 SingleBuffer (const SingleBuffer &)=default
 SingleBuffer (int size, Allocator &allocator=DefaultAllocator)
 Construct a new Single Buffer object.
 SingleBuffer (int size, Allocator &allocator=DefaultAllocator)
 Construct a new Single Buffer object.
T * address () override
 Provides address to beginning of the buffer.
T * address () override
 Provides address to beginning of the buffer.
int available () override
 provides the number of entries that are available to read
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
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
int clearArray (int len) override
 consumes len bytes and moves current data to the beginning
int clearArray (int len) override
 consumes len bytes and moves current data to the beginning
T * data ()
 Provides address of actual data.
T * data ()
 Provides address of actual data.
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
bool isFull () override
 checks if the buffer is full
virtual float levelPercent ()
 Returns the level of the buffer in %.
void onExternalBufferRefilled (void *data, int len)
 notifies that the external buffer has been refilled
void onExternalBufferRefilled (void *data, int len)
 notifies that the external buffer has been refilled
SingleBuffer & operator= (const SingleBuffer &)=default
SingleBuffer & operator= (const SingleBuffer &)=default
virtual bool peek (uint8_t &result)=0
 peeks the actual entry from the buffer
bool peek (T &result) override
bool peek (T &result) override
int peekArray (uint8_t *data, int len)
int peekArray (uint8_t *data, int len)
virtual bool read (uint8_t &result)=0
 reads a single value
bool read (T &result) override
bool read (T &result) override
virtual int readArray (uint8_t data[], int len)
 reads multiple values
void reset () override
 clears the buffer
void reset () override
 clears the buffer
bool resize (size_t size)
 Resizes the buffer if supported: returns false if not supported.
bool resize (size_t size)
 Resizes the buffer if supported: returns false if not supported.
size_t setAvailable (size_t available_size)
size_t setAvailable (size_t available_size)
void setClearWithZero (bool flag)
 Sets the buffer to 0 on clear.
void setClearWithZero (bool flag)
 Sets the buffer to 0 on clear.
void setWritePos (int pos)
 Updates the actual available data size.
void setWritePos (int pos)
 Updates the actual available data size.
size_t size () override
size_t size () override
void trim ()
 Moves the unprocessed data to the beginning of the buffer.
void trim ()
 Moves the unprocessed data to the beginning of the buffer.
virtual bool write (uint8_t data)=0
 write add an entry to the buffer
bool write (T sample) override
bool write (T sample) override
virtual int writeArray (const uint8_t data[], int len)
 Fills the buffer data.
int writeArray (const T data[], int len) override
int writeArray (const T data[], int len) override
virtual int writeArrayOverwrite (const uint8_t data[], int len)
 Fills the buffer data and overwrites the oldest data if the buffer is full.

Public Attributes

bool active = true
 Optional active/inactive status.
int id = 0
 Optional ID.
uint64_t timestamp = 0
 Optional timestamp.

Protected Attributes

Allocator _allocator
Vector< T > buffer {0, _allocator}
int current_read_pos = 0
int current_write_pos = 0
bool is_clear_with_zero = false
bool owns_buffer = true

Detailed Description

template<typename T = uint8_t>
class audio_tools::audio_tools::SingleBuffer< T >

A simple Buffer implementation which just uses a (dynamically sized) array.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ SingleBuffer() [1/6]

template<typename T = uint8_t>
SingleBuffer ( int size,
Allocator & allocator = DefaultAllocator )
inline

Construct a new Single Buffer object.

Parameters
sizein entries

◆ SingleBuffer() [2/6]

template<typename T = uint8_t>
SingleBuffer ( const SingleBuffer< T > & )
default

◆ SingleBuffer() [3/6]

template<typename T = uint8_t>
SingleBuffer ( )
inline

Construct a new Single Buffer w/o allocating any memory.

◆ SingleBuffer() [4/6]

template<typename T = uint8_t>
SingleBuffer ( int size,
Allocator & allocator = DefaultAllocator )
inline

Construct a new Single Buffer object.

Parameters
sizein entries

◆ SingleBuffer() [5/6]

template<typename T = uint8_t>
SingleBuffer ( const SingleBuffer< T > & )
default

◆ SingleBuffer() [6/6]

template<typename T = uint8_t>
SingleBuffer ( )
inline

Construct a new Single Buffer w/o allocating any memory.

Member Function Documentation

◆ address() [1/2]

template<typename T = uint8_t>
T * address ( )
inlineoverridevirtual

Provides address to beginning of the buffer.

Implements BaseBuffer< uint8_t >.

◆ address() [2/2]

template<typename T = uint8_t>
T * address ( )
inlineoverridevirtual

Provides address to beginning of the buffer.

Implements BaseBuffer< uint8_t >.

◆ available() [1/2]

template<typename T = uint8_t>
int available ( )
inlineoverridevirtual

provides the number of entries that are available to read

Implements BaseBuffer< uint8_t >.

◆ available() [2/2]

template<typename T = uint8_t>
int available ( )
inlineoverridevirtual

provides the number of entries that are available to read

Implements BaseBuffer< uint8_t >.

◆ availableForWrite() [1/2]

template<typename T = uint8_t>
int availableForWrite ( )
inlineoverridevirtual

provides the number of entries that are available to write

Implements BaseBuffer< uint8_t >.

◆ availableForWrite() [2/2]

template<typename T = uint8_t>
int availableForWrite ( )
inlineoverridevirtual

provides the number of entries that are available to write

Implements BaseBuffer< uint8_t >.

◆ bufferCountEmpty()

virtual int bufferCountEmpty ( )
inlinevirtualinherited

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

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

◆ bufferCountFilled()

virtual int bufferCountFilled ( )
inlinevirtualinherited

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

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

◆ clear()

void clear ( )
inlineinherited

same as reset

◆ clearArray() [1/2]

template<typename T = uint8_t>
int clearArray ( int len)
inlineoverridevirtual

consumes len bytes and moves current data to the beginning

Reimplemented from BaseBuffer< uint8_t >.

◆ clearArray() [2/2]

template<typename T = uint8_t>
int clearArray ( int len)
inlineoverridevirtual

consumes len bytes and moves current data to the beginning

Reimplemented from BaseBuffer< uint8_t >.

◆ data() [1/2]

template<typename T = uint8_t>
T * data ( )
inline

Provides address of actual data.

◆ data() [2/2]

template<typename T = uint8_t>
T * data ( )
inline

Provides address of actual data.

◆ 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 >, NBuffer< T >, NBuffer< uint8_t >, and NBuffer< T >.

◆ freePercent()

virtual float freePercent ( )
inlinevirtualinherited

Returns the free space of the buffer in %.

◆ isEmpty()

bool isEmpty ( )
inlineinherited

◆ isFull() [1/2]

template<typename T = uint8_t>
bool isFull ( )
inlineoverridevirtual

checks if the buffer is full

Reimplemented from BaseBuffer< uint8_t >.

◆ isFull() [2/2]

template<typename T = uint8_t>
bool isFull ( )
inlineoverridevirtual

checks if the buffer is full

Reimplemented from BaseBuffer< uint8_t >.

◆ levelPercent()

virtual float levelPercent ( )
inlinevirtualinherited

Returns the level of the buffer in %.

Reimplemented in AdaptiveResamplingBuffer.

◆ onExternalBufferRefilled() [1/2]

template<typename T = uint8_t>
void onExternalBufferRefilled ( void * data,
int len )
inline

notifies that the external buffer has been refilled

◆ onExternalBufferRefilled() [2/2]

template<typename T = uint8_t>
void onExternalBufferRefilled ( void * data,
int len )
inline

notifies that the external buffer has been refilled

◆ operator=() [1/2]

template<typename T = uint8_t>
SingleBuffer & operator= ( const SingleBuffer< T > & )
default

◆ operator=() [2/2]

template<typename T = uint8_t>
SingleBuffer & operator= ( const SingleBuffer< T > & )
default

◆ peek() [1/3]

virtual bool peek ( uint8_t & result)
pure virtualinherited

◆ peek() [2/3]

template<typename T = uint8_t>
bool peek ( T & result)
inlineoverride

◆ peek() [3/3]

template<typename T = uint8_t>
bool peek ( T & result)
inlineoverride

◆ peekArray() [1/2]

template<typename T = uint8_t>
int peekArray ( uint8_t * data,
int len )
inline

◆ peekArray() [2/2]

template<typename T = uint8_t>
int peekArray ( uint8_t * data,
int len )
inline

◆ read() [1/3]

virtual bool read ( uint8_t & result)
pure virtualinherited

◆ read() [2/3]

template<typename T = uint8_t>
bool read ( T & result)
inlineoverride

◆ read() [3/3]

template<typename T = uint8_t>
bool read ( T & result)
inlineoverride

◆ readArray()

virtual int readArray ( uint8_t data[],
int len )
inlinevirtualinherited

◆ reset() [1/2]

template<typename T = uint8_t>
void reset ( )
inlineoverridevirtual

clears the buffer

Implements BaseBuffer< uint8_t >.

◆ reset() [2/2]

template<typename T = uint8_t>
void reset ( )
inlineoverridevirtual

clears the buffer

Implements BaseBuffer< uint8_t >.

◆ resize() [1/2]

template<typename T = uint8_t>
bool resize ( size_t bytes)
inlinevirtual

Resizes the buffer if supported: returns false if not supported.

Reimplemented from BaseBuffer< uint8_t >.

◆ resize() [2/2]

template<typename T = uint8_t>
bool resize ( size_t bytes)
inlinevirtual

Resizes the buffer if supported: returns false if not supported.

Reimplemented from BaseBuffer< uint8_t >.

◆ setAvailable() [1/2]

template<typename T = uint8_t>
size_t setAvailable ( size_t available_size)
inline

If we load values directly into the address we need to set the avialeble size

◆ setAvailable() [2/2]

template<typename T = uint8_t>
size_t setAvailable ( size_t available_size)
inline

If we load values directly into the address we need to set the avialeble size

◆ setClearWithZero() [1/2]

template<typename T = uint8_t>
void setClearWithZero ( bool flag)
inline

Sets the buffer to 0 on clear.

◆ setClearWithZero() [2/2]

template<typename T = uint8_t>
void setClearWithZero ( bool flag)
inline

Sets the buffer to 0 on clear.

◆ setWritePos() [1/2]

template<typename T = uint8_t>
void setWritePos ( int pos)
inline

Updates the actual available data size.

◆ setWritePos() [2/2]

template<typename T = uint8_t>
void setWritePos ( int pos)
inline

Updates the actual available data size.

◆ size() [1/2]

template<typename T = uint8_t>
size_t size ( )
inlineoverridevirtual

Implements BaseBuffer< uint8_t >.

◆ size() [2/2]

template<typename T = uint8_t>
size_t size ( )
inlineoverridevirtual

Implements BaseBuffer< uint8_t >.

◆ trim() [1/2]

template<typename T = uint8_t>
void trim ( )
inline

Moves the unprocessed data to the beginning of the buffer.

◆ trim() [2/2]

template<typename T = uint8_t>
void trim ( )
inline

Moves the unprocessed data to the beginning of the buffer.

◆ write() [1/3]

virtual bool write ( uint8_t data)
pure virtualinherited

◆ write() [2/3]

template<typename T = uint8_t>
bool write ( T sample)
inlineoverride

◆ write() [3/3]

template<typename T = uint8_t>
bool write ( T sample)
inlineoverride

◆ writeArray() [1/3]

virtual int writeArray ( const uint8_t data[],
int len )
inlinevirtualinherited

◆ writeArray() [2/3]

template<typename T = uint8_t>
int writeArray ( const T data[],
int len )
inlineoverride

◆ writeArray() [3/3]

template<typename T = uint8_t>
int writeArray ( const T data[],
int len )
inlineoverride

◆ writeArrayOverwrite()

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

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

Member Data Documentation

◆ _allocator

template<typename T = uint8_t>
Allocator _allocator
protected

◆ active

template<typename T = uint8_t>
bool active = true

Optional active/inactive status.

◆ buffer

template<typename T = uint8_t>
Vector< T > buffer {0, _allocator}
protected

◆ current_read_pos

template<typename T = uint8_t>
int current_read_pos = 0
protected

◆ current_write_pos

template<typename T = uint8_t>
int current_write_pos = 0
protected

◆ id

template<typename T = uint8_t>
int id = 0

Optional ID.

◆ is_clear_with_zero

template<typename T = uint8_t>
bool is_clear_with_zero = false
protected

◆ owns_buffer

template<typename T = uint8_t>
bool owns_buffer = true
protected

◆ timestamp

template<typename T = uint8_t>
uint64_t timestamp = 0

Optional timestamp.


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