pub struct SharedAudioBuffer { /* private fields */ }Expand description
Mutex-protected audio ring buffer with typed sample interface
Wraps an AudioRingBuffer with a spin mutex to support multiple
producers writing interleaved i16 samples.
Implementations§
Sourcepub fn new(capacity_frames: u32, config: AudioConfig) -> Self
pub fn new(capacity_frames: u32, config: AudioConfig) -> Self
Create a new shared audio buffer
§Arguments
capacity_frames- Number of audio frames the buffer can holdconfig- Audio configuration (determines frame size)
Sourcepub fn write_samples(&self, samples: &[i16]) -> usize
pub fn write_samples(&self, samples: &[i16]) -> usize
Write i16 samples into the buffer
Converts the sample slice to bytes and writes into the ring buffer. Returns the number of samples actually written.
Sourcepub fn read_samples(&self, output: &mut [i16]) -> usize
pub fn read_samples(&self, output: &mut [i16]) -> usize
Read i16 samples from the buffer
Reads bytes from the ring buffer and reinterprets as i16 samples. Returns the number of samples actually read.
Sourcepub fn available_read_frames(&self) -> u32
pub fn available_read_frames(&self) -> u32
Number of frames available to read
Sourcepub fn available_write_frames(&self) -> u32
pub fn available_write_frames(&self) -> u32
Number of frames available to write
Sourcepub fn config(&self) -> &AudioConfig
pub fn config(&self) -> &AudioConfig
Get the audio configuration for this buffer