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/d2_11pf.c
     35  Functions:
     36 
     37      Date: 01/28/2002
     38 
     39 ------------------------------------------------------------------------------
     40  REVISION HISTORY
     41 
     42  Description: Modified to place file in the correct template format. Eliminated
     43  use of special functions to perform simple mathematical operations.
     44 
     45  Description: Per review comments...
     46  (1) Removed include of "count.h" and "basic_op.h"
     47 
     48  Description:  Replaced "int" and/or "char" with OSCL defined types.
     49 
     50  Description:
     51 
     52 ------------------------------------------------------------------------------
     53  MODULE DESCRIPTION
     54 */
     55 
     56 /*----------------------------------------------------------------------------
     57 ; INCLUDES
     58 ----------------------------------------------------------------------------*/
     59 #include "d2_11pf.h"
     60 #include "typedef.h"
     61 #include "cnst.h"
     62 
     63 
     64 /*----------------------------------------------------------------------------
     65 ; MACROS
     66 ; Define module specific macros here
     67 ----------------------------------------------------------------------------*/
     68 
     69 /*----------------------------------------------------------------------------
     70 ; DEFINES
     71 ; Include all pre-processor statements here. Include conditional
     72 ; compile variables also.
     73 ----------------------------------------------------------------------------*/
     74 #define NB_PULSE  2
     75 
     76 
     77 /*----------------------------------------------------------------------------
     78 ; LOCAL FUNCTION DEFINITIONS
     79 ; Function Prototype declaration
     80 ----------------------------------------------------------------------------*/
     81 
     82 /*----------------------------------------------------------------------------
     83 ; LOCAL VARIABLE DEFINITIONS
     84 ; Variable declaration - defined here and used outside this module
     85 ----------------------------------------------------------------------------*/
     86 
     87 /*
     88 ------------------------------------------------------------------------------
     89  FUNCTION NAME: decode_2i40_11bits
     90 ------------------------------------------------------------------------------
     91  INPUT AND OUTPUT DEFINITIONS
     92 
     93  Inputs:
     94     sign  -- Word16 -- signs of 2 pulses.
     95     index -- Word16 -- Positions of the 2 pulses.
     96 
     97  Outputs:
     98     cod[] -- array of type Word16 -- algebraic (fixed) codebook excitation
     99 
    100  Returns:
    101     None
    102 
    103  Global Variables Used:
    104     None
    105 
    106  Local Variables Needed:
    107     None
    108 
    109 ------------------------------------------------------------------------------
    110  FUNCTION DESCRIPTION
    111 
    112 
    113 ------------------------------------------------------------------------------
    114  REQUIREMENTS
    115 
    116  None
    117 
    118 ------------------------------------------------------------------------------
    119  REFERENCES
    120 
    121  d2_11pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
    122 
    123 ------------------------------------------------------------------------------
    124  PSEUDO-CODE
    125 
    126 
    127 ------------------------------------------------------------------------------
    128  RESOURCES USED [optional]
    129 
    130  When the code is written for a specific target processor the
    131  the resources used should be documented below.
    132 
    133  HEAP MEMORY USED: x bytes
    134 
    135  STACK MEMORY USED: x bytes
    136 
    137  CLOCK CYCLES: (cycle count equation for this function) + (variable
    138                 used to represent cycle count for each subroutine
    139                 called)
    140      where: (cycle count variable) = cycle count for [subroutine
    141                                      name]
    142 
    143 ------------------------------------------------------------------------------
    144  CAUTION [optional]
    145  [State any special notes, constraints or cautions for users of this function]
    146 
    147 ------------------------------------------------------------------------------
    148 */
    149 
    150 void decode_2i40_11bits(
    151     Word16 sign,   /* i : signs of 2 pulses.                       */
    152     Word16 index,  /* i : Positions of the 2 pulses.               */
    153     Word16 cod[]   /* o : algebraic (fixed) codebook excitation    */
    154 )
    155 
    156 {
    157     Word16 i;
    158     Word16 j;
    159 
    160     Word16 pos[NB_PULSE];
    161 
    162     /* Decode the positions */
    163 
    164     j = index & 0x1;
    165 
    166     index >>= 1;
    167 
    168     i = index & 0x7;
    169 
    170     pos[0] = i * 5 + j * 2 + 1;
    171 
    172 
    173 
    174 
    175     index >>= 3;
    176 
    177     j = index & 0x3;
    178 
    179     index >>= 2;
    180 
    181     i = index & 0x7;
    182 
    183     if (j == 3)
    184     {
    185         pos[1] = i * 5 + 4;
    186     }
    187     else
    188     {
    189         pos[1] = i * 5 + j;
    190     }
    191 
    192 
    193 
    194 
    195     /* decode the signs  and build the codeword */
    196     for (i = 0; i < L_SUBFR; i++)
    197     {
    198         cod[i] = 0;
    199     }
    200 
    201     for (j = 0; j < NB_PULSE; j++)
    202     {
    203         i = sign & 1;
    204 
    205         /* This line is equivalent to...
    206          *
    207          *
    208          *  if (i == 1)
    209          *  {
    210          *      cod[pos[j]] = 8191;
    211          *  }
    212          *  if (i == 0)
    213          *  {
    214          *      cod[pos[j]] = -8192;
    215          *  }
    216          */
    217 
    218         cod[pos[j]] = i * 16383 - 8192;
    219 
    220         sign >>= 1;
    221     }
    222 
    223     return;
    224 }
    225