1 /*
2 
3  * Revision 1.2  1996/08/20  20:20:24  jaf
4  * Removed all static local variables that were SAVE'd in the Fortran
5  * code, and put them in struct lpc10_encoder_state that is passed as an
6  * argument.
7  *
8  * Revision 1.1  1996/08/19  22:40:31  jaf
9  * Initial revision
10  *
11 
12 */
13 
14 /*  -- translated by f2c (version 19951025).
15    You must link the resulting object file with the libraries:
16 	-lf2c -lm   (in that order)
17 */
18 
19 #include "f2c.h"
20 
21 int chanwr_(integer *order, integer *ipitv, integer *irms, integer *irc, integer *ibits, struct lpc10_encoder_state *st);
22 int chanrd_(integer *order, integer *ipitv, integer *irms, integer *irc, integer *ibits);
23 
24 /* *********************************************************************** */
25 
26 /* 	CHANL Version 49 */
27 
28 /*
29  * Revision 1.2  1996/08/20  20:20:24  jaf
30  * Removed all static local variables that were SAVE'd in the Fortran
31  * code, and put them in struct lpc10_encoder_state that is passed as an
32  * argument.
33  *
34  * Revision 1.1  1996/08/19  22:40:31  jaf
35  * Initial revision
36  * */
37 /* Revision 1.3  1996/03/21  15:14:57  jaf */
38 /* Added comments about which indices of argument arrays are read or */
39 /* written, and about the one bit of local state in CHANWR.  CHANRD */
40 /* has no local state. */
41 
42 /* Revision 1.2  1996/03/13  18:55:10  jaf */
43 /* Comments added explaining which of the local variables of this */
44 /* subroutine need to be saved from one invocation to the next, and which */
45 /* do not. */
46 
47 /* Revision 1.1  1996/02/07 14:43:31  jaf */
48 /* Initial revision */
49 
50 
51 /* *********************************************************************** */
52 
53 /* CHANWR: */
54 /*   Place quantized parameters into bitstream */
55 
56 /* Input: */
57 /*  ORDER  - Number of reflection coefficients (not really variable) */
58 /*  IPITV  - Quantized pitch/voicing parameter */
59 /*  IRMS   - Quantized energy parameter */
60 /*  IRC    - Quantized reflection coefficients */
61 /*           Indices 1 through ORDER read. */
62 /* Output: */
63 /*  IBITS  - Serial bitstream */
64 /*           Indices 1 through 54 written. */
65 /*           Bit 54, the SYNC bit, alternates from one call to the next. */
66 
67 /* Subroutine CHANWR maintains one bit of local state from one call to */
68 /* the next, in the variable ISYNC.  I believe that this one bit is only */
69 /* intended to allow a receiver to resynchronize its interpretation of */
70 /* the bit stream, by looking for which of the 54 bits alternates every */
71 /* frame time.  This is just a simple framing mechanism that is not */
72 /* useful when other, higher overhead framing mechanisms are used to */
73 /* transmit the coded frames. */
74 
75 /* I'm not going to make an entry to reinitialize this bit, since it */
76 /* doesn't help a receiver much to know whether the first sync bit is a 0 */
77 /* or a 1.  It needs to examine several frames in sequence to have */
78 /* reasonably good assurance that its framing is correct. */
79 
80 
81 /* CHANRD: */
82 /*   Reconstruct parameters from bitstream */
83 
84 /* Input: */
85 /*  ORDER  - Number of reflection coefficients (not really variable) */
86 /*  IBITS  - Serial bitstream */
87 /*           Indices 1 through 53 read (SYNC bit is ignored). */
88 /* Output: */
89 /*  IPITV  - Quantized pitch/voicing parameter */
90 /*  IRMS   - Quantized energy parameter */
91 /*  IRC    - Quantized reflection coefficients */
92 /*           Indices 1 through ORDER written */
93 
94 /* Entry CHANRD has no local state. */
95 
96 
97 
98 /*   IBITS is 54 bits of LPC data ordered as follows: */
99 /* 	R1-0, R2-0, R3-0,  P-0,  A-0, */
100 /* 	R1-1, R2-1, R3-1,  P-1,  A-1, */
101 /* 	R1-2, R4-0, R3-2,  A-2,  P-2, R4-1, */
102 /* 	R1-3, R2-2, R3-3, R4-2,  A-3, */
103 /* 	R1-4, R2-3, R3-4, R4-3,  A-4, */
104 /* 	 P-3, R2-4, R7-0, R8-0,  P-4, R4-4, */
105 /* 	R5-0, R6-0, R7-1,R10-0, R8-1, */
106 /* 	R5-1, R6-1, R7-2, R9-0,  P-5, */
107 /* 	R5-2, R6-2,R10-1, R8-2,  P-6, R9-1, */
108 /* 	R5-3, R6-3, R7-3, R9-2, R8-3, SYNC */
chanwr_0_(int n__,integer * order,integer * ipitv,integer * irms,integer * irc,integer * ibits,struct lpc10_encoder_state * st)109 static int chanwr_0_(int n__, integer *order, integer *ipitv,
110 	integer *irms, integer *irc, integer *ibits,
111 			       struct lpc10_encoder_state *st)
112 {
113     /* Initialized data */
114 
115     integer *isync;
116     static integer bit[10] = { 2,4,8,8,8,8,16,16,16,16 };
117     static integer iblist[53] = { 13,12,11,1,2,13,12,11,1,2,13,10,11,2,1,10,
118 	    13,12,11,10,2,13,12,11,10,2,1,12,7,6,1,10,9,8,7,4,6,9,8,7,5,1,9,8,
119 	    4,6,1,5,9,8,7,5,6 };
120 
121     /* System generated locals */
122     integer i__1;
123 
124     /* Local variables */
125     integer itab[13], i__;
126 
127 /*       Arguments */
128 /*       Parameters/constants */
129 /*       These arrays are not Fortran PARAMETER's, but they are defined */
130 /*       by DATA statements below, and their contents are never altered.
131 */
132 /*       Local variables that need not be saved */
133 /*       Local state */
134 /*       ISYNC is only used by CHANWR, not by ENTRY CHANRD. */
135 
136     /* Parameter adjustments */
137     --irc;
138     --ibits;
139 
140     /* Function Body */
141     switch(n__) {
142 	case 1: goto L_chanrd;
143 	}
144 
145     isync = &(st->isync);
146 
147 /* ***********************************************************************
148  */
149 /* 	Place quantized parameters into bitstream */
150 /* ***********************************************************************
151  */
152 /*   Place parameters into ITAB */
153     itab[0] = *ipitv;
154     itab[1] = *irms;
155     itab[2] = 0;
156     i__1 = *order;
157     for (i__ = 1; i__ <= i__1; ++i__) {
158 	itab[i__ + 2] = irc[*order + 1 - i__] & 32767;
159     }
160 /*   Put 54 bits into IBITS array */
161     for (i__ = 1; i__ <= 53; ++i__) {
162 	ibits[i__] = itab[iblist[i__ - 1] - 1] & 1;
163 	itab[iblist[i__ - 1] - 1] /= 2;
164     }
165     ibits[54] = *isync & 1;
166     *isync = 1 - *isync;
167     return 0;
168 /* ***********************************************************************
169  */
170 /* 	Reconstruct parameters from bitstream */
171 /* ***********************************************************************
172  */
173 
174 L_chanrd:
175 /*   Reconstruct ITAB */
176     for (i__ = 1; i__ <= 13; ++i__) {
177 	itab[i__ - 1] = 0;
178     }
179     for (i__ = 1; i__ <= 53; ++i__) {
180 	itab[iblist[54 - i__ - 1] - 1] = (itab[iblist[54 - i__ - 1] - 1] << 1)
181 		 + ibits[54 - i__];
182     }
183 /*   Sign extend RC's */
184     i__1 = *order;
185     for (i__ = 1; i__ <= i__1; ++i__) {
186 	if ((itab[i__ + 2] & bit[i__ - 1]) != 0) {
187 	    itab[i__ + 2] -= bit[i__ - 1] << 1;
188 	}
189     }
190 /*   Restore variables */
191     *ipitv = itab[0];
192     *irms = itab[1];
193     i__1 = *order;
194     for (i__ = 1; i__ <= i__1; ++i__) {
195 	irc[i__] = itab[*order + 4 - i__ - 1];
196     }
197     return 0;
198 } /* chanwr_ */
199 
chanwr_(integer * order,integer * ipitv,integer * irms,integer * irc,integer * ibits,struct lpc10_encoder_state * st)200 /* Subroutine */ int chanwr_(integer *order, integer *ipitv, integer *irms,
201 	integer *irc, integer *ibits, struct lpc10_encoder_state *st)
202 {
203     return chanwr_0_(0, order, ipitv, irms, irc, ibits, st);
204     }
205 
chanrd_(integer * order,integer * ipitv,integer * irms,integer * irc,integer * ibits)206 /* Subroutine */ int chanrd_(integer *order, integer *ipitv, integer *irms,
207 	integer *irc, integer *ibits)
208 {
209     return chanwr_0_(1, order, ipitv, irms, irc, ibits, 0);
210     }
211