Extract even more from the loop body

This commit is contained in:
Gwilym Inzani 2023-06-27 21:50:46 +01:00
parent 57f0a8c889
commit 38868cb269

View file

@ -422,25 +422,31 @@ impl MixerBuffer {
) { ) {
working_buffer.fill(0.into()); working_buffer.fill(0.into());
for channel in channels.filter(|channel| !channel.is_done) { for (channel, playback_speed) in
let playback_speed = if channel.is_stereo { channels
2.into() .filter(|channel| !channel.is_done)
} else { .filter_map(|channel| {
channel.playback_speed let playback_speed = if channel.is_stereo {
}; 2.into()
} else {
channel.playback_speed
};
if (channel.pos + playback_speed * self.frequency.buffer_size() as u32).floor() if (channel.pos + playback_speed * self.frequency.buffer_size() as u32).floor()
>= channel.data.len() as u32 >= channel.data.len() as u32
{ {
// TODO: This should probably play what's left rather than skip the last bit // TODO: This should probably play what's left rather than skip the last bit
if channel.should_loop { if channel.should_loop {
channel.pos = 0.into(); channel.pos = 0.into();
} else { } else {
channel.is_done = true; channel.is_done = true;
continue; return None;
} }
} }
Some((channel, playback_speed))
})
{
if channel.volume != 0.into() { if channel.volume != 0.into() {
if channel.is_stereo { if channel.is_stereo {
unsafe { unsafe {