Keep track of whether a channel is done

This commit is contained in:
Gwilym Kuiper 2021-06-10 23:35:12 +01:00
parent 063af3fc40
commit f82ed3d7c1
2 changed files with 7 additions and 0 deletions

View file

@ -82,6 +82,10 @@ impl MixerBuffer {
let mut buffer: [Num<i16, 4>; SOUND_BUFFER_SIZE * 2] = [Num::new(0); SOUND_BUFFER_SIZE * 2];
for channel in channels {
if channel.is_done {
continue;
}
let mut current_point = channel.pos;
let right_amount = (channel.panning - 1) / 2;
@ -96,6 +100,7 @@ impl MixerBuffer {
if channel.should_loop {
channel.pos -= channel.data.len();
} else {
channel.is_done = true;
continue;
}
}

View file

@ -26,6 +26,7 @@ pub struct SoundChannel {
playback_speed: Num<usize, 8>,
panning: Num<i16, 4>, // between -1 and 1
is_done: bool,
}
impl SoundChannel {
@ -36,6 +37,7 @@ impl SoundChannel {
should_loop: false,
playback_speed: 1.into(),
panning: 0.into(),
is_done: false,
}
}