d2_11pf.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 : d2_11pf.c
  11. * Purpose : Algebraic codebook decoder
  12. *
  13. ********************************************************************************
  14. */
  15. /*
  16. ********************************************************************************
  17. * MODULE INCLUDE FILE AND VERSION ID
  18. ********************************************************************************
  19. */
  20. #include "d2_11pf.h"
  21. const char d2_11pf_c_id[] = "@(#)$Id $" d2_11pf_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 NB_PULSE 2 /* number of pulses */
  37. /*
  38. ********************************************************************************
  39. * PUBLIC PROGRAM CODE
  40. ********************************************************************************
  41. */
  42. /*************************************************************************
  43. *
  44. * FUNCTION: decode_2i40_11bits (decod_ACELP())
  45. *
  46. * PURPOSE: Algebraic codebook decoder
  47. *
  48. *************************************************************************/
  49. void decode_2i40_11bits(
  50. Word16 sign, /* i : signs of 2 pulses. */
  51. Word16 index, /* i : Positions of the 2 pulses. */
  52. Word16 cod[] /* o : algebraic (fixed) codebook excitation */
  53. )
  54. {
  55. Word16 i, j;
  56. Word16 pos[NB_PULSE];
  57. /* Decode the positions */
  58. j = index & 1; logic16 ();
  59. index = shr_ex(index, 1);
  60. i = index & 7; logic16 ();
  61. i = add_ex(i, shl_ex(i, 2)); /* pos0 =i*5+1+j*2 */
  62. i = add_ex(i, 1);
  63. j = shl_ex(j, 1);
  64. pos[0] = add_ex(i, j); move16 ();
  65. index = shr_ex(index, 3);
  66. j = index & 3; logic16 ();
  67. index = shr_ex(index, 2);
  68. i = index & 7; logic16 ();
  69. test();
  70. if (sub_ex(j, 3) == 0)
  71. {
  72. i = add_ex(i, shl_ex(i, 2)); /* pos1 =i*5+4 */
  73. pos[1] = add_ex(i, 4); move16 ();
  74. }
  75. else
  76. {
  77. i = add_ex(i, shl_ex(i, 2)); /* pos1 =i*5+j */
  78. pos[1] = add_ex(i, j); move16 ();
  79. }
  80. /* decode the signs and build the codeword */
  81. for (i = 0; i < L_SUBFR; i++) {
  82. cod[i] = 0; move16 ();
  83. }
  84. for (j = 0; j < NB_PULSE; j++) {
  85. i = sign & 1; logic16 ();
  86. sign = shr_ex(sign, 1);
  87. test ();
  88. if (i != 0) {
  89. cod[pos[j]] = 8191; move16 (); /* +1.0 */
  90. } else {
  91. cod[pos[j]] = -8192; move16 (); /* -1.0 */
  92. }
  93. }
  94. return;
  95. }