Only do the if statement once per channel rather than once per index

This commit is contained in:
Gwilym Kuiper 2021-06-18 22:56:49 +01:00
parent ea9441f40b
commit 057467ecf8

View file

@ -91,22 +91,23 @@ impl MixerBuffer {
let right_amount = (channel.panning + 1) / 2; let right_amount = (channel.panning + 1) / 2;
let left_amount = -right_amount + 1; let left_amount = -right_amount + 1;
for i in 0..SOUND_BUFFER_SIZE { if channel.pos + channel.playback_speed * SOUND_BUFFER_SIZE >= channel.data.len().into()
if channel.pos.floor() >= channel.data.len() { {
if channel.should_loop { // TODO: This should probably play what's left rather than skip the last bit
channel.pos -= channel.data.len(); if channel.should_loop {
} else { channel.pos -= channel.data.len();
channel.is_done = true; } else {
continue; channel.is_done = true;
} continue;
} }
}
for i in 0..SOUND_BUFFER_SIZE {
let v = (channel.data[channel.pos.floor()] as i8) as i16; let v = (channel.data[channel.pos.floor()] as i8) as i16;
let v: Num<i16, 4> = v.into();
channel.pos += channel.playback_speed; channel.pos += channel.playback_speed;
buffer[i] += v * left_amount; buffer[i] += left_amount * v;
buffer[i + SOUND_BUFFER_SIZE] += v * right_amount; buffer[i + SOUND_BUFFER_SIZE] += right_amount * v;
} }
} }