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
Generator | Meaning for SamplePlayer |
|---|---|
frequency | Pitch: rate = freq * len / sample_rate |
phase | Normalised position (0 = start, 1 = end of buffer) |
amplitude | Output gain |
Implementations§
Source§impl<T: Transcendental> SamplePlayer<T>
impl<T: Transcendental> SamplePlayer<T>
Sourcepub fn from_boxed(buffer: Box<[T]>) -> Self
pub fn from_boxed(buffer: Box<[T]>) -> Self
Create a new SamplePlayer from a pre-allocated boxed slice.
Sourcepub fn set_loop_mode(&mut self, mode: LoopMode)
pub fn set_loop_mode(&mut self, mode: LoopMode)
Set the loop behaviour.
Sourcepub fn loop_start(&self) -> f64
pub fn loop_start(&self) -> f64
Loop start position in samples.
Sourcepub fn set_loop_start(&mut self, start: f64)
pub fn set_loop_start(&mut self, start: f64)
Set the loop start position.
Sourcepub fn set_loop_end(&mut self, end: f64)
pub fn set_loop_end(&mut self, end: f64)
Set the loop end position.
Sourcepub fn set_gate(&mut self, gate: bool)
pub fn set_gate(&mut self, gate: bool)
Start / stop playback.
Setting gate = true restarts from the beginning.
Sourcepub fn play_state(&self) -> PlayState
pub fn play_state(&self) -> PlayState
Current playback state (stopped or playing).
Sourcepub fn set_buffer(&mut self, buffer: Vec<T>)
pub fn set_buffer(&mut self, buffer: Vec<T>)
Replace the sample buffer and reset to loop-start.
Sourcepub fn set_cubic(&mut self, cubic: bool)
pub fn set_cubic(&mut self, cubic: bool)
Enable (true) or disable (false) cubic Hermite interpolation.
Sourcepub fn set_playback_rate(&mut self, rate: f64)
pub fn set_playback_rate(&mut self, rate: f64)
Set the playback rate in samples per output sample.
Sourcepub fn playback_rate(&self) -> f64
pub fn playback_rate(&self) -> f64
Current playback rate.
Trait Implementations§
Source§impl<T: Transcendental> Algorithm<T> for SamplePlayer<T>
impl<T: Transcendental> Algorithm<T> for SamplePlayer<T>
Source§fn process(
&mut self,
_input: Option<&[T]>,
output: &mut [T],
) -> ProcessResult<()>
fn process( &mut self, _input: Option<&[T]>, output: &mut [T], ) -> ProcessResult<()>
Process one block of signal. Read more
Source§fn metadata(&self) -> AlgorithmMetadata
fn metadata(&self) -> AlgorithmMetadata
Descriptive metadata (defaults to empty).
Source§fn apply_command(&mut self, _value: T)
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>
impl<T: Transcendental + Copy> Generator<T> for SamplePlayer<T>
Source§fn reset_phase(&mut self)
fn reset_phase(&mut self)
Reset phase to 0
Source§fn set_frequency(&mut self, freq: f32)
fn set_frequency(&mut self, freq: f32)
Set frequency
Source§fn set_amplitude(&mut self, amp: T)
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more