arduino-audio-tools
Loading...
Searching...
No Matches
RingBufferFile< File, T > Class Template Reference

An File backed Ring Buffer that we can use to receive streaming audio. We expect an open file as parameter. More...

#include <Buffers.h>

Inheritance diagram for RingBufferFile< File, T >:
BaseBuffer< T >

Classes

struct  OffsetInfo

Public Member Functions

 RingBufferFile (int size)
 RingBufferFile (int size, File &file)
 ~RingBufferFile ()
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
bool begin (File &bufferFile)
 Assigns the p_file to be used.
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 %.
bool peek (T &result) override
 peeks the actual entry from the buffer
int peekArray (T data[], int count)
 gets multiple values w/o removing them
bool read (T &result) override
 Reads a single value from the buffer.
int readArray (T data[], int count) override
 reads multiple values
void reset () override
 clears the buffer
bool resize (size_t size)
 Defines the capacity.
size_t size () override
 Provides the capacity.
bool write (T data) override
 write add a single entry to the buffer
int writeArray (const T data[], int len) override
 Fills the data from the buffer.
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

int file_read (T *result, int count)
 Writes the indicated number of objects.
bool file_seek (int pos)
 Seeks to the given object position.
int file_write (const T *data, int count)
 Reed the indicated number of objects.
OffsetInfo getOffset (int pos, int len)

Protected Attributes

int element_count = 0
int max_size = 0
File * p_file = nullptr
int read_pos = 0
int write_pos = 0

Detailed Description

template<class File, typename T>
class audio_tools::RingBufferFile< File, T >

An File backed Ring Buffer that we can use to receive streaming audio. We expect an open file as parameter.

Template Parameters
Filefile class
Tthe buffered object type

Constructor & Destructor Documentation

◆ RingBufferFile() [1/2]

template<class File, typename T>
RingBufferFile ( int size)
inline

◆ RingBufferFile() [2/2]

template<class File, typename T>
RingBufferFile ( int size,
File & file )
inline

◆ ~RingBufferFile()

template<class File, typename T>
~RingBufferFile ( )
inline

Member Function Documentation

◆ address()

template<class File, typename T>
T * address ( )
inlineoverridevirtual

returns the address of the start of the physical read buffer

Implements BaseBuffer< T >.

◆ available()

template<class File, typename T>
int available ( )
inlineoverridevirtual

provides the number of entries that are available to read

Implements BaseBuffer< T >.

◆ availableForWrite()

template<class File, typename T>
int availableForWrite ( )
inlineoverridevirtual

provides the number of entries that are available to write

Implements BaseBuffer< T >.

◆ begin()

template<class File, typename T>
bool begin ( File & bufferFile)
inline

Assigns the p_file to be used.

◆ bufferCountEmpty()

virtual int bufferCountEmpty ( )
inlinevirtualinherited

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

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

◆ bufferCountFilled()

virtual int bufferCountFilled ( )
inlinevirtualinherited

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

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

◆ clear()

void clear ( )
inlineinherited

same as reset

◆ clearArray()

virtual int clearArray ( int len)
inlinevirtualinherited

Removes the next len entries.

Reimplemented in SingleBuffer< T >.

◆ file_read()

template<class File, typename T>
int file_read ( T * result,
int count )
inlineprotected

Writes the indicated number of objects.

◆ file_seek()

template<class File, typename T>
bool file_seek ( int pos)
inlineprotected

Seeks to the given object position.

◆ file_write()

template<class File, typename T>
int file_write ( const T * data,
int count )
inlineprotected

Reed the indicated number of objects.

◆ 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 %.

◆ getOffset()

template<class File, typename T>
OffsetInfo getOffset ( int pos,
int len )
inlineprotected

Get positons and sizes to handle overflow wrapping to prevent writing past max_size

◆ isEmpty()

template<class File, typename T>
bool isEmpty ( )
inline

◆ isFull()

template<class File, typename T>
bool isFull ( )
inlineoverridevirtual

checks if the buffer is full

Reimplemented from BaseBuffer< T >.

◆ levelPercent()

virtual float levelPercent ( )
inlinevirtualinherited

Returns the level of the buffer in %.

◆ peek()

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

peeks the actual entry from the buffer

Implements BaseBuffer< T >.

◆ peekArray()

template<class File, typename T>
int peekArray ( T data[],
int count )
inline

gets multiple values w/o removing them

◆ read()

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

Reads a single value from the buffer.

Implements BaseBuffer< T >.

◆ readArray()

template<class File, typename T>
int readArray ( T data[],
int count )
inlineoverridevirtual

reads multiple values

Reimplemented from BaseBuffer< T >.

◆ reset()

template<class File, typename T>
void reset ( )
inlineoverridevirtual

clears the buffer

Implements BaseBuffer< T >.

◆ resize()

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

Defines the capacity.

Reimplemented from BaseBuffer< T >.

◆ size()

template<class File, typename T>
size_t size ( )
inlineoverridevirtual

Provides the capacity.

Implements BaseBuffer< T >.

◆ write()

template<class File, typename T>
bool write ( T data)
inlineoverridevirtual

write add a single entry to the buffer

Implements BaseBuffer< T >.

◆ writeArray()

template<class File, typename T>
int writeArray ( const T data[],
int len )
inlineoverridevirtual

Fills the data from the buffer.

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

◆ element_count

template<class File, typename T>
int element_count = 0
protected

◆ max_size

template<class File, typename T>
int max_size = 0
protected

◆ p_file

template<class File, typename T>
File* p_file = nullptr
protected

◆ read_pos

template<class File, typename T>
int read_pos = 0
protected

◆ write_pos

template<class File, typename T>
int write_pos = 0
protected

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