|
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 | |
| 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 () |
| 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. | |
| 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.
| T | Element type. Works for any trivially-copyable T; the bulk-copy optimisation is most effective for T=uint8_t (audio streams). |
|
default |
|
inlineexplicit |
|
inlineoverride |
|
delete |
returns the address of the start of the physical read buffer
Implements BaseBuffer< T >.
provides the number of entries that are available to read
Implements BaseBuffer< T >.
provides the number of entries that are available to write
Implements BaseBuffer< T >.
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 >.
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 >.
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 >.
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 >.
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 >, 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 >.
Returns the level of the buffer in %.
Reimplemented in AdaptiveResamplingBuffer.
|
delete |
peeks the actual entry from the buffer
Implements BaseBuffer< T >.
reads a single value
Implements BaseBuffer< T >.
reads multiple values
Reimplemented from BaseBuffer< T >.
clears the buffer
Implements BaseBuffer< T >.
Resizes the buffer if supported: returns false if not supported.
Reimplemented from BaseBuffer< T >.
Implements BaseBuffer< T >.
write add an entry to the buffer
Implements BaseBuffer< T >.
Fills the buffer data.
Reimplemented from BaseBuffer< T >.
Fills the buffer data and overwrites the oldest data if the buffer is full.