arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
M4AFileSampleSizeBuffer Class Reference

A buffer that reads sample sizes from an M4A file using the M4AAudioFileDemuxer. No RAM is used to store the sample sizes as they are read directly from the file. More...

#include <M4AFileSampleSizeBuffer.h>

Inheritance diagram for M4AFileSampleSizeBuffer:
BaseBuffer< stsz_sample_size_t >

Public Member Functions

 M4AFileSampleSizeBuffer (AudioPlayer &player, ContainerM4A &container, const char *fileExt=".m4a")
 Constructor.
 
void addFileExtension (const char *fileExt)
 Add a file extension to recognize as relevant for this buffer.
 
stsz_sample_size_taddress () override
 Returns a pointer to the buffer's physical address.
 
int available ()
 Returns the number of samples already read (i.e., the current sample index).
 
int availableForWrite () override
 Returns the available space for writing.
 
void clear ()
 same as reset
 
virtual int clearArray (int len)
 Removes the next len entries.
 
bool isEmpty ()
 
virtual bool isFull ()
 checks if the buffer is full
 
virtual float levelPercent ()
 Returns the level of the buffer in %.
 
bool peek (stsz_sample_size_t &result)
 Peek is not supported for this buffer.
 
bool read (stsz_sample_size_t &data) override
 Get the next sample size from the demuxer.
 
virtual int readArray (stsz_sample_size_t data[], int len)
 reads multiple values
 
void reset ()
 clears the buffer
 
virtual bool resize (int bytes)
 Resizes the buffer if supported: returns false if not supported.
 
void setReadBufferSize (size_t size)
 Defines how many samples are buffered with each file read.
 
size_t size () override
 Returns the total number of samples in the file.
 
bool write (stsz_sample_size_t data)
 Write is ignored; sample sizes are read directly from the file.
 
virtual int writeArray (const stsz_sample_size_t data[], int len)
 Fills the buffer data.
 
virtual int writeArrayOverwrite (const stsz_sample_size_t data[], int len)
 Fills the buffer data and overwrites the oldest data if the buffer is full.
 

Protected Member Functions

bool isRelevantFile (const char *name)
 Checks if the given file name matches any of the registered extensions.
 

Static Protected Member Functions

static void onFileChange (Stream *streamPtr, void *reference)
 Static callback for file change events. Updates the file pointer and re-parses the file if relevant.
 

Protected Attributes

M4AAudioFileDemuxer demuxer
 Demuxer used to extract sample sizes.
 
Vector< const char * > fileExtensions
 List of recognized file extensions.
 
ContainerM4Ap_container = nullptr
 
Filep_file = nullptr
 Pointer to the currently open file.
 
AudioPlayerp_player = nullptr
 Pointer to the AudioPlayer instance.
 

Detailed Description

A buffer that reads sample sizes from an M4A file using the M4AAudioFileDemuxer. No RAM is used to store the sample sizes as they are read directly from the file.

This buffer is designed to be used with an AudioPlayer instance for audio sources which are file based only. It provides a read interface that fetches the next sample size directly from the file via the demuxer, avoiding the need to store the entire sample size table in RAM.

Note
This buffer is can not be used for streaming sources; it is intended for the use with file-based playback.
This class registers a setOnStreamChangeCallback() with the player

Constructor & Destructor Documentation

◆ M4AFileSampleSizeBuffer()

M4AFileSampleSizeBuffer ( AudioPlayer player,
ContainerM4A container,
const char *  fileExt = ".m4a" 
)
inline

Constructor.

Parameters
playerReference to the AudioPlayer instance.
fileExtFile extension to recognize as M4A (default ".m4a").

Member Function Documentation

◆ addFileExtension()

void addFileExtension ( const char *  fileExt)
inline

Add a file extension to recognize as relevant for this buffer.

Parameters
fileExtFile extension string (e.g., ".m4a").

◆ address()

stsz_sample_size_t * address ( )
inlineoverridevirtual

Returns a pointer to the buffer's physical address.

Returns
Always nullptr, as this buffer does not have a physical address.

Implements BaseBuffer< stsz_sample_size_t >.

◆ available()

int available ( )
inlinevirtual

Returns the number of samples already read (i.e., the current sample index).

Returns
Number of samples read so far.

Implements BaseBuffer< stsz_sample_size_t >.

◆ availableForWrite()

int availableForWrite ( )
inlineoverridevirtual

Returns the available space for writing.

Returns
Always 0, as this buffer does not support writing. No write buffer available

Implements BaseBuffer< stsz_sample_size_t >.

◆ isRelevantFile()

bool isRelevantFile ( const char *  name)
inlineprotected

Checks if the given file name matches any of the registered extensions.

Parameters
nameFile name to check.
Returns
true if the file is relevant, false otherwise.

◆ onFileChange()

static void onFileChange ( Stream streamPtr,
void *  reference 
)
inlinestaticprotected

Static callback for file change events. Updates the file pointer and re-parses the file if relevant.

Parameters
streamPtrPointer to the new file stream.
referencePointer to the M4AFileSampleSizeBuffer instance.

◆ peek()

bool peek ( stsz_sample_size_t result)
inlinevirtual

Peek is not supported for this buffer.

Parameters
resultReference to store the peeked value (unused).
Returns
Always false. Peeking is not supported.

Implements BaseBuffer< stsz_sample_size_t >.

◆ read()

bool read ( stsz_sample_size_t data)
inlineoverridevirtual

Get the next sample size from the demuxer.

Parameters
dataReference to store the sample size.
Returns
true if successful, false otherwise.

Implements BaseBuffer< stsz_sample_size_t >.

◆ reset()

void reset ( )
inlinevirtual

clears the buffer

Implements BaseBuffer< stsz_sample_size_t >.

◆ setReadBufferSize()

void setReadBufferSize ( size_t  size)
inline

Defines how many samples are buffered with each file read.

Parameters
sizeNumber of bytes to buffer (will be divided by 4 for sample count).

◆ size()

size_t size ( )
inlineoverridevirtual

Returns the total number of samples in the file.

Returns
Total sample count.

Implements BaseBuffer< stsz_sample_size_t >.

◆ write()

bool write ( stsz_sample_size_t  data)
inlinevirtual

Write is ignored; sample sizes are read directly from the file.

Parameters
dataSample size value (ignored).
Returns
Always true. This buffer is read-only.

Implements BaseBuffer< stsz_sample_size_t >.


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