Remove timer field to mixer

This commit is contained in:
Gwilym Kuiper 2022-06-11 12:57:59 +01:00
parent eea2a3b5f1
commit 0a9a3fdf1d
9 changed files with 21 additions and 29 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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()
}
}

View file

@ -19,29 +19,29 @@ extern "C" {
fn agb_rs__mixer_collapse(sound_buffer: *mut i8, input_buffer: *const Num<i16, 4>);
}
pub struct Mixer<'a> {
pub struct Mixer {
buffer: MixerBuffer,
channels: [Option<SoundChannel>; 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();
}

View file

@ -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);

View file

@ -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();

View file

@ -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,

View file

@ -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);

View file

@ -27,11 +27,11 @@ const BLUE_SPIRIT: &[u8] = agb::include_wav!("sfx/03 - Blue Spirit (Main Loop).w
pub struct Sfx<'a> {
bgm: Option<ChannelId>,
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 }
}