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

Source

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

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn loop_mode(&self) -> LoopMode

Source

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

Source

pub fn loop_start(&self) -> f64

Source

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

Source

pub fn loop_end(&self) -> f64

Source

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

Source

pub fn gate(&self) -> bool

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

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)

Source

pub fn is_cubic(&self) -> bool

Source

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

Source

pub fn playback_rate(&self) -> f64

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], _ctx: &ActionContext<'_>, ) -> ProcessResult<()>

Process one block of audio. 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

Получить текущую фазу (0.0 - 1.0)
Source§

fn set_phase(&mut self, phase: T)

Установить фазу
Source§

fn reset_phase(&mut self)

Сбросить фазу в 0
Source§

fn frequency(&self) -> f32

Получить частоту в Hz
Source§

fn set_frequency(&mut self, freq: f32)

Установить частоту
Source§

fn amplitude(&self) -> T

Получить амплитуду
Source§

fn set_amplitude(&mut self, amp: T)

Установить амплитуду

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<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.