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,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue