expression
Calculate audio buffer duration and sample count
Sample rate counts frames per second for an audio stream. Each frame contains one sample per channel. A buffer of 480 stereo frames at 48000 Hz holds 960 scalar samples and spans 10 ms. This duration is not measured end-to-end latency or a guaranteed callback deadline. Real-time callbacks should avoid unpredictable blocking and allocation. Expected result (NOT RUN): samples: 960, duration: 10.0 ms Common mistake: Dividing scalar interleaved sample count by sample rate or equating one buffer duration with total latency. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
duration_ms = frames * 1000 / sample_rateWorking Example
Example Snippetrust
fn main() { let (frames, channels, hz) = (480usize, 2usize, 48000usize); let samples = frames * channels; let ms = frames as f64 * 1000.0 / hz as f64; println!("samples: {samples}, duration: {ms:.1} ms");}