Skip to main content

FloatParamReadF32

Trait FloatParamReadF32 

Source
pub trait FloatParamReadF32 {
    // Required methods
    fn read(&self) -> f32;
    fn read_into(&self, out: &mut [f32]);
    fn read_after(&self, n_samples: usize) -> f32;
    fn current(&self) -> f32;
    fn value(&self) -> f32;
}
Expand description

Precision-routed read accessors for FloatParam at f32.

The plugin prelude (truce::prelude / truce::prelude32) imports this trait via pub use … as _;, so plugin code reads:

use truce::prelude::*;
let gain = self.params.gain.read();   // f32 - no annotation needed

The trait’s methods shadow nothing - FloatParam has no inherent read / value / current, so name resolution picks the one (and only one) trait that’s in scope. Importing prelude64 instead brings FloatParamReadF64 into scope and the same source resolves to f64. Importing both preludes is a compile error (multiple applicable items in scope) - which is the right error for a file that hasn’t committed to a precision.

Required Methods§

Source

fn read(&self) -> f32

Next smoothed value. Call once per sample in process().

Source

fn read_into(&self, out: &mut [f32])

Fill out with the next out.len() smoothed samples; advance the smoother by out.len() (not by the slice’s capacity). One atomic load + one atomic store amortized over the whole slice. The right primitive when chunking process()’s block dynamically:

let mut delay = [0.0_f32; MAX_BLOCK];
while offset < total {
    let n = (total - offset).min(MAX_BLOCK);
    self.params.delay.read_into(&mut delay[..n]);
    // ... consume delay[..n] for n samples ...
    offset += n;
}
Source

fn read_after(&self, n_samples: usize) -> f32

Advance the smoother by n_samples in one call, returning only the final value. Use for block-rate DSP - hard gates, mode switches, anything that needs one smoothed value per audio block. Pass buffer.num_samples() to keep the smoother’s wall-clock convergence time matching the smoother declaration (smooth = "exp(20)" then actually settles in ~20 ms instead of ~20 blocks). One atomic load + one atomic store; the per-sample envelope is skipped.

Source

fn current(&self) -> f32

Current smoothed value without advancing.

Source

fn value(&self) -> f32

Raw target value (post-set_normalized / host automation), not the smoothed output. Use Self::read / Self::current in the DSP loop.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§