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/d1035pf.c
     35 
     36      Date: 04/14/2000
     37 
     38 ------------------------------------------------------------------------------
     39  REVISION HISTORY
     40 
     41  Description: Updated template used to PV coding template. First attempt at
     42           optimizing C code.
     43 
     44  Description: Updated file per comments gathered from Phase 2/3 review.
     45 
     46  Description: Synchronized file with UTMS version 3.2.0. Updated coding
     47               template. Removed unnecessary include files.
     48 
     49  Description: Removed inclusion of "gray.tab".
     50 
     51  Description:
     52 
     53 ------------------------------------------------------------------------------
     54 */
     55 
     56 /*----------------------------------------------------------------------------
     57 ; INCLUDES
     58 ----------------------------------------------------------------------------*/
     59 #include "d1035pf.h"
     60 #include "typedef.h"
     61 #include "basic_op.h"
     62 #include "cnst.h"
     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  10            /* number of pulses  */
     75 
     76 /*----------------------------------------------------------------------------
     77 ; LOCAL FUNCTION DEFINITIONS
     78 ; Function Prototype declaration
     79 ----------------------------------------------------------------------------*/
     80 
     81 /*----------------------------------------------------------------------------
     82 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
     83 ; Variable declaration - defined here and used outside this module
     84 ----------------------------------------------------------------------------*/
     85 
     86 /*
     87 ------------------------------------------------------------------------------
     88  FUNCTION NAME: dec_10i40_35bits
     89 ------------------------------------------------------------------------------
     90  INPUT AND OUTPUT DEFINITIONS
     91 
     92  Inputs:
     93     index = buffer containing index of 10 pulses; each element is
     94         represented by sign+position
     95     cod = buffer of algebraic (fixed) codebook excitation
     96 
     97  Outputs:
     98     cod buffer contains the new algebraic codebook excitation
     99 
    100  Returns:
    101     None
    102 
    103  Global Variables Used:
    104     dgray = gray decoding table
    105 
    106  Local Variables Needed:
    107     None
    108 
    109 ------------------------------------------------------------------------------
    110  FUNCTION DESCRIPTION
    111 
    112  This function builds the innovative codevector from the received index of
    113  algebraic codebook. See c1035pf.c for more details about the algebraic
    114  codebook structure.
    115 
    116 ------------------------------------------------------------------------------
    117  REQUIREMENTS
    118 
    119  None
    120 
    121 ------------------------------------------------------------------------------
    122  REFERENCES
    123 
    124  d1035pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
    125 
    126 ------------------------------------------------------------------------------
    127  PSEUDO-CODE
    128 
    129 void dec_10i40_35bits (
    130     Word16 index[],    // (i)     : index of 10 pulses (sign+position)
    131     Word16 cod[]       // (o)     : algebraic (fixed) codebook excitation
    132 )
    133 {
    134     Word16 i, j, pos1, pos2, sign, tmp;
    135 
    136     for (i = 0; i < L_CODE; i++)
    137     {
    138         cod[i] = 0;
    139     }
    140 
    141     // decode the positions and signs of pulses and build the codeword
    142 
    143     for (j = 0; j < NB_TRACK; j++)
    144     {
    145         // compute index i
    146 
    147         tmp = index[j];
    148         i = tmp & 7;
    149         i = dgray[i];
    150 
    151         i = extract_l (L_shr (L_mult (i, 5), 1));
    152         pos1 = add (i, j); // position of pulse "j"
    153 
    154         i = shr (tmp, 3) & 1;
    155         if (i == 0)
    156         {
    157             sign = 4096; // +1.0
    158         }
    159         else
    160         {
    161             sign = -4096; // -1.0
    162         }
    163 
    164         cod[pos1] = sign;
    165 
    166         // compute index i
    167 
    168         i = index[add (j, 5)] & 7;
    169         i = dgray[i];
    170         i = extract_l (L_shr (L_mult (i, 5), 1));
    171 
    172         pos2 = add (i, j);      // position of pulse "j+5"
    173 
    174         if (sub (pos2, pos1) < 0)
    175         {
    176             sign = negate (sign);
    177         }
    178         cod[pos2] = add (cod[pos2], sign);
    179     }
    180 
    181     return;
    182 }
    183 
    184 ------------------------------------------------------------------------------
    185  RESOURCES USED [optional]
    186 
    187  When the code is written for a specific target processor the
    188  the resources used should be documented below.
    189 
    190  HEAP MEMORY USED: x bytes
    191 
    192  STACK MEMORY USED: x bytes
    193 
    194  CLOCK CYCLES: (cycle count equation for this function) + (variable
    195                 used to represent cycle count for each subroutine
    196                 called)
    197      where: (cycle count variable) = cycle count for [subroutine
    198                                      name]
    199 
    200 ------------------------------------------------------------------------------
    201  CAUTION [optional]
    202  [State any special notes, constraints or cautions for users of this function]
    203 
    204 ------------------------------------------------------------------------------
    205 */
    206 
    207 void dec_10i40_35bits(
    208     Word16 index[],    /* (i)     : index of 10 pulses (sign+position)       */
    209     Word16 cod[]       /* (o)     : algebraic (fixed) codebook excitation    */
    210 )
    211 {
    212     register Word16 i, j, pos1, pos2;
    213     Word16 sign, tmp;
    214 
    215     for (i = 0; i < L_CODE; i++)
    216     {
    217         *(cod + i) = 0;
    218     }
    219 
    220     /* decode the positions and signs of pulses and build the codeword */
    221 
    222     for (j = 0; j < NB_TRACK; j++)
    223     {
    224         /* compute index i */
    225 
    226         tmp = *(index + j);
    227         i = tmp & 7;
    228         i = *(dgray + i);
    229 
    230         i = (Word16)(i * 5);
    231         pos1 = i + j; /* position of pulse "j" */
    232 
    233         i = (tmp >> 3) & 1;
    234 
    235         if (i == 0)
    236         {
    237             sign = 4096;                                 /* +1.0 */
    238         }
    239         else
    240         {
    241             sign = -4096;                                /* -1.0 */
    242         }
    243 
    244         *(cod + pos1) = sign;
    245 
    246         /* compute index i */
    247 
    248         i = *(index + j + 5) & 7;
    249         i = *(dgray + i);
    250         i = (Word16)(i * 5);
    251 
    252         pos2 = i + j;      /* position of pulse "j+5" */
    253 
    254 
    255         if (pos2 < pos1)
    256         {
    257             sign = negate(sign);
    258         }
    259         *(cod + pos2) += sign;
    260     }
    261 
    262     return;
    263 }
    264