Implement first cases for the non stereo

This commit is contained in:
Gwilym Inzani 2023-06-27 21:48:01 +01:00
parent e1d03929f9
commit f4779208e3
2 changed files with 30 additions and 9 deletions

View file

@ -4,7 +4,8 @@
agb_rs__buffer_size: agb_rs__buffer_size:
.word 0 .word 0
agb_arm_func agb_rs__mixer_add .macro mixer_add fn_name:req is_first:req
agb_arm_func \fn_name
@ Arguments @ Arguments
@ r0 - pointer to the data to be copied (u8 array) @ 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) @ 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 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 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. 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 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 ldrsb r6, [r4] @ load the current sound sample to r6
add r5, r5, r2 @ calculate the position to read the next sample from 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 ldr r4, [r1] @ read the current value
mla r4, r6, r7, r4 @ r4 += r6 * r7 (calculating both the left and right samples together) 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 str r4, [r1], #4 @ store the new value, and increment the pointer
.endr .endr
@ -47,13 +51,13 @@ agb_arm_func agb_rs__mixer_add
pop {{r4-r8}} pop {{r4-r8}}
bx lr bx lr
.Lsame_modification: 3: @ same modification
@ check to see if this is a perfect power of 2 @ check to see if this is a perfect power of 2
@ r5 is a scratch register, r7 = r3 = amount to modify @ r5 is a scratch register, r7 = r3 = amount to modify
sub r5, r7, #1 sub r5, r7, #1
ands r5, r5, r7 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 @ count leading zeros of r7 into r3
mov r3, #0 mov r3, #0
@ -74,11 +78,16 @@ agb_arm_func agb_rs__mixer_add
ldrsb r6, [r4] @ load the current sound sample to r6 ldrsb r6, [r4] @ load the current sound sample to r6
add r5, r5, r2 @ calculate the position to read the next sample from add r5, r5, r2 @ calculate the position to read the next sample from
ldr r4, [r1] @ read the current value
lsl r6, r6, #16 lsl r6, r6, #16
orr r6, r6, lsr #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) 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 str r4, [r1], #4 @ store the new value, and increment the pointer
.endr .endr
@ -89,7 +98,11 @@ agb_arm_func agb_rs__mixer_add
pop {{r4-r8}} pop {{r4-r8}}
bx lr 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 .macro stereo_add_fn fn_name:req is_first:req
agb_arm_func \fn_name agb_arm_func \fn_name

View file

@ -29,6 +29,14 @@ extern "C" {
right_amount: Num<i16, 4>, right_amount: Num<i16, 4>,
); );
fn agb_rs__mixer_add_first(
sound_data: *const u8,
sound_buffer: *mut Num<i16, 4>,
playback_speed: Num<u32, 8>,
left_amount: Num<i16, 4>,
right_amount: Num<i16, 4>,
);
fn agb_rs__mixer_add_stereo( fn agb_rs__mixer_add_stereo(
sound_data: *const u8, sound_data: *const u8,
sound_buffer: *mut Num<i16, 4>, sound_buffer: *mut Num<i16, 4>,
@ -412,7 +420,7 @@ impl MixerBuffer {
working_buffer: &mut [Num<i16, 4>], working_buffer: &mut [Num<i16, 4>],
channels: impl Iterator<Item = &'a mut SoundChannel>, channels: impl Iterator<Item = &'a mut SoundChannel>,
) { ) {
// working_buffer.fill(0.into()); working_buffer.fill(0.into());
for channel in channels { for channel in channels {
if channel.is_done { if channel.is_done {