b_cn_cod.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 : b_cn_cod.c
  11. * Purpose : Contains function for comfort noise generation.
  12. *
  13. ********************************************************************************
  14. */
  15. /*
  16. ********************************************************************************
  17. * MODULE INCLUDE FILE AND VERSION ID
  18. ********************************************************************************
  19. */
  20. #include "b_cn_cod.h"
  21. const char b_cn_cod_id[] = "@(#)$Id $" b_cn_cod_h;
  22. /*
  23. ********************************************************************************
  24. * INCLUDE FILES
  25. ********************************************************************************
  26. */
  27. #include "typedef.h"
  28. #include "basic_op.h"
  29. #include "oper_32b.h"
  30. #include "count.h"
  31. #include "cnst.h"
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include "window.tab"
  35. /*
  36. ********************************************************************************
  37. * LOCAL CONSTANTS
  38. ********************************************************************************
  39. */
  40. #define NB_PULSE 10 /* number of random pulses in DTX operation */
  41. /*
  42. ********************************************************************************
  43. * PUBLIC PROGRAM CODE
  44. ********************************************************************************
  45. */
  46. /*************************************************************************
  47. *
  48. * FUNCTION NAME: pseudonoise
  49. *
  50. *************************************************************************/
  51. Word16 pseudonoise (
  52. Word32 *shift_reg, /* i/o : Old CN generator shift register state */
  53. Word16 no_bits /* i : Number of bits */
  54. )
  55. {
  56. Word16 noise_bits, Sn, i;
  57. noise_bits = 0; move16 ();
  58. for (i = 0; i < no_bits; i++)
  59. {
  60. /* State n == 31 */
  61. test (); logic32 ();
  62. if ((*shift_reg & 0x00000001L) != 0)
  63. {
  64. Sn = 1; move16 ();
  65. }
  66. else
  67. {
  68. Sn = 0; move16 ();
  69. }
  70. /* State n == 3 */
  71. test (); logic32 ();
  72. if ((*shift_reg & 0x10000000L) != 0)
  73. {
  74. Sn = Sn ^ 1; move16 (); logic16 ();
  75. }
  76. else
  77. {
  78. Sn = Sn ^ 0; move16 (); logic16 ();
  79. }
  80. noise_bits = shl_ex (noise_bits, 1);
  81. noise_bits = noise_bits | (extract_l_ex (*shift_reg) & 1);
  82. logic16 (); logic16 (); move16 ();
  83. *shift_reg = L_shr_ex (*shift_reg, 1);
  84. test ();
  85. if (Sn & 1)
  86. {
  87. *shift_reg = *shift_reg | 0x40000000L; move32 (); logic32 ();
  88. }
  89. }
  90. return noise_bits;
  91. }
  92. /***************************************************************************
  93. *
  94. * Function : build_CN_code
  95. *
  96. ***************************************************************************/
  97. void build_CN_code (
  98. Word32 *seed, /* i/o : Old CN generator shift register state */
  99. Word16 cod[] /* o : Generated CN fixed codebook vector */
  100. )
  101. {
  102. Word16 i, j, k;
  103. for (i = 0; i < L_SUBFR; i++)
  104. {
  105. cod[i] = 0; move16 ();
  106. }
  107. for (k = 0; k < NB_PULSE; k++)
  108. {
  109. i = pseudonoise (seed, 2); /* generate pulse position */
  110. i = shr_ex (extract_l_ex (L_mult_ex (i, 10)), 1);
  111. i = add_ex (i, k);
  112. j = pseudonoise (seed, 1); /* generate sign */
  113. test ();
  114. if (j > 0)
  115. {
  116. cod[i] = 4096; move16 ();
  117. }
  118. else
  119. {
  120. cod[i] = -4096; move16 ();
  121. }
  122. }
  123. return;
  124. }
  125. /*************************************************************************
  126. *
  127. * FUNCTION NAME: build_CN_param
  128. *
  129. *************************************************************************/
  130. void build_CN_param (
  131. Word16 *seed, /* i/o : Old CN generator shift register state */
  132. const Word16 n_param, /* i : number of params */
  133. const Word16 param_size_table[],/* i : size of params */
  134. Word16 parm[] /* o : CN Generated params */
  135. )
  136. {
  137. Word16 i;
  138. const Word16 *p;
  139. *seed = extract_l_ex(L_add_ex(L_shr_ex(L_mult_ex(*seed, 31821), 1), 13849L));
  140. p = &window_200_40[*seed & 0x7F]; logic16();
  141. for(i=0; i< n_param;i++){
  142. move16 (); logic16(); logic16(); logic16();
  143. parm[i] = *p++ & ~(0xFFFF<<param_size_table[i]);
  144. }
  145. }