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 ****************************************************************************/
20 /* uncomment this to make filtering calculate lower bits after shifting.
21 * without this, "shift" of the lower bits will be lost here.
23 /* #define HIGH_PRECISION */
26 * void eq_filter(int32_t **x, struct eqfilter *f, unsigned num,
27 * unsigned channels, unsigned shift)
32 ldr r12, [sp] @ get shift parameter
33 stmdb sp!, { r0-r11, lr } @ save all params and clobbered regs
34 ldmia r1!, { r4-r8 } @ load coefs
35 mov r10, r1 @ loop prelude expects filter struct addr in r10
38 ldr r9, [sp] @ get pointer to this channels data
40 str r0, [sp] @ save back pointer to next channels data
41 ldr r9, [r9] @ r9 = x[]
42 ldr r14, [sp, #8] @ r14 = numsamples
43 ldmia r10, { r0-r3 } @ load history, r10 should be filter struct addr
44 str r10, [sp, #4] @ save it for loop end
46 /* r0-r3 = history, r4-r8 = coefs, r9 = x[], r10..r11 = accumulator,
47 * r12 = shift amount, r14 = number of samples.
50 /* Direct form 1 filtering code.
51 * y[n] = b0*x[i] + b1*x[i - 1] + b2*x[i - 2] + a1*y[i - 1] + a2*y[i - 2],
52 * where y[] is output and x[] is input. This is performed out of order to
53 * reuse registers, we're pretty short on regs.
55 smull r10, r11, r6, r1 @ acc = b2*x[i - 2]
56 mov r1, r0 @ fix input history
57 smlal r10, r11, r5, r0 @ acc += b1*x[i - 1]
58 ldr r0, [r9] @ load input and fix history in same operation
59 smlal r10, r11, r4, r0 @ acc += b0*x[i]
60 smlal r10, r11, r7, r2 @ acc += a1*y[i - 1]
61 smlal r10, r11, r8, r3 @ acc += a2*y[i - 2]
62 mov r3, r2 @ fix output history
63 mov r2, r11, asl r12 @ get upper part of result and shift left
65 rsb r11, r12, #32 @ get shift amount for lower part
66 orr r2, r2, r10, lsr r11 @ then mix in correctly shifted lower part
68 str r2, [r9], #4 @ save result
69 subs r14, r14, #1 @ are we done with this channel?
72 ldr r10, [sp, #4] @ load filter struct pointer
73 stmia r10!, { r0-r3 } @ save back history
74 ldr r11, [sp, #12] @ load number of channels
75 subs r11, r11, #1 @ all channels processed?
79 add sp, sp, #16 @ compensate for temp storage
80 ldmia sp!, { r4-r11, pc }