dec_lag6.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_lag6.c
  11. * Purpose : Decoding of fractional pitch lag with 1/6 resolution.
  12. *
  13. ********************************************************************************
  14. */
  15. /*
  16. ********************************************************************************
  17. * MODULE INCLUDE FILE AND VERSION ID
  18. ********************************************************************************
  19. */
  20. #include "dec_lag6.h"
  21. const char dec_lag6_id[] = "@(#)$Id $" dec_lag6_h;
  22. /*
  23. ********************************************************************************
  24. * INCLUDE FILES
  25. ********************************************************************************
  26. */
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include "typedef.h"
  30. #include "basic_op.h"
  31. #include "count.h"
  32. /*
  33. ********************************************************************************
  34. * PUBLIC PROGRAM CODE
  35. ********************************************************************************
  36. */
  37. /*
  38. ************************************************************************
  39. * FUNCTION: Dec_lag6
  40. *
  41. * PURPOSE: Decoding of fractional pitch lag with 1/6 resolution.
  42. * Extract the integer and fraction parts of the pitch lag from
  43. * the received adaptive codebook index.
  44. *
  45. * See "Enc_lag6.c" for more details about the encoding procedure.
  46. *
  47. * The fractional lag in 1st and 3rd subframes is encoded with 9 bits
  48. * while that in 2nd and 4th subframes is relatively encoded with 6 bits.
  49. * Note that in relative encoding only 61 values are used. If the
  50. * decoder receives 61, 62, or 63 as the relative pitch index, it means
  51. * that a transmission error occurred. In this case, the pitch lag from
  52. * previous subframe (actually from previous frame) is used.
  53. *
  54. ************************************************************************
  55. */
  56. void Dec_lag6 (
  57. Word16 index, /* input : received pitch index */
  58. Word16 pit_min, /* input : minimum pitch lag */
  59. Word16 pit_max, /* input : maximum pitch lag */
  60. Word16 i_subfr, /* input : subframe flag */
  61. Word16 *T0, /* in/out: integer part of pitch lag */
  62. Word16 *T0_frac /* output: fractional part of pitch lag */
  63. )
  64. {
  65. Word16 i;
  66. Word16 T0_min, T0_max;
  67. test ();
  68. if (i_subfr == 0) /* if 1st or 3rd subframe */
  69. {
  70. test ();
  71. if (sub_ex (index, 463) < 0)
  72. {
  73. /* T0 = (index+5)/6 + 17 */
  74. *T0 = add_ex (mult_ex (add_ex (index, 5), 5462), 17);
  75. i = add_ex (add_ex (*T0, *T0), *T0);
  76. /* *T0_frac = index - T0*6 + 105 */
  77. *T0_frac = add_ex (sub_ex (index, add_ex (i, i)), 105);
  78. move16 ();
  79. }
  80. else
  81. {
  82. *T0 = sub_ex (index, 368);
  83. *T0_frac = 0; move16 ();
  84. }
  85. }
  86. else
  87. /* second or fourth subframe */
  88. {
  89. /* find T0_min and T0_max for 2nd (or 4th) subframe */
  90. T0_min = sub_ex (*T0, 5);
  91. test ();
  92. if (sub_ex (T0_min, pit_min) < 0)
  93. {
  94. T0_min = pit_min; move16 ();
  95. }
  96. T0_max = add_ex (T0_min, 9);
  97. test ();
  98. if (sub_ex (T0_max, pit_max) > 0)
  99. {
  100. T0_max = pit_max; move16 ();
  101. T0_min = sub_ex (T0_max, 9);
  102. }
  103. /* i = (index+5)/6 - 1 */
  104. i = sub_ex (mult_ex (add_ex (index, 5), 5462), 1);
  105. *T0 = add_ex (i, T0_min);
  106. i = add_ex (add_ex (i, i), i);
  107. *T0_frac = sub_ex (sub_ex (index, 3), add_ex (i, i));
  108. move16 ();
  109. }
  110. }