lsp_avg.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_avg.c
  11. * Purpose: : LSP averaging and history
  12. *
  13. *****************************************************************************
  14. */
  15. /*
  16. *****************************************************************************
  17. * MODULE INCLUDE FILE AND VERSION ID
  18. *****************************************************************************
  19. */
  20. #include "lsp_avg.h"
  21. const char lsp_avg_id[] = "@(#)$Id $" lsp_avg_h;
  22. /*
  23. *****************************************************************************
  24. * INCLUDE FILES
  25. *****************************************************************************
  26. */
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include "basic_op.h"
  30. #include "oper_32b.h"
  31. #include "count.h"
  32. #include "q_plsf_5.tab"
  33. #include "copy.h"
  34. /*
  35. *****************************************************************************
  36. * LOCAL VARIABLES AND TABLES
  37. *****************************************************************************
  38. */
  39. /*
  40. *****************************************************************************
  41. * PUBLIC PROGRAM CODE
  42. *****************************************************************************
  43. */
  44. /*
  45. **************************************************************************
  46. *
  47. * Function : lsp_avg_init
  48. * Purpose : Allocates memory and initializes state variables
  49. *
  50. **************************************************************************
  51. */
  52. int lsp_avg_init (lsp_avgState **state)
  53. {
  54. lsp_avgState* s;
  55. if (state == (lsp_avgState **) NULL){
  56. wfprintf(stderr, "lsp_avg_init: invalid parameter\n");
  57. return -1;
  58. }
  59. *state = NULL;
  60. /* allocate memory */
  61. if ((s = (lsp_avgState *) wmalloc(sizeof(lsp_avgState))) == NULL){
  62. wfprintf(stderr, "lsp_avg_init: can not malloc state structure\n");
  63. return -1;
  64. }
  65. lsp_avg_reset(s);
  66. *state = s;
  67. return 0;
  68. }
  69. /*
  70. **************************************************************************
  71. *
  72. * Function : lsp_avg_reset
  73. * Purpose : Resets state memory
  74. *
  75. **************************************************************************
  76. */
  77. int lsp_avg_reset (lsp_avgState *st)
  78. {
  79. if (st == (lsp_avgState *) NULL){
  80. wfprintf(stderr, "lsp_avg_reset: invalid parameter\n");
  81. return -1;
  82. }
  83. Copy(mean_lsf, &st->lsp_meanSave[0], M);
  84. return 0;
  85. }
  86. /*
  87. **************************************************************************
  88. *
  89. * Function : lsp_avg_exit
  90. * Purpose : The memory used for state memory is freed
  91. *
  92. **************************************************************************
  93. */
  94. void lsp_avg_exit (lsp_avgState **state)
  95. {
  96. if (state == NULL || *state == NULL)
  97. return;
  98. /* deallocate memory */
  99. wfree(*state);
  100. *state = NULL;
  101. return;
  102. }
  103. /*
  104. **************************************************************************
  105. *
  106. * Function : lsp_avg
  107. * Purpose : Calculate the LSP averages
  108. *
  109. **************************************************************************
  110. */
  111. void lsp_avg (
  112. lsp_avgState *st, /* i/o : State struct Q15 */
  113. Word16 *lsp /* i : state of the state machine Q15 */
  114. )
  115. {
  116. Word16 i;
  117. Word32 L_tmp; /* Q31 */
  118. for (i = 0; i < M; i++) {
  119. /* mean = 0.84*mean */
  120. L_tmp = L_deposit_h_ex(st->lsp_meanSave[i]);
  121. L_tmp = L_msu_ex(L_tmp, EXPCONST, st->lsp_meanSave[i]);
  122. /* Add 0.16 of newest LSPs to mean */
  123. L_tmp = L_mac_ex(L_tmp, EXPCONST, lsp[i]);
  124. /* Save means */
  125. st->lsp_meanSave[i] = round_ex(L_tmp); move16(); /* Q15 */
  126. }
  127. return;
  128. }