From f4779208e34d4205ca8f15e503689be3e68464d6 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 27 Jun 2023 21:48:01 +0100 Subject: [PATCH] Implement first cases for the non stereo --- agb/src/sound/mixer/mixer.s | 29 +++++++++++++++++++++-------- agb/src/sound/mixer/sw_mixer.rs | 10 +++++++++- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/agb/src/sound/mixer/mixer.s b/agb/src/sound/mixer/mixer.s index 5806373c..254699c6 100644 --- a/agb/src/sound/mixer/mixer.s +++ b/agb/src/sound/mixer/mixer.s @@ -4,7 +4,8 @@ agb_rs__buffer_size: .word 0 -agb_arm_func agb_rs__mixer_add +.macro mixer_add 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) @@ -18,9 +19,9 @@ agb_arm_func agb_rs__mixer_add ldr r7, [sp, #20] @ load the right channel modification amount into r7 cmp r7, r3 @ check if left and right channel need the same modifications - beq .Lsame_modification + beq 3f @ same modification -.Lmodifications_fallback: +4: @ modification fallback orr r7, r7, r3, lsl #16 @ r7 now is the left channel followed by the right channel modifications. mov r5, #0 @ current index we're reading from @@ -34,9 +35,12 @@ agb_arm_func agb_rs__mixer_add ldrsb r6, [r4] @ load the current sound sample to r6 add r5, r5, r2 @ calculate the position to read the next sample from +.ifc is_first,true + mul r4, r6, r7 @ r4 = r6 * r7 (calculating both the left and right samples together) +.else ldr r4, [r1] @ read the current value - mla r4, r6, r7, r4 @ r4 += r6 * r7 (calculating both the left and right samples together) +.endif str r4, [r1], #4 @ store the new value, and increment the pointer .endr @@ -47,13 +51,13 @@ agb_arm_func agb_rs__mixer_add pop {{r4-r8}} bx lr -.Lsame_modification: +3: @ same modification @ check to see if this is a perfect power of 2 @ r5 is a scratch register, r7 = r3 = amount to modify sub r5, r7, #1 ands r5, r5, r7 - bne .Lmodifications_fallback @ not 0 means we need to do the full modification + bne 4b @ not 0 means we need to do the full modification, jump to modification fallback @ count leading zeros of r7 into r3 mov r3, #0 @@ -74,11 +78,16 @@ agb_arm_func agb_rs__mixer_add ldrsb r6, [r4] @ load the current sound sample to r6 add r5, r5, r2 @ calculate the position to read the next sample from - ldr r4, [r1] @ read the current value lsl r6, r6, #16 orr r6, r6, lsr #16 + +.ifc is_first,true + mov r4, r6, lsl r3 @ r4 = r6 << r3 +.else + ldr r4, [r1] @ read the current value add r4, r4, r6, lsl r3 @ r4 += r6 << r3 (calculating both the left and right samples together) +.endif str r4, [r1], #4 @ store the new value, and increment the pointer .endr @@ -89,7 +98,11 @@ agb_arm_func agb_rs__mixer_add pop {{r4-r8}} bx lr -agb_arm_end agb_rs__mixer_add +agb_arm_end \fn_name +.endm + +mixer_add agb_rs__mixer_add false +mixer_add agb_rs__mixer_add_first true .macro stereo_add_fn fn_name:req is_first:req agb_arm_func \fn_name diff --git a/agb/src/sound/mixer/sw_mixer.rs b/agb/src/sound/mixer/sw_mixer.rs index efa4ce23..ffa637f3 100644 --- a/agb/src/sound/mixer/sw_mixer.rs +++ b/agb/src/sound/mixer/sw_mixer.rs @@ -29,6 +29,14 @@ extern "C" { right_amount: Num, ); + fn agb_rs__mixer_add_first( + sound_data: *const u8, + sound_buffer: *mut Num, + playback_speed: Num, + left_amount: Num, + right_amount: Num, + ); + fn agb_rs__mixer_add_stereo( sound_data: *const u8, sound_buffer: *mut Num, @@ -412,7 +420,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 {