30template <
size_t bytes>
36 _mtx = portMUX_INITIALIZER_UNLOCKED;
78 inline constexpr size_t size() {
90 inline size_t write(
const uint8_t *data,
size_t cnt) {
92 taskENTER_CRITICAL(&_mtx);
95 mutex_enter_blocking(&_mtx);
97 size_t maxWritable = count - _len;
98 size_t toWrite = std::min(cnt, maxWritable);
99 memcpy(_buff + _len, data, toWrite);
102 taskEXIT_CRITICAL(&_mtx);
118 taskENTER_CRITICAL(&_mtx);
121 mutex_enter_blocking(&_mtx);
123 size_t maxWritable = count - _len;
124 size_t toWrite = std::min(cnt, maxWritable);
125 bzero(_buff + _len, toWrite);
128 taskEXIT_CRITICAL(&_mtx);
150 taskENTER_CRITICAL(&_mtx);
153 mutex_enter_blocking(&_mtx);
156 size_t toShift = _len - cnt;
157 memmove(_buff, _buff + cnt, toShift);
163 taskEXIT_CRITICAL(&_mtx);
178 static const size_t count = bytes;
179 uint8_t _buff[count];
199 _mtx = portMUX_INITIALIZER_UNLOCKED;
241 inline constexpr size_t size() {
259 inline size_t write(
const uint8_t *data,
size_t cnt) {
294 taskENTER_CRITICAL(&_mtx);
297 mutex_enter_blocking(&_mtx);
306 taskEXIT_CRITICAL(&_mtx);
321 const uint8_t *_buff;
Special-purpose buffer which never shifts memory and only allows a single written block of data,...
Definition BackgroundAudioBuffers.h:192
void shiftUp(size_t cnt)
Invalidate a portion of buffer and shift remaining data up.
Definition BackgroundAudioBuffers.h:292
size_t availableForWrite()
Determine how much unused space is available in the buffer.
Definition BackgroundAudioBuffers.h:232
size_t write0(size_t cnt)
0-fill a portion of the buffer, but will fail because there is no buffer here
Definition BackgroundAudioBuffers.h:273
constexpr size_t size()
Get total size of the statically allocated buffer.
Definition BackgroundAudioBuffers.h:241
void flush()
Throw away (flush) the input buffer.
Definition BackgroundAudioBuffers.h:316
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.
Definition BackgroundAudioBuffers.h:259
const uint8_t * buffer()
Get access to internal buffer pointer (avoiding memcpy)
Definition BackgroundAudioBuffers.h:214
size_t available()
Determine number of bytes that can be read.
Definition BackgroundAudioBuffers.h:223
Interrupt-safe, multicore-safe biftable buffer for libmad raw data.
Definition BackgroundAudioBuffers.h:31
uint8_t * buffer()
Get access to internal buffer pointer (avoiding memcpy)
Definition BackgroundAudioBuffers.h:51
void flush()
Throw out any data in the buffer.
Definition BackgroundAudioBuffers.h:173
constexpr size_t size()
Get total size of the statically allocated buffer.
Definition BackgroundAudioBuffers.h:78
size_t write(const uint8_t *data, size_t cnt)
Copy a block of memory into the buffer. Will not block.
Definition BackgroundAudioBuffers.h:90
void shiftUp(size_t cnt)
Invalidate a portion of buffer and shift remaining data up.
Definition BackgroundAudioBuffers.h:148
size_t availableForWrite()
Determine how much unused space is available in the buffer.
Definition BackgroundAudioBuffers.h:69
size_t write0(size_t cnt)
0-fill a portion of the buffer
Definition BackgroundAudioBuffers.h:116
size_t available()
Determine number of bytes that can be read.
Definition BackgroundAudioBuffers.h:60