expression
Apply gain and bound normalized audio samples
This model multiplies finite normalized f32 samples by a gain and applies hard clipping at the chosen output range. Hard clipping changes the waveform and may cause audible distortion. It is not a limiter algorithm. Invalid floating-point values require a separate validation policy. No audio is played. Expected result (NOT RUN): [-1.0, 0.0, 0.5, 1.0] Common mistake: Assuming clipping restores the original waveform or increasing gain without managing headroom. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
(sample * gain).clamp(-1.0, 1.0)Working Example
Example Snippetrust
fn main() { let samples = [-0.75f32, 0.0, 0.25, 0.75]; let result = samples.map(|s| (s*2.0).clamp(-1.0,1.0)); println!("{result:?}");}