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