Skip to main content

ParamBlock

Struct ParamBlock 

Source
pub struct ParamBlock {
    pub params: [Param; 8],
    pub count: usize,
}
Expand description

A fixed-size block of parameters for a node. Sized to fit common DSP nodes without heap allocation.

Fields§

§params: [Param; 8]§count: usize

Implementations§

Source§

impl ParamBlock

Source

pub fn new() -> ParamBlock

Source

pub fn add(&mut self, value: f32) -> usize

Source

pub fn get(&self, idx: usize) -> &Param

Examples found in repository?
examples/simple_gain.rs (line 33)
22    fn process(
23        &mut self,
24        inputs: &NodeInputs,
25        output: &mut NodeOutput,
26        params: &mut ParamBlock,
27        _sample_rate: f32,
28    ) {
29        // Get input buffer (or silence if not connected)
30        let input = inputs.get(0);
31
32        // Get current gain value (smoothed automatically)
33        let gain = params.get(0).current;
34
35        // Process each sample
36        for (i, out) in output.iter_mut().enumerate() {
37            *out = input[i] * gain;
38            params.tick_all(); // Advance parameter smoothing
39        }
40    }
More examples
Hide additional examples
examples/tremolo.rs (line 28)
19    fn process(
20        &mut self,
21        inputs: &NodeInputs,
22        output: &mut NodeOutput,
23        params: &mut ParamBlock,
24        sample_rate: f32,
25    ) {
26        let input = inputs.get(0);
27        for (i, out) in output.iter_mut().enumerate() {
28            let rate  = params.get(0).current;
29            let depth = params.get(1).current;
30            // LFO: 1.0 at phase=0, dips to (1-depth) at phase=0.5
31            let lfo = 1.0 - depth * 0.5 * (1.0 - (self.phase * std::f32::consts::TAU).cos());
32            *out = input[i] * lfo;
33            self.phase = (self.phase + rate / sample_rate).fract();
34            params.tick_all();
35        }
36    }
examples/bitcrusher.rs (line 28)
19    fn process(
20        &mut self,
21        inputs: &NodeInputs,
22        output: &mut NodeOutput,
23        params: &mut ParamBlock,
24        _sample_rate: f32,
25    ) {
26        let input = inputs.get(0);
27        for (i, out) in output.iter_mut().enumerate() {
28            let bits  = params.get(0).current.clamp(1.0, 16.0);
29            let crush = params.get(1).current.clamp(1.0, 32.0);
30
31            // Sample-rate reduction
32            self.counter += 1.0;
33            if self.counter >= crush {
34                self.counter = 0.0;
35                // Bit quantization
36                let levels = (2.0f32).powf(bits);
37                self.held_sample = (input[i] * levels).round() / levels;
38            }
39            *out = self.held_sample;
40            params.tick_all();
41        }
42    }
Source

pub fn get_mut(&mut self, idx: usize) -> &mut Param

Source

pub fn tick_all(&mut self)

Tick all active params by one sample.

Examples found in repository?
examples/simple_gain.rs (line 38)
22    fn process(
23        &mut self,
24        inputs: &NodeInputs,
25        output: &mut NodeOutput,
26        params: &mut ParamBlock,
27        _sample_rate: f32,
28    ) {
29        // Get input buffer (or silence if not connected)
30        let input = inputs.get(0);
31
32        // Get current gain value (smoothed automatically)
33        let gain = params.get(0).current;
34
35        // Process each sample
36        for (i, out) in output.iter_mut().enumerate() {
37            *out = input[i] * gain;
38            params.tick_all(); // Advance parameter smoothing
39        }
40    }
More examples
Hide additional examples
examples/tremolo.rs (line 34)
19    fn process(
20        &mut self,
21        inputs: &NodeInputs,
22        output: &mut NodeOutput,
23        params: &mut ParamBlock,
24        sample_rate: f32,
25    ) {
26        let input = inputs.get(0);
27        for (i, out) in output.iter_mut().enumerate() {
28            let rate  = params.get(0).current;
29            let depth = params.get(1).current;
30            // LFO: 1.0 at phase=0, dips to (1-depth) at phase=0.5
31            let lfo = 1.0 - depth * 0.5 * (1.0 - (self.phase * std::f32::consts::TAU).cos());
32            *out = input[i] * lfo;
33            self.phase = (self.phase + rate / sample_rate).fract();
34            params.tick_all();
35        }
36    }
examples/bitcrusher.rs (line 40)
19    fn process(
20        &mut self,
21        inputs: &NodeInputs,
22        output: &mut NodeOutput,
23        params: &mut ParamBlock,
24        _sample_rate: f32,
25    ) {
26        let input = inputs.get(0);
27        for (i, out) in output.iter_mut().enumerate() {
28            let bits  = params.get(0).current.clamp(1.0, 16.0);
29            let crush = params.get(1).current.clamp(1.0, 32.0);
30
31            // Sample-rate reduction
32            self.counter += 1.0;
33            if self.counter >= crush {
34                self.counter = 0.0;
35                // Bit quantization
36                let levels = (2.0f32).powf(bits);
37                self.held_sample = (input[i] * levels).round() / levels;
38            }
39            *out = self.held_sample;
40            params.tick_all();
41        }
42    }

Trait Implementations§

Source§

impl Clone for ParamBlock

Source§

fn clone(&self) -> ParamBlock

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 Debug for ParamBlock

Source§

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

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

impl Default for ParamBlock

Source§

fn default() -> ParamBlock

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

impl Copy for ParamBlock

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.