Skip to main content

SamplePlayer

Struct SamplePlayer 

Source
pub struct SamplePlayer<T: Transcendental> { /* private fields */ }
Expand description

Sample-playback algorithm built on InterpolatedReader.

Plays back a fixed buffer with variable rate, interpolation, and configurable looping. Implements Algorithm for use in signal graphs, and Generator for compatibility with the oscillator trait hierarchy.

§Generator parameter mapping

GeneratorMeaning for SamplePlayer
frequencyPitch: rate = freq * len / sample_rate
phaseNormalised position (0 = start, 1 = end of buffer)
amplitudeOutput gain

Implementations§

Source§

impl<T: Transcendental> SamplePlayer<T>

Source

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

Create a new SamplePlayer from a sample buffer.

Source

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

Create a new SamplePlayer from a pre-allocated boxed slice.

Source

pub fn len(&self) -> usize

Number of samples in the buffer.

Source

pub fn is_empty(&self) -> bool

Returns true if the buffer is empty.

Source

pub fn loop_mode(&self) -> LoopMode

Current loop mode.

Source

pub fn set_loop_mode(&mut self, mode: LoopMode)

Set the loop behaviour.

Source

pub fn loop_start(&self) -> f64

Loop start position in samples.

Source

pub fn set_loop_start(&mut self, start: f64)

Set the loop start position.

Source

pub fn loop_end(&self) -> f64

Loop end position in samples.

Source

pub fn set_loop_end(&mut self, end: f64)

Set the loop end position.

Source

pub fn gate(&self) -> bool

Whether the player is gated (playing).

Source

pub fn set_gate(&mut self, gate: bool)

Start / stop playback.

Setting gate = true restarts from the beginning.

Source

pub fn play_state(&self) -> PlayState

Current playback state (stopped or playing).

Source

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

Replace the sample buffer and reset to loop-start.

Source

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

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

Source

pub fn is_cubic(&self) -> bool

Returns true if cubic interpolation is enabled.

Source

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

Set the playback rate in samples per output sample.

Source

pub fn playback_rate(&self) -> f64

Current playback rate.

Trait Implementations§

Source§

impl<T: Transcendental> Algorithm<T> for SamplePlayer<T>

Source§

fn init(&mut self, sample_rate: f32)

Initialise the algorithm with a sample rate. Read more
Source§

fn reset(&mut self)

Reset the algorithm to its initial state. Read more
Source§

fn process( &mut self, _input: Option<&[T]>, output: &mut [T], ) -> ProcessResult<()>

Process one block of signal. Read more
Source§

fn metadata(&self) -> AlgorithmMetadata

Descriptive metadata (defaults to empty).
Source§

fn apply_command(&mut self, _value: T)

Receive a real-time command value from the control path. Read more
Source§

impl<T: Transcendental + Copy> Generator<T> for SamplePlayer<T>

Source§

fn phase(&self) -> T

Get current phase (0.0 - 1.0)
Source§

fn set_phase(&mut self, phase: T)

Set phase
Source§

fn reset_phase(&mut self)

Reset phase to 0
Source§

fn frequency(&self) -> f32

Get frequency in Hz
Source§

fn set_frequency(&mut self, freq: f32)

Set frequency
Source§

fn amplitude(&self) -> T

Get amplitude
Source§

fn set_amplitude(&mut self, amp: T)

Set amplitude

Auto Trait Implementations§

§

impl<T> Freeze for SamplePlayer<T>
where T: Freeze,

§

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

§

impl<T> Send for SamplePlayer<T>

§

impl<T> Sync for SamplePlayer<T>

§

impl<T> Unpin for SamplePlayer<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for SamplePlayer<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for SamplePlayer<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