diff --git a/agb/examples/mixer_basic.rs b/agb/examples/mixer_basic.rs index a5a982b1..96603df1 100644 --- a/agb/examples/mixer_basic.rs +++ b/agb/examples/mixer_basic.rs @@ -14,8 +14,7 @@ fn main(mut gba: Gba) -> ! { let mut input = ButtonController::new(); let vblank_provider = agb::interrupt::VBlank::get(); - let mut timers = gba.timers.timers(); - let mut mixer = gba.mixer.mixer(&mut timers.timer0); + let mut mixer = gba.mixer.mixer(); mixer.enable(); let channel = SoundChannel::new(DEAD_CODE); diff --git a/agb/examples/stereo_sound.rs b/agb/examples/stereo_sound.rs index a1bf1f07..c3e3535d 100644 --- a/agb/examples/stereo_sound.rs +++ b/agb/examples/stereo_sound.rs @@ -11,11 +11,11 @@ const LET_IT_IN: &[u8] = include_wav!("examples/JoshWoodward-LetItIn.wav"); fn main(mut gba: Gba) -> ! { let vblank_provider = agb::interrupt::VBlank::get(); - let mut timer_controller = gba.timers.timers(); - let mut timer = timer_controller.timer1; + let timer_controller = gba.timers.timers(); + let mut timer = timer_controller.timer2; timer.set_enabled(true); - let mut mixer = gba.mixer.mixer(&mut timer_controller.timer0); + let mut mixer = gba.mixer.mixer(); mixer.enable(); let mut channel = SoundChannel::new(LET_IT_IN); diff --git a/agb/src/sound/mixer/mod.rs b/agb/src/sound/mixer/mod.rs index 9ff2db63..00227076 100644 --- a/agb/src/sound/mixer/mod.rs +++ b/agb/src/sound/mixer/mod.rs @@ -5,7 +5,6 @@ pub use sw_mixer::ChannelId; pub use sw_mixer::Mixer; use crate::fixnum::Num; -use crate::timer::Timer; #[non_exhaustive] pub struct MixerController {} @@ -15,8 +14,8 @@ impl MixerController { MixerController {} } - pub fn mixer<'a>(&mut self, timer: &'a mut Timer) -> Mixer<'a> { - Mixer::new(timer) + pub fn mixer(&mut self) -> Mixer { + Mixer::new() } } diff --git a/agb/src/sound/mixer/sw_mixer.rs b/agb/src/sound/mixer/sw_mixer.rs index 025e0dc1..78c55629 100644 --- a/agb/src/sound/mixer/sw_mixer.rs +++ b/agb/src/sound/mixer/sw_mixer.rs @@ -19,29 +19,29 @@ extern "C" { fn agb_rs__mixer_collapse(sound_buffer: *mut i8, input_buffer: *const Num); } -pub struct Mixer<'a> { +pub struct Mixer { buffer: MixerBuffer, channels: [Option; 8], indices: [i32; 8], - timer: &'a mut Timer, + timer: Timer, } pub struct ChannelId(usize, i32); -impl<'a> Mixer<'a> { - pub(super) fn new(timer: &'a mut Timer) -> Self { +impl Mixer { + pub(super) fn new() -> Self { Mixer { buffer: MixerBuffer::new(), channels: Default::default(), indices: Default::default(), - timer, + timer: unsafe { Timer::new(0) }, } } pub fn enable(&mut self) { - hw::set_timer_counter_for_frequency_and_enable(self.timer, SOUND_FREQUENCY); + hw::set_timer_counter_for_frequency_and_enable(&mut self.timer, SOUND_FREQUENCY); hw::set_sound_control_register_for_mixer(); } diff --git a/agb/src/timer.rs b/agb/src/timer.rs index 92f08806..f9ed9c53 100644 --- a/agb/src/timer.rs +++ b/agb/src/timer.rs @@ -40,8 +40,6 @@ pub struct Timer { #[non_exhaustive] pub struct Timers { - pub timer0: Timer, - pub timer1: Timer, pub timer2: Timer, pub timer3: Timer, } @@ -49,8 +47,6 @@ pub struct Timers { impl Timers { pub(crate) unsafe fn new() -> Self { Self { - timer0: Timer::new(0), - timer1: Timer::new(1), timer2: Timer::new(2), timer3: Timer::new(3), } @@ -58,7 +54,7 @@ impl Timers { } impl Timer { - unsafe fn new(timer_number: u16) -> Self { + pub(crate) unsafe fn new(timer_number: u16) -> Self { let new_timer = Self { timer_number }; new_timer.data_register().set(0); new_timer.control_register().set(0); diff --git a/examples/the-hat-chooses-the-wizard/src/main.rs b/examples/the-hat-chooses-the-wizard/src/main.rs index 36e45152..d387e08a 100644 --- a/examples/the-hat-chooses-the-wizard/src/main.rs +++ b/examples/the-hat-chooses-the-wizard/src/main.rs @@ -809,8 +809,7 @@ fn main(mut agb: agb::Gba) -> ! { vram.set_background_palettes(tile_sheet::background.palettes); let object = agb.display.object.get(); - let mut timer_controller = agb.timers.timers(); - let mut mixer = agb.mixer.mixer(&mut timer_controller.timer0); + let mut mixer = agb.mixer.mixer(); mixer.enable(); let mut music_box = sfx::MusicBox::new(); diff --git a/examples/the-hat-chooses-the-wizard/src/sfx.rs b/examples/the-hat-chooses-the-wizard/src/sfx.rs index 6fbaab7e..f471ae57 100644 --- a/examples/the-hat-chooses-the-wizard/src/sfx.rs +++ b/examples/the-hat-chooses-the-wizard/src/sfx.rs @@ -60,13 +60,13 @@ impl MusicBox { } } -pub struct SfxPlayer<'a, 'b> { - mixer: &'a mut Mixer<'b>, +pub struct SfxPlayer<'a> { + mixer: &'a mut Mixer, frame: i32, } -impl<'a, 'b> SfxPlayer<'a, 'b> { - pub fn new(mixer: &'a mut Mixer<'b>, music_box: &MusicBox) -> Self { +impl<'a> SfxPlayer<'a> { + pub fn new(mixer: &'a mut Mixer, music_box: &MusicBox) -> Self { SfxPlayer { mixer, frame: music_box.frame, diff --git a/examples/the-purple-night/src/main.rs b/examples/the-purple-night/src/main.rs index 6bb170ab..4dc79b56 100644 --- a/examples/the-purple-night/src/main.rs +++ b/examples/the-purple-night/src/main.rs @@ -2205,8 +2205,7 @@ fn game_with_level(gba: &mut agb::Gba) { let vblank = agb::interrupt::VBlank::get(); vblank.wait_for_vblank(); - let mut timers = gba.timers.timers(); - let mut mixer = gba.mixer.mixer(&mut timers.timer0); + let mut mixer = gba.mixer.mixer(); mixer.enable(); let mut sfx = sfx::Sfx::new(&mut mixer); diff --git a/examples/the-purple-night/src/sfx.rs b/examples/the-purple-night/src/sfx.rs index d7f6d089..08f26800 100644 --- a/examples/the-purple-night/src/sfx.rs +++ b/examples/the-purple-night/src/sfx.rs @@ -27,11 +27,11 @@ const BLUE_SPIRIT: &[u8] = agb::include_wav!("sfx/03 - Blue Spirit (Main Loop).w pub struct Sfx<'a> { bgm: Option, - mixer: &'a mut Mixer<'a>, + mixer: &'a mut Mixer, } impl<'a> Sfx<'a> { - pub fn new(mixer: &'a mut Mixer<'a>) -> Self { + pub fn new(mixer: &'a mut Mixer) -> Self { Self { mixer, bgm: None } }