2006-01-29 15:37:03 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2007-02-22 13:55:49 +00:00
|
|
|
* Copyright (C) 2006-2007 Thom Johansen
|
2006-01-29 15:37:03 +00:00
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-02-22 13:55:49 +00:00
|
|
|
/* uncomment this to make filtering calculate lower bits after shifting.
|
|
|
|
* without this, "shift" - 1 of the lower bits will be lost here.
|
|
|
|
*/
|
|
|
|
/* #define HIGH_PRECISION */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* void eq_filter(int32_t **x, struct eqfilter *f, unsigned num,
|
|
|
|
* unsigned channels, unsigned shift)
|
|
|
|
*/
|
2006-01-29 15:37:03 +00:00
|
|
|
.text
|
|
|
|
.global eq_filter
|
|
|
|
eq_filter:
|
|
|
|
lea.l (-11*4, %sp), %sp
|
|
|
|
movem.l %d2-%d7/%a2-%a6, (%sp) | save clobbered regs
|
|
|
|
move.l (11*4+8, %sp), %a5 | fetch filter structure address
|
2007-02-22 13:55:49 +00:00
|
|
|
move.l (11*4+20, %sp), %d7 | load shift count
|
2006-02-01 09:48:47 +00:00
|
|
|
subq.l #1, %d7 | EMAC gives us one free shift
|
2007-02-22 13:55:49 +00:00
|
|
|
#ifdef HIGH_PRECISION
|
|
|
|
moveq.l #8, %d6
|
|
|
|
sub.l %d7, %d6 | shift for lower part of accumulator
|
|
|
|
#endif
|
2006-01-29 15:37:03 +00:00
|
|
|
movem.l (%a5), %a0-%a4 | load coefs
|
|
|
|
lea.l (5*4, %a5), %a5 | point to filter history
|
|
|
|
|
|
|
|
.filterloop:
|
|
|
|
move.l (11*4+4, %sp), %a6 | load input channel pointer
|
2006-01-29 17:52:13 +00:00
|
|
|
addq.l #4, (11*4+4, %sp) | point x to next channel
|
2006-01-29 15:37:03 +00:00
|
|
|
move.l (%a6), %a6
|
|
|
|
move.l (11*4+12, %sp), %d5 | number of samples
|
|
|
|
movem.l (%a5), %d0-%d3 | load filter history
|
2007-02-22 13:55:49 +00:00
|
|
|
|
2007-02-22 17:22:01 +00:00
|
|
|
/* d0-d3 = history, d4 = temp, d5 = sample count, d6 = lower shift amount,
|
|
|
|
* d7 = upper shift amount, a0-a4 = coefs, a5 = history pointer, a6 = x[]
|
2007-02-22 13:55:49 +00:00
|
|
|
*/
|
2006-01-29 15:37:03 +00:00
|
|
|
.loop:
|
2006-01-29 17:52:13 +00:00
|
|
|
/* Direct form 1 filtering code. We assume DSP has put EMAC in frac mode.
|
2007-02-22 13:55:49 +00:00
|
|
|
* y[n] = b0*x[i] + b1*x[i - 1] + b2*x[i - 2] + a1*y[i - 1] + a2*y[i - 2],
|
|
|
|
* where y[] is output and x[] is input. This is performed out of order
|
|
|
|
* to do parallel load of input value.
|
2006-01-29 17:52:13 +00:00
|
|
|
*/
|
2006-02-02 22:11:10 +00:00
|
|
|
mac.l %a2, %d1, %acc0 | acc = b2*x[i - 2]
|
|
|
|
move.l %d0, %d1 | fix input history
|
|
|
|
mac.l %a1, %d0, (%a6), %d0, %acc0 | acc += b1*x[i - 1], x[i] -> d0
|
|
|
|
mac.l %a0, %d0, %acc0 | acc += b0*x[i]
|
2006-01-29 17:52:13 +00:00
|
|
|
mac.l %a3, %d2, %acc0 | acc += a1*y[i - 1]
|
|
|
|
mac.l %a4, %d3, %acc0 | acc += a2*y[i - 2]
|
2006-02-02 22:11:10 +00:00
|
|
|
move.l %d2, %d3 | fix output history
|
2007-02-22 13:55:49 +00:00
|
|
|
#ifdef HIGH_PRECISION
|
|
|
|
move.l %accext01, %d2 | fetch lower part of accumulator
|
|
|
|
move.b %d2, %d4 | clear upper three bytes
|
|
|
|
lsr.l %d6, %d4 | shift lower bits
|
|
|
|
#endif
|
|
|
|
movclr.l %acc0, %d2 | fetch upper part of result
|
2006-01-29 15:37:03 +00:00
|
|
|
asl.l %d7, %d2 | restore fixed point format
|
2007-02-22 13:55:49 +00:00
|
|
|
#ifdef HIGH_PRECISION
|
|
|
|
or.l %d2, %d4 | combine lower and upper parts
|
|
|
|
#endif
|
2006-01-29 15:37:03 +00:00
|
|
|
move.l %d2, (%a6)+ | save result
|
|
|
|
subq.l #1, %d5 | are we done with this channel?
|
|
|
|
jne .loop
|
|
|
|
|
|
|
|
movem.l %d0-%d3, (%a5) | save history back to struct
|
|
|
|
lea.l (4*4, %a5), %a5 | point to next channel's history
|
2007-02-22 13:55:49 +00:00
|
|
|
subq.l #1, (11*4+16, %sp) | have we processed both channels?
|
2006-01-29 15:37:03 +00:00
|
|
|
jne .filterloop
|
|
|
|
|
|
|
|
movem.l (%sp), %d2-%d7/%a2-%a6
|
|
|
|
lea.l (11*4, %sp), %sp
|
|
|
|
rts
|
|
|
|
|