Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SND_PaintChannelFrom8:
- // r0: int true_lvol
- // r1: int true_rvol
- // r2: char *sfx
- // r3: int count
- stmfd sp!, {r4, r5, r6, r7, r8, r10}
- ldr ip, =paintbuffer
- ldr ip, [ip]
- sub r3, r3, #1 // we'll count backwards
- mov r0, r0, asl #16 // pre-scale both volumes by 2^16
- mov r1, r1, asl #16
- // r10 = 0xffff0000
- ldrh r10, =0xffff
- .loop:
- ldrsb r4, [r2, r3] // load *sfx[i] -> r4
- // keep endianness in mind here
- // buffer looks like [left_0, left_1, right_0, right_1] in memory
- // but it is loaded as [right1, right0, left1, left0] to registers
- ldr r8, [ip, r3, lsl #2] // load paintbuffer[0:1] = RIGHTCHANNEL:LEFTCHANNEL
- // handle high half (right channel) first
- mul r5, r4, r1 // SCALEDRIGHT = SFXI * (true_rvol << 16) -- bottom half is zero
- // r7 holds right channel in high half (dirty bottom half)
- qadd r7, r5, r8 // RIGHTCHANORIG = SCALEDRIGHT + RIGHTCHANORIG (high half)
- bic r7, r7, r10 // zero bottom bits of r7
- // trash r5, r6 and handle left channel
- mul r5, r4, r0 // SCALEDLEFT = SFXI * (true_rvol << 16)
- mov r8, r8, lsl #16 // extract original left channel from paintbuffer
- // r8 holds left channel in high half with zero bottom half
- qadd r8, r5, r8
- // combine the two 16-bit samples in r7 as 32-bit [left:right]
- // (use lsr to not sign-extend the lower half)
- orr r7, r7, r8, lsr #16
- str r7, [ip, r3, lsl #2] // write 32-bit to paintbuffer
- subs r3, r3, #1
- bne .loop
- ldmfd sp!, {r4, r5, r6, r7, r8, r10}
- bx lr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement