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: usizeImplementations§
Source§impl ParamBlock
impl ParamBlock
pub fn new() -> ParamBlock
pub fn add(&mut self, value: f32) -> usize
Sourcepub fn get(&self, idx: usize) -> &Param
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
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 }pub fn get_mut(&mut self, idx: usize) -> &mut Param
Sourcepub fn tick_all(&mut self)
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
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
impl Clone for ParamBlock
Source§fn clone(&self) -> ParamBlock
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ParamBlock
impl Debug for ParamBlock
Source§impl Default for ParamBlock
impl Default for ParamBlock
Source§fn default() -> ParamBlock
fn default() -> ParamBlock
Returns the “default value” for a type. Read more
impl Copy for ParamBlock
Auto Trait Implementations§
impl Freeze for ParamBlock
impl RefUnwindSafe for ParamBlock
impl Send for ParamBlock
impl Sync for ParamBlock
impl Unpin for ParamBlock
impl UnsafeUnpin for ParamBlock
impl UnwindSafe for ParamBlock
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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