random.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. $Log$
  3. Revision 1.15 2004/06/26 03:50:14 markster
  4. Merge source cleanups (bug #1911)
  5. Revision 1.14 2003/02/12 13:59:15 matteo
  6. mer feb 12 14:56:57 CET 2003
  7. Revision 1.1.1.1 2003/02/12 13:59:15 matteo
  8. mer feb 12 14:56:57 CET 2003
  9. Revision 1.2 2000/01/05 08:20:39 markster
  10. Some OSS fixes and a few lpc changes to make it actually work
  11. * Revision 1.2 1996/08/20 20:41:32 jaf
  12. * Removed all static local variables that were SAVE'd in the Fortran
  13. * code, and put them in struct lpc10_decoder_state that is passed as an
  14. * argument.
  15. *
  16. * Removed init function, since all initialization is now done in
  17. * init_lpc10_decoder_state().
  18. *
  19. * Revision 1.1 1996/08/19 22:30:49 jaf
  20. * Initial revision
  21. *
  22. */
  23. /* -- translated by f2c (version 19951025).
  24. You must link the resulting object file with the libraries:
  25. -lf2c -lm (in that order)
  26. */
  27. #include "f2c.h"
  28. #ifdef P_R_O_T_O_T_Y_P_E_S
  29. extern integer random_(struct lpc10_decoder_state *st);
  30. #endif
  31. /* ********************************************************************** */
  32. /* RANDOM Version 49 */
  33. /* $Log$
  34. * Revision 1.15 2004/06/26 03:50:14 markster
  35. * Merge source cleanups (bug #1911)
  36. *
  37. * Revision 1.14 2003/02/12 13:59:15 matteo
  38. * mer feb 12 14:56:57 CET 2003
  39. *
  40. * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
  41. * mer feb 12 14:56:57 CET 2003
  42. *
  43. * Revision 1.2 2000/01/05 08:20:39 markster
  44. * Some OSS fixes and a few lpc changes to make it actually work
  45. *
  46. * Revision 1.2 1996/08/20 20:41:32 jaf
  47. * Removed all static local variables that were SAVE'd in the Fortran
  48. * code, and put them in struct lpc10_decoder_state that is passed as an
  49. * argument.
  50. *
  51. * Removed init function, since all initialization is now done in
  52. * init_lpc10_decoder_state().
  53. *
  54. * Revision 1.1 1996/08/19 22:30:49 jaf
  55. * Initial revision
  56. * */
  57. /* Revision 1.3 1996/03/20 16:13:54 jaf */
  58. /* Rearranged comments a little bit, and added comments explaining that */
  59. /* even though there is local state here, there is no need to create an */
  60. /* ENTRY for reinitializing it. */
  61. /* Revision 1.2 1996/03/14 22:25:29 jaf */
  62. /* Just rearranged the comments and local variable declarations a bit. */
  63. /* Revision 1.1 1996/02/07 14:49:01 jaf */
  64. /* Initial revision */
  65. /* ********************************************************************* */
  66. /* Pseudo random number generator based on Knuth, Vol 2, p. 27. */
  67. /* Function Return: */
  68. /* RANDOM - Integer variable, uniformly distributed over -32768 to 32767 */
  69. /* This subroutine maintains local state from one call to the next. */
  70. /* In the context of the LPC10 coder, there is no reason to reinitialize */
  71. /* this local state when switching between audio streams, because its */
  72. /* results are only used to generate noise for unvoiced frames. */
  73. integer random_(struct lpc10_decoder_state *st)
  74. {
  75. /* Initialized data */
  76. integer *j;
  77. integer *k;
  78. shortint *y;
  79. /* System generated locals */
  80. integer ret_val;
  81. /* Parameters/constants */
  82. /* Local state */
  83. /* The following is a 16 bit 2's complement addition, */
  84. /* with overflow checking disabled */
  85. j = &(st->j);
  86. k = &(st->k);
  87. y = &(st->y[0]);
  88. y[*k - 1] += y[*j - 1];
  89. ret_val = y[*k - 1];
  90. --(*k);
  91. if (*k <= 0) {
  92. *k = 5;
  93. }
  94. --(*j);
  95. if (*j <= 0) {
  96. *j = 5;
  97. }
  98. return ret_val;
  99. } /* random_ */