dec_lag3.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 : dec_lag3.c
  11. * Purpose : Decoding of fractional pitch lag with 1/3 resolution.
  12. * Extract the integer and fraction parts of the pitch lag from
  13. * the received adaptive codebook index.
  14. *
  15. ********************************************************************************
  16. */
  17. /*
  18. ********************************************************************************
  19. * MODULE INCLUDE FILE AND VERSION ID
  20. ********************************************************************************
  21. */
  22. #include "dec_lag3.h"
  23. const char dec_lag3_id[] = "@(#)$Id $" dec_lag3_h;
  24. /*
  25. ********************************************************************************
  26. * INCLUDE FILES
  27. ********************************************************************************
  28. */
  29. #include "typedef.h"
  30. #include "basic_op.h"
  31. #include "count.h"
  32. /*
  33. ********************************************************************************
  34. * LOCAL VARIABLES AND TABLES
  35. ********************************************************************************
  36. */
  37. /*
  38. ********************************************************************************
  39. * PUBLIC PROGRAM CODE
  40. ********************************************************************************
  41. */
  42. /*************************************************************************
  43. * FUNCTION: Dec_lag3
  44. *
  45. * PURPOSE: Decoding of fractional pitch lag with 1/3 resolution.
  46. * Extract the integer and fraction parts of the pitch lag from
  47. * the received adaptive codebook index.
  48. *
  49. * See "Enc_lag3.c" for more details about the encoding procedure.
  50. *
  51. * The fractional lag in 1st and 3rd subframes is encoded with 8 bits
  52. * while that in 2nd and 4th subframes is relatively encoded with 4, 5
  53. * and 6 bits depending on the mode.
  54. *
  55. *************************************************************************/
  56. void Dec_lag3(Word16 index, /* i : received pitch index */
  57. Word16 t0_min, /* i : minimum of search range */
  58. Word16 t0_max, /* i : maximum of search range */
  59. Word16 i_subfr, /* i : subframe flag */
  60. Word16 T0_prev, /* i : integer pitch delay of last subframe
  61. used in 2nd and 4th subframes */
  62. Word16 * T0, /* o : integer part of pitch lag */
  63. Word16 * T0_frac, /* o : fractional part of pitch lag */
  64. Word16 flag4 /* i : flag for encoding with 4 bits */
  65. )
  66. {
  67. Word16 i;
  68. Word16 tmp_lag;
  69. test ();
  70. if (i_subfr == 0) { /* if 1st or 3rd subframe */
  71. test ();
  72. if (sub_ex(index, 197) < 0) {
  73. *T0 = add_ex(mult_ex(add_ex(index, 2), 10923), 19);
  74. i = add_ex(add_ex(*T0, *T0), *T0);
  75. *T0_frac = add_ex(sub_ex(index, i), 58);
  76. } else {
  77. *T0 = sub_ex(index, 112);
  78. *T0_frac = 0; move16 ();
  79. }
  80. } else { /* 2nd or 4th subframe */
  81. test ();
  82. if (flag4 == 0) {
  83. /* 'normal' decoding: either with 5 or 6 bit resolution */
  84. i = sub_ex(mult_ex(add_ex(index, 2), 10923), 1);
  85. *T0 = add_ex(i, t0_min);
  86. i = add_ex(add_ex(i, i), i);
  87. *T0_frac = sub_ex(sub_ex(index, 2), i);
  88. }
  89. else {
  90. /* decoding with 4 bit resolution */
  91. tmp_lag = T0_prev; move16 ();
  92. test ();
  93. if ( sub_ex( sub_ex(tmp_lag, t0_min), 5) > 0)
  94. tmp_lag = add_ex (t0_min, 5);
  95. test ();
  96. if ( sub_ex( sub_ex(t0_max, tmp_lag), 4) > 0)
  97. tmp_lag = sub_ex (t0_max, 4);
  98. test ();
  99. if (sub_ex(index, 4) < 0)
  100. {
  101. i = sub_ex(tmp_lag, 5);
  102. *T0 = add_ex(i, index);
  103. *T0_frac = 0; move16 ();
  104. }
  105. else
  106. {
  107. test ();
  108. if (sub_ex(index, 12) < 0)
  109. {
  110. i = sub_ex(mult_ex(sub_ex(index, 5), 10923), 1);
  111. *T0 = add_ex(i, tmp_lag);
  112. i = add_ex(add_ex(i, i), i);
  113. *T0_frac = sub_ex(sub_ex(index, 9), i);
  114. }
  115. else
  116. {
  117. i = add_ex( sub_ex (index, 12), tmp_lag);
  118. *T0 = add_ex (i, 1);
  119. *T0_frac = 0; move16 ();
  120. }
  121. }
  122. } /* end if (decoding with 4 bit resolution) */
  123. }
  124. return;
  125. }