CircularBuffer

Struct CircularBuffer 

Source
pub struct CircularBuffer { /* private fields */ }
Expand description

A fixed-size circular buffer

  • buffer: The underlying storage for the circular buffer.
  • max_size: The maximum capacity of the buffer.
  • write_index: The position in the buffer where the next chunk will be written.

Implementations§

Source§

impl CircularBuffer

Source

pub fn new(max_size: usize) -> Self

Creates a new circular buffer with a specified maximum size.

§Arguments
  • max_size - The capacity of the buffer (number of elements it can hold).
§Returns

A CircularBuffer instance initialized with zeros.

Source

pub fn add_chunk(&mut self, chunk: &[f32])

Adds a chunk of data to the circular buffer.

If the chunk is larger than the buffer size, only the last max_size elements are stored. If the chunk wraps around the end of the buffer, it is split and written in two parts.

§Arguments
  • chunk - A slice of f32 values to add to the buffer.
Source

pub fn copy_to_buffer(&self, output: &mut [f32])

Copies the current state of the circular buffer into an output slice.

The data is copied in order, starting from the oldest data to the newest.

§Arguments
  • output - A mutable slice where the buffer contents will be copied.
§Panics

Panics if output is not the same length as the circular buffer (max_size).

Source

pub fn get_buffer(&self) -> Vec<f32>

Returns a copy of the current state of the buffer as a vector.

The data is ordered, starting from the oldest to the newest values.

§Returns

A Vec<f32> containing the buffer contents.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,