Debian Codegraph @

codecs/lpc10/lpcini.c

raw symbols SCIP
1 /*
2
3 $Log$
4 Revision 1.18 2003/10/21 18:08:11 markster
5 Fix include order
6
7 Revision 1.5 2003/10/21 18:08:11 markster
8 Fix include order
9
10 Revision 1.4 2003/10/21 02:57:29 markster
11 FreeBSD patch, take 2
12
13 Revision 1.3 2003/10/16 21:11:30 martinp
14 Revert the previous patch since it's braking compilation
15
16 Revision 1.1 2003/02/12 13:59:15 matteo
17 Initial revision
18
19 Revision 1.2 2000/01/05 08:20:39 markster
20 Some OSS fixes and a few lpc changes to make it actually work
21
22 * Revision 1.2 1996/08/20 20:35:41 jaf
23 * Added functions for allocating and initializing lpc10_encoder_state
24 * and lpc10_decoder_state structures.
25 *
26 * Revision 1.1 1996/08/19 22:31:40 jaf
27 * Initial revision
28 *
29
30 */
31
32 /* -- translated by f2c (version 19951025).
33 You must link the resulting object file with the libraries:
34 -lf2c -lm (in that order)
35 */
36
37 #define ASTMM_LIBC ASTMM_REDIRECT
38 #include "asterisk.h"
39 #include "f2c.h"
40
41 #ifdef P_R_O_T_O_T_Y_P_E_S
42 extern int lpcini_(void);
43 /* comlen contrl_ 12 */
44 /*:ref: initlpcenc_ 14 0 */
45 /*:ref: initlpcdec_ 14 0 */
46 #endif
47
48 /* Common Block Declarations */
49
50 struct {
51 integer order, lframe;
52 logical corrp;
53 } contrl_;
54
55 #define contrl_1 contrl_
56
57 /* ***************************************************************** */
58
59 /* $Log$
60 * Revision 1.18 2003/10/21 18:08:11 markster
61 * Fix include order
62 *
63 * Revision 1.5 2003/10/21 18:08:11 markster
64 * Fix include order
65 *
66 * Revision 1.4 2003/10/21 02:57:29 markster
67 * FreeBSD patch, take 2
68 *
69 * Revision 1.3 2003/10/16 21:11:30 martinp
70 * Revert the previous patch since it's braking compilation
71 *
72 * Revision 1.1 2003/02/12 13:59:15 matteo
73 * Initial revision
74 *
75 * Revision 1.2 2000/01/05 08:20:39 markster
76 * Some OSS fixes and a few lpc changes to make it actually work
77 *
78 * Revision 1.2 1996/08/20 20:35:41 jaf
79 * Added functions for allocating and initializing lpc10_encoder_state
80 * and lpc10_decoder_state structures.
81 *
82 * Revision 1.1 1996/08/19 22:31:40 jaf
83 * Initial revision
84 * */
85 /* Revision 1.1 1996/03/28 00:04:05 jaf */
86 /* Initial revision */
87
88
89 /* ***************************************************************** */
90
91 /* Initialize COMMON block variables used by LPC-10 encoder and decoder, */
92 /* and call initialization routines for both of them. */
93
94 /* Subroutine */ int lpcini_(void)
95 {
96
97 /* $Log$
98 * Revision 1.18 2003/10/21 18:08:11 markster
99 * Fix include order
100 *
101 * Revision 1.5 2003/10/21 18:08:11 markster
102 * Fix include order
103 *
104 * Revision 1.4 2003/10/21 02:57:29 markster
105 * FreeBSD patch, take 2
106 *
107 * Revision 1.3 2003/10/16 21:11:30 martinp
108 * Revert the previous patch since it's braking compilation
109 *
110 * Revision 1.1 2003/02/12 13:59:15 matteo
111 * Initial revision
112 *
113 * Revision 1.2 2000/01/05 08:20:39 markster
114 * Some OSS fixes and a few lpc changes to make it actually work
115 *
116 * Revision 1.2 1996/08/20 20:35:41 jaf
117 * Added functions for allocating and initializing lpc10_encoder_state
118 * and lpc10_decoder_state structures.
119 *
120 * Revision 1.1 1996/08/19 22:31:40 jaf
121 * Initial revision
122 * */
123 /* Revision 1.3 1996/03/29 22:03:47 jaf */
124 /* Removed definitions for any constants that were no longer used. */
125
126 /* Revision 1.2 1996/03/26 19:34:33 jaf */
127 /* Added comments indicating which constants are not needed in an */
128 /* application that uses the LPC-10 coder. */
129
130 /* Revision 1.1 1996/02/07 14:43:51 jaf */
131 /* Initial revision */
132
133 /* LPC Configuration parameters: */
134 /* Frame size, Prediction order, Pitch period */
135 /* $Log$
136 * Revision 1.18 2003/10/21 18:08:11 markster
137 * Fix include order
138 *
139 * Revision 1.5 2003/10/21 18:08:11 markster
140 * Fix include order
141 *
142 * Revision 1.4 2003/10/21 02:57:29 markster
143 * FreeBSD patch, take 2
144 *
145 * Revision 1.3 2003/10/16 21:11:30 martinp
146 * Revert the previous patch since it's braking compilation
147 *
148 * Revision 1.1 2003/02/12 13:59:15 matteo
149 * Initial revision
150 *
151 * Revision 1.2 2000/01/05 08:20:39 markster
152 * Some OSS fixes and a few lpc changes to make it actually work
153 *
154 * Revision 1.2 1996/08/20 20:35:41 jaf
155 * Added functions for allocating and initializing lpc10_encoder_state
156 * and lpc10_decoder_state structures.
157 *
158 * Revision 1.1 1996/08/19 22:31:40 jaf
159 * Initial revision
160 * */
161 /* Revision 1.3 1996/03/29 22:05:55 jaf */
162 /* Commented out the common block variables that are not needed by the */
163 /* embedded version. */
164
165 /* Revision 1.2 1996/03/26 19:34:50 jaf */
166 /* Added comments indicating which constants are not needed in an */
167 /* application that uses the LPC-10 coder. */
168
169 /* Revision 1.1 1996/02/07 14:44:09 jaf */
170 /* Initial revision */
171
172 /* LPC Processing control variables: */
173
174 /* *** Read-only: initialized in setup */
175
176 /* Files for Speech, Parameter, and Bitstream Input & Output, */
177 /* and message and debug outputs. */
178
179 /* Here are the only files which use these variables: */
180
181 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
182
183 /* Many files which use fdebug are not listed, since it is only used in */
184 /* those other files conditionally, to print trace statements. */
185 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
186 /* LPC order, Frame size, Quantization rate, Bits per frame, */
187 /* Error correction */
188 /* Subroutine SETUP is the only place where order is assigned a value, */
189 /* and that value is 10. It could increase efficiency 1% or so to */
190 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
191 */
192 /* a variable in a COMMON block, since it is used in many places in the */
193 /* core of the coding and decoding routines. Actually, I take that back.
194 */
195 /* At least when compiling with f2c, the upper bound of DO loops is */
196 /* stored in a local variable before the DO loop begins, and then that is
197 */
198 /* compared against on each iteration. */
199 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
200 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
201 /* is used in only a few places, and never in the core coding and */
202 /* decoding routines, so it could be eliminated entirely. */
203 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
204 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
205 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
206 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
207 */
208 /* a constant or a variable, since it is only examined once per frame. */
209 /* Leaving it as a variable that is set to .TRUE. seems like a good */
210 /* idea, since it does enable some error-correction capability for */
211 /* unvoiced frames, with no change in the coding rate, and no noticeable
212 */
213 /* quality difference in the decoded speech. */
214 /* integer quant, nbits */
215 /* *** Read/write: variables for debugging, not needed for LPC algorithm
216 */
217
218 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
219 */
220 /* Debug listing detail level, Line count on listing page */
221
222 /* nframe is not needed for an embedded LPC10 at all. */
223 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
224 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
225 /* an application, I would recommend removing the call to ERROR in RCCHK,
226 */
227 /* and remove ERROR and nunsfm completely. */
228 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
229 */
230 /* sread.f. When LPC10 is embedded into an application, one might want */
231 /* to cause it to be incremented in a routine that takes the output of */
232 /* SYNTHS and sends it to an audio device. It could be optionally */
233 /* displayed, for those that might want to know what it is. */
234 /* maxosp is never initialized to 0 in SETUP, although it probably should
235 */
236 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
237 /* would be of much interest to an application in which LPC10 is */
238 /* embedded. */
239 /* listl and lincnt are not needed for an embedded LPC10 at all. */
240 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
241 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
242 /* common /contrl/ quant, nbits */
243 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
244 contrl_1.order = 10;
245 contrl_1.lframe = 180;
246 contrl_1.corrp = TRUE_;
247 return 0;
248 } /* lpcini_ */
249
250
251
252 /* Allocate memory for, and initialize, the state that needs to be
253 kept from encoding one frame to the next for a single
254 LPC-10-compressed audio stream. Return 0 if malloc fails,
255 otherwise return pointer to new structure. */
256
257 struct lpc10_encoder_state *
258 create_lpc10_encoder_state()
259 {
260 struct lpc10_encoder_state *st;
261
262 st = (struct lpc10_encoder_state *)
263 malloc((unsigned) sizeof (struct lpc10_encoder_state));
264 if (st != 0) {
265 init_lpc10_encoder_state(st);
266 }
267 return (st);
268 }
269
270
271
272 void init_lpc10_encoder_state(struct lpc10_encoder_state *st)
273 {
274 int i;
275
276 lpcini_();
277
278 /* State used only by function hp100 */
279 st->z11 = 0.0f;
280 st->z21 = 0.0f;
281 st->z12 = 0.0f;
282 st->z22 = 0.0f;
283
284 /* State used by function analys */
285 for (i = 0; i < 540; i++) {
286 st->inbuf[i] = 0.0f;
287 st->pebuf[i] = 0.0f;
288 }
289 for (i = 0; i < 696; i++) {
290 st->lpbuf[i] = 0.0f;
291 }
292 for (i = 0; i < 312; i++) {
293 st->ivbuf[i] = 0.0f;
294 }
295 st->bias = 0.0f;
296 /* integer osbuf[10]; */ /* no initial value necessary */
297 st->osptr = 1;
298 for (i = 0; i < 3; i++) {
299 st->obound[i] = 0;
300 }
301 st->vwin[4] = 307;
302 st->vwin[5] = 462;
303 st->awin[4] = 307;
304 st->awin[5] = 462;
305 for (i = 0; i < 8; i++) {
306 st->voibuf[i] = 0;
307 }
308 for (i = 0; i < 3; i++) {
309 st->rmsbuf[i] = 0.0f;
310 }
311 for (i = 0; i < 30; i++) {
312 st->rcbuf[i] = 0.0f;
313 }
314 st->zpre = 0.0f;
315
316
317 /* State used by function onset */
318 st->n = 0.0f;
319 st->d__ = 1.0f;
320 /* real fpc; */ /* no initial value necessary */
321 for (i = 0; i < 16; i++) {
322 st->l2buf[i] = 0.0f;
323 }
324 st->l2sum1 = 0.0f;
325 st->l2ptr1 = 1;
326 st->l2ptr2 = 9;
327 /* integer lasti; */ /* no initial value necessary */
328 st->hyst = FALSE_;
329
330 /* State used by function voicin */
331 st->dither = 20.0f;
332 st->maxmin = 0.0f;
333 for (i = 0; i < 6; i++) {
334 st->voice[i] = 0.0f;
335 }
336 st->lbve = 3000;
337 st->fbve = 3000;
338 st->fbue = 187;
339 st->ofbue = 187;
340 st->sfbue = 187;
341 st->lbue = 93;
342 st->olbue = 93;
343 st->slbue = 93;
344 st->snr = (real) (st->fbve / st->fbue << 6);
345
346 /* State used by function dyptrk */
347 for (i = 0; i < 60; i++) {
348 st->s[i] = 0.0f;
349 }
350 for (i = 0; i < 120; i++) {
351 st->p[i] = 0;
352 }
353 st->ipoint = 0;
354 st->alphax = 0.0f;
355
356 /* State used by function chanwr */
357 st->isync = 0;
358
359 }
360
361
362
363 /* Allocate memory for, and initialize, the state that needs to be
364 kept from decoding one frame to the next for a single
365 LPC-10-compressed audio stream. Return 0 if malloc fails,
366 otherwise return pointer to new structure. */
367
368 struct lpc10_decoder_state *
369 create_lpc10_decoder_state()
370 {
371 struct lpc10_decoder_state *st;
372
373 st = (struct lpc10_decoder_state *)
374 malloc((unsigned) sizeof (struct lpc10_decoder_state));
375 if (st != 0) {
376 init_lpc10_decoder_state(st);
377 }
378 return (st);
379 }
380
381
382
383 void init_lpc10_decoder_state(struct lpc10_decoder_state *st)
384 {
385 int i;
386
387 lpcini_();
388
389 /* State used by function decode */
390 st->iptold = 60;
391 st->first = TRUE_;
392 st->ivp2h = 0;
393 st->iovoic = 0;
394 st->iavgp = 60;
395 st->erate = 0;
396 for (i = 0; i < 30; i++) {
397 st->drc[i] = 0;
398 }
399 for (i = 0; i < 3; i++) {
400 st->dpit[i] = 0;
401 st->drms[i] = 0;
402 }
403
404 /* State used by function synths */
405 for (i = 0; i < 360; i++) {
406 st->buf[i] = 0.0f;
407 }
408 st->buflen = 180;
409
410 /* State used by function pitsyn */
411 /* ivoico; */ /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
412 /* ipito; */ /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
413 st->rmso = 1.0f;
414 /* rco[10]; */ /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
415 /* integer jsamp; */ /* no initial value necessary as long as first_pitsyn is initially TRUE_ */
416 st->first_pitsyn = TRUE_;
417
418 /* State used by function bsynz */
419 st->ipo = 0;
420 for (i = 0; i < 166; i++) {
421 st->exc[i] = 0.0f;
422 st->exc2[i] = 0.0f;
423 }
424 st->lpi1 = 0.0f;
425 st->lpi2 = 0.0f;
426 st->lpi3 = 0.0f;
427 st->hpi1 = 0.0f;
428 st->hpi2 = 0.0f;
429 st->hpi3 = 0.0f;
430 st->rmso_bsynz = 0.0f;
431
432 /* State used by function random */
433 st->j = 2;
434 st->k = 5;
435 st->y[0] = (shortint) -21161;
436 st->y[1] = (shortint) -8478;
437 st->y[2] = (shortint) 30892;
438 st->y[3] = (shortint) -10216;
439 st->y[4] = (shortint) 16950;
440
441 /* State used by function deemp */
442 st->dei1 = 0.0f;
443 st->dei2 = 0.0f;
444 st->deo1 = 0.0f;
445 st->deo2 = 0.0f;
446 st->deo3 = 0.0f;
447 }