mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-26 17:16:34 +11:00
Remove timer field to mixer
This commit is contained in:
parent
eea2a3b5f1
commit
0a9a3fdf1d
9 changed files with 21 additions and 29 deletions
|
@ -14,8 +14,7 @@ fn main(mut gba: Gba) -> ! {
|
||||||
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 timers = gba.timers.timers();
|
let mut mixer = gba.mixer.mixer();
|
||||||
let mut mixer = gba.mixer.mixer(&mut timers.timer0);
|
|
||||||
mixer.enable();
|
mixer.enable();
|
||||||
|
|
||||||
let channel = SoundChannel::new(DEAD_CODE);
|
let channel = SoundChannel::new(DEAD_CODE);
|
||||||
|
|
|
@ -11,11 +11,11 @@ const LET_IT_IN: &[u8] = include_wav!("examples/JoshWoodward-LetItIn.wav");
|
||||||
fn main(mut gba: Gba) -> ! {
|
fn main(mut gba: Gba) -> ! {
|
||||||
let vblank_provider = agb::interrupt::VBlank::get();
|
let vblank_provider = agb::interrupt::VBlank::get();
|
||||||
|
|
||||||
let mut timer_controller = gba.timers.timers();
|
let timer_controller = gba.timers.timers();
|
||||||
let mut timer = timer_controller.timer1;
|
let mut timer = timer_controller.timer2;
|
||||||
timer.set_enabled(true);
|
timer.set_enabled(true);
|
||||||
|
|
||||||
let mut mixer = gba.mixer.mixer(&mut timer_controller.timer0);
|
let mut mixer = gba.mixer.mixer();
|
||||||
mixer.enable();
|
mixer.enable();
|
||||||
|
|
||||||
let mut channel = SoundChannel::new(LET_IT_IN);
|
let mut channel = SoundChannel::new(LET_IT_IN);
|
||||||
|
|
|
@ -5,7 +5,6 @@ pub use sw_mixer::ChannelId;
|
||||||
pub use sw_mixer::Mixer;
|
pub use sw_mixer::Mixer;
|
||||||
|
|
||||||
use crate::fixnum::Num;
|
use crate::fixnum::Num;
|
||||||
use crate::timer::Timer;
|
|
||||||
|
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct MixerController {}
|
pub struct MixerController {}
|
||||||
|
@ -15,8 +14,8 @@ impl MixerController {
|
||||||
MixerController {}
|
MixerController {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mixer<'a>(&mut self, timer: &'a mut Timer) -> Mixer<'a> {
|
pub fn mixer(&mut self) -> Mixer {
|
||||||
Mixer::new(timer)
|
Mixer::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,29 +19,29 @@ 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<'a> {
|
pub struct Mixer {
|
||||||
buffer: MixerBuffer,
|
buffer: MixerBuffer,
|
||||||
channels: [Option<SoundChannel>; 8],
|
channels: [Option<SoundChannel>; 8],
|
||||||
indices: [i32; 8],
|
indices: [i32; 8],
|
||||||
|
|
||||||
timer: &'a mut Timer,
|
timer: Timer,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ChannelId(usize, i32);
|
pub struct ChannelId(usize, i32);
|
||||||
|
|
||||||
impl<'a> Mixer<'a> {
|
impl Mixer {
|
||||||
pub(super) fn new(timer: &'a mut Timer) -> Self {
|
pub(super) fn new() -> Self {
|
||||||
Mixer {
|
Mixer {
|
||||||
buffer: MixerBuffer::new(),
|
buffer: MixerBuffer::new(),
|
||||||
channels: Default::default(),
|
channels: Default::default(),
|
||||||
indices: Default::default(),
|
indices: Default::default(),
|
||||||
|
|
||||||
timer,
|
timer: unsafe { Timer::new(0) },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable(&mut self) {
|
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();
|
hw::set_sound_control_register_for_mixer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,6 @@ pub struct Timer {
|
||||||
|
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct Timers {
|
pub struct Timers {
|
||||||
pub timer0: Timer,
|
|
||||||
pub timer1: Timer,
|
|
||||||
pub timer2: Timer,
|
pub timer2: Timer,
|
||||||
pub timer3: Timer,
|
pub timer3: Timer,
|
||||||
}
|
}
|
||||||
|
@ -49,8 +47,6 @@ pub struct Timers {
|
||||||
impl Timers {
|
impl Timers {
|
||||||
pub(crate) unsafe fn new() -> Self {
|
pub(crate) unsafe fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
timer0: Timer::new(0),
|
|
||||||
timer1: Timer::new(1),
|
|
||||||
timer2: Timer::new(2),
|
timer2: Timer::new(2),
|
||||||
timer3: Timer::new(3),
|
timer3: Timer::new(3),
|
||||||
}
|
}
|
||||||
|
@ -58,7 +54,7 @@ impl Timers {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Timer {
|
impl Timer {
|
||||||
unsafe fn new(timer_number: u16) -> Self {
|
pub(crate) unsafe fn new(timer_number: u16) -> Self {
|
||||||
let new_timer = Self { timer_number };
|
let new_timer = Self { timer_number };
|
||||||
new_timer.data_register().set(0);
|
new_timer.data_register().set(0);
|
||||||
new_timer.control_register().set(0);
|
new_timer.control_register().set(0);
|
||||||
|
|
|
@ -809,8 +809,7 @@ fn main(mut agb: agb::Gba) -> ! {
|
||||||
vram.set_background_palettes(tile_sheet::background.palettes);
|
vram.set_background_palettes(tile_sheet::background.palettes);
|
||||||
|
|
||||||
let object = agb.display.object.get();
|
let object = agb.display.object.get();
|
||||||
let mut timer_controller = agb.timers.timers();
|
let mut mixer = agb.mixer.mixer();
|
||||||
let mut mixer = agb.mixer.mixer(&mut timer_controller.timer0);
|
|
||||||
|
|
||||||
mixer.enable();
|
mixer.enable();
|
||||||
let mut music_box = sfx::MusicBox::new();
|
let mut music_box = sfx::MusicBox::new();
|
||||||
|
|
|
@ -60,13 +60,13 @@ impl MusicBox {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SfxPlayer<'a, 'b> {
|
pub struct SfxPlayer<'a> {
|
||||||
mixer: &'a mut Mixer<'b>,
|
mixer: &'a mut Mixer,
|
||||||
frame: i32,
|
frame: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> SfxPlayer<'a, 'b> {
|
impl<'a> SfxPlayer<'a> {
|
||||||
pub fn new(mixer: &'a mut Mixer<'b>, music_box: &MusicBox) -> Self {
|
pub fn new(mixer: &'a mut Mixer, music_box: &MusicBox) -> Self {
|
||||||
SfxPlayer {
|
SfxPlayer {
|
||||||
mixer,
|
mixer,
|
||||||
frame: music_box.frame,
|
frame: music_box.frame,
|
||||||
|
|
|
@ -2205,8 +2205,7 @@ fn game_with_level(gba: &mut agb::Gba) {
|
||||||
let vblank = agb::interrupt::VBlank::get();
|
let vblank = agb::interrupt::VBlank::get();
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
|
|
||||||
let mut timers = gba.timers.timers();
|
let mut mixer = gba.mixer.mixer();
|
||||||
let mut mixer = gba.mixer.mixer(&mut timers.timer0);
|
|
||||||
mixer.enable();
|
mixer.enable();
|
||||||
|
|
||||||
let mut sfx = sfx::Sfx::new(&mut mixer);
|
let mut sfx = sfx::Sfx::new(&mut mixer);
|
||||||
|
|
|
@ -27,11 +27,11 @@ const BLUE_SPIRIT: &[u8] = agb::include_wav!("sfx/03 - Blue Spirit (Main Loop).w
|
||||||
|
|
||||||
pub struct Sfx<'a> {
|
pub struct Sfx<'a> {
|
||||||
bgm: Option<ChannelId>,
|
bgm: Option<ChannelId>,
|
||||||
mixer: &'a mut Mixer<'a>,
|
mixer: &'a mut Mixer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Sfx<'a> {
|
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 }
|
Self { mixer, bgm: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue