Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      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
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 /****************************************************************************************
     19 Portions of this file are derived from the following 3GPP standard:
     20 
     21     3GPP TS 26.173
     22     ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
     23     Available from http://www.3gpp.org
     24 
     25 (C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
     26 Permission to distribute, modify and use this file under the standard license
     27 terms listed above has been obtained from the copyright holder.
     28 ****************************************************************************************/
     29 /*
     30 ------------------------------------------------------------------------------
     31 
     32 
     33 
     34  Filename: band_pass_6k_7k.cpp
     35 
     36      Date: 05/08/2004
     37 
     38 ------------------------------------------------------------------------------
     39  REVISION HISTORY
     40 
     41 
     42  Description:
     43 
     44 ------------------------------------------------------------------------------
     45  INPUT AND OUTPUT DEFINITIONS
     46 
     47      int16 signal[],             input signal / output is divided by 16
     48      int16 lg,                   lenght of signal
     49      int16 mem[]                 in/out: memory (size=30)
     50      int16 x[]                   scratch mem ( size= 60)
     51 
     52 ------------------------------------------------------------------------------
     53  FUNCTION DESCRIPTION
     54 
     55    15th order band pass 6kHz to 7kHz FIR filter.
     56 
     57    frequency:  4kHz   5kHz  5.5kHz  6kHz  6.5kHz 7kHz  7.5kHz  8kHz
     58    dB loss:   -60dB  -45dB  -13dB   -3dB   0dB   -3dB  -13dB  -45dB
     59 
     60 
     61 ------------------------------------------------------------------------------
     62  REQUIREMENTS
     63 
     64 
     65 ------------------------------------------------------------------------------
     66  REFERENCES
     67 
     68 ------------------------------------------------------------------------------
     69  PSEUDO-CODE
     70 
     71 ------------------------------------------------------------------------------
     72 */
     73 
     74 
     75 /*----------------------------------------------------------------------------
     76 ; INCLUDES
     77 ----------------------------------------------------------------------------*/
     78 
     79 
     80 #include "pv_amr_wb_type_defs.h"
     81 #include "pvamrwbdecoder_basic_op.h"
     82 #include "pvamrwbdecoder_acelp.h"
     83 #include "pvamrwbdecoder_cnst.h"
     84 
     85 /*----------------------------------------------------------------------------
     86 ; MACROS
     87 ; Define module specific macros here
     88 ----------------------------------------------------------------------------*/
     89 
     90 
     91 /*----------------------------------------------------------------------------
     92 ; DEFINES
     93 ; Include all pre-processor statements here. Include conditional
     94 ; compile variables also.
     95 ----------------------------------------------------------------------------*/
     96 
     97 #define L_FIR 30
     98 
     99 /*----------------------------------------------------------------------------
    100 ; LOCAL FUNCTION DEFINITIONS
    101 ; Function Prototype declaration
    102 ----------------------------------------------------------------------------*/
    103 
    104 /*----------------------------------------------------------------------------
    105 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    106 ; Variable declaration - defined here and used outside this module
    107 ----------------------------------------------------------------------------*/
    108 
    109 /* filter coefficients (gain=4.0) */
    110 
    111 const int16 fir_6k_7k[L_FIR] =
    112 {
    113     -32,     47,     32,    -27,
    114     -369,   1122,  -1421,      0,
    115     3798,  -8880,  12349, -10984,
    116     3548,   7766, -18001,
    117     22118,
    118     -18001,   7766,   3548, -10984,
    119     12349,  -8880,   3798,      0,
    120     -1421,   1122,   -369,    -27,
    121     32,     47
    122 };
    123 
    124 /*----------------------------------------------------------------------------
    125 ; EXTERNAL FUNCTION REFERENCES
    126 ; Declare functions defined elsewhere and referenced in this module
    127 ----------------------------------------------------------------------------*/
    128 
    129 /*----------------------------------------------------------------------------
    130 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    131 ; Declare variables used in this module but defined elsewhere
    132 ----------------------------------------------------------------------------*/
    133 
    134 /*----------------------------------------------------------------------------
    135 ; FUNCTION CODE
    136 ----------------------------------------------------------------------------*/
    137 
    138 void band_pass_6k_7k_init(int16 mem[])         /* mem[30] */
    139 {
    140     pv_memset((void *)mem, 0, L_FIR*sizeof(*mem));
    141 }
    142 
    143 
    144 /*----------------------------------------------------------------------------
    145 ; FUNCTION CODE
    146 ----------------------------------------------------------------------------*/
    147 
    148 
    149 void band_pass_6k_7k(
    150     int16 signal[],                      /* input:  signal                  */
    151     int16 lg,                            /* input:  length of input         */
    152     int16 mem[],                         /* in/out: memory (size=30)        */
    153     int16 x[]
    154 )
    155 {
    156     int16 i, j;
    157     int32 L_tmp1;
    158     int32 L_tmp2;
    159     int32 L_tmp3;
    160     int32 L_tmp4;
    161 
    162     int16 *pt_sign = signal;
    163 
    164     pv_memcpy((void *)x, (void *)mem, L_FIR*sizeof(*x));
    165 
    166 
    167     for (i = 0; i < lg >> 2; i++)
    168     {
    169 
    170         x[(i<<2) + L_FIR    ] = *(pt_sign) >> 2;        /* gain of filter = 4 */
    171         x[(i<<2) + L_FIR + 1] = *(pt_sign + 1) >> 2;    /* gain of filter = 4 */
    172         x[(i<<2) + L_FIR + 2] = *(pt_sign + 2) >> 2;    /* gain of filter = 4 */
    173         x[(i<<2) + L_FIR + 3] = *(pt_sign + 3) >> 2;    /* gain of filter = 4 */
    174 
    175         L_tmp1 = 0x00004000;
    176         L_tmp2 = 0x00004000;
    177         L_tmp3 = 0x00004000;
    178         L_tmp4 = 0x00004000;
    179 
    180         L_tmp1 -= ((int32)x[(i<<2)+L_FIR  ] << 5);
    181         L_tmp2 -= ((int32)x[(i<<2)+L_FIR+1] << 5);
    182         L_tmp3 -= ((int32)x[(i<<2)+L_FIR+2] << 5);
    183         L_tmp4 -= ((int32)x[(i<<2)+L_FIR+3] << 5);
    184 
    185         L_tmp1 -= ((int32)x[(i<<2)] << 5);
    186         L_tmp2 -= ((int32)x[(i<<2)+1] << 5);
    187         L_tmp3 -= ((int32)x[(i<<2)+2] << 5);
    188         L_tmp4 -= ((int32)x[(i<<2)+3] << 5);
    189 
    190 
    191         for (j = 1; j < L_FIR - 1; j += 4)
    192         {
    193             int16 tmp1 = x[(i<<2)+j  ];
    194             int16 tmp2 = x[(i<<2)+j+1];
    195             int16 tmp3 = x[(i<<2)+j+2];
    196 
    197             L_tmp1 = fxp_mac_16by16(tmp1, fir_6k_7k[j  ], L_tmp1);
    198             L_tmp2 = fxp_mac_16by16(tmp2, fir_6k_7k[j  ], L_tmp2);
    199             L_tmp1 = fxp_mac_16by16(tmp2, fir_6k_7k[j+1], L_tmp1);
    200             L_tmp2 = fxp_mac_16by16(tmp3, fir_6k_7k[j+1], L_tmp2);
    201             L_tmp3 = fxp_mac_16by16(tmp3, fir_6k_7k[j  ], L_tmp3);
    202             L_tmp1 = fxp_mac_16by16(tmp3, fir_6k_7k[j+2], L_tmp1);
    203 
    204             tmp1 = x[(i<<2)+j+3];
    205             tmp2 = x[(i<<2)+j+4];
    206 
    207             L_tmp2 = fxp_mac_16by16(tmp1, fir_6k_7k[j+2], L_tmp2);
    208             L_tmp4 = fxp_mac_16by16(tmp1, fir_6k_7k[j  ], L_tmp4);
    209             L_tmp3 = fxp_mac_16by16(tmp1, fir_6k_7k[j+1], L_tmp3);
    210             L_tmp1 = fxp_mac_16by16(tmp1, fir_6k_7k[j+3], L_tmp1);
    211             L_tmp2 = fxp_mac_16by16(tmp2, fir_6k_7k[j+3], L_tmp2);
    212             L_tmp4 = fxp_mac_16by16(tmp2, fir_6k_7k[j+1], L_tmp4);
    213             L_tmp3 = fxp_mac_16by16(tmp2, fir_6k_7k[j+2], L_tmp3);
    214 
    215             tmp1 = x[(i<<2)+j+5];
    216             tmp2 = x[(i<<2)+j+6];
    217 
    218             L_tmp4 = fxp_mac_16by16(tmp1, fir_6k_7k[j+2], L_tmp4);
    219             L_tmp3 = fxp_mac_16by16(tmp1, fir_6k_7k[j+3], L_tmp3);
    220             L_tmp4 = fxp_mac_16by16(tmp2, fir_6k_7k[j+3], L_tmp4);
    221 
    222         }
    223 
    224         L_tmp1 = fxp_mac_16by16(x[(i<<2)+j  ], fir_6k_7k[L_FIR-1  ], L_tmp1);
    225         L_tmp2 = fxp_mac_16by16(x[(i<<2)+j+1], fir_6k_7k[L_FIR-1  ], L_tmp2);
    226         L_tmp3 = fxp_mac_16by16(x[(i<<2)+j+2], fir_6k_7k[L_FIR-1  ], L_tmp3);
    227         L_tmp4 = fxp_mac_16by16(x[(i<<2)+j+3], fir_6k_7k[L_FIR-1  ], L_tmp4);
    228 
    229 
    230         *(pt_sign++) = (int16)(L_tmp1 >> 15);
    231         *(pt_sign++) = (int16)(L_tmp2 >> 15);
    232         *(pt_sign++) = (int16)(L_tmp3 >> 15);
    233         *(pt_sign++) = (int16)(L_tmp4 >> 15);
    234 
    235     }
    236 
    237     pv_memcpy((void *)mem, (void *)(x + lg), L_FIR*sizeof(*mem));
    238 
    239 }
    240 
    241