mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-23 07:36:33 +11:00
Only do the if statement once per channel rather than once per index
This commit is contained in:
parent
ea9441f40b
commit
057467ecf8
1 changed files with 12 additions and 11 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue