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

语音压缩

开发平台:

C/C++

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