From 86ba30937710675f418616108686240eae8f6787 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 6 Jun 2021 15:47:57 +0100 Subject: [PATCH 1/2] Add ability to set that a channel should loop --- agb/src/sound/mixer.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/agb/src/sound/mixer.rs b/agb/src/sound/mixer.rs index 6b01ac9..f97c674 100644 --- a/agb/src/sound/mixer.rs +++ b/agb/src/sound/mixer.rs @@ -70,11 +70,21 @@ impl Mixer { pub struct SoundChannel { data: &'static [u8], pos: usize, + should_loop: bool, } impl SoundChannel { pub fn new(data: &'static [u8]) -> Self { - SoundChannel { data, pos: 0 } + SoundChannel { + data, + pos: 0, + should_loop: false, + } + } + + pub fn should_loop(mut self) -> Self { + self.should_loop = true; + self } } From 40f7975f465384b0594888430ce84327352f2fa1 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 6 Jun 2021 15:48:52 +0100 Subject: [PATCH 2/2] Loop if requested --- agb/src/sound/mixer.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/agb/src/sound/mixer.rs b/agb/src/sound/mixer.rs index f97c674..3c0fbfd 100644 --- a/agb/src/sound/mixer.rs +++ b/agb/src/sound/mixer.rs @@ -43,7 +43,11 @@ impl Mixer { some_channel.pos += SOUND_BUFFER_SIZE; if some_channel.pos >= some_channel.data.len() { - has_finished = true; + if some_channel.should_loop { + some_channel.pos = 0; + } else { + has_finished = true; + } } }