3 @ Generic routines for mixing audio samples
4 @ (c) Copyright 2007, Grazvydas "notaz" Ignotas
10 @ this assumes src is word aligned
11 .global mix_16h_to_32 @ int *dest, short *src, int count
21 add r3, r3, r4, asr #1
32 add r4, r4, r12,asr #17 @ we use half volume
34 add r3, r3, r12,asr #17
35 add r6, r6, lr, asr #17
37 add r5, r5, lr, asr #17
47 add r3, r3, r12,asr #17
48 add r4, r4, r5, asr #17
53 ldmeqfd sp!, {r4-r6,pc}
56 add r3, r3, r4, asr #1
64 .global mix_16h_to_32_s1 @ int *dest, short *src, int count
77 add r4, r4, r12,asr #17
79 add r3, r3, r12,asr #17 @ we use half volume
80 add r6, r6, lr, asr #17
82 add r5, r5, lr, asr #17
88 beq m16_32_s1_no_unal2
92 add r3, r3, r12,asr #17
93 add r4, r4, r5, asr #17
98 ldmeqfd sp!, {r4-r6,pc}
101 add r3, r3, r4, asr #1
104 ldmfd sp!, {r4-r6,lr}
109 .global mix_16h_to_32_s2 @ int *dest, short *src, int count
112 stmfd sp!, {r4-r6,lr}
122 add r4, r4, r12,asr #17
124 add r3, r3, r12,asr #17 @ we use half volume
125 add r6, r6, lr, asr #17
127 add r5, r5, lr, asr #17
133 beq m16_32_s2_no_unal2
137 add r3, r3, r12,asr #17
138 add r4, r4, r5, asr #17
143 ldmeqfd sp!, {r4-r6,pc}
146 add r3, r3, r4, asr #1
149 ldmfd sp!, {r4-r6,lr}
155 @ reg=int_sample, lr=1, r3=tmp, kills flags
157 add r3, lr, \reg, asr #15
158 bics r3, r3, #1 @ in non-overflow conditions r3 is 0 or 1
164 @ limit and shift up by 16
165 @ reg=int_sample, lr=1, r3=tmp, kills flags
167 @ movs r4, r3, asr #16
169 @ beq c32_16_no_overflow
174 add r3, lr, \reg, asr #15
175 bics r3, r3, #1 @ in non-overflow conditions r3 is 0 or 1
176 moveq \reg, \reg, lsl #16
177 movne \reg, #0x80000000
178 subpl \reg, \reg, #0x00010000
182 @ mix 32bit audio (with 16bits really used, upper bits indicate overflow) with normal 16 bit audio with left channel only
183 @ warning: this function assumes dest is word aligned
184 .global mix_32_to_16l_stereo @ short *dest, int *src, int count
186 mix_32_to_16l_stereo:
187 stmfd sp!, {r4-r8,lr}
200 add r4, r4, r8, asr #16
201 add r5, r5, r8, asr #16
202 add r6, r6, r12,asr #16
203 add r7, r7, r12,asr #16
209 orr r4, r5, r4, lsr #16
210 orr r5, r7, r6, lsr #16
215 @ check for remaining bytes to convert
217 beq m32_16l_st_no_unal2
224 orr r4, r5, r4, lsr #16
228 ldmfd sp!, {r4-r8,lr}
232 @ mix 32bit audio (with 16bits really used, upper bits indicate overflow) with normal 16 bit audio (for mono sound)
233 .global mix_32_to_16_mono @ short *dest, int *src, int count
236 stmfd sp!, {r4-r8,lr}
240 @ check if dest is word aligned
242 beq m32_16_mo_no_unalw
257 add r5, r5, r8, asr #16
259 add r4, r4, r8, asr #16
260 add r7, r7, r12,asr #16
262 add r6, r6, r12,asr #16
268 orr r4, r5, r4, lsr #16
269 orr r5, r7, r6, lsr #16
274 @ check for remaining bytes to convert
276 beq m32_16_mo_no_unal2
279 add r5, r5, r6, asr #16
281 add r4, r4, r6, asr #16
284 orr r4, r5, r4, lsr #16
289 ldmeqfd sp!, {r4-r8,pc}
296 ldmfd sp!, {r4-r8,lr}
304 .global mix_32_to_16l_level
311 @ same as mix_32_to_16l_stereo, but with additional shift
312 .global mix_32_to_16l_stereo_lvl @ short *dest, int *src, int count
314 mix_32_to_16l_stereo_lvl:
315 stmfd sp!, {r4-r9,lr}
317 ldr r9, =mix_32_to_16l_level
330 add r4, r4, r8, asr #16
331 add r5, r5, r8, asr #16
332 add r6, r6, r12,asr #16
333 add r7, r7, r12,asr #16
343 orr r4, r5, r4, lsr #16
344 orr r5, r7, r6, lsr #16
346 bpl m32_16l_st_l_loop
349 @ check for remaining bytes to convert
351 beq m32_16l_st_l_no_unal2
360 orr r4, r5, r4, lsr #16
363 m32_16l_st_l_no_unal2:
364 ldmfd sp!, {r4-r9,lr}