lsp.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 : lsp.c
  11. * Purpose : From A(z) to lsp. LSP quantization and interpolation
  12. *
  13. ********************************************************************************
  14. */
  15. /*
  16. ********************************************************************************
  17. * MODULE INCLUDE FILE AND VERSION ID
  18. ********************************************************************************
  19. */
  20. #include "lsp.h"
  21. const char lsp_id[] = "@(#)$Id $" lsp_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 "oper_32b.h"
  32. #include "q_plsf.h"
  33. #include "copy.h"
  34. #include "az_lsp.h"
  35. #include "int_lpc.h"
  36. #include "count.h"
  37. #include "lsp.tab"
  38. /*
  39. ********************************************************************************
  40. * PUBLIC PROGRAM CODE
  41. ********************************************************************************
  42. */
  43. /*
  44. **************************************************************************
  45. *
  46. * Function : lsp_init
  47. *
  48. **************************************************************************
  49. */
  50. int lsp_init (lspState **st)
  51. {
  52. lspState* s;
  53. if (st == (lspState **) NULL){
  54. wfprintf(stderr, "lsp_init: invalid parameter\n");
  55. return -1;
  56. }
  57. *st = NULL;
  58. /* allocate memory */
  59. if ((s= (lspState *) wmalloc(sizeof(lspState))) == NULL){
  60. wfprintf(stderr, "lsp_init: can not malloc state structure\n");
  61. return -1;
  62. }
  63. /* Initialize quantization state */
  64. Q_plsf_init(&s->qSt);
  65. lsp_reset(s);
  66. *st = s;
  67. return 0;
  68. }
  69. /*
  70. **************************************************************************
  71. *
  72. * Function : lsp_reset
  73. *
  74. **************************************************************************
  75. */
  76. int lsp_reset (lspState *st)
  77. {
  78. if (st == (lspState *) NULL){
  79. wfprintf(stderr, "lsp_reset: invalid parameter\n");
  80. return -1;
  81. }
  82. /* Init lsp_old[] */
  83. Copy(lsp_init_data, &st->lsp_old[0], M);
  84. /* Initialize lsp_old_q[] */
  85. Copy(st->lsp_old, st->lsp_old_q, M);
  86. /* Reset quantization state */
  87. Q_plsf_reset(st->qSt);
  88. return 0;
  89. }
  90. /*
  91. **************************************************************************
  92. *
  93. * Function : lsp_exit
  94. *
  95. **************************************************************************
  96. */
  97. void lsp_exit (lspState **st)
  98. {
  99. if (st == NULL || *st == NULL)
  100. return;
  101. /* Deallocate members */
  102. Q_plsf_exit(&(*st)->qSt);
  103. /* deallocate memory */
  104. wfree(*st);
  105. *st = NULL;
  106. return;
  107. }
  108. /*************************************************************************
  109. *
  110. * FUNCTION: lsp()
  111. *
  112. ************************************************************************/
  113. int lsp(lspState *st, /* i/o : State struct */
  114. enum Mode req_mode, /* i : requested coder mode */
  115. enum Mode used_mode, /* i : used coder mode */
  116. Word16 az[], /* i/o : interpolated LP parameters Q12 */
  117. Word16 azQ[], /* o : quantization interpol. LP parameters Q12*/
  118. Word16 lsp_new[], /* o : new lsp vector */
  119. Word16 **anap /* o : analysis parameters */)
  120. {
  121. Word16 lsp_new_q[M]; /* LSPs at 4th subframe */
  122. Word16 lsp_mid[M], lsp_mid_q[M]; /* LSPs at 2nd subframe */
  123. Word16 pred_init_i; /* init index for MA prediction in DTX mode */
  124. test ();
  125. if ( sub_ex (req_mode, MR122) == 0)
  126. {
  127. Az_lsp (&az[MP1], lsp_mid, st->lsp_old);
  128. Az_lsp (&az[MP1 * 3], lsp_new, lsp_mid);
  129. /*--------------------------------------------------------------------*
  130. * Find interpolated LPC parameters in all subframes (both quantized *
  131. * and unquantized). *
  132. * The interpolated parameters are in array A_t[] of size (M+1)*4 *
  133. * and the quantized interpolated parameters are in array Aq_t[] *
  134. *--------------------------------------------------------------------*/
  135. Int_lpc_1and3_2 (st->lsp_old, lsp_mid, lsp_new, az);
  136. test ();
  137. if ( sub_ex (used_mode, MRDTX) != 0)
  138. {
  139. /* LSP quantization (lsp_mid[] and lsp_new[] jointly quantized) */
  140. Q_plsf_5 (st->qSt, lsp_mid, lsp_new, lsp_mid_q, lsp_new_q, *anap);
  141. Int_lpc_1and3 (st->lsp_old_q, lsp_mid_q, lsp_new_q, azQ);
  142. /* Advance analysis parameters pointer */
  143. (*anap) += add_ex(0,5); move16 ();
  144. }
  145. }
  146. else
  147. {
  148. Az_lsp(&az[MP1 * 3], lsp_new, st->lsp_old); /* From A(z) to lsp */
  149. /*--------------------------------------------------------------------*
  150. * Find interpolated LPC parameters in all subframes (both quantized *
  151. * and unquantized). *
  152. * The interpolated parameters are in array A_t[] of size (M+1)*4 *
  153. * and the quantized interpolated parameters are in array Aq_t[] *
  154. *--------------------------------------------------------------------*/
  155. Int_lpc_1to3_2(st->lsp_old, lsp_new, az);
  156. test ();
  157. if ( sub_ex (used_mode, MRDTX) != 0)
  158. {
  159. /* LSP quantization */
  160. Q_plsf_3(st->qSt, req_mode, lsp_new, lsp_new_q, *anap, &pred_init_i);
  161. Int_lpc_1to3(st->lsp_old_q, lsp_new_q, azQ);
  162. /* Advance analysis parameters pointer */
  163. (*anap) += add_ex (0, 3); move16 ();
  164. }
  165. }
  166. /* update the LSPs for the next frame */
  167. Copy (lsp_new, st->lsp_old, M);
  168. Copy (lsp_new_q, st->lsp_old_q, M);
  169. return 0;
  170. }