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