Allow use of timer again after mixer is done

This commit is contained in:
Gwilym Kuiper 2021-11-22 19:14:51 +00:00
parent bfc02e0aa8
commit f7a10677dd
4 changed files with 8 additions and 8 deletions

View file

@ -17,7 +17,7 @@ fn main() -> ! {
let mut input = ButtonController::new(); let mut input = ButtonController::new();
let vblank_provider = agb::interrupt::VBlank::get(); let vblank_provider = agb::interrupt::VBlank::get();
let mut mixer = gba.mixer.mixer(gba.timers.timer0); let mut mixer = gba.mixer.mixer(&mut gba.timers.timer0);
mixer.enable(); mixer.enable();
let channel = SoundChannel::new(DEAD_CODE); let channel = SoundChannel::new(DEAD_CODE);

View file

@ -14,11 +14,11 @@ fn main() -> ! {
let mut gba = Gba::new(); let mut gba = Gba::new();
let vblank_provider = agb::interrupt::VBlank::get(); let vblank_provider = agb::interrupt::VBlank::get();
let timer_controller = gba.timers; let mut timer_controller = gba.timers;
let mut timer = timer_controller.timer1; let mut timer = timer_controller.timer1;
timer.set_enabled(true); timer.set_enabled(true);
let mut mixer = gba.mixer.mixer(timer_controller.timer0); let mut mixer = gba.mixer.mixer(&mut timer_controller.timer0);
mixer.enable(); mixer.enable();
let mut channel = SoundChannel::new(LET_IT_IN); let mut channel = SoundChannel::new(LET_IT_IN);

View file

@ -15,7 +15,7 @@ impl MixerController {
MixerController {} MixerController {}
} }
pub fn mixer(&mut self, timer: Timer) -> Mixer { pub fn mixer<'a>(&mut self, timer: &'a mut Timer) -> Mixer<'a> {
Mixer::new(timer) Mixer::new(timer)
} }
} }

View file

@ -19,18 +19,18 @@ extern "C" {
fn agb_rs__mixer_collapse(sound_buffer: *mut i8, input_buffer: *const Num<i16, 4>); fn agb_rs__mixer_collapse(sound_buffer: *mut i8, input_buffer: *const Num<i16, 4>);
} }
pub struct Mixer { pub struct Mixer<'a> {
buffer: MixerBuffer, buffer: MixerBuffer,
channels: [Option<SoundChannel>; 8], channels: [Option<SoundChannel>; 8],
indices: [i32; 8], indices: [i32; 8],
timer: Timer, timer: &'a mut Timer,
} }
pub struct ChannelId(usize, i32); pub struct ChannelId(usize, i32);
impl Mixer { impl<'a> Mixer<'a> {
pub(super) fn new(timer: Timer) -> Self { pub(super) fn new(timer: &'a mut Timer) -> Self {
Mixer { Mixer {
buffer: MixerBuffer::new(), buffer: MixerBuffer::new(),
channels: Default::default(), channels: Default::default(),