mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 09:31:34 +11:00
Have the constants only in one place
This commit is contained in:
parent
a514625122
commit
26620e850e
|
@ -64,5 +64,5 @@ b .Initialise_mb
|
|||
b 1b
|
||||
.pool
|
||||
|
||||
.include "src/sound/mixer/mixer.s"
|
||||
.include "interrupt_handler.s"
|
||||
.include "src/sound/mixer/mixer.s"
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
.equ SOUND_BUFFER_SIZE, 176
|
||||
.section .iwram
|
||||
.global agb_rs__buffer_size
|
||||
.balign 4
|
||||
agb_rs__buffer_size:
|
||||
.word
|
||||
|
||||
agb_arm_func agb_rs__mixer_add
|
||||
@ Arguments
|
||||
|
@ -19,8 +23,8 @@ agb_arm_func agb_rs__mixer_add
|
|||
modifications_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
|
||||
mov r8, #SOUND_BUFFER_SIZE @ the number of steps left
|
||||
mov r5, #0 @ current index we're reading from
|
||||
ldr r8, agb_rs__buffer_size @ the number of steps left
|
||||
|
||||
|
||||
1:
|
||||
|
@ -62,8 +66,8 @@ same_modification:
|
|||
lsrs r7, r7, #1
|
||||
bne 1b
|
||||
|
||||
mov r5, #0 @ current index we're reading from
|
||||
mov r8, #SOUND_BUFFER_SIZE @ the number of steps left
|
||||
mov r5, #0 @ current index we're reading from
|
||||
ldr r8, agb_rs__buffer_size @ the number of steps left
|
||||
|
||||
.macro mixer_add_loop_simple
|
||||
add r4, r0, r5, asr #8 @ calculate the address of the next read from the sound buffer
|
||||
|
@ -132,7 +136,7 @@ agb_arm_func agb_rs__mixer_add_stereo
|
|||
str r4, [r1], #4 @ store the new value, and increment the pointer
|
||||
.endm
|
||||
|
||||
mov r8, #SOUND_BUFFER_SIZE
|
||||
ldr r8, agb_rs__buffer_size
|
||||
1:
|
||||
mixer_add_loop_simple_stereo
|
||||
mixer_add_loop_simple_stereo
|
||||
|
@ -159,8 +163,10 @@ 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)
|
||||
push {r4}
|
||||
|
||||
mov r2, #SOUND_BUFFER_SIZE @ loop counter
|
||||
ldr r2, agb_rs__buffer_size @ loop counter
|
||||
mov r4, r2
|
||||
|
||||
1:
|
||||
@ r12 = *r1; r1++
|
||||
|
@ -173,11 +179,12 @@ agb_arm_func agb_rs__mixer_collapse
|
|||
clamp_s8 r12 @ clamp the audio to 8 bit values
|
||||
clamp_s8 r3
|
||||
|
||||
strb r3, [r0, #SOUND_BUFFER_SIZE] @ *(r0 + SOUND_BUFFER_SIZE) = r3
|
||||
strb r3, [r0, r4] @ *(r0 + r4 = SOUND_BUFFER_SIZE) = r3
|
||||
strb r12, [r0], #1 @ *r0 = r12; r0++
|
||||
|
||||
subs r2, r2, #1 @ r2 -= 1
|
||||
bne 1b @ loop if not 0
|
||||
|
||||
pop {r4}
|
||||
bx lr
|
||||
agb_arm_end agb_rs__mixer_collapse
|
||||
agb_arm_end agb_rs__mixer_collapse
|
||||
|
|
|
@ -94,6 +94,16 @@ impl Mixer {
|
|||
const SOUND_FREQUENCY: i32 = 10512;
|
||||
const SOUND_BUFFER_SIZE: usize = 176;
|
||||
|
||||
fn set_asm_buffer_size() {
|
||||
extern "C" {
|
||||
static mut agb_rs__buffer_size: usize;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
agb_rs__buffer_size = SOUND_BUFFER_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C, align(4))]
|
||||
struct SoundBuffer([i8; SOUND_BUFFER_SIZE * 2]);
|
||||
|
||||
|
@ -106,6 +116,8 @@ struct MixerBuffer {
|
|||
|
||||
impl MixerBuffer {
|
||||
fn new() -> Self {
|
||||
set_asm_buffer_size();
|
||||
|
||||
MixerBuffer {
|
||||
buffer1: SoundBuffer([0; SOUND_BUFFER_SIZE * 2]),
|
||||
buffer2: SoundBuffer([0; SOUND_BUFFER_SIZE * 2]),
|
||||
|
|
Loading…
Reference in a new issue