From f82ed3d7c189208ca883120bc06c196f94e34060 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 10 Jun 2021 23:35:12 +0100 Subject: [PATCH] Keep track of whether a channel is done --- agb/src/sound/mixer/mixer.rs | 5 +++++ agb/src/sound/mixer/mod.rs | 2 ++ 2 files changed, 7 insertions(+) diff --git a/agb/src/sound/mixer/mixer.rs b/agb/src/sound/mixer/mixer.rs index f79d0640..f66030d9 100644 --- a/agb/src/sound/mixer/mixer.rs +++ b/agb/src/sound/mixer/mixer.rs @@ -82,6 +82,10 @@ impl MixerBuffer { let mut buffer: [Num; 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; } } diff --git a/agb/src/sound/mixer/mod.rs b/agb/src/sound/mixer/mod.rs index 280f111c..d445c04b 100644 --- a/agb/src/sound/mixer/mod.rs +++ b/agb/src/sound/mixer/mod.rs @@ -26,6 +26,7 @@ pub struct SoundChannel { playback_speed: Num, panning: Num, // 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, } }