Add accessors for channel data
This is needed when you want to modify the same sample multiple times within an outer loop.
This commit is contained in:
parent
e3d445cea6
commit
693b618bc5
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue