Use 32-bit numbers more for more performance (and start tracking that)

This commit is contained in:
Gwilym Inzani 2023-07-18 22:49:56 +01:00
parent b8adf08382
commit 6f8633861d
4 changed files with 28 additions and 7 deletions

View file

@ -10,8 +10,8 @@ pub struct Track<'a> {
pub patterns_to_play: &'a [usize],
pub num_channels: usize,
pub frames_per_tick: Num<u16, 8>,
pub ticks_per_step: u16,
pub frames_per_tick: Num<u32, 8>,
pub ticks_per_step: u32,
}
#[derive(Debug)]

View file

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

View file

@ -29,8 +29,8 @@ pub struct Tracker {
track: &'static Track<'static>,
channels: Vec<TrackerChannel>,
frame: Num<u16, 8>,
tick: u16,
frame: Num<u32, 8>,
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<u32, 8>,
) {
if let Some(channel) = self

View file

@ -272,7 +272,7 @@ pub fn parse_module(module: &Module) -> TokenStream {
.collect::<Vec<_>>();
// Number 150 here deduced experimentally
let frames_per_tick = Num::<u16, 8>::new(150) / module.default_bpm;
let frames_per_tick = Num::<u32, 8>::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)