1 /*
2 
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.
7  *
8  * Removed init function, since all initialization is now done in
9  * init_lpc10_decoder_state().
10  *
11  * Revision 1.1  1996/08/19  22:30:49  jaf
12  * Initial revision
13  *
14 
15 */
16 
17 /*  -- translated by f2c (version 19951025).
18    You must link the resulting object file with the libraries:
19 	-lf2c -lm   (in that order)
20 */
21 
22 #include "f2c.h"
23 
24 extern integer random_(struct lpc10_decoder_state *st);
25 
26 /* ********************************************************************** */
27 
28 /* 	RANDOM Version 49 */
29 
30 /*
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.
35  *
36  * Removed init function, since all initialization is now done in
37  * init_lpc10_decoder_state().
38  *
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. */
46 
47 /* Revision 1.2  1996/03/14  22:25:29  jaf */
48 /* Just rearranged the comments and local variable declarations a bit. */
49 
50 /* Revision 1.1  1996/02/07 14:49:01  jaf */
51 /* Initial revision */
52 
53 
54 /* ********************************************************************* */
55 
56 /*  Pseudo random number generator based on Knuth, Vol 2, p. 27. */
57 
58 /* Function Return: */
59 /*  RANDOM - Integer variable, uniformly distributed over -32768 to 32767 */
60 
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. */
65 
random_(struct lpc10_decoder_state * st)66 integer random_(struct lpc10_decoder_state *st)
67 {
68     /* Initialized data */
69 
70     integer *j;
71     integer *k;
72     shortint *y;
73 
74     /* System generated locals */
75     integer ret_val;
76 
77 /* 	Parameters/constants */
78 /*       Local state */
79 /*   The following is a 16 bit 2's complement addition, */
80 /*   with overflow checking disabled */
81 
82     j = &(st->j);
83     k = &(st->k);
84     y = &(st->y[0]);
85 
86     y[*k - 1] += y[*j - 1];
87     ret_val = y[*k - 1];
88     --(*k);
89     if (*k <= 0) {
90 	*k = 5;
91     }
92     --(*j);
93     if (*j <= 0) {
94 	*j = 5;
95     }
96     return ret_val;
97 } /* random_ */
98 
99