Home | History | Annotate | Download | only in src
      1 /*
      2  ** Copyright 2003-2010, VisualOn, Inc.
      3  **
      4  ** Licensed under the Apache License, Version 2.0 (the "License");
      5  ** you may not use this file except in compliance with the License.
      6  ** You may obtain a copy of the License at
      7  **
      8  **     http://www.apache.org/licenses/LICENSE-2.0
      9  **
     10  ** Unless required by applicable law or agreed to in writing, software
     11  ** distributed under the License is distributed on an "AS IS" BASIS,
     12  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  ** See the License for the specific language governing permissions and
     14  ** limitations under the License.
     15  */
     16 
     17 /***********************************************************************
     18 *       File: syn_filt.c                                               *
     19 *                                                                      *
     20 *       Description: Do the synthesis filtering 1/A(z)                 *
     21 *                                                                      *
     22 ************************************************************************/
     23 
     24 #include "typedef.h"
     25 #include "basic_op.h"
     26 #include "math_op.h"
     27 #include "cnst.h"
     28 
     29 #define UNUSED(x) (void)(x)
     30 
     31 void Syn_filt(
     32         Word16 a[],                           /* (i) Q12 : a[m+1] prediction coefficients           */
     33         Word16 x[],                           /* (i)     : input signal                             */
     34         Word16 y[],                           /* (o)     : output signal                            */
     35         Word16 lg,                            /* (i)     : size of filtering                        */
     36         Word16 mem[],                         /* (i/o)   : memory associated with this filtering.   */
     37         Word16 update                         /* (i)     : 0=no update, 1=update of memory.         */
     38          )
     39 {
     40     Word32 i, a0;
     41     Word16 y_buf[L_SUBFR16k + M16k];
     42     Word32 L_tmp;
     43     Word16 *yy, *p1, *p2;
     44     yy = &y_buf[0];
     45     /* copy initial filter states into synthesis buffer */
     46     for (i = 0; i < 16; i++)
     47     {
     48         *yy++ = mem[i];
     49     }
     50     a0 = (a[0] >> 1);                     /* input / 2 */
     51     /* Do the filtering. */
     52     for (i = 0; i < lg; i++)
     53     {
     54         p1 = &a[1];
     55         p2 = &yy[i-1];
     56         L_tmp  = vo_mult32(a0, x[i]);
     57         L_tmp -= vo_mult32((*p1++), (*p2--));
     58         L_tmp -= vo_mult32((*p1++), (*p2--));
     59         L_tmp -= vo_mult32((*p1++), (*p2--));
     60         L_tmp -= vo_mult32((*p1++), (*p2--));
     61         L_tmp -= vo_mult32((*p1++), (*p2--));
     62         L_tmp -= vo_mult32((*p1++), (*p2--));
     63         L_tmp -= vo_mult32((*p1++), (*p2--));
     64         L_tmp -= vo_mult32((*p1++), (*p2--));
     65         L_tmp -= vo_mult32((*p1++), (*p2--));
     66         L_tmp -= vo_mult32((*p1++), (*p2--));
     67         L_tmp -= vo_mult32((*p1++), (*p2--));
     68         L_tmp -= vo_mult32((*p1++), (*p2--));
     69         L_tmp -= vo_mult32((*p1++), (*p2--));
     70         L_tmp -= vo_mult32((*p1++), (*p2--));
     71         L_tmp -= vo_mult32((*p1++), (*p2--));
     72         L_tmp -= vo_mult32((*p1), (*p2));
     73 
     74         L_tmp = L_shl2(L_tmp, 4);
     75         y[i] = yy[i] = extract_h(L_add(L_tmp, 0x8000));
     76     }
     77     /* Update memory if required */
     78     if (update)
     79         for (i = 0; i < 16; i++)
     80         {
     81             mem[i] = yy[lg - 16 + i];
     82         }
     83     return;
     84 }
     85 
     86 
     87 void Syn_filt_32(
     88         Word16 a[],                           /* (i) Q12 : a[m+1] prediction coefficients */
     89         Word16 m,                             /* (i)     : order of LP filter             */
     90         Word16 exc[],                         /* (i) Qnew: excitation (exc[i] >> Qnew)    */
     91         Word16 Qnew,                          /* (i)     : exc scaling = 0(min) to 8(max) */
     92         Word16 sig_hi[],                      /* (o) /16 : synthesis high                 */
     93         Word16 sig_lo[],                      /* (o) /16 : synthesis low                  */
     94         Word16 lg                             /* (i)     : size of filtering              */
     95         )
     96 {
     97     Word32 i,a0;
     98     Word32 L_tmp, L_tmp1;
     99     Word16 *p1, *p2, *p3;
    100         UNUSED(m);
    101 
    102     a0 = a[0] >> (4 + Qnew);          /* input / 16 and >>Qnew */
    103     /* Do the filtering. */
    104     for (i = 0; i < lg; i++)
    105     {
    106         L_tmp  = 0;
    107         L_tmp1 = 0;
    108         p1 = a;
    109         p2 = &sig_lo[i - 1];
    110         p3 = &sig_hi[i - 1];
    111 
    112         L_tmp  -= vo_mult32((*p2--), (*p1));
    113         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    114         L_tmp  -= vo_mult32((*p2--), (*p1));
    115         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    116         L_tmp  -= vo_mult32((*p2--), (*p1));
    117         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    118         L_tmp  -= vo_mult32((*p2--), (*p1));
    119         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    120         L_tmp  -= vo_mult32((*p2--), (*p1));
    121         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    122         L_tmp  -= vo_mult32((*p2--), (*p1));
    123         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    124         L_tmp  -= vo_mult32((*p2--), (*p1));
    125         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    126         L_tmp  -= vo_mult32((*p2--), (*p1));
    127         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    128         L_tmp  -= vo_mult32((*p2--), (*p1));
    129         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    130         L_tmp  -= vo_mult32((*p2--), (*p1));
    131         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    132         L_tmp  -= vo_mult32((*p2--), (*p1));
    133         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    134         L_tmp  -= vo_mult32((*p2--), (*p1));
    135         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    136         L_tmp  -= vo_mult32((*p2--), (*p1));
    137         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    138         L_tmp  -= vo_mult32((*p2--), (*p1));
    139         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    140         L_tmp  -= vo_mult32((*p2--), (*p1));
    141         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    142         L_tmp  -= vo_mult32((*p2--), (*p1));
    143         L_tmp1 -= vo_mult32((*p3--), (*p1++));
    144 
    145         L_tmp = L_tmp >> 11;
    146         L_tmp += vo_L_mult(exc[i], a0);
    147 
    148         /* sig_hi = bit16 to bit31 of synthesis */
    149         L_tmp = L_tmp - (L_tmp1<<1);
    150 
    151         L_tmp = L_tmp >> 3;           /* ai in Q12 */
    152         sig_hi[i] = extract_h(L_tmp);
    153 
    154         /* sig_lo = bit4 to bit15 of synthesis */
    155         L_tmp >>= 4;           /* 4 : sig_lo[i] >> 4 */
    156         sig_lo[i] = (Word16)((L_tmp - (sig_hi[i] << 13)));
    157     }
    158 
    159     return;
    160 }
    161 
    162 
    163 
    164 
    165