blob: 30a28b9d99cfac87c16a67728a9db70512ff169e [file] [log] [blame]
Thom Johansen55ff4562006-01-29 15:37:03 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
Thom Johansenc4ccd9e2007-02-22 13:55:49 +000010 * Copyright (C) 2006-2007 Thom Johansen
Thom Johansen55ff4562006-01-29 15:37:03 +000011 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
Thom Johansen55ff4562006-01-29 15:37:03 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
Thom Johansenc4ccd9e2007-02-22 13:55:49 +000022/* uncomment this to make filtering calculate lower bits after shifting.
23 * without this, "shift" - 1 of the lower bits will be lost here.
24 */
25/* #define HIGH_PRECISION */
26
27/*
28 * void eq_filter(int32_t **x, struct eqfilter *f, unsigned num,
29 * unsigned channels, unsigned shift)
30 */
Thom Johansen55ff4562006-01-29 15:37:03 +000031 .text
32 .global eq_filter
33eq_filter:
34 lea.l (-11*4, %sp), %sp
35 movem.l %d2-%d7/%a2-%a6, (%sp) | save clobbered regs
36 move.l (11*4+8, %sp), %a5 | fetch filter structure address
Thom Johansenc4ccd9e2007-02-22 13:55:49 +000037 move.l (11*4+20, %sp), %d7 | load shift count
Thom Johansen7df51ad2006-02-01 09:48:47 +000038 subq.l #1, %d7 | EMAC gives us one free shift
Thom Johansenc4ccd9e2007-02-22 13:55:49 +000039#ifdef HIGH_PRECISION
40 moveq.l #8, %d6
41 sub.l %d7, %d6 | shift for lower part of accumulator
42#endif
Thom Johansen55ff4562006-01-29 15:37:03 +000043 movem.l (%a5), %a0-%a4 | load coefs
44 lea.l (5*4, %a5), %a5 | point to filter history
Thom Johansen55ff4562006-01-29 15:37:03 +000045
46.filterloop:
47 move.l (11*4+4, %sp), %a6 | load input channel pointer
Thom Johansen65721f02006-01-29 17:52:13 +000048 addq.l #4, (11*4+4, %sp) | point x to next channel
Thom Johansen55ff4562006-01-29 15:37:03 +000049 move.l (%a6), %a6
50 move.l (11*4+12, %sp), %d5 | number of samples
Thom Johansen55ff4562006-01-29 15:37:03 +000051 movem.l (%a5), %d0-%d3 | load filter history
Thom Johansenc4ccd9e2007-02-22 13:55:49 +000052
Thom Johansen10a22842007-02-22 17:22:01 +000053 /* d0-d3 = history, d4 = temp, d5 = sample count, d6 = lower shift amount,
54 * d7 = upper shift amount, a0-a4 = coefs, a5 = history pointer, a6 = x[]
Thom Johansenc4ccd9e2007-02-22 13:55:49 +000055 */
Thom Johansen55ff4562006-01-29 15:37:03 +000056.loop:
Thom Johansen65721f02006-01-29 17:52:13 +000057 /* Direct form 1 filtering code. We assume DSP has put EMAC in frac mode.
Thom Johansenc4ccd9e2007-02-22 13:55:49 +000058 * y[n] = b0*x[i] + b1*x[i - 1] + b2*x[i - 2] + a1*y[i - 1] + a2*y[i - 2],
59 * where y[] is output and x[] is input. This is performed out of order
60 * to do parallel load of input value.
Thom Johansen65721f02006-01-29 17:52:13 +000061 */
Thom Johansen3495e752006-02-02 22:11:10 +000062 mac.l %a2, %d1, %acc0 | acc = b2*x[i - 2]
63 move.l %d0, %d1 | fix input history
64 mac.l %a1, %d0, (%a6), %d0, %acc0 | acc += b1*x[i - 1], x[i] -> d0
65 mac.l %a0, %d0, %acc0 | acc += b0*x[i]
Thom Johansen65721f02006-01-29 17:52:13 +000066 mac.l %a3, %d2, %acc0 | acc += a1*y[i - 1]
67 mac.l %a4, %d3, %acc0 | acc += a2*y[i - 2]
Thom Johansen3495e752006-02-02 22:11:10 +000068 move.l %d2, %d3 | fix output history
Thom Johansenc4ccd9e2007-02-22 13:55:49 +000069#ifdef HIGH_PRECISION
70 move.l %accext01, %d2 | fetch lower part of accumulator
71 move.b %d2, %d4 | clear upper three bytes
72 lsr.l %d6, %d4 | shift lower bits
73#endif
74 movclr.l %acc0, %d2 | fetch upper part of result
Thom Johansen55ff4562006-01-29 15:37:03 +000075 asl.l %d7, %d2 | restore fixed point format
Thom Johansenc4ccd9e2007-02-22 13:55:49 +000076#ifdef HIGH_PRECISION
77 or.l %d2, %d4 | combine lower and upper parts
78#endif
Thom Johansen55ff4562006-01-29 15:37:03 +000079 move.l %d2, (%a6)+ | save result
80 subq.l #1, %d5 | are we done with this channel?
81 jne .loop
82
83 movem.l %d0-%d3, (%a5) | save history back to struct
84 lea.l (4*4, %a5), %a5 | point to next channel's history
Thom Johansenc4ccd9e2007-02-22 13:55:49 +000085 subq.l #1, (11*4+16, %sp) | have we processed both channels?
Thom Johansen55ff4562006-01-29 15:37:03 +000086 jne .filterloop
87
88 movem.l (%sp), %d2-%d7/%a2-%a6
89 lea.l (11*4, %sp), %sp
90 rts
91