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