lpc.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 : lpc.c
  11. *
  12. ********************************************************************************
  13. */
  14. /*
  15. ********************************************************************************
  16. * MODULE INCLUDE FILE AND VERSION ID
  17. ********************************************************************************
  18. */
  19. #include "lpc.h"
  20. const char lpc_id[] = "@(#)$Id $" lpc_h;
  21. /*
  22. ********************************************************************************
  23. * INCLUDE FILES
  24. ********************************************************************************
  25. */
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include "typedef.h"
  29. #include "basic_op.h"
  30. #include "oper_32b.h"
  31. #include "autocorr.h"
  32. #include "lag_wind.h"
  33. #include "levinson.h"
  34. #include "cnst.h"
  35. #include "mode.h"
  36. #include "count.h"
  37. /*
  38. ********************************************************************************
  39. * LOCAL VARIABLES AND TABLES
  40. ********************************************************************************
  41. */
  42. #include "window.tab"
  43. /*
  44. ********************************************************************************
  45. * PUBLIC PROGRAM CODE
  46. ********************************************************************************
  47. */
  48. /*************************************************************************
  49. *
  50. * Function: lpc_init
  51. *
  52. **************************************************************************
  53. */
  54. int lpc_init (lpcState **state)
  55. {
  56. lpcState* s;
  57. if (state == (lpcState **) NULL){
  58. wfprintf(stderr, "lpc_init: invalid parameter\n");
  59. return -1;
  60. }
  61. *state = NULL;
  62. /* allocate memory */
  63. if ((s= (lpcState *) wmalloc(sizeof(lpcState))) == NULL){
  64. wfprintf(stderr, "lpc_init: can not malloc state structure\n");
  65. return -1;
  66. }
  67. s->levinsonSt = NULL;
  68. /* Init sub_ex states */
  69. if (Levinson_init(&s->levinsonSt)) {
  70. lpc_exit(&s);
  71. return -1;
  72. }
  73. lpc_reset(s);
  74. *state = s;
  75. return 0;
  76. }
  77. /*************************************************************************
  78. *
  79. * Function: lpc_reset
  80. *
  81. **************************************************************************
  82. */
  83. int lpc_reset (lpcState *state)
  84. {
  85. if (state == (lpcState *) NULL){
  86. wfprintf(stderr, "lpc_reset: invalid parameter\n");
  87. return -1;
  88. }
  89. Levinson_reset(state->levinsonSt);
  90. return 0;
  91. }
  92. /*************************************************************************
  93. *
  94. * Function: lpc_exit
  95. *
  96. **************************************************************************
  97. */
  98. void lpc_exit (lpcState **state)
  99. {
  100. if (state == NULL || *state == NULL)
  101. return;
  102. Levinson_exit(&(*state)->levinsonSt);
  103. /* deallocate memory */
  104. wfree(*state);
  105. *state = NULL;
  106. return;
  107. }
  108. int lpc(
  109. lpcState *st, /* i/o: State struct */
  110. enum Mode mode, /* i : coder mode */
  111. Word16 x[], /* i : Input signal Q15 */
  112. Word16 x_12k2[], /* i : Input signal (EFR) Q15 */
  113. Word16 a[] /* o : predictor coefficients Q12 */
  114. )
  115. {
  116. Word16 rc[4]; /* First 4 reflection coefficients Q15 */
  117. Word16 rLow[MP1], rHigh[MP1]; /* Autocorrelations low and hi */
  118. /* No fixed Q value but normalized */
  119. /* so that overflow is avoided */
  120. test ();
  121. if ( sub_ex (mode, MR122) == 0)
  122. {
  123. /* Autocorrelations */
  124. Autocorr(x_12k2, M, rHigh, rLow, window_160_80);
  125. /* Lag windowing */
  126. Lag_window(M, rHigh, rLow);
  127. /* Levinson Durbin */
  128. Levinson(st->levinsonSt, rHigh, rLow, &a[MP1], rc);
  129. /* Autocorrelations */
  130. Autocorr(x_12k2, M, rHigh, rLow, window_232_8);
  131. /* Lag windowing */
  132. Lag_window(M, rHigh, rLow);
  133. /* Levinson Durbin */
  134. Levinson(st->levinsonSt, rHigh, rLow, &a[MP1 * 3], rc);
  135. }
  136. else
  137. {
  138. /* Autocorrelations */
  139. Autocorr(x, M, rHigh, rLow, window_200_40);
  140. /* Lag windowing */
  141. Lag_window(M, rHigh, rLow);
  142. /* Levinson Durbin */
  143. Levinson(st->levinsonSt, rHigh, rLow, &a[MP1 * 3], rc);
  144. }
  145. return 0;
  146. }