pub struct ParamBlock {
pub params: [Param; 8],
pub count: usize,
}Expand description
A fixed-size block of parameters for a node.
Stores up to 8 parameters without heap allocation. Most DSP nodes need 1-4 parameters (gain, frequency, resonance, etc.), so 8 is sufficient for the vast majority of cases.
§Example
use aether_core::param::ParamBlock;
let mut params = ParamBlock::new();
// Add parameters
let gain_idx = params.add(0.75); // Gain: 0.75
let cutoff_idx = params.add(1000.0); // Cutoff: 1000 Hz
let res_idx = params.add(0.5); // Resonance: 0.5
assert_eq!(params.count, 3);
// Access parameters
let gain = params.get(gain_idx);
assert_eq!(gain.current, 0.75);
// Modify parameters
params.get_mut(cutoff_idx).set_target(2000.0, 480);
// Tick all parameters
params.tick_all();§Capacity
If you need more than 8 parameters, consider:
- Splitting into multiple nodes
- Using a custom parameter storage system
- Increasing the array size (requires modifying the constant)
§See Also
Param- Individual parameter
Fields§
§params: [Param; 8]§count: usizeImplementations§
Source§impl ParamBlock
impl ParamBlock
Sourcepub fn add(&mut self, value: f32) -> usize
pub fn add(&mut self, value: f32) -> usize
Adds a parameter with the given initial value.
§Arguments
value- Initial parameter value
§Returns
The parameter’s index (0-7), used to access it later.
§Panics
Panics if the block is full (8 parameters already added).
§Example
use aether_core::param::ParamBlock;
let mut params = ParamBlock::new();
let gain_idx = params.add(0.5);
let freq_idx = params.add(440.0);
assert_eq!(gain_idx, 0);
assert_eq!(freq_idx, 1);
assert_eq!(params.count, 2);Sourcepub fn get(&self, idx: usize) -> &Param
pub fn get(&self, idx: usize) -> &Param
Gets an immutable reference to a parameter.
§Arguments
idx- Parameter index (0-7)
§Returns
Reference to the parameter.
§Panics
Panics if idx is out of bounds.
§Example
use aether_core::param::ParamBlock;
let mut params = ParamBlock::new();
let gain_idx = params.add(0.75);
let gain = params.get(gain_idx);
assert_eq!(gain.current, 0.75);Sourcepub fn get_mut(&mut self, idx: usize) -> &mut Param
pub fn get_mut(&mut self, idx: usize) -> &mut Param
Gets a mutable reference to a parameter.
§Arguments
idx- Parameter index (0-7)
§Returns
Mutable reference to the parameter.
§Panics
Panics if idx is out of bounds.
§Example
use aether_core::param::ParamBlock;
let mut params = ParamBlock::new();
let cutoff_idx = params.add(1000.0);
// Schedule a ramp
params.get_mut(cutoff_idx).set_target(2000.0, 480);Sourcepub fn tick_all(&mut self)
pub fn tick_all(&mut self)
Tick all active params by one sample.
Advances all parameters in the block by one sample. Call this once
per sample in your node’s process() function.
§Example
use aether_core::param::ParamBlock;
use aether_core::BUFFER_SIZE;
let mut params = ParamBlock::new();
let gain_idx = params.add(0.0);
params.get_mut(gain_idx).set_target(1.0, BUFFER_SIZE as u32);
// Tick through buffer
for _ in 0..BUFFER_SIZE {
let gain_value = params.get(gain_idx).current;
// Use gain_value for processing...
params.tick_all();
}
assert_eq!(params.get(gain_idx).current, 1.0);§Performance
This function is highly optimized:
- Inlined for zero call overhead
- Only ticks active parameters (count)
- Each tick is branch-free when not ramping
Trait Implementations§
Source§impl Clone for ParamBlock
impl Clone for ParamBlock
Source§fn clone(&self) -> ParamBlock
fn clone(&self) -> ParamBlock
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ParamBlock
impl Debug for ParamBlock
Source§impl Default for ParamBlock
impl Default for ParamBlock
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
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>
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>
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