Thom Johansen | 55ff456 | 2006-01-29 15:37:03 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
Thom Johansen | c4ccd9e | 2007-02-22 13:55:49 +0000 | [diff] [blame] | 10 | * Copyright (C) 2006-2007 Thom Johansen |
Thom Johansen | 55ff456 | 2006-01-29 15:37:03 +0000 | [diff] [blame] | 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 12 | * 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 Johansen | 55ff456 | 2006-01-29 15:37:03 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
Thom Johansen | c4ccd9e | 2007-02-22 13:55:49 +0000 | [diff] [blame] | 22 | /* 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 Johansen | 55ff456 | 2006-01-29 15:37:03 +0000 | [diff] [blame] | 31 | .text |
| 32 | .global eq_filter |
| 33 | eq_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 Johansen | c4ccd9e | 2007-02-22 13:55:49 +0000 | [diff] [blame] | 37 | move.l (11*4+20, %sp), %d7 | load shift count |
Thom Johansen | 7df51ad | 2006-02-01 09:48:47 +0000 | [diff] [blame] | 38 | subq.l #1, %d7 | EMAC gives us one free shift |
Thom Johansen | c4ccd9e | 2007-02-22 13:55:49 +0000 | [diff] [blame] | 39 | #ifdef HIGH_PRECISION |
| 40 | moveq.l #8, %d6 |
| 41 | sub.l %d7, %d6 | shift for lower part of accumulator |
| 42 | #endif |
Thom Johansen | 55ff456 | 2006-01-29 15:37:03 +0000 | [diff] [blame] | 43 | movem.l (%a5), %a0-%a4 | load coefs |
| 44 | lea.l (5*4, %a5), %a5 | point to filter history |
Thom Johansen | 55ff456 | 2006-01-29 15:37:03 +0000 | [diff] [blame] | 45 | |
| 46 | .filterloop: |
| 47 | move.l (11*4+4, %sp), %a6 | load input channel pointer |
Thom Johansen | 65721f0 | 2006-01-29 17:52:13 +0000 | [diff] [blame] | 48 | addq.l #4, (11*4+4, %sp) | point x to next channel |
Thom Johansen | 55ff456 | 2006-01-29 15:37:03 +0000 | [diff] [blame] | 49 | move.l (%a6), %a6 |
| 50 | move.l (11*4+12, %sp), %d5 | number of samples |
Thom Johansen | 55ff456 | 2006-01-29 15:37:03 +0000 | [diff] [blame] | 51 | movem.l (%a5), %d0-%d3 | load filter history |
Thom Johansen | c4ccd9e | 2007-02-22 13:55:49 +0000 | [diff] [blame] | 52 | |
Thom Johansen | 10a2284 | 2007-02-22 17:22:01 +0000 | [diff] [blame] | 53 | /* 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 Johansen | c4ccd9e | 2007-02-22 13:55:49 +0000 | [diff] [blame] | 55 | */ |
Thom Johansen | 55ff456 | 2006-01-29 15:37:03 +0000 | [diff] [blame] | 56 | .loop: |
Thom Johansen | 65721f0 | 2006-01-29 17:52:13 +0000 | [diff] [blame] | 57 | /* Direct form 1 filtering code. We assume DSP has put EMAC in frac mode. |
Thom Johansen | c4ccd9e | 2007-02-22 13:55:49 +0000 | [diff] [blame] | 58 | * 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 Johansen | 65721f0 | 2006-01-29 17:52:13 +0000 | [diff] [blame] | 61 | */ |
Thom Johansen | 3495e75 | 2006-02-02 22:11:10 +0000 | [diff] [blame] | 62 | 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 Johansen | 65721f0 | 2006-01-29 17:52:13 +0000 | [diff] [blame] | 66 | mac.l %a3, %d2, %acc0 | acc += a1*y[i - 1] |
| 67 | mac.l %a4, %d3, %acc0 | acc += a2*y[i - 2] |
Thom Johansen | 3495e75 | 2006-02-02 22:11:10 +0000 | [diff] [blame] | 68 | move.l %d2, %d3 | fix output history |
Thom Johansen | c4ccd9e | 2007-02-22 13:55:49 +0000 | [diff] [blame] | 69 | #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 Johansen | 55ff456 | 2006-01-29 15:37:03 +0000 | [diff] [blame] | 75 | asl.l %d7, %d2 | restore fixed point format |
Thom Johansen | c4ccd9e | 2007-02-22 13:55:49 +0000 | [diff] [blame] | 76 | #ifdef HIGH_PRECISION |
| 77 | or.l %d2, %d4 | combine lower and upper parts |
| 78 | #endif |
Thom Johansen | 55ff456 | 2006-01-29 15:37:03 +0000 | [diff] [blame] | 79 | 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 Johansen | c4ccd9e | 2007-02-22 13:55:49 +0000 | [diff] [blame] | 85 | subq.l #1, (11*4+16, %sp) | have we processed both channels? |
Thom Johansen | 55ff456 | 2006-01-29 15:37:03 +0000 | [diff] [blame] | 86 | jne .filterloop |
| 87 | |
| 88 | movem.l (%sp), %d2-%d7/%a2-%a6 |
| 89 | lea.l (11*4, %sp), %sp |
| 90 | rts |
| 91 | |