Skip to main content

InterpolatedReader

Struct InterpolatedReader 

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

Heap-allocated buffer reader with fractional-position interpolation.

When wrap is true the position wraps modulo len (periodic / wavetable mode). When wrap is false the position clamps at buffer boundaries (sample mode).

Implementations§

Source§

impl<T: Transcendental + Copy> InterpolatedReader<T>

Source

pub fn new(buffer: Vec<T>) -> Self

Create a new reader from a Vec<T>.

The reader starts at position 0 with unit rate and linear interpolation.

Source

pub fn from_boxed(buffer: Box<[T]>) -> Self

Create a new reader from a pre-allocated Box<[T]>.

Source

pub fn len(&self) -> usize

Return the number of samples in the buffer.

Source

pub fn is_empty(&self) -> bool

Returns true if the buffer is empty.

Source

pub fn position(&self) -> f64

Current read position in samples (fractional).

Source

pub fn set_position(&mut self, pos: f64)

Set the read position (in samples).

Source

pub fn rate(&self) -> f64

Playback rate in samples per output sample (1.0 = normal speed).

Source

pub fn set_rate(&mut self, rate: f64)

Set the playback rate.

Source

pub fn is_cubic(&self) -> bool

Returns true if cubic Hermite interpolation is enabled.

Source

pub fn set_cubic(&mut self, cubic: bool)

Enable (true) or disable (false) cubic Hermite interpolation.

Source

pub fn is_wrap(&self) -> bool

Returns true when the read position wraps at buffer boundaries.

Source

pub fn set_wrap(&mut self, wrap: bool)

Enable (true) or disable (false) wrap mode (periodic / wavetable).

Source

pub fn set_buffer(&mut self, buffer: Vec<T>)

Replace the internal buffer and reset the position to 0.

Source

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

Return the internal buffer as an immutable slice.

Source

pub fn read_one(&self) -> T

Read a single sample at the current position without advancing.

Source

pub fn advance(&mut self)

Advance position by self.rate (one sample).

Source

pub fn render_block(&mut self, output: &mut [T])

Read the next block of samples, advancing self.position.

Auto Trait Implementations§

§

impl<T> Freeze for InterpolatedReader<T>

§

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

§

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

§

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

§

impl<T> Unpin for InterpolatedReader<T>

§

impl<T> UnsafeUnpin for InterpolatedReader<T>

§

impl<T> UnwindSafe for InterpolatedReader<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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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