d_plsf.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.c
  11. * Purpose : common part (init, exit, reset) of LSF decoder
  12. * module (rest in d_plsf_3.c and d_plsf_5.c)
  13. *
  14. *****************************************************************************
  15. */
  16. /*
  17. *****************************************************************************
  18. * MODULE INCLUDE FILE AND VERSION ID
  19. *****************************************************************************
  20. */
  21. #include "d_plsf.h"
  22. const char d_plsf_id[] = "@(#)$Id $" d_plsf_h;
  23. /*
  24. *****************************************************************************
  25. * INCLUDE FILES
  26. *****************************************************************************
  27. */
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30. #include "typedef.h"
  31. #include "basic_op.h"
  32. #include "count.h"
  33. #include "cnst.h"
  34. #include "copy.h"
  35. #include "q_plsf_5.tab"
  36. /*
  37. *--------------------------------------------------*
  38. * Constants (defined in cnst.h) *
  39. *--------------------------------------------------*
  40. * M : LPC order
  41. *--------------------------------------------------*
  42. */
  43. /*
  44. *****************************************************************************
  45. * PUBLIC PROGRAM CODE
  46. *****************************************************************************
  47. */
  48. /*
  49. **************************************************************************
  50. *
  51. * Function : D_plsf_init
  52. * Purpose : Allocates and initializes state memory
  53. *
  54. **************************************************************************
  55. */
  56. int D_plsf_init (D_plsfState **state)
  57. {
  58. D_plsfState* s;
  59. if (state == (D_plsfState **) NULL){
  60. wfprintf(stderr, "D_plsf_init: invalid parameter\n");
  61. return -1;
  62. }
  63. *state = NULL;
  64. /* allocate memory */
  65. if ((s= (D_plsfState *) wmalloc(sizeof(D_plsfState))) == NULL){
  66. wfprintf(stderr, "D_plsf_init: can not malloc state structure\n");
  67. return -1;
  68. }
  69. D_plsf_reset(s);
  70. *state = s;
  71. return 0;
  72. }
  73. /*
  74. **************************************************************************
  75. *
  76. * Function : D_plsf_reset
  77. * Purpose : Resets state memory
  78. *
  79. **************************************************************************
  80. */
  81. int D_plsf_reset (D_plsfState *state)
  82. {
  83. Word16 i;
  84. if (state == (D_plsfState *) NULL){
  85. wfprintf(stderr, "D_plsf_reset: invalid parameter\n");
  86. return -1;
  87. }
  88. for (i = 0; i < M; i++){
  89. state->past_r_q[i] = 0; /* Past quantized prediction error */
  90. }
  91. /* Past dequantized lsfs */
  92. Copy(mean_lsf, &state->past_lsf_q[0], M);
  93. return 0;
  94. }
  95. /*
  96. **************************************************************************
  97. *
  98. * Function : D_plsf_exit
  99. * Purpose : The memory used for state memory is freed
  100. *
  101. **************************************************************************
  102. */
  103. void D_plsf_exit (D_plsfState **state)
  104. {
  105. if (state == NULL || *state == NULL)
  106. return;
  107. /* deallocate memory */
  108. wfree(*state);
  109. *state = NULL;
  110. return;
  111. }