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: dec_acelp_4p_in_64.cpp
     35 
     36      Date: 05/08/2007
     37 
     38 ------------------------------------------------------------------------------
     39  REVISION HISTORY
     40 
     41 
     42  Description:
     43 
     44 ------------------------------------------------------------------------------
     45  INPUT AND OUTPUT DEFINITIONS
     46 
     47      int16 index[],    (i) : index (20): 5+5+5+5 = 20 bits.
     48                        (i) : index (36): 9+9+9+9 = 36 bits.
     49                        (i) : index (44): 13+9+13+9 = 44 bits.
     50                        (i) : index (52): 13+13+13+13 = 52 bits.
     51                        (i) : index (64): 2+2+2+2+14+14+14+14 = 64 bits.
     52                        (i) : index (72): 10+2+10+2+10+14+10+14 = 72 bits.
     53                        (i) : index (88): 11+11+11+11+11+11+11+11 = 88 bits.
     54      int16 nbbits,     (i) : 20, 36, 44, 52, 64, 72 or 88 bits
     55      int16 code[]      (o) Q9: algebraic (fixed) codebook excitation
     56 
     57 ------------------------------------------------------------------------------
     58  FUNCTION DESCRIPTION
     59 
     60    20, 36, 44, 52, 64, 72, 88 bits algebraic codebook decoder.
     61    4 tracks x 16 positions per track = 64 samples.
     62 
     63    20 bits --> 4 pulses in a frame of 64 samples.
     64    36 bits --> 8 pulses in a frame of 64 samples.
     65    44 bits --> 10 pulses in a frame of 64 samples.
     66    52 bits --> 12 pulses in a frame of 64 samples.
     67    64 bits --> 16 pulses in a frame of 64 samples.
     68    72 bits --> 18 pulses in a frame of 64 samples.
     69    88 bits --> 24 pulses in a frame of 64 samples.
     70 
     71    All pulses can have two (2) possible amplitudes: +1 or -1.
     72    Each pulse can have sixteen (16) possible positions.
     73 
     74 ------------------------------------------------------------------------------
     75  REQUIREMENTS
     76 
     77 
     78 ------------------------------------------------------------------------------
     79  REFERENCES
     80 
     81 ------------------------------------------------------------------------------
     82  PSEUDO-CODE
     83 
     84 ------------------------------------------------------------------------------
     85 */
     86 
     87 
     88 /*----------------------------------------------------------------------------
     89 ; INCLUDES
     90 ----------------------------------------------------------------------------*/
     91 
     92 #include "pv_amr_wb_type_defs.h"
     93 #include "pvamrwbdecoder_basic_op.h"
     94 #include "pvamrwbdecoder_cnst.h"
     95 #include "pvamrwbdecoder_acelp.h"
     96 
     97 #include "q_pulse.h"
     98 
     99 /*----------------------------------------------------------------------------
    100 ; MACROS
    101 ; Define module specific macros here
    102 ----------------------------------------------------------------------------*/
    103 
    104 
    105 /*----------------------------------------------------------------------------
    106 ; DEFINES
    107 ; Include all pre-processor statements here. Include conditional
    108 ; compile variables also.
    109 ----------------------------------------------------------------------------*/
    110 #define L_CODE    64                       /* codevector length  */
    111 #define NB_TRACK  4                        /* number of track    */
    112 #define NB_POS    16                       /* number of position */
    113 
    114 /*----------------------------------------------------------------------------
    115 ; LOCAL FUNCTION DEFINITIONS
    116 ; Function Prototype declaration
    117 ----------------------------------------------------------------------------*/
    118 #ifdef __cplusplus
    119 extern "C"
    120 {
    121 #endif
    122 
    123     void add_pulses(int16 pos[], int16 nb_pulse, int16 track, int16 code[]);
    124 
    125 #ifdef __cplusplus
    126 }
    127 #endif
    128 
    129 /*----------------------------------------------------------------------------
    130 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    131 ; Variable declaration - defined here and used outside this module
    132 ----------------------------------------------------------------------------*/
    133 
    134 /*----------------------------------------------------------------------------
    135 ; EXTERNAL FUNCTION REFERENCES
    136 ; Declare functions defined elsewhere and referenced in this module
    137 ----------------------------------------------------------------------------*/
    138 
    139 /*----------------------------------------------------------------------------
    140 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    141 ; Declare variables used in this module but defined elsewhere
    142 ----------------------------------------------------------------------------*/
    143 
    144 /*----------------------------------------------------------------------------
    145 ; FUNCTION CODE
    146 ----------------------------------------------------------------------------*/
    147 
    148 void dec_acelp_4p_in_64(
    149     int16 index[],  /* (i) : index (20): 5+5+5+5 = 20 bits.                 */
    150     /* (i) : index (36): 9+9+9+9 = 36 bits.                 */
    151     /* (i) : index (44): 13+9+13+9 = 44 bits.               */
    152     /* (i) : index (52): 13+13+13+13 = 52 bits.             */
    153     /* (i) : index (64): 2+2+2+2+14+14+14+14 = 64 bits.     */
    154     /* (i) : index (72): 10+2+10+2+10+14+10+14 = 72 bits.   */
    155     /* (i) : index (88): 11+11+11+11+11+11+11+11 = 88 bits. */
    156     int16 nbbits,   /* (i) : 20, 36, 44, 52, 64, 72 or 88 bits              */
    157     int16 code[]    /* (o) Q9: algebraic (fixed) codebook excitation        */
    158 )
    159 {
    160     int16 k, pos[6];
    161     int32 L_index;
    162     pv_memset(code, 0, L_CODE*sizeof(*code));
    163 
    164     /* decode the positions and signs of pulses and build the codeword */
    165 
    166 
    167     switch (nbbits)
    168     {
    169         case 20:
    170             for (k = 0; k < NB_TRACK; k++)
    171             {
    172                 L_index = index[k];
    173                 dec_1p_N1(L_index, 4, 0, pos);
    174                 add_pulses(pos, 1, k, code);
    175             }
    176             break;
    177 
    178         case  36:
    179             for (k = 0; k < NB_TRACK; k++)
    180             {
    181                 L_index = index[k];
    182                 dec_2p_2N1(L_index, 4, 0, pos);
    183                 add_pulses(pos, 2, k, code);
    184             }
    185             break;
    186         case 44:
    187             for (k = 0; k < NB_TRACK - 2; k++)
    188             {
    189                 L_index = index[k];
    190                 dec_3p_3N1(L_index, 4, 0, pos);
    191                 add_pulses(pos, 3, k, code);
    192             }
    193             for (k = 2; k < NB_TRACK; k++)
    194             {
    195                 L_index = index[k];
    196                 dec_2p_2N1(L_index, 4, 0, pos);
    197                 add_pulses(pos, 2, k, code);
    198             }
    199             break;
    200         case 52:
    201             for (k = 0; k < NB_TRACK; k++)
    202             {
    203                 L_index = index[k];
    204                 dec_3p_3N1(L_index, 4, 0, pos);
    205                 add_pulses(pos, 3, k, code);
    206             }
    207             break;
    208         case 64:
    209             for (k = 0; k < NB_TRACK; k++)
    210             {
    211                 L_index = ((int32)index[k] << 14) + index[k + NB_TRACK];
    212                 dec_4p_4N(L_index, 4, 0, pos);
    213                 add_pulses(pos, 4, k, code);
    214             }
    215             break;
    216         case 72:
    217             for (k = 0; k < NB_TRACK - 2; k++)
    218             {
    219                 L_index = ((int32)index[k] << 10) + index[k + NB_TRACK];
    220                 dec_5p_5N(L_index, 4, 0, pos);
    221                 add_pulses(pos, 5, k, code);
    222             }
    223             for (k = 2; k < NB_TRACK; k++)
    224             {
    225                 L_index = ((int32)index[k] << 14) + index[k + NB_TRACK];
    226                 dec_4p_4N(L_index, 4, 0, pos);
    227                 add_pulses(pos, 4, k, code);
    228             }
    229             break;
    230         case 88:
    231             for (k = 0; k < NB_TRACK; k++)
    232             {
    233                 L_index = ((int32)index[k] << 11) + index[k + NB_TRACK];
    234                 dec_6p_6N_2(L_index, 4, 0, pos);
    235                 add_pulses(pos, 6, k, code);
    236             }
    237         default:
    238             break;
    239     }
    240 
    241 
    242 }
    243 
    244 
    245 
    246 void add_pulses(int16 pos[], int16 nb_pulse, int16 track, int16 code[])
    247 {
    248     int16 i, k;
    249 
    250     for (k = 0; k < nb_pulse; k++)
    251     {
    252         /* i = ((pos[k] & (NB_POS-1))*NB_TRACK) + track; */
    253         i = ((pos[k] & (NB_POS - 1)) << 2) + track;
    254 
    255         if ((pos[k] & NB_POS) == 0)
    256         {
    257             code[i] +=  512;
    258         }
    259         else
    260         {
    261             code[i] -=  512;
    262         }
    263     }
    264 
    265 }
    266