a_refl.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 : a_refl.c
  11. * Purpose : Convert from direct form coefficients to
  12. * reflection coefficients
  13. *
  14. ********************************************************************************
  15. */
  16. /*
  17. ********************************************************************************
  18. * MODULE INCLUDE FILE AND VERSION ID
  19. ********************************************************************************
  20. */
  21. #include "a_refl.h"
  22. const char a_refl_id[] = "@(#)$Id $" a_refl_h;
  23. /*
  24. ********************************************************************************
  25. * INCLUDE FILES
  26. ********************************************************************************
  27. */
  28. #include "typedef.h"
  29. #include "basic_op.h"
  30. #include "oper_32b.h"
  31. #include "count.h"
  32. #include "cnst.h"
  33. /*
  34. ********************************************************************************
  35. * LOCAL VARIABLES AND TABLES
  36. ********************************************************************************
  37. */
  38. /*
  39. ********************************************************************************
  40. * PUBLIC PROGRAM CODE
  41. ********************************************************************************
  42. */
  43. /*
  44. **************************************************************************
  45. *
  46. * Function : A_Refl
  47. *
  48. **************************************************************************
  49. */
  50. void A_Refl(
  51. Word16 a[], /* i : Directform coefficients */
  52. Word16 refl[] /* o : Reflection coefficients */
  53. )
  54. {
  55. /* local variables */
  56. Word16 i,j;
  57. Word16 aState[M];
  58. Word16 bState[M];
  59. Word16 normShift;
  60. Word16 normProd;
  61. Word32 L_acc;
  62. Word16 scale;
  63. Word32 L_temp;
  64. Word16 temp;
  65. Word16 mult_ex;
  66. /* initialize states */
  67. for (i = 0; i < M; i++)
  68. {
  69. aState[i] = a[i]; move16 ();
  70. }
  71. /* backward Levinson recursion */
  72. for (i = M-1; i >= 0; i--)
  73. {
  74. if (sub_ex(abs_s_ex(aState[i]), 4096) >= 0)
  75. {
  76. goto ExitRefl;
  77. }
  78. refl[i] = shl_ex(aState[i], 3);
  79. L_temp = L_mult_ex(refl[i], refl[i]);
  80. L_acc = L_sub_ex(MAX_32, L_temp);
  81. normShift = norm_l_ex(L_acc);
  82. scale = sub_ex(15, normShift);
  83. L_acc = L_shl_ex(L_acc, normShift);
  84. normProd = round_ex(L_acc);
  85. mult_ex = div_s(16384, normProd);
  86. for (j = 0; j < i; j++)
  87. {
  88. L_acc = L_deposit_h_ex(aState[j]);
  89. L_acc = L_msu_ex(L_acc, refl[i], aState[i-j-1]);
  90. temp = round_ex(L_acc);
  91. L_temp = L_mult_ex(mult_ex, temp);
  92. L_temp = L_shr_r_ex(L_temp, scale);
  93. if (L_sub_ex(L_abs_ex(L_temp), 32767) > 0)
  94. {
  95. goto ExitRefl;
  96. }
  97. bState[j] = extract_l_ex(L_temp);
  98. }
  99. for (j = 0; j < i; j++)
  100. {
  101. aState[j] = bState[j]; move16 ();
  102. }
  103. }
  104. return;
  105. ExitRefl:
  106. for (i = 0; i < M; i++)
  107. {
  108. refl[i] = 0; move16 ();
  109. }
  110. }