From 8009ffea0951a8f4f1bf70f42c072ba3d50ea2cb Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 12 Jan 2023 21:54:08 +0000 Subject: [PATCH] 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, + ); + } } }