1
0
Fork 0

Add nicer adapter for repeating channel iteration

This commit is contained in:
Robbert van der Helm 2022-02-12 23:16:07 +01:00
parent fb382520af
commit 2c394aabd5
2 changed files with 7 additions and 5 deletions

View file

@ -198,11 +198,7 @@ impl Plugin for Diopser {
for filter_idx in 0..self.params.filter_stages.value as usize { for filter_idx in 0..self.params.filter_stages.value as usize {
// Because of this filter_idx outer loop we can't directly iterate over // Because of this filter_idx outer loop we can't directly iterate over
// `channel_samples` as the iterator would be empty after the first loop // `channel_samples` as the iterator would be empty after the first loop
for (channel_idx, filters) in for (sample, filters) in channel_samples.reset_iter().zip(self.filters.iter_mut()) {
(0..channel_samples.len()).zip(self.filters.iter_mut())
{
// SAFETY: The bounds have already been checked here
let sample = unsafe { channel_samples.get_unchecked_mut(channel_idx) };
*sample = filters[filter_idx].process(*sample); *sample = filters[filter_idx].process(*sample);
} }
} }

View file

@ -125,6 +125,12 @@ impl<'outer, 'inner> Iterator for Channels<'outer, 'inner> {
impl<'outer, 'inner> ExactSizeIterator for Channels<'outer, 'inner> {} impl<'outer, 'inner> ExactSizeIterator for Channels<'outer, 'inner> {}
impl<'outer, 'inner> Channels<'outer, 'inner> { impl<'outer, 'inner> Channels<'outer, 'inner> {
/// A resetting iterator. This lets you iterate over the same channels multiple times.
pub fn reset_iter(&mut self) -> &mut Self {
self.current_channel = 0;
self
}
/// Access a sample by index. Useful when you would otehrwise iterate over this 'Channels' /// Access a sample by index. Useful when you would otehrwise iterate over this 'Channels'
/// iterator multiple times. /// iterator multiple times.
#[inline] #[inline]