d_plsf_3.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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_3.c
  11. * Purpose : Decodes the LSP parameters using the received
  12. * quantization indices. 1st order MA prediction and
  13. * split by 3 vector quantization (split-VQ)
  14. *
  15. ********************************************************************************
  16. */
  17. /*
  18. ********************************************************************************
  19. * MODULE INCLUDE FILE AND VERSION ID
  20. ********************************************************************************
  21. */
  22. #include "d_plsf.h"
  23. const char d_plsf_3_id[] = "@(#)$Id $" d_plsf_h;
  24. /*
  25. ********************************************************************************
  26. * INCLUDE FILES
  27. ********************************************************************************
  28. */
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include "typedef.h"
  32. #include "basic_op.h"
  33. #include "count.h"
  34. #include "lsp_lsf.h"
  35. #include "reorder.h"
  36. #include "copy.h"
  37. /*
  38. ********************************************************************************
  39. * LOCAL VARIABLES AND TABLES
  40. ********************************************************************************
  41. */
  42. #include "q_plsf_3.tab" /* Codebooks of LSF prediction residual */
  43. /* ALPHA -> 0.9 */
  44. /* ONE_ALPHA-> (1.0-ALPHA) */
  45. #define ALPHA 29491
  46. #define ONE_ALPHA 3277
  47. /*
  48. ********************************************************************************
  49. * PUBLIC PROGRAM CODE
  50. ********************************************************************************
  51. */
  52. /*************************************************************************
  53. *
  54. * FUNCTION: D_plsf_3()
  55. *
  56. * PURPOSE: Decodes the LSP parameters using the received quantization
  57. * indices.1st order MA prediction and split by 3 vector
  58. * quantization (split-VQ)
  59. *
  60. *************************************************************************/
  61. void D_plsf_3(
  62. D_plsfState *st, /* i/o: State struct */
  63. enum Mode mode, /* i : coder mode */
  64. Word16 bfi, /* i : bad frame indicator (set to 1 if a */
  65. /* bad frame is received) */
  66. Word16 * indice, /* i : quantization indices of 3 submatrices, Q0 */
  67. Word16 * lsp1_q /* o : quantized 1st LSP vector, Q15 */
  68. )
  69. {
  70. Word16 i, index;
  71. Word16 *p_cb1, *p_cb2, *p_cb3, *p_dico, temp;
  72. Word16 lsf1_r[M];
  73. Word16 lsf1_q[M];
  74. test ();
  75. if (bfi != 0) /* if bad frame */
  76. {
  77. /* use the past LSFs slightly shifted towards their mean */
  78. for (i = 0; i < M; i++)
  79. {
  80. /* lsfi_q[i] = ALPHA*past_lsf_q[i] + ONE_ALPHA*mean_lsf[i]; */
  81. lsf1_q[i] = add_ex(mult_ex(st->past_lsf_q[i], ALPHA),
  82. mult_ex(mean_lsf[i], ONE_ALPHA));
  83. move16 ();
  84. }
  85. /* estimate past quantized residual to be used in next frame */
  86. test();
  87. if (sub_ex(mode, MRDTX) != 0) {
  88. for (i = 0; i < M; i++) {
  89. /* temp = mean_lsf[i] + past_r2_q[i] * PRED_FAC; */
  90. temp = add_ex(mean_lsf[i], mult_ex(st->past_r_q[i], pred_fac[i]));
  91. st->past_r_q[i] = sub_ex(lsf1_q[i], temp); move16 ();
  92. }
  93. } else {
  94. for (i = 0; i < M; i++) {
  95. /* temp = mean_lsf[i] + past_r2_q[i]; */
  96. temp = add_ex(mean_lsf[i], st->past_r_q[i]);
  97. st->past_r_q[i] = sub_ex(lsf1_q[i], temp); move16 ();
  98. }
  99. }
  100. }
  101. else /* if good LSFs received */
  102. {
  103. test (); test ();
  104. if (sub_ex (mode, MR475) == 0 || sub_ex (mode, MR515) == 0)
  105. { /* MR475, MR515 */
  106. p_cb1 = dico1_lsf; move16 ();
  107. p_cb2 = dico2_lsf; move16 ();
  108. p_cb3 = mr515_3_lsf; move16 ();
  109. }
  110. else if (sub_ex (mode, MR795) == 0)
  111. { /* MR795 */
  112. test();
  113. p_cb1 = mr795_1_lsf; move16 ();
  114. p_cb2 = dico2_lsf; move16 ();
  115. p_cb3 = dico3_lsf; move16 ();
  116. }
  117. else
  118. { /* MR59, MR67, MR74, MR102, MRDTX */
  119. test();
  120. p_cb1 = dico1_lsf; move16 ();
  121. p_cb2 = dico2_lsf; move16 ();
  122. p_cb3 = dico3_lsf; move16 ();
  123. }
  124. /* decode prediction residuals from 3 received indices */
  125. index = *indice++; move16 ();
  126. p_dico = &p_cb1[add_ex(index, add_ex(index, index))]; move16 ();
  127. lsf1_r[0] = *p_dico++; move16 ();
  128. lsf1_r[1] = *p_dico++; move16 ();
  129. lsf1_r[2] = *p_dico++; move16 ();
  130. index = *indice++; move16 ();
  131. test (); test ();
  132. if ((sub_ex (mode, MR475) == 0) || (sub_ex (mode, MR515) == 0))
  133. { /* MR475, MR515 only using every second entry */
  134. index = shl_ex(index,1);
  135. }
  136. p_dico = &p_cb2[add_ex(index, add_ex(index, index))]; move16 ();
  137. lsf1_r[3] = *p_dico++; move16 ();
  138. lsf1_r[4] = *p_dico++; move16 ();
  139. lsf1_r[5] = *p_dico++; move16 ();
  140. index = *indice++; move16 ();
  141. p_dico = &p_cb3[shl_ex(index, 2)]; move16 ();
  142. lsf1_r[6] = *p_dico++; move16 ();
  143. lsf1_r[7] = *p_dico++; move16 ();
  144. lsf1_r[8] = *p_dico++; move16 ();
  145. lsf1_r[9] = *p_dico++; move16 ();
  146. /* Compute quantized LSFs and update the past quantized residual */
  147. if (sub_ex(mode, MRDTX) != 0)
  148. for (i = 0; i < M; i++) {
  149. temp = add_ex(mean_lsf[i], mult_ex(st->past_r_q[i], pred_fac[i]));
  150. lsf1_q[i] = add_ex(lsf1_r[i], temp); move16 ();
  151. st->past_r_q[i] = lsf1_r[i]; move16 ();
  152. }
  153. else
  154. for (i = 0; i < M; i++) {
  155. temp = add_ex(mean_lsf[i], st->past_r_q[i]);
  156. lsf1_q[i] = add_ex(lsf1_r[i], temp); move16 ();
  157. st->past_r_q[i] = lsf1_r[i]; move16 ();
  158. }
  159. }
  160. /* verification that LSFs has minimum distance of LSF_GAP Hz */
  161. Reorder_lsf(lsf1_q, LSF_GAP, M);
  162. Copy (lsf1_q, st->past_lsf_q, M);
  163. /* convert LSFs to the cosine domain */
  164. Lsf_lsp(lsf1_q, lsp1_q, M);
  165. return;
  166. }
  167. void Init_D_plsf_3(D_plsfState *st, /* i/o: State struct */
  168. Word16 index /* i : past_rq_init[] index [0, 7] */)
  169. {
  170. Copy(&past_rq_init[index * M], st->past_r_q, M);
  171. }