pub struct RingBuffer { /* private fields */ }Expand description
Simple ring buffer for audio data Uses monotonic counters (frames_written, frames_consumed) for clean overflow handling.
Implementations§
Source§impl RingBuffer
impl RingBuffer
pub fn new(capacity_frames: usize, channels: usize) -> Self
Sourcepub fn write(&mut self, samples: &[f64]) -> (usize, Option<u64>)
pub fn write(&mut self, samples: &[f64]) -> (usize, Option<u64>)
Write frames to the buffer, returns number of frames written If buffer would overflow, drops the oldest data (ring buffer behavior) Returns (frames_written, overflow_new_consumed) — overflow_new_consumed is the updated frames_consumed value that external read positions must respect.
Sourcepub fn read(&self, start_frame: u64, output: &mut [f64]) -> usize
pub fn read(&self, start_frame: u64, output: &mut [f64]) -> usize
Read frames from the buffer at a given position
Sourcepub fn advance_read_pos(&mut self, frames: u64)
pub fn advance_read_pos(&mut self, frames: u64)
Update consumed position (call after reading)
Sourcepub fn available_frames(&self, read_pos: u64) -> u64
pub fn available_frames(&self, read_pos: u64) -> u64
Get number of frames available for reading from a given position
Sourcepub fn total_written(&self) -> u64
pub fn total_written(&self) -> u64
Get total frames written
Sourcepub fn overflow_count(&self) -> u64
pub fn overflow_count(&self) -> u64
Get overflow count
Auto Trait Implementations§
impl Freeze for RingBuffer
impl RefUnwindSafe for RingBuffer
impl Send for RingBuffer
impl Sync for RingBuffer
impl Unpin for RingBuffer
impl UnsafeUnpin for RingBuffer
impl UnwindSafe for RingBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more