From 306be59cdea49c5d96aa6ede598b9e15353f8819 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 27 Jun 2023 21:31:06 +0100 Subject: [PATCH] Add implementation for if this is the first --- agb/src/sound/mixer/mixer.s | 17 +++++++++++++++-- agb/src/sound/mixer/sw_mixer.rs | 8 +++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/agb/src/sound/mixer/mixer.s b/agb/src/sound/mixer/mixer.s index 2299a22b..4fb974c8 100644 --- a/agb/src/sound/mixer/mixer.s +++ b/agb/src/sound/mixer/mixer.s @@ -91,7 +91,8 @@ same_modification: agb_arm_end agb_rs__mixer_add -agb_arm_func agb_rs__mixer_add_stereo +.macro stereo_add_fn fn_name:req is_first:req +agb_arm_func \fn_name @ Arguments @ r0 - pointer to the data to be copied (u8 array) @ r1 - pointer to the sound buffer (i16 array which will alternate left and right channels, 32-bit aligned) @@ -127,16 +128,24 @@ agb_arm_func agb_rs__mixer_add_stereo lsl r6, r6, #24 @ r6 = | R | 0 | 0 | 0 | drop everything except the right sample orr r6, r7, r6, asr #8 @ r6 = | 1 | R | 1 | L | now we have it perfectly set up +.ifc \is_first,true + mul \sample_reg, r6, r2 +.else mla \sample_reg, r6, r2, \sample_reg @ r4 += r6 * r2 (calculating both the left and right samples together) +.endif .endm 1: +.ifc \is_first,true +.else ldmia r1, {{r9-r12}} @ read the current values +.endif add_stereo_sample r9 add_stereo_sample r10 add_stereo_sample r11 add_stereo_sample r12 +.purgem add_stereo_sample stmia r1!, {{r9-r12}} @ store the new value, and increment the pointer @@ -146,7 +155,11 @@ agb_arm_func agb_rs__mixer_add_stereo pop {{r4-r11}} bx lr -agb_arm_end agb_rs__mixer_add_stereo +agb_arm_end \fn_name +.endm + +stereo_add_fn agb_rs__mixer_add_stereo false +stereo_add_fn agb_rs__mixer_add_stereo_first true agb_arm_func agb_rs__mixer_collapse @ Arguments: diff --git a/agb/src/sound/mixer/sw_mixer.rs b/agb/src/sound/mixer/sw_mixer.rs index 387c67fb..efa4ce23 100644 --- a/agb/src/sound/mixer/sw_mixer.rs +++ b/agb/src/sound/mixer/sw_mixer.rs @@ -35,6 +35,12 @@ extern "C" { volume: Num, ); + fn agb_rs__mixer_add_stereo_first( + sound_data: *const u8, + sound_buffer: *mut Num, + volume: Num, + ); + fn agb_rs__mixer_collapse( sound_buffer: *mut i8, input_buffer: *const Num, @@ -406,7 +412,7 @@ impl MixerBuffer { working_buffer: &mut [Num], channels: impl Iterator, ) { - working_buffer.fill(0.into()); + // working_buffer.fill(0.into()); for channel in channels { if channel.is_done {