DEC_GAIN.C
上传用户:meifeng08
上传日期:2013-06-18
资源大小:5304k
文件大小:5k
源码类别:

语音压缩

开发平台:

C/C++

  1. /* Version 3.3    Last modified: December 26, 1995 */
  2. #include "typedef.h"
  3. #include "basic_op.h"
  4. #include "ld8k.h"
  5. #include "tab_ld8k.h"
  6. /*---------------------------------------------------------------------------*
  7.  * Function  Dec_gain                                                        *
  8.  * ~~~~~~~~~~~~~~~~~~                                                        *
  9.  * Decode the pitch and codebook gains                                       *
  10.  *                                                                           *
  11.  *---------------------------------------------------------------------------*
  12.  * input arguments:                                                          *
  13.  *                                                                           *
  14.  *   index      :Quantization index                                          *
  15.  *   code[]     :Innovative code vector                                      *
  16.  *   L_subfr    :Subframe size                                               *
  17.  *   bfi        :Bad frame indicator                                         *
  18.  *                                                                           *
  19.  * output arguments:                                                         *
  20.  *                                                                           *
  21.  *   gain_pit   :Quantized pitch gain                                        *
  22.  *   gain_cod   :Quantized codebook gain                                     *
  23.  *                                                                           *
  24.  *---------------------------------------------------------------------------*/
  25. void Dec_gain(
  26.    Word16 index,        /* (i)     :Index of quantization.         */
  27.    Word16 code[],       /* (i) Q13 :Innovative vector.             */
  28.    Word16 L_subfr,      /* (i)     :Subframe length.               */
  29.    Word16 bfi,          /* (i)     :Bad frame indicator            */
  30.    Word16 *gain_pit,    /* (o) Q14 :Pitch gain.                    */
  31.    Word16 *gain_cod     /* (o) Q1  :Code gain.                     */
  32. )
  33. {
  34.    Word16  index1, index2, tmp;
  35.    Word16  gcode0, exp_gcode0;
  36.    Word32  L_gbk12, L_acc, L_accb;
  37.    void    Gain_predict( Word16 past_qua_en[], Word16 code[], Word16 L_subfr,
  38.                         Word16 *gcode0, Word16 *exp_gcode0 );
  39.    void    Gain_update( Word16 past_qua_en[], Word32 L_gbk12 );
  40.    void    Gain_update_erasure( Word16 past_qua_en[] );
  41.         /* Gain predictor, Past quantized energies = -14.0 in Q10 */
  42.    static Word16 past_qua_en[4] = { -14336, -14336, -14336, -14336 };
  43.    /*-------------- Case of erasure. ---------------*/
  44.    if(bfi != 0){
  45.       *gain_pit = mult( *gain_pit, 29491 );      /* *0.9 in Q15 */
  46.       if (sub( *gain_pit, 29491) > 0) *gain_pit = 29491;
  47.       *gain_cod = mult( *gain_cod, 32111 );      /* *0.98 in Q15 */
  48.      /*----------------------------------------------*
  49.       * update table of past quantized energies      *
  50.       *                              (frame erasure) *
  51.       *----------------------------------------------*/
  52.       Gain_update_erasure(past_qua_en);
  53.       return;
  54.    }
  55.    /*-------------- Decode pitch gain ---------------*/
  56.    index1 = imap1[ shr(index,NCODE2_B) ] ;
  57.    index2 = imap2[ index & (NCODE2-1) ] ;
  58.    *gain_pit = add( gbk1[index1][0], gbk2[index2][0] );
  59.    /*-------------- Decode codebook gain ---------------*/
  60.   /*---------------------------------------------------*
  61.    *-  energy due to innovation                       -*
  62.    *-  predicted energy                               -*
  63.    *-  predicted codebook gain => gcode0[exp_gcode0]  -*
  64.    *---------------------------------------------------*/
  65.    Gain_predict( past_qua_en, code, L_subfr, &gcode0, &exp_gcode0 );
  66.   /*-----------------------------------------------------------------*
  67.    * *gain_code = (gbk1[indice1][1]+gbk2[indice2][1]) * gcode0;      *
  68.    *-----------------------------------------------------------------*/
  69.    L_acc = L_deposit_l( gbk1[index1][1] );
  70.    L_accb = L_deposit_l( gbk2[index2][1] );
  71.    L_gbk12 = L_add( L_acc, L_accb );                       /* Q13 */
  72.    tmp = extract_l( L_shr( L_gbk12,1 ) );                  /* Q12 */
  73.    L_acc = L_mult(tmp, gcode0);             /* Q[exp_gcode0+12+1] */
  74.    L_acc = L_shl(L_acc, add( negate(exp_gcode0),(-12-1+1+16) ));
  75.    *gain_cod = extract_h( L_acc );                          /* Q1 */
  76.   /*----------------------------------------------*
  77.    * update table of past quantized energies      *
  78.    *----------------------------------------------*/
  79.    Gain_update( past_qua_en, L_gbk12 );
  80.    return;
  81. }