/* Copyright (C) 2005 Analog Devices */ /** @file filters_bfin.h @brief Various analysis/synthesis filters (Blackfin version) */ /* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define OVERRIDE_NORMALIZE16 int normalize16(const spx_sig_t *x, spx_word16_t *y, spx_sig_t max_scale, int len) { spx_sig_t max_val=1; int sig_shift; __asm__ ( "%0 = 0;\n\t" "I0 = %1;\n\t" "L0 = 0;\n\t" "R1 = [I0++];\n\t" "LOOP norm_max%= LC0 = %2;\n\t" "LOOP_BEGIN norm_max%=;\n\t" "R2 = ABS R1 || R1 = [I0++];\n\t" "%0 = MAX(%0, R2);\n\t" "LOOP_END norm_max%=;\n\t" : "=&d" (max_val) : "a" (x), "a" (len) : "R1", "R2" ); sig_shift=0; while (max_val>max_scale) { sig_shift++; max_val >>= 1; } __asm__ __volatile__ ( "I0 = %0;\n\t" "L0 = 0;\n\t" "P1 = %1;\n\t" "R0 = [I0++];\n\t" "LOOP norm_shift%= LC0 = %3;\n\t" "LOOP_BEGIN norm_shift%=;\n\t" "R1 = ASHIFT R0 by %2.L || R0 = [I0++];\n\t" "W[P1++] = R1;\n\t" "LOOP_END norm_shift%=;\n\t" "R1 = ASHIFT R0 by %2.L;\n\t" "W[P1++] = R1;\n\t" : : "a" (x), "a" (y), "d" (-sig_shift), "a" (len-1) : "I0", "L0", "P1", "R0", "R1", "memory" ); return sig_shift; } #define OVERRIDE_FILTER_MEM16 void filter_mem16(const spx_word16_t *_x, const spx_coef_t *num, const spx_coef_t *den, spx_word16_t *_y, int N, int ord, spx_mem_t *mem, char *stack) { VARDECL(spx_word32_t *xy2); VARDECL(spx_word32_t *numden_a); spx_word32_t *xy; spx_word16_t *numden; int i; ALLOC(xy2, (N+1), spx_word32_t); ALLOC(numden_a, (2*ord+2), spx_word32_t); xy = xy2+1; numden = (spx_word16_t*) numden_a; for (i=0;i>> 13;\n\t" "W[%0] = R3.L;\n\t" "R0 <<= 1;\n\t" "R1 = R1 + R0;\n\t" "R1 >>>= 13;\n\t" "W[%1] = R1.L;\n\t" "LOOP_END samples%=;\n\t" : "=a" (ytmp2), "=a" (y) : "a" (awk2), "a" (ak), "d" (ord), "m" (N), "0" (ytmp2), "1" (y) : "A0", "A1", "R0", "R1", "R2", "R3", "I0", "I1", "I2", "I3", "L0", "L1", "L2", "L3", "A0", "A1" ); } #if 0 /* Equivalent C function for filter_mem2 and compute_impulse_response */ #define min(a,b) ((a)<(b) ? (a):(b)) void compute_impulse_response(const spx_coef_t *ak, const spx_coef_t *awk1, const spx_coef_t *awk2, spx_word16_t *y, int N, int ord, char *stack) { int i,j; VARDECL(spx_word16_t *ytmp); ALLOC(ytmp, N, spx_word16_t); y[0] = LPC_SCALING; for (i=0;i