pred_lt.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 : pred_lt.c
  11. * Purpose : Compute the result of long term prediction
  12. *
  13. ********************************************************************************
  14. */
  15. /*
  16. ********************************************************************************
  17. * MODULE INCLUDE FILE AND VERSION ID
  18. ********************************************************************************
  19. */
  20. #include "pred_lt.h"
  21. const char pred_lt_id[] = "@(#)$Id $" pred_lt_h;
  22. /*
  23. ********************************************************************************
  24. * INCLUDE FILES
  25. ********************************************************************************
  26. */
  27. #include "typedef.h"
  28. #include "basic_op.h"
  29. #include "count.h"
  30. #include "cnst.h"
  31. /*
  32. ********************************************************************************
  33. * LOCAL VARIABLES AND TABLES
  34. ********************************************************************************
  35. */
  36. #define UP_SAMP_MAX 6
  37. #define L_INTER10 (L_INTERPOL-1)
  38. #define FIR_SIZE (UP_SAMP_MAX*L_INTER10+1)
  39. /* 1/6 resolution interpolation filter (-3 dB at 3600 Hz) */
  40. /* Note: the 1/3 resolution filter is simply a subsampled
  41. * version of the 1/6 resolution filter, i.e. it uses
  42. * every second coefficient:
  43. *
  44. * inter_3l[k] = inter_6[2*k], 0 <= k <= 3*L_INTER10
  45. */
  46. static const Word16 inter_6[FIR_SIZE] =
  47. {
  48. 29443,
  49. 28346, 25207, 20449, 14701, 8693, 3143,
  50. -1352, -4402, -5865, -5850, -4673, -2783,
  51. -672, 1211, 2536, 3130, 2991, 2259,
  52. 1170, 0, -1001, -1652, -1868, -1666,
  53. -1147, -464, 218, 756, 1060, 1099,
  54. 904, 550, 135, -245, -514, -634,
  55. -602, -451, -231, 0, 191, 308,
  56. 340, 296, 198, 78, -36, -120,
  57. -163, -165, -132, -79, -19, 34,
  58. 73, 91, 89, 70, 38, 0
  59. };
  60. /*
  61. ********************************************************************************
  62. * PUBLIC PROGRAM CODE
  63. ********************************************************************************
  64. */
  65. /*************************************************************************
  66. *
  67. * FUNCTION: Pred_lt_3or6()
  68. *
  69. * PURPOSE: Compute the result of long term prediction with fractional
  70. * interpolation of resolution 1/3 or 1/6. (Interpolated past
  71. * excitation).
  72. *
  73. * DESCRIPTION:
  74. * The past excitation signal at the given delay is interpolated at
  75. * the given fraction to build the adaptive codebook excitation.
  76. * On return exc[0..L_subfr-1] contains the interpolated signal
  77. * (adaptive codebook excitation).
  78. *
  79. *************************************************************************/
  80. void Pred_lt_3or6 (
  81. Word16 exc[], /* in/out: excitation buffer */
  82. Word16 T0, /* input : integer pitch lag */
  83. Word16 frac, /* input : fraction of lag */
  84. Word16 L_subfr, /* input : subframe size */
  85. Word16 flag3 /* input : if set, upsampling rate = 3 (6 otherwise) */
  86. )
  87. {
  88. Word16 i, j, k;
  89. Word16 *x0, *x1, *x2;
  90. const Word16 *c1, *c2;
  91. Word32 s;
  92. x0 = &exc[-T0]; move16 ();
  93. frac = negate_ex (frac);
  94. test();
  95. if (flag3 != 0)
  96. {
  97. frac = shl_ex (frac, 1); /* inter_3l[k] = inter_6[2*k] -> k' = 2*k */
  98. }
  99. test ();
  100. if (frac < 0)
  101. {
  102. frac = add_ex (frac, UP_SAMP_MAX);
  103. x0--;
  104. }
  105. for (j = 0; j < L_subfr; j++)
  106. {
  107. x1 = x0++; move16 ();
  108. x2 = x0; move16 ();
  109. c1 = &inter_6[frac];
  110. c2 = &inter_6[sub_ex (UP_SAMP_MAX, frac)];
  111. s = 0; move32 ();
  112. for (i = 0, k = 0; i < L_INTER10; i++, k += UP_SAMP_MAX)
  113. {
  114. s = L_mac_ex (s, x1[-i], c1[k]);
  115. s = L_mac_ex (s, x2[i], c2[k]);
  116. }
  117. exc[j] = round_ex (s); move16 ();
  118. }
  119. return;
  120. }