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.073
     22     ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
     23     Available from http://www.3gpp.org
     24 
     25 (C) 2004, 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  Pathname: ./audio/gsm-amr/c/src/inter_36.c
     35 
     36      Date: 01/31/2002
     37 
     38 ------------------------------------------------------------------------------
     39  REVISION HISTORY
     40 
     41  Description:
     42               1. Eliminated unused include files.
     43               2. Replaced array addressing by pointers
     44               3. Eliminated math operations that unnecessary checked for
     45                  saturation
     46               4. Unrolled loops to speed up processing, use decrement loops
     47               5. Eliminated call to round by proper initialization
     48 
     49  Description:  Added casting to eliminate warnings
     50 
     51  Description:  Replaced "int" and/or "char" with OSCL defined types.
     52 
     53  Description: Changed round function name to pv_round to avoid conflict with
     54               round function in C standard library.
     55 
     56  Description: Using intrinsics from fxp_arithmetic.h .
     57 
     58  Description: Replacing fxp_arithmetic.h with basic_op.h.
     59 
     60  Description:
     61 
     62 ------------------------------------------------------------------------------
     63 */
     64 
     65 /*----------------------------------------------------------------------------
     66 ; INCLUDES
     67 ----------------------------------------------------------------------------*/
     68 #include "inter_36.h"
     69 #include "cnst.h"
     70 #include "inter_36_tab.h"
     71 #include "basic_op.h"
     72 
     73 /*----------------------------------------------------------------------------
     74 ; MACROS
     75 ; Define module specific macros here
     76 ----------------------------------------------------------------------------*/
     77 
     78 
     79 /*----------------------------------------------------------------------------
     80 ; DEFINES
     81 ; Include all pre-processor statements here. Include conditional
     82 ; compile variables also.
     83 ----------------------------------------------------------------------------*/
     84 #define UP_SAMP_MAX  6
     85 
     86 /*----------------------------------------------------------------------------
     87 ; LOCAL FUNCTION DEFINITIONS
     88 ; Function Prototype declaration
     89 ----------------------------------------------------------------------------*/
     90 
     91 
     92 /*----------------------------------------------------------------------------
     93 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
     94 ; Variable declaration - defined here and used outside this module
     95 ----------------------------------------------------------------------------*/
     96 
     97 
     98 /*
     99 ------------------------------------------------------------------------------
    100  FUNCTION NAME: inter_36
    101 ------------------------------------------------------------------------------
    102  INPUT AND OUTPUT DEFINITIONS
    103 
    104  Inputs:
    105     pX    = pointer to input vector of type Word16
    106     frac  = fraction  (-2..2 for 3*, -3..3 for 6*)  of type Word16
    107     flag3 = if set, upsampling rate = 3 (6 otherwise) of type Word16
    108     pOverflow = pointer to overflow flag
    109 
    110  Outputs:
    111     None
    112 
    113  Returns:
    114     None
    115 
    116  Global Variables Used:
    117     None.
    118 
    119  Local Variables Needed:
    120     None.
    121 
    122 ------------------------------------------------------------------------------
    123  FUNCTION DESCRIPTION
    124 
    125       File             : inter_36.c
    126       Purpose          : Interpolating the normalized correlation
    127                        : with 1/3 or 1/6 resolution.
    128 
    129 ------------------------------------------------------------------------------
    130  REQUIREMENTS
    131 
    132  None.
    133 
    134 ------------------------------------------------------------------------------
    135  REFERENCES
    136 
    137  inter_36.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
    138 
    139 ------------------------------------------------------------------------------
    140  PSEUDO-CODE
    141 
    142     Word16 i, k;
    143     Word16 *x1, *x2;
    144     const Word16 *c1, *c2;
    145     Word32 s;
    146 
    147     if (flag3 != 0)
    148     {
    149       frac = shl (frac, 1);   // inter_3[k] = inter_6[2*k] -> k' = 2*k
    150     }
    151 
    152     if (frac < 0)
    153     {
    154         frac = add (frac, UP_SAMP_MAX);
    155         x--;
    156     }
    157 
    158     x1 = &x[0];
    159     x2 = &x[1];
    160     c1 = &inter_6[frac];
    161     c2 = &inter_6[sub (UP_SAMP_MAX, frac)];
    162 
    163     s = 0;
    164     for (i = 0, k = 0; i < L_INTER_SRCH; i++, k += UP_SAMP_MAX)
    165     {
    166         s = L_mac (s, x1[-i], c1[k]);
    167         s = L_mac (s, x2[i], c2[k]);
    168     }
    169 
    170     return pv_round (s);
    171 
    172 ------------------------------------------------------------------------------
    173  RESOURCES USED [optional]
    174 
    175  When the code is written for a specific target processor the
    176  the resources used should be documented below.
    177 
    178  HEAP MEMORY USED: x bytes
    179 
    180  STACK MEMORY USED: x bytes
    181 
    182  CLOCK CYCLES: (cycle count equation for this function) + (variable
    183                 used to represent cycle count for each subroutine
    184                 called)
    185      where: (cycle count variable) = cycle count for [subroutine
    186                                      name]
    187 
    188 ------------------------------------------------------------------------------
    189  CAUTION [optional]
    190  [State any special notes, constraints or cautions for users of this function]
    191 
    192 ------------------------------------------------------------------------------
    193 */
    194 Word16 Interpol_3or6(   /* o : interpolated value                        */
    195     Word16 *pX,         /* i : input vector                              */
    196     Word16 frac,        /* i : fraction  (-2..2 for 3*, -3..3 for 6*)    */
    197     Word16 flag3,       /* i : if set, upsampling rate = 3 (6 otherwise) */
    198     Flag   *pOverflow
    199 )
    200 {
    201     Word16 i;
    202     Word16 k;
    203     Word16 *pX1;
    204     Word16 *pX2;
    205     const Word16 *pC1;
    206     const Word16 *pC2;
    207     Word32 s;
    208     Word16 temp1;
    209 
    210     OSCL_UNUSED_ARG(pOverflow);
    211 
    212     if (flag3 != 0)
    213     {
    214         frac <<= 1;
    215         /* inter_3[k] = inter_6[2*k] -> k' = 2*k */
    216     }
    217 
    218     if (frac < 0)
    219     {
    220         frac += UP_SAMP_MAX;
    221         pX--;
    222     }
    223 
    224     pX1   = &pX[0];
    225     pX2   = &pX[1];
    226     pC1   = &inter_6[frac];
    227     temp1 = UP_SAMP_MAX - frac;
    228     pC2   = &inter_6[temp1];
    229 
    230     s = 0x04000;
    231     k = 0;
    232 
    233     for (i = (L_INTER_SRCH >> 1); i != 0; i--)
    234     {
    235         s = amrnb_fxp_mac_16_by_16bb((Word32) * (pX1--), (Word32) pC1[k], s);
    236         s = amrnb_fxp_mac_16_by_16bb((Word32) * (pX2++), (Word32) pC2[k], s);
    237         k += UP_SAMP_MAX;
    238         s = amrnb_fxp_mac_16_by_16bb((Word32) * (pX1--), (Word32) pC1[k], s);
    239         s = amrnb_fxp_mac_16_by_16bb((Word32) * (pX2++), (Word32) pC2[k], s);
    240         k <<= 1;
    241     }
    242 
    243     return((Word16)(s >> 15));
    244 }
    245 
    246 
    247 
    248 
    249 
    250 
    251