mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-25 01:01:34 +11:00
Attempt to support changing the volume of stereo sound
This commit is contained in:
parent
3d579390c8
commit
a5e0e145d2
|
@ -95,10 +95,12 @@ agb_arm_func agb_rs__mixer_add_stereo
|
||||||
@ 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)
|
||||||
|
@ r2 - volume to play the sound at
|
||||||
@
|
@
|
||||||
@ The sound buffer must be SOUND_BUFFER_SIZE * 2 in size = 176 * 2
|
@ The sound buffer must be SOUND_BUFFER_SIZE * 2 in size = 176 * 2
|
||||||
push {r4-r8}
|
push {r4-r9}
|
||||||
|
|
||||||
|
mov r9, r2
|
||||||
ldr r5, =0x00000FFF
|
ldr r5, =0x00000FFF
|
||||||
|
|
||||||
ldr r8, =agb_rs__buffer_size
|
ldr r8, =agb_rs__buffer_size
|
||||||
|
@ -128,7 +130,7 @@ agb_arm_func agb_rs__mixer_add_stereo
|
||||||
lsl r6, r6, #24 @ r6 = | R | 0 | 0 | 0 | drop everything except the right sample
|
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
|
orr r6, r7, r6, asr #8 @ r6 = | 1 | R | 1 | L | now we have it perfectly set up
|
||||||
|
|
||||||
add r4, r4, r6, lsl #4 @ r4 += r6 << 4 (calculating both the left and right samples together)
|
mla r4, r6, r9, r4 @ r4 += r6 * r9 (calculating both the left and right samples together)
|
||||||
|
|
||||||
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
|
||||||
|
@ -136,7 +138,7 @@ agb_arm_func agb_rs__mixer_add_stereo
|
||||||
subs r8, r8, #4 @ loop counter
|
subs r8, r8, #4 @ loop counter
|
||||||
bne 1b @ jump back if we're done with the loop
|
bne 1b @ jump back if we're done with the loop
|
||||||
|
|
||||||
pop {r4-r8}
|
pop {r4-r9}
|
||||||
bx lr
|
bx lr
|
||||||
|
|
||||||
agb_arm_end agb_rs__mixer_add_stereo
|
agb_arm_end agb_rs__mixer_add_stereo
|
||||||
|
|
|
@ -25,7 +25,11 @@ extern "C" {
|
||||||
right_amount: Num<i16, 4>,
|
right_amount: Num<i16, 4>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn agb_rs__mixer_add_stereo(sound_data: *const u8, sound_buffer: *mut Num<i16, 4>);
|
fn agb_rs__mixer_add_stereo(
|
||||||
|
sound_data: *const u8,
|
||||||
|
sound_buffer: *mut Num<i16, 4>,
|
||||||
|
volume: Num<i16, 4>,
|
||||||
|
);
|
||||||
|
|
||||||
fn agb_rs__mixer_collapse(sound_buffer: *mut i8, input_buffer: *const Num<i16, 4>);
|
fn agb_rs__mixer_collapse(sound_buffer: *mut i8, input_buffer: *const Num<i16, 4>);
|
||||||
}
|
}
|
||||||
|
@ -447,6 +451,7 @@ impl MixerBuffer {
|
||||||
agb_rs__mixer_add_stereo(
|
agb_rs__mixer_add_stereo(
|
||||||
channel.data.as_ptr().add(channel.pos.floor()),
|
channel.data.as_ptr().add(channel.pos.floor()),
|
||||||
buffer.as_mut_ptr(),
|
buffer.as_mut_ptr(),
|
||||||
|
channel.volume,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue