BackgroundAudio 1.3.3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ROMDataBuffer Class Reference

Special-purpose buffer which never shifts memory and only allows a single written block of data, used for ROM sources. More...

#include <BackgroundAudioBuffers.h>

Public Member Functions

const uint8_t * buffer ()
 Get access to internal buffer pointer (avoiding memcpy)
 
size_t available ()
 Determine number of bytes that can be read.
 
size_t availableForWrite ()
 Determine how much unused space is available in the buffer.
 
constexpr size_t size ()
 Get total size of the statically allocated buffer.
 
size_t write (const uint8_t *data, size_t cnt)
 Copy a pointer to a block of memory into the buffer, replacing any existing data.
 
size_t write0 (size_t cnt)
 0-fill a portion of the buffer, but will fail because there is no buffer here
 
void shiftUp (size_t cnt)
 Invalidate a portion of buffer and shift remaining data up.
 
void flush ()
 Throw away (flush) the input buffer.
 

Detailed Description

Special-purpose buffer which never shifts memory and only allows a single written block of data, used for ROM sources.

Member Function Documentation

◆ available()

size_t ROMDataBuffer::available ( )
inline

Determine number of bytes that can be read.

Returns
Available bytes

◆ availableForWrite()

size_t ROMDataBuffer::availableForWrite ( )
inline

Determine how much unused space is available in the buffer.

Returns
0 because this buffer can never really be written (but write does work)

◆ buffer()

const uint8_t * ROMDataBuffer::buffer ( )
inline

Get access to internal buffer pointer (avoiding memcpy)

Returns
Buffer pointer

◆ shiftUp()

void ROMDataBuffer::shiftUp ( size_t  cnt)
inline

Invalidate a portion of buffer and shift remaining data up.

Decoders need to be able to read an entier frame's worth of raw data from a contiguous memory region. They all operate by using the internal buffer pointer plus an offset, which they track, to avoid having to shift old data out every single frame (i.e. avoiding memcpys). When they have accumulated enough of a virtual shift in their reading, they call shiftUp to actually do the memory copy and invalidate that old portion of the buffer.

Because this is a ROM image, we don't actually have to memcpy and just adjust the internal pointer.

In general decoders want to call this function ad infrequently as possible.

◆ size()

constexpr size_t ROMDataBuffer::size ( )
inlineconstexpr

Get total size of the statically allocated buffer.

Returns
Number of bytes in total

◆ write()

size_t ROMDataBuffer::write ( const uint8_t *  data,
size_t  cnt 
)
inline

Copy a pointer to a block of memory into the buffer, replacing any existing data.

This differs from RawDataBuffer in that no data is actually copied and there is no local buffer. Only the pointer to the ROM data and its size is captured here. The same ROMDataBuffer can have write called multiple times as long as all the existing data is already emptied by the decoder or cleared using flush.

Parameters
[in]dataRaw data bytes
[in]cntNumber of bytes to write
Returns
Number of bytes actually written

◆ write0()

size_t ROMDataBuffer::write0 ( size_t  cnt)
inline

0-fill a portion of the buffer, but will fail because there is no buffer here

Parameters
[in]cntNumber of 0 bytes to write
Returns
0 due to unsupported

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