From 6ebe08e52874ddb6953f0bf138533c8a263aba03 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 12 Jan 2023 21:53:54 +0000 Subject: [PATCH 1/3] Fix out by 1 while calcuating leading zeros --- agb/src/sound/mixer/mixer.s | 2 ++ 1 file changed, 2 insertions(+) diff --git a/agb/src/sound/mixer/mixer.s b/agb/src/sound/mixer/mixer.s index 4af591e1..65f7c50d 100644 --- a/agb/src/sound/mixer/mixer.s +++ b/agb/src/sound/mixer/mixer.s @@ -64,6 +64,8 @@ same_modification: lsrs r7, r7, #1 bne 1b + sub r3, r3, #1 + mov r5, #0 @ current index we're reading from ldr r8, =agb_rs__buffer_size @ the number of steps left ldr r8, [r8] From 8009ffea0951a8f4f1bf70f42c072ba3d50ea2cb Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 12 Jan 2023 21:54:08 +0000 Subject: [PATCH 2/3] If volume is 0, don't actually play anything --- agb/src/sound/mixer/sw_mixer.rs | 40 +++++++++++++++++---------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/agb/src/sound/mixer/sw_mixer.rs b/agb/src/sound/mixer/sw_mixer.rs index 44c17c4f..f7155156 100644 --- a/agb/src/sound/mixer/sw_mixer.rs +++ b/agb/src/sound/mixer/sw_mixer.rs @@ -446,26 +446,28 @@ impl MixerBuffer { } } - if channel.is_stereo { - unsafe { - agb_rs__mixer_add_stereo( - channel.data.as_ptr().add(channel.pos.floor()), - self.working_buffer.as_mut_ptr(), - channel.volume, - ); - } - } else { - let right_amount = ((channel.panning + 1) / 2) * channel.volume; - let left_amount = ((-channel.panning + 1) / 2) * channel.volume; + if channel.volume != 0.into() { + if channel.is_stereo { + unsafe { + agb_rs__mixer_add_stereo( + channel.data.as_ptr().add(channel.pos.floor()), + self.working_buffer.as_mut_ptr(), + channel.volume, + ); + } + } else { + let right_amount = ((channel.panning + 1) / 2) * channel.volume; + let left_amount = ((-channel.panning + 1) / 2) * channel.volume; - unsafe { - agb_rs__mixer_add( - channel.data.as_ptr().add(channel.pos.floor()), - self.working_buffer.as_mut_ptr(), - playback_speed, - left_amount, - right_amount, - ); + unsafe { + agb_rs__mixer_add( + channel.data.as_ptr().add(channel.pos.floor()), + self.working_buffer.as_mut_ptr(), + playback_speed, + left_amount, + right_amount, + ); + } } } From 9796174a5755532bf87f8e357e77d74eb8878abb Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 12 Jan 2023 21:55:25 +0000 Subject: [PATCH 3/3] Add changelog entry for fixes --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11497da3..6915d45c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Text renderer can now be re-used which is useful for rpg style character/word at a time text boxes. +### Fixed +- Zero volume now plays no sound. +- Fixed issue where volume was incorrect for volumes which were powers of 2. + ## [0.12.2] - 2022/10/22 This is a minor release to fix an alignment issue with background tiles.