Skip to main content

DelayLine

Struct DelayLine 

Source
pub struct DelayLine<T, const MAX_DELAY: usize>
where T: Transcendental,
{ /* private fields */ }
Expand description

Delay line for audio effects — single-threaded circular buffer.

Provides a circular buffer for implementing delay, reverb, and other time-based effects.

§Thread safety

DelayLine is not thread-safe. It is designed for single-threaded use inside the audio graph. Use PipeBuffer or RingBuffer for cross-thread communication.

Implementations§

Source§

impl<T, const MAX_DELAY: usize> DelayLine<T, MAX_DELAY>
where T: Transcendental,

Source

pub fn new(sample_rate: f32) -> DelayLine<T, MAX_DELAY>

Create a new delay line with the given sample rate.

§Panics

Panics if MAX_DELAY is 0.

Source

pub fn set_delay(&mut self, delay_sec: f32)

Set the delay time in seconds.

Source

pub fn set_delay_samples(&mut self, samples: usize)

Set the delay time in samples.

Source

pub fn delay_samples(&self) -> usize

Current delay in samples.

Source

pub const fn max_delay(&self) -> usize

Maximum possible delay (const generic parameter).

Source

pub fn sample_rate(&self) -> f32

The sample rate used for sec-to-sample conversion.

Source

pub fn write(&mut self, input: T) -> T

Write a sample and return the delayed sample.

Source

pub fn read(&self) -> T

Read the delayed sample without writing.

Source

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

Read sample at arbitrary delay (0 = most recent).

Source

pub fn read_interpolated(&self, delay_frac: f32) -> T

Read with linear interpolation between samples.

Source

pub fn clear(&mut self)

Clear the delay line (fill with zeros).

Source

pub fn write_position(&self) -> usize

Current write cursor position in the circular buffer.

Trait Implementations§

Source§

impl<T, const MAX_DELAY: usize> Buffer<T> for DelayLine<T, MAX_DELAY>
where T: Transcendental,

Source§

fn capacity(&self) -> usize

Maximum number of elements the buffer can hold.
Source§

fn len(&self) -> usize

Current number of elements in the buffer.
Source§

fn is_empty(&self) -> bool

Whether the buffer is empty (len() == 0).
Source§

fn is_full(&self) -> bool

Whether the buffer is full (len() == capacity()).
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)

Fill the entire buffer with a value.
Source§

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

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

fn clear(&mut self)

Remove all items from the buffer.
Source§

fn stats(&self) -> BufferStats

Snapshot of performance statistics.
Source§

fn reset_stats(&mut self)

Reset performance counters (not the data).
Source§

impl<T, const MAX_DELAY: usize> Index<usize> for DelayLine<T, MAX_DELAY>
where T: Transcendental,

Source§

type Output = T

The returned type after indexing.
Source§

fn index( &self, index: usize, ) -> &<DelayLine<T, MAX_DELAY> as Index<usize>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const MAX_DELAY: usize> IndexMut<usize> for DelayLine<T, MAX_DELAY>
where T: Transcendental,

Source§

fn index_mut( &mut self, index: usize, ) -> &mut <DelayLine<T, MAX_DELAY> as Index<usize>>::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<T, const MAX_DELAY: usize> !Freeze for DelayLine<T, MAX_DELAY>

§

impl<T, const MAX_DELAY: usize> RefUnwindSafe for DelayLine<T, MAX_DELAY>
where T: RefUnwindSafe,

§

impl<T, const MAX_DELAY: usize> Send for DelayLine<T, MAX_DELAY>

§

impl<T, const MAX_DELAY: usize> Sync for DelayLine<T, MAX_DELAY>

§

impl<T, const MAX_DELAY: usize> Unpin for DelayLine<T, MAX_DELAY>
where T: Unpin,

§

impl<T, const MAX_DELAY: usize> UnsafeUnpin for DelayLine<T, MAX_DELAY>
where T: UnsafeUnpin,

§

impl<T, const MAX_DELAY: usize> UnwindSafe for DelayLine<T, MAX_DELAY>
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V