7 @@@@@@@@@@@@@@@@@@@@@@@@@@@@
8 @ Function called with:
9 @ r0 - Raw brr data (s8*)
10 @ r1 - Decoded sample data (s16*)
11 @ r2 - DspChannel *channel
12 @@@@@@@@@@@@@@@@@@@@@@@@@@@@
18 @ r9 - number of iterations left
28 .GLOBAL DecodeSampleBlockAsm
30 stmfd sp!, {r4-r12,r14}
32 @ Save the channel pointer
35 /* @ Hash the block, and skip the decode if we can
37 ldr r8, =0x050C5D1F @ (2166136261 * 16777619)
45 @ r8 is the hashed value
49 @ Compute the actual brr location minus the apu ram base
54 @ Compute the address of the cached samples in brrHash
57 add r3, r3, r6, lsl #5
59 @ Load the previous hash value
60 ldr r5, [r4, r6, lsl #2]
61 str r8, [r4, r6, lsl #2]
65 @ Load the cached samples
82 @ Compute the index into the brrTab to load the bytes from
85 add r8, r8, r9, lsl #5 @ brrTabPtr = brrTab + (r4 * 32)
91 @ 16 samples to decode, but do two at a time
93 @ Figure out the type of decode filter
96 ldr pc, [pc, r4, lsl #2]
104 and r5, r10, r4, lsl #1
106 and r4, r10, r4, lsr #3
125 and r5, r10, r4, lsl #1
127 and r4, r10, r4, lsr #3
130 @ r3 = r4 + (last1 >> 1) - (last1 >> 5)
131 add r3, r4, r2, asr #1
132 sub r3, r3, r2, asr #5
144 add r2, r5, r3, asr #1
145 sub r2, r2, r3, asr #5
163 and r5, r10, r4, lsl #1
165 and r4, r10, r4, lsr #3
170 rsb r6, r6, r3, asr #5
172 add r7, r2, r2, asr #1
174 add r6, r6, r7, asr #5
188 rsb r6, r6, r3, asr #5
190 add r7, r2, r2, asr #1
192 add r6, r6, r7, asr #5
211 and r5, r10, r4, lsl #1
213 and r4, r10, r4, lsr #3
217 add r6, r3, r3, asr #1
219 sub r6, r6, r3, asr #1
221 add r7, r2, r2, lsl #2
222 add r7, r7, r2, lsl #3
224 add r6, r6, r7, asr #7
237 add r6, r3, r3, asr #1
239 sub r6, r6, r3, asr #1
241 add r7, r2, r2, lsl #2
242 add r7, r7, r2, lsl #3
244 add r6, r6, r7, asr #7
270 ldmfd sp!, {r4-r12,r14}
273 #define ENVSTATE_INCREASE 6
274 #define ENVSTATE_BENTLINE 7
275 #define ENVSTATE_DECREASE 8
276 #define ENVSTATE_DECEXP 9
278 @@@@@@@@@@@@@@@@@@@@@@@@@@@@
279 @ Function called with:
280 @ r0 - int Number of samples to mix
281 @ r1 - u16* mix buffer (left first, right is always 4000 * 4 bytes ahead
282 @@@@@@@@@@@@@@@@@@@@@@@@@@@@
284 #define PREVDECODE_OFFSET 16
285 #define BLOCKPOS_OFFSET 66
286 #define KEYWAIT_OFFSET 76
288 @ r0 - channel structure base
290 @ r2 - echo buffer ptr
296 @ r8 - sampleValue (value of the current sample)
304 .GLOBAL DspMixSamplesStereo
305 .FUNC DspMixSamplesStereo
307 stmfd sp!, {r4-r12, lr}
313 @ Store the original mix buffer for use later
316 @ Clear the left and right mix buffers, saving their initial positions
332 @ Load the initial mix buffer and echo position
338 @ Check if active == 0, then next
341 beq nextChannelNothingDone
343 @ Save the start position of the mix buffer & echo buffer
346 @ Get echo enabled, then replace the opcode there if it's enabled
349 ldr r3, =0x01A00000 @ mov r0, r0
350 streq r3, branchLocation
353 @ Load the important variables into registers
360 @ Commence the mixing
370 ldr pc, [pc, r12, lsl #2]
372 @ Jump table for envelope handling
373 .word noEnvelopeUpdate
376 .word envStateSustain
377 .word envStateRelease
378 .word noEnvelopeUpdate @ Actually direct, but we don't need to do anything
379 .word envStateIncrease
380 .word envStateBentline
381 .word envStateDecrease
382 .word envStateSustain @ Actually decrease exponential, but it's the same code
389 @ envx = 0x7f, state = decay, speed = decaySpeed
397 rsb r9, r9, r9, lsl #8
403 @ state = sustain, speed = sustainSpeed
412 @ If not, end channel, then go to next channel
413 stmfd sp!, {r0-r3, r14}
416 ldmfd sp!, {r0-r3, r14}
420 rsb r9, r9, r9, lsl #8
427 @ If not, end channel, then go to next channel
428 stmfd sp!, {r0-r3,r14}
431 ldmfd sp!, {r0-r3,r14}
441 @ If not, end channel, then go to next channel
442 stmfd sp!, {r0-r3,r14}
445 ldmfd sp!, {r0-r3,r14}
453 @ envx = 0x7f, state = direct, speed = 0
462 addgt r9, r9, #1 << 8
463 addle r9, r9, #4 << 8
467 @ envx = 0x7f, state = direct, speed = 0
481 @ If not, end channel, then go to next channel
482 stmfd sp!, {r0-r3,r14}
485 ldmfd sp!, {r0-r3,r14}
491 @ Recalculate leftCalcVol and rightCalcVol
505 @ Decode next 16 bytes...
506 sub r5, r5, #16 << 12
508 @ Decode the sample block, r0 = DspChannel*
509 stmfd sp!, {r0-r3, r14}
512 ldmfd sp!, {r0-r3, r14}
516 @ This is really a >> 12 then << 1, but since samplePos bit 0 will never be set, it's safe.
517 @ Must ensure that sampleSpeed bit 0 is never set, and samplePos is never set to anything but 0
518 @ TODO - The speed up hack doesn't work. Find out why
520 add r12, r0, r12, lsl #1
553 add r12, r12, r3, lsl #4
568 @ Store changing values
571 @ Reload mix&echo buffer position
574 nextChannelNothingDone:
575 @ Move to next channel
578 @ Increment channelNum
585 @ This is the end of normal mixing
588 @ Store the original mix & echo buffers, cause we trash these regs
596 @ r5 - echo volume (right)
598 @ r7 - echo in apu ram (r/w)
599 @ r8 - echo mix buffer (r/w)
600 @ r9 - end of echo in apu ram
601 @ r10 - echo volume (left)
602 @ r11 - echo feedback
603 @ r12 - FIR coefficients in DSP ram
604 @ r13 - FIR table base
607 @ Process the echo filter stuff
613 ldrsb r10, [r0, #0x2C] @ Get left echo volume
615 ldrsb r5, [r0, #0x3C] @ Get right echo volume
619 ldrsb r11, [r0, #0x0D]
621 @ Check if echo is enabled
624 @ Get echo base (APU_MEM + DSP_ESA << 8)
627 str r7, echoBufferStart
628 @ Set up end of echo delay area in r8
633 @ Set up current echo cursor location
643 @ Offset firTable to start at FIR #7
650 @ Load the old echo value (l,r)
654 /* @ Increment and wrap firOffset
656 and r14, r14, #(8 * 2) - 1
658 @ Get &firTable[firOffset + 8] into r13
659 ldr r13, =firTable + ((8 * 2) * 4)
660 add r13, r13, r14, lsl #2
662 @ Store the computed samples in the FIR ring buffer
665 str r0, [r13, #-8 * 2 * 4]
666 str r1, [r13, #(-8 * 2 * 4) + 4]
668 @ Process FIR sample 0 (special)
671 ldrsb r4, [r12], #-0x10
678 ldrsb r4, [r12], #-0x10
689 @ Last FIR sample (special)
692 ldrsb r4, [r12], #0x70
697 @ Get rid of volume multiplication stuff
701 @ r0,r1 contains the filtered samples
703 @ Left channel = (feedback * filtered) >> 7
708 @ Right channel = (feedback * filtered) >> 7
712 @ Store (filtered * echoFB) + echobuffer into echobuffer
718 ldrge r7, echoBufferStart
720 @ Store (filtered * echoVol) into echomix
733 @ Store changed values
737 ldr r3, echoBufferStart
742 @ Reload mix buffer & echo positions
748 @ Put the original output buffer into r3
751 @ Set up the preamp & overall volume
756 ldrsb r4, [r9, #0x0C] @ Main left volume
757 ldrsb r6, [r9, #0x1C] @ Main right volume
769 @ r5 - TMP (assigned to sample value)
779 @ Do volume multiplication, mix in echo buffer and clipping here
783 @ Load and scale by volume (LEFT)
788 add r5, r5, r7, asr #7
797 add r3, r3, #4000 * 4
799 @ Load and scale by volume (RIGHT)
804 add r5, r5, r7, asr #7
813 sub r3, r3, #4000 * 4
819 ldmfd sp!, {r4-r12, lr}