From cb2824021bc62a4331d350a6e757dee85c212af4 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 5 Jan 2023 16:10:56 +0100 Subject: [PATCH] Fix buffer adapter size hints for zero channels And the SamplesIter one was simply not correct when yielded by the block iterator. --- src/buffer/blocks.rs | 9 +++++---- src/buffer/samples.rs | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/buffer/blocks.rs b/src/buffer/blocks.rs index 3207231a..16a60ba1 100644 --- a/src/buffer/blocks.rs +++ b/src/buffer/blocks.rs @@ -45,7 +45,7 @@ impl<'slice, 'sample> Iterator for BlocksIter<'slice, 'sample> { #[inline] fn next(&mut self) -> Option { - let buffer_len = unsafe { (*self.buffers)[0].len() }; + let buffer_len = unsafe { (*self.buffers).first().map(|b| b.len()).unwrap_or(0) }; if self.current_block_start < buffer_len { let current_block_start = self.current_block_start; let current_block_end = @@ -67,9 +67,9 @@ impl<'slice, 'sample> Iterator for BlocksIter<'slice, 'sample> { #[inline] fn size_hint(&self) -> (usize, Option) { - let remaining = ((unsafe { (*self.buffers)[0].len() } - self.current_block_start) as f32 - / self.max_block_size as f32) - .ceil() as usize; + let buffer_len = unsafe { (*self.buffers).first().map(|b| b.len()).unwrap_or(0) }; + let remaining = (buffer_len as f32 / self.max_block_size as f32).ceil() as usize; + (remaining, Some(remaining)) } } @@ -116,6 +116,7 @@ impl<'slice, 'sample> Iterator for BlockChannelsIter<'slice, 'sample> { #[inline] fn size_hint(&self) -> (usize, Option) { let remaining = unsafe { (*self.buffers).len() } - self.current_channel; + (remaining, Some(remaining)) } } diff --git a/src/buffer/samples.rs b/src/buffer/samples.rs index 417c417f..f20cc627 100644 --- a/src/buffer/samples.rs +++ b/src/buffer/samples.rs @@ -61,7 +61,8 @@ impl<'slice, 'sample> Iterator for SamplesIter<'slice, 'sample> { #[inline] fn size_hint(&self) -> (usize, Option) { - let remaining = unsafe { (*self.buffers)[0].len() } - self.current_sample; + let remaining = self.samples_end - self.current_sample; + (remaining, Some(remaining)) } } @@ -107,6 +108,7 @@ impl<'slice, 'sample> Iterator for ChannelSamplesIter<'slice, 'sample> { #[inline] fn size_hint(&self) -> (usize, Option) { let remaining = unsafe { (*self.buffers).len() } - self.current_channel; + (remaining, Some(remaining)) } }