prm2bits.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 : prm2bits.c
  11. * Purpose : Converts the encoder parameter vector into a
  12. * : vector of serial bits.
  13. *
  14. ********************************************************************************
  15. */
  16. /*
  17. ********************************************************************************
  18. * MODULE INCLUDE FILE AND VERSION ID
  19. ********************************************************************************
  20. */
  21. #include "prm2bits.h"
  22. const char prm2bits_id[] = "@(#)$Id $" prm2bits_h;
  23. /*
  24. ********************************************************************************
  25. * INCLUDE FILES
  26. ********************************************************************************
  27. */
  28. #include "typedef.h"
  29. #include "basic_op.h"
  30. #include "count.h"
  31. #include "mode.h"
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. /*
  35. ********************************************************************************
  36. * LOCAL VARIABLES AND TABLES
  37. ********************************************************************************
  38. */
  39. #include "bitno.tab"
  40. #define MASK 0x0001
  41. /*
  42. ********************************************************************************
  43. * LOCAL PROGRAM CODE
  44. ********************************************************************************
  45. */
  46. /*************************************************************************
  47. *
  48. * FUNCTION: Int2bin
  49. *
  50. * PURPOSE: convert integer to binary and write the bits to the array
  51. * bitstream[]. The most significant bits are written first.
  52. *
  53. *************************************************************************/
  54. static void Int2bin (
  55. Word16 value, /* input : value to be converted to binary */
  56. Word16 no_of_bits, /* input : number of bits associated with value */
  57. Word16 *bitstream /* output: address where bits are written */
  58. )
  59. {
  60. Word16 *pt_bitstream, i, bit;
  61. pt_bitstream = &bitstream[no_of_bits]; move16 ();
  62. for (i = 0; i < no_of_bits; i++)
  63. {
  64. bit = value & MASK; logic16 ();
  65. test ();
  66. if (bit == 0)
  67. {
  68. *--pt_bitstream = BIT_0; move16 ();
  69. }
  70. else
  71. {
  72. *--pt_bitstream = BIT_1; move16 ();
  73. }
  74. value = shr_ex (value, 1);
  75. }
  76. }
  77. /*
  78. ********************************************************************************
  79. * PUBLIC PROGRAM CODE
  80. ********************************************************************************
  81. */
  82. /*************************************************************************
  83. *
  84. * FUNCTION: Prm2bits
  85. *
  86. * PURPOSE: converts the encoder parameter vector into a vector of serial
  87. * bits.
  88. *
  89. * DESCRIPTION: depending on the mode, different numbers of parameters
  90. * (with differing numbers of bits) are processed. Details
  91. * are found in bitno.tab
  92. *
  93. *************************************************************************/
  94. void Prm2bits (
  95. enum Mode mode, /* i : AMR mode */
  96. Word16 prm[], /* i : analysis parameters (size <= MAX_PRM_SIZE) */
  97. Word16 bits[] /* o : serial bits (size <= MAX_SERIAL_SIZE) */
  98. )
  99. {
  100. Word16 i;
  101. move16(); /* account for pointer init (bitno[mode]) */
  102. for (i = 0; i < prmno[mode]; i++)
  103. {
  104. Int2bin (prm[i], bitno[mode][i], bits);
  105. bits += bitno[mode][i];
  106. add_ex(0,0); /* account for above pointer update */
  107. }
  108. return;
  109. }