bits2prm.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 : bits2prm.c
  11. *
  12. ********************************************************************************
  13. */
  14. /*
  15. ********************************************************************************
  16. * MODULE INCLUDE FILE AND VERSION ID
  17. ********************************************************************************
  18. */
  19. #include "bits2prm.h"
  20. const char bits2prm_id[] = "@(#)$Id $" bits2prm_h;
  21. /*
  22. ********************************************************************************
  23. * INCLUDE FILES
  24. ********************************************************************************
  25. */
  26. #include "typedef.h"
  27. #include "basic_op.h"
  28. #include "count.h"
  29. #include "mode.h"
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. /*
  33. ********************************************************************************
  34. * LOCAL VARIABLES AND TABLES
  35. ********************************************************************************
  36. */
  37. #include "bitno.tab"
  38. /*
  39. ********************************************************************************
  40. * LOCAL PROGRAM CODE
  41. ********************************************************************************
  42. */
  43. /*
  44. **************************************************************************
  45. *
  46. * Function : Bin2int
  47. * Purpose : Read "no_of_bits" bits from the array bitstream[]
  48. * and convert to integer.
  49. *
  50. **************************************************************************
  51. */
  52. static Word16 Bin2int ( /* Reconstructed parameter */
  53. Word16 no_of_bits, /* input : number of bits associated with value */
  54. Word16 *bitstream /* output: address where bits are written */
  55. )
  56. {
  57. Word16 value, i, bit;
  58. value = 0; move16 ();
  59. for (i = 0; i < no_of_bits; i++)
  60. {
  61. value = shl_ex (value, 1);
  62. bit = *bitstream++; move16 ();
  63. test ();
  64. if (sub_ex (bit, BIT_1) == 0)
  65. value = add_ex (value, 1);
  66. }
  67. return (value);
  68. }
  69. /*
  70. ********************************************************************************
  71. * PUBLIC PROGRAM CODE
  72. ********************************************************************************
  73. */
  74. /*
  75. **************************************************************************
  76. *
  77. * Function : Bits2prm
  78. * Purpose : Retrieves the vector of encoder parameters from
  79. * the received serial bits in a frame.
  80. *
  81. **************************************************************************
  82. */
  83. void Bits2prm (
  84. enum Mode mode, /* i : AMR mode */
  85. Word16 bits[], /* i : serial bits (size <= MAX_SERIAL_SIZE) */
  86. Word16 prm[] /* o : analysis parameters (size <= MAX_PRM_SIZE) */
  87. )
  88. {
  89. Word16 i;
  90. move16(); /* account for pointer init (bitno[mode]) */
  91. for (i = 0; i < prmno[mode]; i++)
  92. {
  93. prm[i] = Bin2int (bitno[mode][i], bits); move16 ();
  94. bits += bitno[mode][i];
  95. add_ex(0,0); /* account for above pointer update */
  96. }
  97. return;
  98. }