From 0875e640de5982bd576434490c392b624b953bbe Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 6 Jun 2021 14:48:01 +0100 Subject: [PATCH] Handle sounds of length not exactly a multiple of SOUND_BUFFER_SIZE --- agb/src/sound/mixer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agb/src/sound/mixer.rs b/agb/src/sound/mixer.rs index a49c68b..6b01ac9 100644 --- a/agb/src/sound/mixer.rs +++ b/agb/src/sound/mixer.rs @@ -115,10 +115,10 @@ impl MixerBuffer { } fn write_channel(&mut self, channel: &SoundChannel) { - let data_to_copy = &channel.data[channel.pos..(channel.pos + SOUND_BUFFER_SIZE)]; + let data_to_copy = &channel.data[channel.pos..]; let place_to_write_to = self.get_write_buffer(); - for (i, v) in data_to_copy.iter().enumerate() { + for (i, v) in data_to_copy.iter().take(SOUND_BUFFER_SIZE).enumerate() { let v = *v as i8; place_to_write_to[i] = place_to_write_to[i].saturating_add(v); }