pub struct AudioRingBuffer { /* private fields */ }Expand description
Lock-free single-producer single-consumer ring buffer for audio data
Uses atomic read/write positions to allow concurrent access from one producer and one consumer without locking.
Implementations§
Source§impl AudioRingBuffer
impl AudioRingBuffer
Sourcepub fn new(capacity_frames: u32, frame_size: u16) -> Self
pub fn new(capacity_frames: u32, frame_size: u16) -> Self
Create a new ring buffer with the given capacity in frames
The actual byte capacity is capacity_frames * frame_size.
Sourcepub fn write(&self, data: &[u8]) -> usize
pub fn write(&self, data: &[u8]) -> usize
Write data into the ring buffer
Returns the number of bytes actually written. May be less than
data.len() if the buffer is nearly full.
Sourcepub fn read(&self, output: &mut [u8]) -> usize
pub fn read(&self, output: &mut [u8]) -> usize
Read data from the ring buffer
Returns the number of bytes actually read. May be less than
output.len() if the buffer does not contain enough data.
Sourcepub fn available_read(&self) -> u32
pub fn available_read(&self) -> u32
Number of frames available to read
Sourcepub fn available_write(&self) -> u32
pub fn available_write(&self) -> u32
Number of frames available to write