Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Media: checked offset and as_chunks_mut in the stereo interleave (#305 follow-up)

Brandon Thomascae67546dd8d
diff --git a/crates/media/src/pool.rs b/crates/media/src/pool.rs
index e9cf4bc03..8cdb62618 100644
--- a/crates/media/src/pool.rs
+++ b/crates/media/src/pool.rs
@@ -684,9 +684,10 @@ fn read_stereo(src: &SharedSource, path: &str, s0: i64, frames: usize, rate: u32
}
};
let (Some(l), Some(r)) = (buf.channels.first(), buf.channels.get(1).or(buf.channels.first())) else { return out };
- for (o, (a, b)) in out[skip * 2..].chunks_exact_mut(2).zip(l.iter().zip(r)) {
- o[0] = *a;
- o[1] = *b;
+ let Some(dst) = skip.checked_mul(2).and_then(|i| out.get_mut(i..)) else { return out };
+ for ([o0, o1], (a, b)) in dst.as_chunks_mut::<2>().0.iter_mut().zip(l.iter().zip(r)) {
+ *o0 = *a;
+ *o1 = *b;
}
out
}