From b2dcd8c8547a743cb94f27e60ce684275a7f6f23 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Sun, 18 Jun 2023 16:02:14 +0100 Subject: [PATCH] Pass buffer size as an argument --- agb/src/sound/mixer/mixer.s | 3 +-- agb/src/sound/mixer/sw_mixer.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/agb/src/sound/mixer/mixer.s b/agb/src/sound/mixer/mixer.s index 28d58e58..66bec925 100644 --- a/agb/src/sound/mixer/mixer.s +++ b/agb/src/sound/mixer/mixer.s @@ -152,6 +152,7 @@ agb_arm_func agb_rs__mixer_collapse @ Arguments: @ r0 = target buffer (i8) @ r1 = input buffer (i16) of fixnums with 4 bits of precision (read in sets of i16 in an i32) + @ r2 = loop counter push {{r4-r11,lr}} @@ -164,8 +165,6 @@ SWAP_SIGN .req r11 ldr CONST_127, =127 ldr SWAP_SIGN, =0x80808080 - ldr r2, =agb_rs__buffer_size @ loop counter - ldr r2, [r2] mov r4, r2 @ The idea for this solution came from pimpmobile: diff --git a/agb/src/sound/mixer/sw_mixer.rs b/agb/src/sound/mixer/sw_mixer.rs index 1962fef9..5c01181b 100644 --- a/agb/src/sound/mixer/sw_mixer.rs +++ b/agb/src/sound/mixer/sw_mixer.rs @@ -35,7 +35,11 @@ extern "C" { volume: Num, ); - fn agb_rs__mixer_collapse(sound_buffer: *mut i8, input_buffer: *const Num); + fn agb_rs__mixer_collapse( + sound_buffer: *mut i8, + input_buffer: *const Num, + num_samples: usize, + ); } /// The main software mixer struct. @@ -458,7 +462,11 @@ impl MixerBuffer { let write_buffer = free(|cs| self.state.borrow(cs).borrow_mut().active_advanced()); unsafe { - agb_rs__mixer_collapse(write_buffer, working_buffer.as_ptr()); + agb_rs__mixer_collapse( + write_buffer, + working_buffer.as_ptr(), + self.frequency.buffer_size(), + ); } } }