calc_en.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 : calc_en.h
  11. * Purpose : calculation of energy coefficients for quantizers
  12. *
  13. ********************************************************************************
  14. */
  15. #ifndef calc_en_h
  16. #define calc_en_h "$Id $"
  17. /*
  18. ********************************************************************************
  19. * INCLUDE FILES
  20. ********************************************************************************
  21. */
  22. #include "typedef.h"
  23. #include "mode.h"
  24. /*
  25. ********************************************************************************
  26. * DECLARATION OF PROTOTYPES
  27. ********************************************************************************
  28. */
  29. /*************************************************************************
  30. *
  31. * FUNCTION: calc_unfilt_energies
  32. *
  33. * PURPOSE: calculation of several energy coefficients for unfiltered
  34. * excitation signals and the LTP coding gain
  35. *
  36. * frac_en[0]*2^exp_en[0] = <res res> // LP residual energy
  37. * frac_en[1]*2^exp_en[1] = <exc exc> // LTP residual energy
  38. * frac_en[2]*2^exp_en[2] = <exc code> // LTP/CB innovation dot product
  39. * frac_en[3]*2^exp_en[3] = <lres lres> // LTP residual energy
  40. * // (lres = res - gain_pit*exc)
  41. * ltpg = log2(LP_res_en / LTP_res_en)
  42. *
  43. *************************************************************************/
  44. void
  45. calc_unfilt_energies(
  46. Word16 res[], /* i : LP residual, Q0 */
  47. Word16 exc[], /* i : LTP excitation (unfiltered), Q0 */
  48. Word16 code[], /* i : CB innovation (unfiltered), Q13 */
  49. Word16 gain_pit, /* i : pitch gain, Q14 */
  50. Word16 L_subfr, /* i : Subframe length */
  51. Word16 frac_en[], /* o : energy coefficients (3), fraction part, Q15 */
  52. Word16 exp_en[], /* o : energy coefficients (3), exponent part, Q0 */
  53. Word16 *ltpg /* o : LTP coding gain (log2()), Q13 */
  54. );
  55. /*************************************************************************
  56. *
  57. * FUNCTION: calc_filt_energies
  58. *
  59. * PURPOSE: calculation of several energy coefficients for filtered
  60. * excitation signals
  61. *
  62. * Compute coefficients need for the quantization and the optimum
  63. * codebook gain gcu (for MR475 only).
  64. *
  65. * coeff[0] = y1 y1
  66. * coeff[1] = -2 xn y1
  67. * coeff[2] = y2 y2
  68. * coeff[3] = -2 xn y2
  69. * coeff[4] = 2 y1 y2
  70. *
  71. *
  72. * gcu = <xn2, y2> / <y2, y2> (0 if <xn2, y2> <= 0)
  73. *
  74. * Product <y1 y1> and <xn y1> have been computed in G_pitch() and
  75. * are in vector g_coeff[].
  76. *
  77. *************************************************************************/
  78. void
  79. calc_filt_energies(
  80. enum Mode mode, /* i : coder mode */
  81. Word16 xn[], /* i : LTP target vector, Q0 */
  82. Word16 xn2[], /* i : CB target vector, Q0 */
  83. Word16 y1[], /* i : Adaptive codebook, Q0 */
  84. Word16 Y2[], /* i : Filtered innovative vector, Q12 */
  85. Word16 g_coeff[], /* i : Correlations <xn y1> <y1 y1> */
  86. /* computed in G_pitch() */
  87. Word16 frac_coeff[],/* o : energy coefficients (5), fraction part, Q15 */
  88. Word16 exp_coeff[], /* o : energy coefficients (5), exponent part, Q0 */
  89. Word16 *cod_gain_frac,/* o: optimum codebook gain (fraction part), Q15 */
  90. Word16 *cod_gain_exp /* o: optimum codebook gain (exponent part), Q0 */
  91. );
  92. /*************************************************************************
  93. *
  94. * FUNCTION: calc_target_energy
  95. *
  96. * PURPOSE: calculation of target energy
  97. *
  98. * en = <xn, xn>
  99. *
  100. *************************************************************************/
  101. void
  102. calc_target_energy(
  103. Word16 xn[], /* i: LTP target vector, Q0 */
  104. Word16 *en_exp, /* o: optimum codebook gain (exponent part), Q0 */
  105. Word16 *en_frac /* o: optimum codebook gain (fraction part), Q15 */
  106. );
  107. #endif