Expand description
Float and Sample - the precision-routing traits that let
plugin code stay in one float type without per-call-site casts.
Plugin authors don’t usually name these traits directly. They
pick a precision via the prelude (truce::prelude /
truce::prelude32 for f32, truce::prelude64 for f64); the
prelude’s type Sample alias resolves the bound at the call
sites. The traits surface only when DSP code wants to convert
between precisions per value:
use truce_params::sample::Float;
let v_f32: f32 = 0.5;
let v_f64: f64 = v_f32.to_f64(); // widen
let back: f32 = f32::from_f64(v_f64); // narrowBoth traits are sealed at f32 and f64. Downstream code can’t
add new impls; numeric types beyond these two have never been
worth the complexity for audio.
§Two traits, why
Floatis the broad math bound. Use it for utilities likedb_to_linear,midi_note_to_freq- values that happen to bef32orf64but aren’t audio samples. The bound carries the precision-routing methods (from_f32/from_f64/to_f32/to_f64) plus a handful of math primitives (exp,log10,powf).Float::from_f64’s NaN debug-assert is the same asSample’s, because anywhere a NaN narrowing slips through is a bug regardless of whether the value is a sample or a gain coefficient.SampleisFloatplus the marker bounds that buffer code needs (Default + Send + Sync + 'static) so the wrapper can default-construct scratch buffers and pass them across threads. This is the bound that goes onAudioBuffer<S>,Plugin::Sample, and theFloatParamRead<S>extension trait.
Traits§
- Float
- Broad numeric trait for code that operates on
f32orf64but isn’t necessarily handling audio samples. Use this for math utilities (gain conversions, frequency math, filter coefficients). For audio-sample-typed surfaces (AudioBuffer<S>, smoother reads), useSampleinstead, which extendsFloatwith the marker bounds buffer code needs. - Sample
- Audio-sample subtype of
Float. Adds theDefault + Send + Sync + 'staticmarker bounds that buffer code, scratch allocators, and the param-read extension trait need.