expression
Mix interleaved stereo frames into mono
An interleaved stereo frame holds two consecutive samples, left then right. Average both channels using finite normalized floating-point values. The average avoids doubling amplitude, but phase cancellation may reduce signal strength; a professional downmix may use different gains. A planar buffer uses separate channel arrays. Expected result (NOT RUN): [0.25, 0.0] Common mistake: Counting individual channel samples as frames or treating a planar buffer as interleaved. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
mono = (left + right) * 0.5Working Example
Example Snippetrust
fn main() { let stereo = [0.5f32, 0.0, -0.5, 0.5]; let frames = stereo.chunks_exact(2); assert!(frames.remainder().is_empty()); let mono: Vec<f32> = frames.map(|f| (f[0]+f[1])*0.5).collect(); println!("{mono:?}");}