diff --git a/tracker/agb-tracker-interop/src/lib.rs b/tracker/agb-tracker-interop/src/lib.rs index c0bd85e4..d165d612 100644 --- a/tracker/agb-tracker-interop/src/lib.rs +++ b/tracker/agb-tracker-interop/src/lib.rs @@ -10,8 +10,8 @@ pub struct Track<'a> { pub patterns_to_play: &'a [usize], pub num_channels: usize, - pub frames_per_tick: Num, - pub ticks_per_step: u16, + pub frames_per_tick: Num, + pub ticks_per_step: u32, } #[derive(Debug)] diff --git a/tracker/agb-tracker/examples/basic.rs b/tracker/agb-tracker/examples/basic.rs index 2f7d7139..2835a2c0 100644 --- a/tracker/agb-tracker/examples/basic.rs +++ b/tracker/agb-tracker/examples/basic.rs @@ -11,14 +11,35 @@ const DB_TOFFE: Track = import_xm!("examples/db_toffe.xm"); fn main(mut gba: Gba) -> ! { let vblank_provider = agb::interrupt::VBlank::get(); + let timer_controller = gba.timers.timers(); + let mut timer = timer_controller.timer2; + let mut timer2 = timer_controller.timer3; + timer.set_enabled(true); + timer2.set_cascade(true).set_enabled(true); + let mut mixer = gba.mixer.mixer(Frequency::Hz18157); mixer.enable(); let mut tracker = Tracker::new(&DB_TOFFE); loop { + let before_mixing_cycles_high = timer2.value(); + let before_mixing_cycles_low = timer.value(); + tracker.step(&mut mixer); + mixer.frame(); + let after_mixing_cycles_low = timer.value(); + let after_mixing_cycles_high = timer2.value(); + vblank_provider.wait_for_vblank(); + + let before_mixing_cycles = + ((before_mixing_cycles_high as u32) << 16) + before_mixing_cycles_low as u32; + let after_mixing_cycles = + ((after_mixing_cycles_high as u32) << 16) + after_mixing_cycles_low as u32; + let total_cycles = after_mixing_cycles.wrapping_sub(before_mixing_cycles); + + agb::println!("{total_cycles} cycles"); } } diff --git a/tracker/agb-tracker/src/lib.rs b/tracker/agb-tracker/src/lib.rs index 903feebf..f3c1b4c9 100644 --- a/tracker/agb-tracker/src/lib.rs +++ b/tracker/agb-tracker/src/lib.rs @@ -29,8 +29,8 @@ pub struct Tracker { track: &'static Track<'static>, channels: Vec, - frame: Num, - tick: u16, + frame: Num, + tick: u32, first: bool, current_row: usize, @@ -164,7 +164,7 @@ impl TrackerChannel { &mut self, mixer: &mut Mixer<'_>, effect: &PatternEffect, - tick: u16, + tick: u32, speed: Num, ) { if let Some(channel) = self diff --git a/tracker/agb-xm-core/src/lib.rs b/tracker/agb-xm-core/src/lib.rs index f47d20bb..da3fc4f8 100644 --- a/tracker/agb-xm-core/src/lib.rs +++ b/tracker/agb-xm-core/src/lib.rs @@ -272,7 +272,7 @@ pub fn parse_module(module: &Module) -> TokenStream { .collect::>(); // Number 150 here deduced experimentally - let frames_per_tick = Num::::new(150) / module.default_bpm; + let frames_per_tick = Num::::new(150) / module.default_bpm as u32; let ticks_per_step = module.default_tempo; let interop = agb_tracker_interop::Track { @@ -283,7 +283,7 @@ pub fn parse_module(module: &Module) -> TokenStream { patterns_to_play: &patterns_to_play, frames_per_tick, - ticks_per_step, + ticks_per_step: ticks_per_step.into(), }; quote!(#interop)