d_gain_c.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. ********************************************************************************
  3. *
  4. * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
  5. * R99 Version 3.3.0
  6. * REL-4 Version 4.1.0
  7. *
  8. ********************************************************************************
  9. *
  10. * File : d_gain_c.c
  11. *
  12. ********************************************************************************
  13. */
  14. /*
  15. ********************************************************************************
  16. * MODULE INCLUDE FILE AND VERSION ID
  17. ********************************************************************************
  18. */
  19. #include "d_gain_c.h"
  20. const char d_gain_c_id[] = "@(#)$Id $" d_gain_c_h;
  21. /*
  22. ********************************************************************************
  23. * INCLUDE FILES
  24. ********************************************************************************
  25. */
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include "typedef.h"
  29. #include "mode.h"
  30. #include "basic_op.h"
  31. #include "oper_32b.h"
  32. #include "count.h"
  33. #include "cnst.h"
  34. #include "log2.h"
  35. #include "pow2.h"
  36. #include "gc_pred.h"
  37. /*
  38. ********************************************************************************
  39. * LOCAL VARIABLES AND TABLES
  40. ********************************************************************************
  41. */
  42. #include "gains.tab"
  43. /*
  44. ********************************************************************************
  45. * PUBLIC PROGRAM CODE
  46. ********************************************************************************
  47. */
  48. /*
  49. **************************************************************************
  50. *
  51. * Function : d_gain_code
  52. * Purpose : Decode the fixed codebook gain using the received index.
  53. *
  54. **************************************************************************
  55. */
  56. void d_gain_code (
  57. gc_predState *pred_state, /* i/o : MA predictor state */
  58. enum Mode mode, /* i : AMR mode (MR795 or MR122) */
  59. Word16 index, /* i : received quantization index */
  60. Word16 code[], /* i : innovation codevector */
  61. Word16 *gain_code /* o : decoded innovation gain */
  62. )
  63. {
  64. Word16 gcode0, exp, frac;
  65. const Word16 *p;
  66. Word16 qua_ener_MR122, qua_ener;
  67. Word16 exp_inn_en;
  68. Word16 frac_inn_en;
  69. Word32 L_tmp;
  70. /*-------------- Decode codebook gain ---------------*/
  71. /*-------------------------------------------------------------------*
  72. * predict codebook gain *
  73. * ~~~~~~~~~~~~~~~~~~~~~ *
  74. * gc0 = Pow2(int(d)+frac(d)) *
  75. * = 2^exp + 2^frac *
  76. * *
  77. *-------------------------------------------------------------------*/
  78. gc_pred(pred_state, mode, code, &exp, &frac,
  79. &exp_inn_en, &frac_inn_en);
  80. p = &qua_gain_code[add_ex (add_ex (index, index), index)];
  81. /* Different scalings between MR122 and the other modes */
  82. test ();
  83. if (sub_ex(mode, MR122) == 0)
  84. {
  85. gcode0 = extract_l_ex (Pow2 (exp, frac)); /* predicted gain */
  86. gcode0 = shl_ex (gcode0, 4);
  87. *gain_code = shl_ex (mult_ex (gcode0, *p++), 1); move16 ();
  88. }
  89. else
  90. {
  91. gcode0 = extract_l_ex (Pow2 (14, frac));
  92. L_tmp = L_mult_ex(*p++, gcode0);
  93. L_tmp = L_shr_ex(L_tmp, sub_ex(9, exp));
  94. *gain_code = extract_h_ex(L_tmp); /* Q1 */
  95. }
  96. /*-------------------------------------------------------------------*
  97. * update table of past quantized energies *
  98. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
  99. *-------------------------------------------------------------------*/
  100. qua_ener_MR122 = *p++; move16();
  101. qua_ener = *p++; move16();
  102. gc_pred_update(pred_state, qua_ener_MR122, qua_ener);
  103. return;
  104. }