From 5b1f85a6195a22595d28999b6128bd19d9d1ebbe Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 10 Jun 2021 22:46:21 +0100 Subject: [PATCH] Make the current position in the audio sample a fix point --- agb/src/sound/mixer/mixer.rs | 6 +++--- agb/src/sound/mixer/mod.rs | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/agb/src/sound/mixer/mixer.rs b/agb/src/sound/mixer/mixer.rs index a88d0355..9d386719 100644 --- a/agb/src/sound/mixer/mixer.rs +++ b/agb/src/sound/mixer/mixer.rs @@ -36,9 +36,9 @@ impl Mixer { self.buffer_r.write_channel(some_channel); some_channel.pos += SOUND_BUFFER_SIZE; - if some_channel.pos >= some_channel.data.len() { + if some_channel.pos.floor() >= some_channel.data.len() { if some_channel.should_loop { - some_channel.pos = 0; + some_channel.pos = 0.into(); } else { has_finished = true; } @@ -105,7 +105,7 @@ impl MixerBuffer { } fn write_channel(&mut self, channel: &SoundChannel) { - let data_to_copy = &channel.data[channel.pos..]; + let data_to_copy = &channel.data[channel.pos.floor()..]; let place_to_write_to = self.get_write_buffer(); for (i, v) in data_to_copy.iter().take(SOUND_BUFFER_SIZE).enumerate() { diff --git a/agb/src/sound/mixer/mod.rs b/agb/src/sound/mixer/mod.rs index 5e6f8019..99ead31b 100644 --- a/agb/src/sound/mixer/mod.rs +++ b/agb/src/sound/mixer/mod.rs @@ -3,6 +3,8 @@ mod mixer; pub use mixer::Mixer; +use crate::number::Num; + #[non_exhaustive] pub struct MixerController {} @@ -18,7 +20,7 @@ impl MixerController { pub struct SoundChannel { data: &'static [u8], - pos: usize, + pos: Num, should_loop: bool, } @@ -26,7 +28,7 @@ impl SoundChannel { pub fn new(data: &'static [u8]) -> Self { SoundChannel { data, - pos: 0, + pos: 0.into(), should_loop: false, } }