1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006-2007 Thom Johansen
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 * void apply_crossfeed(int count, int32_t* src[])
24 .global apply_crossfeed
26 @ unfortunately, we ended up in a bit of a register squeeze here, and need
27 @ to keep both the count and the delay line index on the stack :/
28 stmdb sp!, { r4-r11, lr } @ stack modified regs
29 ldmia r1, { r2-r3 } @ r2 = src[0], r3 = src[1]
31 ldr r1, =crossfeed_data
32 ldmia r1!, { r4-r11 } @ load direct gain and filter data
33 add r12, r1, #13*4*2 @ calculate end of delay
34 stmdb sp!, { r0, r12 } @ stack count and end of delay adr
35 ldr r0, [r1, #13*4*2] @ fetch current delay line address
37 /* Register usage in loop:
38 * r0 = &delay[index][0], r1 = accumulator high, r2 = src[0], r3 = src[1],
39 * r4 = direct gain, r5-r7 = b0, b1, a1 (filter coefs),
40 * r8-r11 = filter history, r12 = temp, r14 = accumulator low
43 smull r14, r1, r6, r8 @ acc = b1*dr[n - 1]
44 smlal r14, r1, r7, r9 @ acc += a1*y_l[n - 1]
45 ldr r8, [r0, #4] @ r8 = dr[n]
46 smlal r14, r1, r5, r8 @ acc += b0*dr[n]
47 mov r9, r1, lsl #1 @ fix format for filter history
48 ldr r12, [r2] @ load left input
49 smlal r14, r1, r4, r12 @ acc += gain*x_l[n]
50 mov r1, r1, lsl #1 @ fix format
51 str r1, [r2], #4 @ save result
53 smull r14, r1, r6, r10 @ acc = b1*dl[n - 1]
54 smlal r14, r1, r7, r11 @ acc += a1*y_r[n - 1]
55 ldr r10, [r0] @ r10 = dl[n]
56 str r12, [r0], #4 @ save left input to delay line
57 smlal r14, r1, r5, r10 @ acc += b0*dl[n]
58 mov r11, r1, lsl #1 @ fix format for filter history
59 ldr r12, [r3] @ load right input
60 smlal r14, r1, r4, r12 @ acc += gain*x_r[n]
61 str r12, [r0], #4 @ save right input to delay line
62 mov r1, r1, lsl #1 @ fix format
63 str r1, [r3], #4 @ save result
65 ldr r12, [sp, #4] @ fetch delay line end addr from stack
66 cmp r0, r12 @ need to wrap to start of delay?
67 subeq r0, r0, #13*4*2 @ wrap back delay line ptr to start
69 ldr r1, [sp] @ fetch count from stack
70 subs r1, r1, #1 @ are we finished?
71 strne r1, [sp] @ nope, save count back to stack
74 @ save data back to struct
75 ldr r12, =crossfeed_data + 4*4
76 stmia r12, { r8-r11 } @ save filter history
77 str r0, [r12, #30*4] @ save delay line index
78 add sp, sp, #8 @ remove temp variables from stack
79 ldmia sp!, { r4-r11, pc }