d_plsf_5.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 : d_plsf_5.c
  11. *
  12. *****************************************************************************
  13. */
  14. /*
  15. *****************************************************************************
  16. * MODULE INCLUDE FILE AND VERSION ID
  17. *****************************************************************************
  18. */
  19. #include "d_plsf.h"
  20. const char d_plsf_5_id[] = "@(#)$Id $" d_plsf_h;
  21. /*
  22. *****************************************************************************
  23. * INCLUDE FILES
  24. *****************************************************************************
  25. */
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include "typedef.h"
  29. #include "basic_op.h"
  30. #include "count.h"
  31. #include "lsp_lsf.h"
  32. #include "reorder.h"
  33. #include "cnst.h"
  34. #include "copy.h"
  35. /*
  36. *****************************************************************************
  37. * LOCAL VARIABLES AND TABLES
  38. *****************************************************************************
  39. */
  40. #include "q_plsf_5.tab" /* Codebooks of LSF prediction residual */
  41. /* ALPHA -> 0.95 */
  42. /* ONE_ALPHA-> (1.0-ALPHA) */
  43. #define ALPHA 31128
  44. #define ONE_ALPHA 1639
  45. /*
  46. *--------------------------------------------------*
  47. * Constants (defined in cnst.h) *
  48. *--------------------------------------------------*
  49. * M : LPC order
  50. *--------------------------------------------------*
  51. */
  52. /*
  53. *****************************************************************************
  54. * PUBLIC PROGRAM CODE
  55. *****************************************************************************
  56. */
  57. /*
  58. **************************************************************************
  59. *
  60. * Function : D_plsf_5
  61. * Purpose : Decodes the 2 sets of LSP parameters in a frame
  62. * using the received quantization indices.
  63. *
  64. **************************************************************************
  65. */
  66. int D_plsf_5 (
  67. D_plsfState *st, /* i/o: State variables */
  68. Word16 bfi, /* i : bad frame indicator (set to 1 if a bad
  69. frame is received) */
  70. Word16 *indice, /* i : quantization indices of 5 submatrices, Q0 */
  71. Word16 *lsp1_q, /* o : quantized 1st LSP vector (M), Q15 */
  72. Word16 *lsp2_q /* o : quantized 2nd LSP vector (M), Q15 */
  73. )
  74. {
  75. Word16 i;
  76. const Word16 *p_dico;
  77. Word16 temp, sign;
  78. Word16 lsf1_r[M], lsf2_r[M];
  79. Word16 lsf1_q[M], lsf2_q[M];
  80. test ();
  81. if (bfi != 0) /* if bad frame */
  82. {
  83. /* use the past LSFs slightly shifted towards their mean */
  84. for (i = 0; i < M; i++)
  85. {
  86. /* lsfi_q[i] = ALPHA*st->past_lsf_q[i] + ONE_ALPHA*mean_lsf[i]; */
  87. lsf1_q[i] = add_ex (mult_ex (st->past_lsf_q[i], ALPHA),
  88. mult_ex (mean_lsf[i], ONE_ALPHA));
  89. move16 ();
  90. lsf2_q[i] = lsf1_q[i]; move16 ();
  91. }
  92. /* estimate past quantized residual to be used in next frame */
  93. for (i = 0; i < M; i++)
  94. {
  95. /* temp = mean_lsf[i] + st->past_r_q[i] * LSP_PRED_FAC_MR122; */
  96. temp = add_ex (mean_lsf[i], mult_ex (st->past_r_q[i],
  97. LSP_PRED_FAC_MR122));
  98. st->past_r_q[i] = sub_ex (lsf2_q[i], temp);
  99. move16 ();
  100. }
  101. }
  102. else
  103. /* if good LSFs received */
  104. {
  105. /* decode prediction residuals from 5 received indices */
  106. p_dico = &dico1_lsf[shl_ex (indice[0], 2)];move16 ();
  107. lsf1_r[0] = *p_dico++; move16 ();
  108. lsf1_r[1] = *p_dico++; move16 ();
  109. lsf2_r[0] = *p_dico++; move16 ();
  110. lsf2_r[1] = *p_dico++; move16 ();
  111. p_dico = &dico2_lsf[shl_ex (indice[1], 2)];move16 ();
  112. lsf1_r[2] = *p_dico++; move16 ();
  113. lsf1_r[3] = *p_dico++; move16 ();
  114. lsf2_r[2] = *p_dico++; move16 ();
  115. lsf2_r[3] = *p_dico++; move16 ();
  116. sign = indice[2] & 1; logic16 ();
  117. i = shr_ex (indice[2], 1);
  118. p_dico = &dico3_lsf[shl_ex (i, 2)]; move16 ();
  119. test ();
  120. if (sign == 0)
  121. {
  122. lsf1_r[4] = *p_dico++; move16 ();
  123. lsf1_r[5] = *p_dico++; move16 ();
  124. lsf2_r[4] = *p_dico++; move16 ();
  125. lsf2_r[5] = *p_dico++; move16 ();
  126. }
  127. else
  128. {
  129. lsf1_r[4] = negate_ex (*p_dico++); move16 ();
  130. lsf1_r[5] = negate_ex (*p_dico++); move16 ();
  131. lsf2_r[4] = negate_ex (*p_dico++); move16 ();
  132. lsf2_r[5] = negate_ex (*p_dico++); move16 ();
  133. }
  134. p_dico = &dico4_lsf[shl_ex (indice[3], 2)];move16 ();
  135. lsf1_r[6] = *p_dico++; move16 ();
  136. lsf1_r[7] = *p_dico++; move16 ();
  137. lsf2_r[6] = *p_dico++; move16 ();
  138. lsf2_r[7] = *p_dico++; move16 ();
  139. p_dico = &dico5_lsf[shl_ex (indice[4], 2)];move16 ();
  140. lsf1_r[8] = *p_dico++; move16 ();
  141. lsf1_r[9] = *p_dico++; move16 ();
  142. lsf2_r[8] = *p_dico++; move16 ();
  143. lsf2_r[9] = *p_dico++; move16 ();
  144. /* Compute quantized LSFs and update the past quantized residual */
  145. for (i = 0; i < M; i++)
  146. {
  147. temp = add_ex (mean_lsf[i], mult_ex (st->past_r_q[i],
  148. LSP_PRED_FAC_MR122));
  149. lsf1_q[i] = add_ex (lsf1_r[i], temp);
  150. move16 ();
  151. lsf2_q[i] = add_ex (lsf2_r[i], temp);
  152. move16 ();
  153. st->past_r_q[i] = lsf2_r[i]; move16 ();
  154. }
  155. }
  156. /* verification that LSFs have minimum distance of LSF_GAP Hz */
  157. Reorder_lsf (lsf1_q, LSF_GAP, M);
  158. Reorder_lsf (lsf2_q, LSF_GAP, M);
  159. Copy (lsf2_q, st->past_lsf_q, M);
  160. /* convert LSFs to the cosine domain */
  161. Lsf_lsp (lsf1_q, lsp1_q, M);
  162. Lsf_lsp (lsf2_q, lsp2_q, M);
  163. return 0;
  164. }