formats: clarify setting of reverse_bytes
[sox.git] / lpc10 / random.c
blobfb5e3625e4b42a8ecc15dfb00f1252db055ff413
1 /*
3 * Revision 1.2 1996/08/20 20:41:32 jaf
4 * Removed all static local variables that were SAVE'd in the Fortran
5 * code, and put them in struct lpc10_decoder_state that is passed as an
6 * argument.
8 * Removed init function, since all initialization is now done in
9 * init_lpc10_decoder_state().
11 * Revision 1.1 1996/08/19 22:30:49 jaf
12 * Initial revision
17 /* -- translated by f2c (version 19951025).
18 You must link the resulting object file with the libraries:
19 -lf2c -lm (in that order)
22 #include "f2c.h"
24 extern integer random_(struct lpc10_decoder_state *st);
26 /* ********************************************************************** */
28 /* RANDOM Version 49 */
31 * Revision 1.2 1996/08/20 20:41:32 jaf
32 * Removed all static local variables that were SAVE'd in the Fortran
33 * code, and put them in struct lpc10_decoder_state that is passed as an
34 * argument.
36 * Removed init function, since all initialization is now done in
37 * init_lpc10_decoder_state().
39 * Revision 1.1 1996/08/19 22:30:49 jaf
40 * Initial revision
41 * */
42 /* Revision 1.3 1996/03/20 16:13:54 jaf */
43 /* Rearranged comments a little bit, and added comments explaining that */
44 /* even though there is local state here, there is no need to create an */
45 /* ENTRY for reinitializing it. */
47 /* Revision 1.2 1996/03/14 22:25:29 jaf */
48 /* Just rearranged the comments and local variable declarations a bit. */
50 /* Revision 1.1 1996/02/07 14:49:01 jaf */
51 /* Initial revision */
54 /* ********************************************************************* */
56 /* Pseudo random number generator based on Knuth, Vol 2, p. 27. */
58 /* Function Return: */
59 /* RANDOM - Integer variable, uniformly distributed over -32768 to 32767 */
61 /* This subroutine maintains local state from one call to the next. */
62 /* In the context of the LPC10 coder, there is no reason to reinitialize */
63 /* this local state when switching between audio streams, because its */
64 /* results are only used to generate noise for unvoiced frames. */
66 integer random_(struct lpc10_decoder_state *st)
68 /* Initialized data */
70 integer *j;
71 integer *k;
72 shortint *y;
74 /* System generated locals */
75 integer ret_val;
77 /* Parameters/constants */
78 /* Local state */
79 /* The following is a 16 bit 2's complement addition, */
80 /* with overflow checking disabled */
82 j = &(st->j);
83 k = &(st->k);
84 y = &(st->y[0]);
86 y[*k - 1] += y[*j - 1];
87 ret_val = y[*k - 1];
88 --(*k);
89 if (*k <= 0) {
90 *k = 5;
92 --(*j);
93 if (*j <= 0) {
94 *j = 5;
96 return ret_val;
97 } /* random_ */