Yield offsets in the block iterator
This commit is contained in:
parent
f389e0341e
commit
c3f4e7e2d9
1 changed files with 8 additions and 6 deletions
|
@ -50,7 +50,8 @@ pub struct ChannelsIter<'slice, 'sample: 'slice> {
|
||||||
// Per-block per-channel per-sample iterators
|
// Per-block per-channel per-sample iterators
|
||||||
|
|
||||||
/// An iterator over all samples in the buffer, slicing over the sample-dimension with a maximum
|
/// An iterator over all samples in the buffer, slicing over the sample-dimension with a maximum
|
||||||
/// size of [Self::max_block_size]. See [Buffer::iter_blocks()].
|
/// size of [Self::max_block_size]. See [Buffer::iter_blocks()]. Yields both the block and the
|
||||||
|
/// offset from the start of the buffer.
|
||||||
pub struct BlocksIter<'slice, 'sample: 'slice> {
|
pub struct BlocksIter<'slice, 'sample: 'slice> {
|
||||||
/// The raw output buffers.
|
/// The raw output buffers.
|
||||||
pub(self) buffers: *mut [&'sample mut [f32]],
|
pub(self) buffers: *mut [&'sample mut [f32]],
|
||||||
|
@ -134,23 +135,24 @@ impl<'slice, 'sample> Iterator for BlockChannelsIter<'slice, 'sample> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'slice, 'sample> Iterator for BlocksIter<'slice, 'sample> {
|
impl<'slice, 'sample> Iterator for BlocksIter<'slice, 'sample> {
|
||||||
type Item = Block<'slice, 'sample>;
|
type Item = (usize, Block<'slice, 'sample>);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let buffer_len = unsafe { (*self.buffers)[0].len() };
|
let buffer_len = unsafe { (*self.buffers)[0].len() };
|
||||||
if self.current_block_start < buffer_len {
|
if self.current_block_start < buffer_len {
|
||||||
|
let current_block_start = self.current_block_start;
|
||||||
let current_block_end =
|
let current_block_end =
|
||||||
(self.current_block_start + self.max_block_size).min(buffer_len);
|
(self.current_block_start + self.max_block_size).min(buffer_len);
|
||||||
let block = Block {
|
let block = Block {
|
||||||
buffers: self.buffers,
|
buffers: self.buffers,
|
||||||
current_block_start: self.current_block_start,
|
current_block_start,
|
||||||
current_block_end,
|
current_block_end,
|
||||||
_marker: self._marker,
|
_marker: self._marker,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.current_block_start += self.max_block_size;
|
self.current_block_start += self.max_block_size;
|
||||||
|
|
||||||
Some(block)
|
Some((current_block_start, block))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -430,8 +432,8 @@ mod miri {
|
||||||
|
|
||||||
// These iterators should not alias
|
// These iterators should not alias
|
||||||
let mut blocks = buffer.iter_blocks(16);
|
let mut blocks = buffer.iter_blocks(16);
|
||||||
let block1 = blocks.next().unwrap();
|
let (_block1_offset, block1) = blocks.next().unwrap();
|
||||||
let block2 = blocks.next().unwrap();
|
let (_block2_offset, block2) = blocks.next().unwrap();
|
||||||
for channel in block1 {
|
for channel in block1 {
|
||||||
for sample in channel.iter_mut() {
|
for sample in channel.iter_mut() {
|
||||||
*sample += 0.001;
|
*sample += 0.001;
|
||||||
|
|
Loading…
Add table
Reference in a new issue