Fix issues discovered while testing

This commit is contained in:
Gwilym Kuiper 2021-06-10 23:45:19 +01:00
parent f82ed3d7c1
commit bcee6be7df

View file

@ -31,9 +31,11 @@ impl Mixer {
pub fn play_sound(&mut self, new_channel: SoundChannel) { pub fn play_sound(&mut self, new_channel: SoundChannel) {
for channel in self.channels.iter_mut() { for channel in self.channels.iter_mut() {
if channel.is_some() { if let Some(some_channel) = channel {
if !some_channel.is_done {
continue; continue;
} }
}
channel.replace(new_channel); channel.replace(new_channel);
return; return;
@ -86,17 +88,11 @@ impl MixerBuffer {
continue; continue;
} }
let mut current_point = channel.pos;
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 { for i in 0..SOUND_BUFFER_SIZE {
let v = (channel.data[current_point.floor()] as i8) as i16; if channel.pos.floor() >= channel.data.len() {
let v: Num<i16, 4> = v.into();
current_point += channel.playback_speed;
if current_point.floor() >= channel.data.len() {
if channel.should_loop { if channel.should_loop {
channel.pos -= channel.data.len(); channel.pos -= channel.data.len();
} else { } else {
@ -105,8 +101,12 @@ impl MixerBuffer {
} }
} }
buffer[i] += v * left_amount; let v = (channel.data[channel.pos.floor()] as i8) as i16;
buffer[i + SOUND_BUFFER_SIZE] += v * right_amount; let v: Num<i16, 4> = v.into();
channel.pos += channel.playback_speed;
buffer[i] += v;
buffer[i + SOUND_BUFFER_SIZE] += v;
} }
} }