diff --git a/agb/src/sound/mixer/mod.rs b/agb/src/sound/mixer/mod.rs index f3dc224c..dbef2c9d 100644 --- a/agb/src/sound/mixer/mod.rs +++ b/agb/src/sound/mixer/mod.rs @@ -228,6 +228,7 @@ pub struct SoundChannel { should_loop: bool, restart_point: Num, + is_playing: bool, playback_speed: Num, volume: Num, // between 0 and 1 @@ -272,6 +273,7 @@ impl SoundChannel { pos: 0.into(), should_loop: false, playback_speed: 1.into(), + is_playing: true, panning: 0.into(), is_done: false, priority: SoundPriority::Low, @@ -316,6 +318,7 @@ impl SoundChannel { pos: 0.into(), should_loop: false, playback_speed: 1.into(), + is_playing: true, panning: 0.into(), is_done: false, priority: SoundPriority::High, @@ -419,4 +422,18 @@ impl SoundChannel { self.pos = pos.into(); self } + + /// Pause this channel. You can resume later by using [`.resume()`](SoundChannel::resume()) + #[inline] + pub fn pause(&mut self) -> &mut Self { + self.is_playing = false; + self + } + + /// Resume a paused channel paused by [`.pause()`](SoundChannel::pause()) + #[inline] + pub fn resume(&mut self) -> &mut Self { + self.is_playing = true; + self + } } diff --git a/agb/src/sound/mixer/sw_mixer.rs b/agb/src/sound/mixer/sw_mixer.rs index 917b6657..88c0a871 100644 --- a/agb/src/sound/mixer/sw_mixer.rs +++ b/agb/src/sound/mixer/sw_mixer.rs @@ -414,8 +414,8 @@ impl MixerBuffer { working_buffer: &mut [Num], channels: impl Iterator, ) { - let mut channels = - channels.filter(|channel| !channel.is_done && channel.volume != 0.into()); + let mut channels = channels + .filter(|channel| !channel.is_done && channel.volume != 0.into() && channel.is_playing); if let Some(channel) = channels.next() { if channel.is_stereo {