-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#368 GBA sound samples and music playback optimization
- Loading branch information
Showing
8 changed files
with
300 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "common_asm.inc" | ||
|
||
state .req r0 | ||
buffer .req r1 | ||
data .req r2 | ||
size .req r3 | ||
smp .req r4 | ||
idx .req r5 | ||
stepLUT .req r6 | ||
step .req r7 | ||
n .req r8 | ||
index .req r9 | ||
outA .req r12 | ||
outB .req lr | ||
tmp .req outB | ||
|
||
IMA_STEP_SIZE = 88 | ||
|
||
.macro decode4 n, out | ||
ldr step, [stepLUT, idx, lsl #2] | ||
|
||
and index, \n, #7 | ||
mov tmp, step, lsl #1 | ||
mla step, index, tmp, step | ||
tst \n, #8 | ||
subne smp, smp, step, lsr #3 | ||
addeq smp, smp, step, lsr #3 | ||
|
||
subs index, #3 | ||
suble idx, idx, #1 | ||
bicle idx, idx, idx, asr #31 | ||
addgt idx, idx, index, lsl #1 | ||
cmpgt idx, #IMA_STEP_SIZE | ||
movgt idx, #IMA_STEP_SIZE | ||
|
||
mov \out, smp, asr #2 | ||
.endm | ||
|
||
.global sndIMA_asm | ||
sndIMA_asm: | ||
stmfd sp!, {r4-r9, lr} | ||
|
||
ldmia state, {smp, idx} | ||
|
||
ldr stepLUT, =IMA_STEP | ||
|
||
.loop: | ||
ldrb n, [data], #1 | ||
|
||
decode4 n, outA | ||
|
||
mov n, n, lsr #4 | ||
|
||
decode4 n, outB | ||
|
||
stmia buffer!, {outA, outB} | ||
|
||
subs size, #1 | ||
bne .loop | ||
|
||
stmia state, {smp, idx} | ||
|
||
ldmfd sp!, {r4-r9, lr} | ||
bx lr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "common_asm.inc" | ||
|
||
pos .req r0 | ||
inc .req r1 | ||
size .req r2 | ||
volume .req r3 | ||
|
||
data .req r4 | ||
buffer .req r5 | ||
count .req r6 | ||
ampA .req r7 | ||
ampB .req r8 | ||
outA .req r9 | ||
outB .req r12 | ||
last .req count | ||
tmp .req outB | ||
|
||
.global sndPCM_asm | ||
sndPCM_asm: | ||
mov tmp, sp | ||
stmfd sp!, {r4-r9} | ||
|
||
ldmia tmp, {data, buffer, count} | ||
|
||
mla last, inc, count, pos | ||
cmp last, size | ||
movgt last, size | ||
|
||
.loop: | ||
ldrb ampA, [data, pos, lsr #8] | ||
add pos, pos, inc | ||
ldrb ampB, [data, pos, lsr #8] | ||
add pos, pos, inc | ||
cmp pos, last | ||
|
||
sub ampA, ampA, #128 | ||
sub ampB, ampB, #128 | ||
|
||
ldmia buffer, {outA, outB} | ||
mla outA, volume, ampA, outA | ||
mla outB, volume, ampB, outB | ||
stmia buffer!, {outA, outB} | ||
|
||
blt .loop | ||
|
||
.done: | ||
ldmfd sp!, {r4-r9} | ||
bx lr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "common_asm.inc" | ||
|
||
buffer .req r0 | ||
count .req r1 | ||
data .req r2 | ||
vA .req r3 | ||
vB .req r4 | ||
vC .req r5 | ||
vD .req r12 | ||
|
||
SND_VOL_SHIFT = 6 | ||
|
||
.macro encode amp | ||
mov \amp, \amp, asr #SND_VOL_SHIFT | ||
cmp \amp, #-128 | ||
movlt \amp, #-128 | ||
cmp \amp, #127 | ||
movgt \amp, #127 | ||
.endm | ||
|
||
.global sndWrite_asm | ||
sndWrite_asm: | ||
stmfd sp!, {r4-r5} | ||
.loop: | ||
ldmia data!, {vA, vB, vC, vD} | ||
|
||
encode vA | ||
encode vB | ||
encode vC | ||
encode vD | ||
|
||
and vA, vA, #0xFF | ||
and vB, vB, #0xFF | ||
and vC, vC, #0xFF | ||
orr vA, vA, vB, lsl #8 | ||
orr vA, vA, vC, lsl #16 | ||
orr vA, vA, vD, lsl #24 | ||
str vA, [buffer], #4 | ||
|
||
subs count, #4 | ||
bne .loop | ||
|
||
ldmfd sp!, {r4-r5} | ||
bx lr |
Oops, something went wrong.