Skip to main content

TapeLoop

Struct TapeLoop 

Source
pub struct TapeLoop<T> { /* private fields */ }
Expand description

Heap-allocated ring buffer for tape delay — single-threaded.

Unlike DelayLine, TapeLoop does NOT use const generics for its capacity — the buffer is allocated on the heap at runtime. This allows arbitrarily large delay lines (millions of samples) without stack overflow.

§Thread safety

TapeLoop is not thread-safe. It uses plain T, not AtomicCell, because it is only accessed from the single audio thread.

§Example

use rill_core::buffer::TapeLoop;

let mut tape = TapeLoop::<f32>::new(96000).unwrap();
tape.write(0.5);
let sample = tape.read(100);

Implementations§

Source§

impl<T: Transcendental> TapeLoop<T>

Source

pub fn new(capacity: usize) -> Option<Self>

Allocate a new tape loop with the given capacity (in samples).

Source

pub fn capacity(&self) -> usize

Maximum capacity in samples.

Source

pub fn write_pos(&self) -> usize

Current write cursor position.

Source

pub fn write(&mut self, sample: T)

Write a single sample and advance the write cursor.

Source

pub fn read(&self, delay: usize) -> T

Read a sample at delay samples behind the write position.

Source

pub fn read_interpolated(&self, delay: f64) -> T

Read with linear interpolation between samples.

Source

pub fn write_block(&mut self, block: &[T])

Write a full block of samples.

Source

pub fn read_block(&self, delay: usize, output: &mut [T])

Read a full block starting at delay samples behind write position.

Source

pub fn fill(&mut self, value: T)

Fill the entire buffer with a constant value.

Source

pub fn clear(&mut self)

Reset write position and zero the buffer.

Trait Implementations§

Source§

impl<T: Transcendental> Buffer<T> for TapeLoop<T>

Source§

fn len(&self) -> usize

Number of samples in the buffer.
Source§

fn as_slice(&self) -> &[T]

Read-only access to the buffer data.
Source§

fn as_mut_slice(&mut self) -> &mut [T]

Mutable access to the buffer data.
Source§

fn fill(&mut self, value: T)
where T: Copy,

Fill the entire buffer with a value.
Source§

fn copy_from(&mut self, src: &[T])
where T: Copy,

Copy data from a slice. Copies min(src.len(), self.len()) samples.
Source§

fn is_empty(&self) -> bool

Whether the buffer is empty.
Source§

impl<T: Debug> Debug for TapeLoop<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for TapeLoop<T>

§

impl<T> RefUnwindSafe for TapeLoop<T>
where T: RefUnwindSafe,

§

impl<T> Send for TapeLoop<T>
where T: Send,

§

impl<T> Sync for TapeLoop<T>
where T: Sync,

§

impl<T> Unpin for TapeLoop<T>

§

impl<T> UnsafeUnpin for TapeLoop<T>

§

impl<T> UnwindSafe for TapeLoop<T>
where T: UnwindSafe,

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> AsAny for T
where T: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert to &dyn std::any::Any
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert to &mut dyn std::any::Any
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<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> 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.