Skip to main content

KarplusPluck

Struct KarplusPluck 

Source
pub struct KarplusPluck<const N: usize> { /* private fields */ }
Expand description

A plucked string voice with a fixed-capacity delay line of N samples.

N bounds the lowest playable frequency: at a given sample_rate_hz, frequencies below sample_rate_hz / N clamp to the longest period the buffer can hold. For a 16 kHz engine, N = 512 reaches down to ~31 Hz.

Implementations§

Source§

impl<const N: usize> KarplusPluck<N>

Source

pub const fn new() -> Self

Creates a stopped string voice. Call Self::pluck to start it ringing.

Source

pub fn set_brightness_q8(&mut self, brightness_q8: u8)

Sets the tone’s brightness/decay-speed balance. Lower values sound darker and decay faster.

Source

pub fn set_decay_q8(&mut self, decay_q8: u8)

Sets extra overall feedback loss per pass. 255 lets the string ring until re-plucked; lower values shorten the sustain independently of brightness_q8.

Source

pub fn pluck( &mut self, freq_hz: u32, amplitude: i8, duration_ms: u16, sample_rate_hz: u32, )

Excites the string at freq_hz with a pseudo-random noise burst of amplitude, ringing for duration_ms before auto-stopping (matching crate::synth::ToneVoice’s convention).

Source

pub fn stop(&mut self)

Silences the string immediately.

Source

pub fn is_active(&self) -> bool

Whether the string is still ringing (has not reached duration_ms or been stopped).

Source

pub fn next_sample(&mut self) -> Option<i8>

Advances the string by one sample, returning None once it has stopped.

Trait Implementations§

Source§

impl<const N: usize> Clone for KarplusPluck<N>

Source§

fn clone(&self) -> KarplusPluck<N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for KarplusPluck<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for KarplusPluck<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for KarplusPluck<N>
where [i8; N]: Freeze,

§

impl<const N: usize> RefUnwindSafe for KarplusPluck<N>
where [i8; N]: RefUnwindSafe,

§

impl<const N: usize> Send for KarplusPluck<N>
where [i8; N]: Send,

§

impl<const N: usize> Sync for KarplusPluck<N>
where [i8; N]: Sync,

§

impl<const N: usize> Unpin for KarplusPluck<N>
where [i8; N]: Unpin,

§

impl<const N: usize> UnsafeUnpin for KarplusPluck<N>
where [i8; N]: UnsafeUnpin,

§

impl<const N: usize> UnwindSafe for KarplusPluck<N>
where [i8; N]: 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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.