diff --git a/agb/src/sound/mixer/mod.rs b/agb/src/sound/mixer/mod.rs index 06875cdd..2068655d 100644 --- a/agb/src/sound/mixer/mod.rs +++ b/agb/src/sound/mixer/mod.rs @@ -18,6 +18,12 @@ impl MixerController { } } +#[derive(PartialEq, Eq)] +enum SoundPriority { + High, + Low, +} + pub struct SoundChannel { data: &'static [u8], pos: Num, @@ -27,6 +33,8 @@ pub struct SoundChannel { panning: Num, // between -1 and 1 is_done: bool, + + priority: SoundPriority, } impl SoundChannel { @@ -38,6 +46,7 @@ impl SoundChannel { playback_speed: 1.into(), panning: 0.into(), is_done: false, + priority: SoundPriority::Low, } } @@ -58,4 +67,9 @@ impl SoundChannel { self.panning = panning; self } + + pub fn high_priority(mut self) -> Self { + self.priority = SoundPriority::High; + self + } } diff --git a/agb/src/sound/mixer/sw_mixer.rs b/agb/src/sound/mixer/sw_mixer.rs index 69484d4b..4f6ca3f5 100644 --- a/agb/src/sound/mixer/sw_mixer.rs +++ b/agb/src/sound/mixer/sw_mixer.rs @@ -1,6 +1,6 @@ use super::hw; use super::hw::LeftOrRight; -use super::SoundChannel; +use super::{SoundChannel, SoundPriority}; use crate::number::Num; pub struct Mixer { @@ -41,6 +41,19 @@ impl Mixer { return; } + if new_channel.priority == SoundPriority::Low { + return; // don't bother even playing it + } + + for channel in self.channels.iter_mut() { + if channel.as_ref().unwrap().priority == SoundPriority::High { + continue; + } + + channel.replace(new_channel); + return; + } + panic!("Cannot play more than 16 sounds at once"); } }