mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 08:41:34 +11:00
Add sound priorities
This commit is contained in:
parent
53cf1a5064
commit
574e91df2f
|
@ -18,6 +18,12 @@ impl MixerController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq)]
|
||||||
|
enum SoundPriority {
|
||||||
|
High,
|
||||||
|
Low,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct SoundChannel {
|
pub struct SoundChannel {
|
||||||
data: &'static [u8],
|
data: &'static [u8],
|
||||||
pos: Num<usize, 8>,
|
pos: Num<usize, 8>,
|
||||||
|
@ -27,6 +33,8 @@ pub struct SoundChannel {
|
||||||
|
|
||||||
panning: Num<i16, 4>, // between -1 and 1
|
panning: Num<i16, 4>, // between -1 and 1
|
||||||
is_done: bool,
|
is_done: bool,
|
||||||
|
|
||||||
|
priority: SoundPriority,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SoundChannel {
|
impl SoundChannel {
|
||||||
|
@ -38,6 +46,7 @@ impl SoundChannel {
|
||||||
playback_speed: 1.into(),
|
playback_speed: 1.into(),
|
||||||
panning: 0.into(),
|
panning: 0.into(),
|
||||||
is_done: false,
|
is_done: false,
|
||||||
|
priority: SoundPriority::Low,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,4 +67,9 @@ impl SoundChannel {
|
||||||
self.panning = panning;
|
self.panning = panning;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn high_priority(mut self) -> Self {
|
||||||
|
self.priority = SoundPriority::High;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use super::hw;
|
use super::hw;
|
||||||
use super::hw::LeftOrRight;
|
use super::hw::LeftOrRight;
|
||||||
use super::SoundChannel;
|
use super::{SoundChannel, SoundPriority};
|
||||||
use crate::number::Num;
|
use crate::number::Num;
|
||||||
|
|
||||||
pub struct Mixer {
|
pub struct Mixer {
|
||||||
|
@ -41,6 +41,19 @@ impl Mixer {
|
||||||
return;
|
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");
|
panic!("Cannot play more than 16 sounds at once");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue