diff --git a/src/buffer.rs b/src/buffer.rs index d008f05d..dac80e21 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -123,3 +123,25 @@ impl<'outer, 'inner> Iterator for Channels<'outer, 'inner> { } impl<'outer, 'inner> ExactSizeIterator for Channels<'outer, 'inner> {} + +impl<'outer, 'inner> Channels<'outer, 'inner> { + /// Access a sample by index. Useful when you would otehrwise iterate over this 'Channels' + /// iterator multiple times. + #[inline] + pub fn get_mut(&mut self, index: usize) -> Option<&mut f32> { + // SAFETY: The channel bound has already been checked + unsafe { + self.buffers + .get_unchecked_mut(self.current_channel) + .get_mut(index) + } + } + + /// The same as [Self::get_mut], but without any bounds checking. + #[inline] + pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut f32 { + self.buffers + .get_unchecked_mut(self.current_channel) + .get_unchecked_mut(index) + } +}