q_plsf.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 : q_plsf.c
  11. * Purpose : common part (init, exit, reset) of LSF quantization
  12. * module (rest in q_plsf_3.c and q_plsf_5.c)
  13. *
  14. ********************************************************************************
  15. */
  16. /*
  17. ********************************************************************************
  18. * MODULE INCLUDE FILE AND VERSION ID
  19. ********************************************************************************
  20. */
  21. #include "q_plsf.h"
  22. const char q_plsf_id[] = "@(#)$Id $" q_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. /*
  33. ********************************************************************************
  34. * PUBLIC PROGRAM CODE
  35. ********************************************************************************
  36. */
  37. /*
  38. **************************************************************************
  39. *
  40. * Function : Q_plsf_init
  41. * Purpose : Allocates memory and initializes state variables
  42. *
  43. **************************************************************************
  44. */
  45. int Q_plsf_init (Q_plsfState **state)
  46. {
  47. Q_plsfState* s;
  48. if (state == (Q_plsfState **) NULL){
  49. wfprintf(stderr, "Q_plsf_init: invalid parameter\n");
  50. return -1;
  51. }
  52. *state = NULL;
  53. /* allocate memory */
  54. if ((s= (Q_plsfState *) wmalloc(sizeof(Q_plsfState))) == NULL){
  55. wfprintf(stderr, "Q_plsf_init: can not malloc state structure\n");
  56. return -1;
  57. }
  58. Q_plsf_reset(s);
  59. *state = s;
  60. return 0;
  61. }
  62. /*
  63. **************************************************************************
  64. *
  65. * Function : Q_plsf_reset
  66. * Purpose : Resets state memory
  67. *
  68. **************************************************************************
  69. */
  70. int Q_plsf_reset (Q_plsfState *state)
  71. {
  72. Word16 i;
  73. if (state == (Q_plsfState *) NULL){
  74. wfprintf(stderr, "Q_plsf_reset: invalid parameter\n");
  75. return -1;
  76. }
  77. for ( i = 0; i < M; i++)
  78. state->past_rq[i] = 0;
  79. return 0;
  80. }
  81. /*
  82. **************************************************************************
  83. *
  84. * Function : Q_plsf_exit
  85. * Purpose : The memory used for state memory is freed
  86. *
  87. **************************************************************************
  88. */
  89. void Q_plsf_exit (Q_plsfState **state)
  90. {
  91. if (state == NULL || *state == NULL)
  92. return;
  93. /* deallocate memory */
  94. wfree(*state);
  95. *state = NULL;
  96. return;
  97. }