|
arduino-audio-tools
|
Lock-free Single-Producer Single-Consumer ring buffer. More...
#include <RingBufferSPSC.h>


Public Member Functions | |
| RingBufferSPSC ()=default | |
| RingBufferSPSC (const RingBufferSPSC &)=delete | |
| RingBufferSPSC (size_t capacity) | |
| ~RingBufferSPSC () override=default | |
| 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 | |
| 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 () |
| virtual bool | isFull () |
| checks if the buffer is full | |
| virtual float | levelPercent () |
| Returns the level of the buffer in %. | |
| RingBufferSPSC & | operator= (const RingBufferSPSC &)=delete |
| bool | peek (T &result) override |
| peeks the actual entry from the buffer | |
| bool | read (T &result) override |
| reads a single value | |
| int | readArray (T data[], int len) override |
| reads multiple values | |
| void | reset () override |
| clears the buffer | |
| bool | resize (size_t capacity) override |
| Resizes the buffer if supported: returns false if not supported. | |
| virtual bool | resize (size_t size, int count) |
| Resize the buffer by indicating the size and count (allocated bytes = size * count) | |
| void | setUsePSRAM (bool flag) |
| size_t | size () override |
| bool | write (T data) override |
| write add an entry to the buffer | |
| int | writeArray (const T data[], int len) override |
| Fills the buffer data. | |
| virtual int | writeArrayOverwrite (const T data[], int len) |
| Fills the buffer data and overwrites the oldest data if the buffer is full. | |
Lock-free Single-Producer Single-Consumer ring buffer.
Safe to use from two cores / contexts simultaneously only when there is exactly one writer and exactly one reader — e.g. an ISR or a second core filling the buffer while the main loop drains it (USB audio RX path on RP2040 with core-1 tud_task).
Design ──────
Not suitable for MPMC (multiple producers or consumers); use QueueLockFree for that.
Backing storage is a Vector<T>, using Vector's own default allocator (plain heap - unaffected, existing callers like the I2S/USB audio TX/RX buffers see no change at all). setUsePSRAM(true), called before the first resize(), switches it to an allocator that prefers PSRAM and falls back to the plain heap silently where PSRAM isn't available - useful for a buffer sized to soak up bursty backlogs (see e.g. PacedVideoOutput) where a few hundred KB would be far too much to ask of internal RAM but is a rounding error against multiple MB of PSRAM.
| T | Element type. Works for any trivially-copyable T; the bulk-copy optimisation is most effective for T=uint8_t (audio streams). |
|
default |
|
inlineexplicit |
|
overridedefault |
|
delete |
|
inlineoverridevirtual |
returns the address of the start of the physical read buffer
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
provides the number of entries that are available to read
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
provides the number of entries that are available to write
Implements BaseBuffer< T >.
|
inlinevirtualinherited |
Provides the number of entries that are available to write: -1 does not apply.
Reimplemented in SynchronizedNBufferRTOST< T >, SynchronizedNBufferZephyrT< T >, NBuffer< T >, NBuffer< Frame >, NBuffer< T >, and NBuffer< uint8_t >.
|
inlinevirtualinherited |
Provides the number of entries that are available to read: -1 does not apply.
Reimplemented in SynchronizedNBufferRTOST< T >, SynchronizedNBufferZephyrT< T >, NBuffer< T >, NBuffer< Frame >, NBuffer< T >, and NBuffer< uint8_t >.
|
inlineinherited |
same as reset
Removes the next len entries.
Reimplemented in SingleBuffer< T >, SingleBuffer< float >, SingleBuffer< int16_t >, SingleBuffer< int32_t >, SingleBuffer< stsz_sample_size_t >, SingleBuffer< T >, SingleBuffer< uint32_t >, and SingleBuffer< uint8_t >.
|
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< Frame >, NBuffer< T >, and NBuffer< uint8_t >.
|
inlinevirtualinherited |
Returns the free space of the buffer in %.
|
inlineinherited |
|
inlinevirtualinherited |
checks if the buffer is full
Reimplemented in VariableSpeedRingBufferSimple< T >, VariableSpeedRingBuffer180< T >, VariableSpeedRingBuffer< T >, VariableSpeedRingBuffer< int16_t >, NBuffer< T >, NBuffer< Frame >, NBuffer< T >, NBuffer< uint8_t >, BufferBlocking< T >, BufferRP2040T< T >, BufferRTOS< T >, BufferRTOS< uint8_t >, SynchronizedBuffer< T >, BufferZephyr< T >, SingleBuffer< T >, SingleBuffer< float >, SingleBuffer< int16_t >, SingleBuffer< int32_t >, SingleBuffer< stsz_sample_size_t >, SingleBuffer< T >, SingleBuffer< uint32_t >, SingleBuffer< uint8_t >, RingBuffer< T >, RingBuffer< int16_t >, RingBuffer< Sample >, RingBuffer< T >, RingBuffer< uint16_t >, RingBuffer< uint8_t >, RingBufferFile< File, T >, and DynamicMultiBuffer< T, BufferType >.
|
inlinevirtualinherited |
Returns the level of the buffer in %.
Reimplemented in AdaptiveResamplingBuffer.
|
delete |
|
inlineoverridevirtual |
peeks the actual entry from the buffer
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
reads a single value
Implements BaseBuffer< T >.
reads multiple values
Reimplemented from BaseBuffer< T >.
|
inlineoverridevirtual |
clears the buffer
Implements BaseBuffer< T >.
Resizes the buffer if supported: returns false if not supported.
Reimplemented from BaseBuffer< T >.
|
inlinevirtualinherited |
Resize the buffer by indicating the size and count (allocated bytes = size * count)
Reimplemented in SynchronizedNBufferRTOST< T >, SynchronizedNBufferZephyrT< T >, NBuffer< T >, NBuffer< Frame >, NBuffer< T >, and NBuffer< uint8_t >.
|
inline |
|
inlineoverridevirtual |
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
write add an entry to the buffer
Implements BaseBuffer< T >.
Fills the buffer data.
Reimplemented from BaseBuffer< T >.
|
inlinevirtualinherited |
Fills the buffer data and overwrites the oldest data if the buffer is full.