1 /*
2
3 $Log: analys.c,v $
4 Revision 1.2 2006/08/01 13:06:49 rjongbloed
5 Added a raft of unvalidated audio codecs from OpenH323 tree
6
7 Revision 1.1.2.1 2006/07/22 14:03:13 rjongbloed
8 Added more plug ins
9
10 Revision 1.1.2.1 2006/05/08 13:49:57 rjongbloed
11 Imported all the audio codec plug ins from OpenH323
12
13 Revision 1.1 2004/05/04 11:16:42 csoutheren
14 Initial version
15
16 Revision 1.2 2002/02/15 03:57:55 yurik
17 Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com
18
19 Revision 1.1 2000/06/05 04:45:12 robertj
20 Added LPC-10 2400bps codec
21
22 * Revision 1.2 1996/08/20 20:16:01 jaf
23 * Removed all static local variables that were SAVE'd in the Fortran
24 * code, and put them in struct lpc10_encoder_state that is passed as an
25 * argument.
26 *
27 * Removed init function, since all initialization is now done in
28 * init_lpc10_encoder_state().
29 *
30 * Revision 1.1 1996/08/19 22:29:08 jaf
31 * Initial revision
32 *
33
34 */
35
36 #ifdef P_R_O_T_O_T_Y_P_E_S
37 extern int analys_(real *speech, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_encoder_state *st);
38 /* comlen contrl_ 12 */
39 /*:ref: preemp_ 14 5 6 6 4 6 6 */
40 /*:ref: onset_ 14 7 6 4 4 4 4 4 4 */
41 /*:ref: placev_ 14 11 4 4 4 4 4 4 4 4 4 4 4 */
42 /*:ref: lpfilt_ 14 4 6 6 4 4 */
43 /*:ref: ivfilt_ 14 5 6 6 4 4 6 */
44 /*:ref: tbdm_ 14 8 6 4 4 4 6 4 4 4 */
45 /*:ref: voicin_ 14 12 4 6 6 4 4 6 6 4 6 4 4 4 */
46 /*:ref: dyptrk_ 14 6 6 4 4 4 4 4 */
47 /*:ref: placea_ 14 9 4 4 4 4 4 4 4 4 4 */
48 /*:ref: dcbias_ 14 3 4 6 6 */
49 /*:ref: energy_ 14 3 4 6 6 */
50 /*:ref: mload_ 14 6 4 4 4 6 6 6 */
51 /*:ref: invert_ 14 4 4 6 6 6 */
52 /*:ref: rcchk_ 14 3 4 6 6 */
53 /*:ref: initonset_ 14 0 */
54 /*:ref: initvoicin_ 14 0 */
55 /*:ref: initdyptrk_ 14 0 */
56 /* Rerunning f2c -P may change prototypes or declarations. */
57 #endif
58
59 /* -- translated by f2c (version 19951025).
60 You must link the resulting object file with the libraries:
61 -lf2c -lm (in that order)
62 */
63
64 #include "f2c.h"
65
66 /* Common Block Declarations */
67
68 extern struct {
69 integer order, lframe;
70 logical corrp;
71 } contrl_;
72
73 #define contrl_1 contrl_
74
75 /* Table of constant values */
76
77 static integer c__10 = 10;
78 static integer c__181 = 181;
79 static integer c__720 = 720;
80 static integer c__3 = 3;
81 static integer c__90 = 90;
82 static integer c__156 = 156;
83 static integer c__307 = 307;
84 static integer c__462 = 462;
85 static integer c__312 = 312;
86 static integer c__60 = 60;
87 static integer c__1 = 1;
88
89 /* ****************************************************************** */
90
91 /* ANALYS Version 55 */
92
93 /* $Log: analys.c,v $
94 /* Revision 1.2 2006/08/01 13:06:49 rjongbloed
95 /* Added a raft of unvalidated audio codecs from OpenH323 tree
96 /*
97 /* Revision 1.1.2.1 2006/07/22 14:03:13 rjongbloed
98 /* Added more plug ins
99 /*
100 /* Revision 1.1.2.1 2006/05/08 13:49:57 rjongbloed
101 /* Imported all the audio codec plug ins from OpenH323
102 /*
103 /* Revision 1.1 2004/05/04 11:16:42 csoutheren
104 /* Initial version
105 /*
106 /* Revision 1.2 2002/02/15 03:57:55 yurik
107 /* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com
108 /*
109 /* Revision 1.1 2000/06/05 04:45:12 robertj
110 /* Added LPC-10 2400bps codec
111 /*
112 * Revision 1.2 1996/08/20 20:16:01 jaf
113 * Removed all static local variables that were SAVE'd in the Fortran
114 * code, and put them in struct lpc10_encoder_state that is passed as an
115 * argument.
116 *
117 * Removed init function, since all initialization is now done in
118 * init_lpc10_encoder_state().
119 *
120 * Revision 1.1 1996/08/19 22:29:08 jaf
121 * Initial revision
122 * */
123 /* Revision 1.9 1996/05/23 19:41:07 jaf */
124 /* Commented out some unnecessary lines that were reading uninitialized */
125 /* values. */
126
127 /* Revision 1.8 1996/03/27 23:57:55 jaf */
128 /* Added some comments about which indices of the local buffers INBUF, */
129 /* LPBUF, etc., get read or modified by some of the subroutine calls. I */
130 /* just did this while trying to figure out the discrepancy between the */
131 /* embedded code compiled with all local variables implicitly saved, and */
132 /* without. */
133
134 /* I added some debugging write statements in hopes of finding a problem. */
135 /* None of them ever printed anything while running with the long input */
136 /* speech file dam9.spd provided in the distribution. */
137
138 /* Revision 1.7 1996/03/27 18:06:20 jaf */
139 /* Commented out access to MAXOSP, which is just a debugging variable */
140 /* that was defined in the COMMON block CONTRL in contrl.fh. */
141
142 /* Revision 1.6 1996/03/26 19:31:33 jaf */
143 /* Commented out trace statements. */
144
145 /* Revision 1.5 1996/03/21 15:19:35 jaf */
146 /* Added comments for ENTRY PITDEC. */
147
148 /* Revision 1.4 1996/03/19 20:54:27 jaf */
149 /* Added a line to INITANALYS. See comments there. */
150
151 /* Revision 1.3 1996/03/19 20:52:49 jaf */
152 /* Rearranged the order of the local variables quite a bit, to separate */
153 /* them into groups of "constants", "locals that don't need to be saved */
154 /* from one call to the next", and "local that do need to be saved from */
155 /* one call to the next". */
156
157 /* Several locals in the last set should have been given initial values, */
158 /* but weren't. I gave them all initial values of 0. */
159
160 /* Added a separate ENTRY INITANALYS that initializes all local state */
161 /* that should be, and also calls the corresponding entries of the */
162 /* subroutines called by ANALYS that also have local state. */
163
164 /* There used to be DATA statements in ANALYS. I got rid of most of */
165 /* them, and added a local logical variable FIRST that calls the entry */
166 /* INITANALYS on the first call to ANALYS. This is just so that one need */
167 /* not remember to call INITANALYS first in order for the state to be */
168 /* initialized. */
169
170 /* Revision 1.2 1996/03/11 23:29:32 jaf */
171 /* Added several comments with my own personal questions about the */
172 /* Fortran 77 meaning of the parameters passed to the subroutine PREEMP. */
173
174 /* Revision 1.1 1996/02/07 14:42:29 jaf */
175 /* Initial revision */
176
177
178 /* ****************************************************************** */
179
180 /* SUBROUTINE ANALYS */
181
182 /* Input: */
183 /* SPEECH */
184 /* Indices 1 through LFRAME read. */
185 /* Output: */
186 /* VOICE */
187 /* Indices 1 through 2 written. */
188 /* PITCH */
189 /* Written in subroutine DYPTRK, and then perhaps read and written */
190 /* some more. */
191 /* RMS */
192 /* Written. */
193 /* RC */
194 /* Indices 1 through ORDER written (ORDER defined in contrl.fh). */
195
196 /* This subroutine maintains local state from one call to the next. If */
197 /* you want to switch to using a new audio stream for this filter, or */
198 /* reinitialize its state for any other reason, call the ENTRY */
199 /* INITANALYS. */
200
201
202 /* ENTRY PITDEC */
203
204 /* Input: */
205 /* PITCH - Encoded pitch index */
206 /* Output: */
207 /* PTAU - Decoded pitch period */
208
209 /* This entry has no local state. It accesses a "constant" array */
210 /* declared in ANALYS. */
211
analys_(real * speech,integer * voice,integer * pitch,real * rms,real * rc,struct lpc10_encoder_state * st)212 /* Subroutine */ int analys_(real *speech, integer *voice, integer
213 *pitch, real *rms, real *rc, struct lpc10_encoder_state *st)
214 {
215 /* Initialized data */
216
217 static integer tau[60] = { 20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,
218 35,36,37,38,39,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,
219 74,76,78,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,
220 140,144,148,152,156 };
221 static integer buflim[4] = { 181,720,25,720 };
222 static real precoef = .9375f;
223
224 /* System generated locals */
225 integer i__1;
226
227 /* Local variables */
228 real amdf[60];
229 integer half;
230 real abuf[156];
231 real *bias;
232 extern /* Subroutine */ int tbdm_(real *, integer *, integer *, integer *,
233 real *, integer *, integer *, integer *);
234 integer *awin;
235 integer midx, ewin[6] /* was [2][3] */;
236 real ivrc[2], temp;
237 real *zpre;
238 integer *vwin;
239 integer i__, j, lanal;
240 extern /* Subroutine */ int rcchk_(integer *, real *, real *), mload_(
241 integer *, integer *, integer *, real *, real *, real *);
242 real *inbuf, *pebuf;
243 real *lpbuf, *ivbuf;
244 real *rcbuf;
245 integer *osbuf;
246 extern /* Subroutine */ int onset_(real *, integer *, integer *, integer *
247 , integer *, integer *, integer *, struct lpc10_encoder_state *);
248 integer *osptr;
249 extern /* Subroutine */ placea_(integer *, integer *
250 , integer *, integer *, integer *, integer *, integer *, integer *
251 , integer *), dcbias_(integer *, real *, real *), placev_(integer
252 *, integer *, integer *, integer *, integer *, integer *, integer
253 *, integer *, integer *, integer *, integer *);
254 integer ipitch;
255 integer *obound;
256 extern /* Subroutine */ int preemp_(real *, real *, integer *, real *,
257 real *), voicin_(integer *, real *, real *, integer *, integer *,
258 real *, real *, integer *, real *, integer *, integer *, integer *,
259 struct lpc10_encoder_state *);
260 integer *voibuf;
261 integer mintau;
262 real *rmsbuf;
263 extern /* Subroutine */ int lpfilt_(real *, real *, integer *, integer *),
264 ivfilt_(real *, real *, integer *, integer *, real *), energy_(
265 integer *, real *, real *), invert_(integer *, real *, real *,
266 real *);
267 integer minptr, maxptr;
268 extern /* Subroutine */ int dyptrk_(real *, integer *, integer *, integer
269 *, integer *, integer *, struct lpc10_encoder_state *);
270 real phi[100] /* was [10][10] */, psi[10];
271
272 /* $Log: analys.c,v $
273 /* Revision 1.2 2006/08/01 13:06:49 rjongbloed
274 /* Added a raft of unvalidated audio codecs from OpenH323 tree
275 /*
276 /* Revision 1.1.2.1 2006/07/22 14:03:13 rjongbloed
277 /* Added more plug ins
278 /*
279 /* Revision 1.1.2.1 2006/05/08 13:49:57 rjongbloed
280 /* Imported all the audio codec plug ins from OpenH323
281 /*
282 /* Revision 1.1 2004/05/04 11:16:42 csoutheren
283 /* Initial version
284 /*
285 /* Revision 1.2 2002/02/15 03:57:55 yurik
286 /* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com
287 /*
288 /* Revision 1.1 2000/06/05 04:45:12 robertj
289 /* Added LPC-10 2400bps codec
290 /*
291 * Revision 1.2 1996/08/20 20:16:01 jaf
292 * Removed all static local variables that were SAVE'd in the Fortran
293 * code, and put them in struct lpc10_encoder_state that is passed as an
294 * argument.
295 *
296 * Removed init function, since all initialization is now done in
297 * init_lpc10_encoder_state().
298 *
299 * Revision 1.1 1996/08/19 22:29:08 jaf
300 * Initial revision
301 * */
302 /* Revision 1.3 1996/03/29 22:03:47 jaf */
303 /* Removed definitions for any constants that were no longer used. */
304
305 /* Revision 1.2 1996/03/26 19:34:33 jaf */
306 /* Added comments indicating which constants are not needed in an */
307 /* application that uses the LPC-10 coder. */
308
309 /* Revision 1.1 1996/02/07 14:43:51 jaf */
310 /* Initial revision */
311
312 /* LPC Configuration parameters: */
313 /* Frame size, Prediction order, Pitch period */
314 /* Arguments to ANALYS */
315 /* $Log: analys.c,v $
316 /* Revision 1.2 2006/08/01 13:06:49 rjongbloed
317 /* Added a raft of unvalidated audio codecs from OpenH323 tree
318 /*
319 /* Revision 1.1.2.1 2006/07/22 14:03:13 rjongbloed
320 /* Added more plug ins
321 /*
322 /* Revision 1.1.2.1 2006/05/08 13:49:57 rjongbloed
323 /* Imported all the audio codec plug ins from OpenH323
324 /*
325 /* Revision 1.1 2004/05/04 11:16:42 csoutheren
326 /* Initial version
327 /*
328 /* Revision 1.2 2002/02/15 03:57:55 yurik
329 /* Warnings removed during compilation, patch courtesy of Jehan Bing, jehan@bravobrava.com
330 /*
331 /* Revision 1.1 2000/06/05 04:45:12 robertj
332 /* Added LPC-10 2400bps codec
333 /*
334 * Revision 1.2 1996/08/20 20:16:01 jaf
335 * Removed all static local variables that were SAVE'd in the Fortran
336 * code, and put them in struct lpc10_encoder_state that is passed as an
337 * argument.
338 *
339 * Removed init function, since all initialization is now done in
340 * init_lpc10_encoder_state().
341 *
342 * Revision 1.1 1996/08/19 22:29:08 jaf
343 * Initial revision
344 * */
345 /* Revision 1.3 1996/03/29 22:05:55 jaf */
346 /* Commented out the common block variables that are not needed by the */
347 /* embedded version. */
348
349 /* Revision 1.2 1996/03/26 19:34:50 jaf */
350 /* Added comments indicating which constants are not needed in an */
351 /* application that uses the LPC-10 coder. */
352
353 /* Revision 1.1 1996/02/07 14:44:09 jaf */
354 /* Initial revision */
355
356 /* LPC Processing control variables: */
357
358 /* *** Read-only: initialized in setup */
359
360 /* Files for Speech, Parameter, and Bitstream Input & Output, */
361 /* and message and debug outputs. */
362
363 /* Here are the only files which use these variables: */
364
365 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
366
367 /* Many files which use fdebug are not listed, since it is only used in */
368 /* those other files conditionally, to print trace statements. */
369 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
370 /* LPC order, Frame size, Quantization rate, Bits per frame, */
371 /* Error correction */
372 /* Subroutine SETUP is the only place where order is assigned a value, */
373 /* and that value is 10. It could increase efficiency 1% or so to */
374 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
375 */
376 /* a variable in a COMMON block, since it is used in many places in the */
377 /* core of the coding and decoding routines. Actually, I take that back.
378 */
379 /* At least when compiling with f2c, the upper bound of DO loops is */
380 /* stored in a local variable before the DO loop begins, and then that is
381 */
382 /* compared against on each iteration. */
383 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
384 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
385 /* is used in only a few places, and never in the core coding and */
386 /* decoding routines, so it could be eliminated entirely. */
387 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
388 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
389 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
390 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
391 */
392 /* a constant or a variable, since it is only examined once per frame. */
393 /* Leaving it as a variable that is set to .TRUE. seems like a good */
394 /* idea, since it does enable some error-correction capability for */
395 /* unvoiced frames, with no change in the coding rate, and no noticeable
396 */
397 /* quality difference in the decoded speech. */
398 /* integer quant, nbits */
399 /* *** Read/write: variables for debugging, not needed for LPC algorithm
400 */
401
402 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
403 */
404 /* Debug listing detail level, Line count on listing page */
405
406 /* nframe is not needed for an embedded LPC10 at all. */
407 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
408 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
409 /* an application, I would recommend removing the call to ERROR in RCCHK,
410 */
411 /* and remove ERROR and nunsfm completely. */
412 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
413 */
414 /* sread.f. When LPC10 is embedded into an application, one might want */
415 /* to cause it to be incremented in a routine that takes the output of */
416 /* SYNTHS and sends it to an audio device. It could be optionally */
417 /* displayed, for those that might want to know what it is. */
418 /* maxosp is never initialized to 0 in SETUP, although it probably should
419 */
420 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
421 /* would be of much interest to an application in which LPC10 is */
422 /* embedded. */
423 /* listl and lincnt are not needed for an embedded LPC10 at all. */
424 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
425 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
426 /* common /contrl/ quant, nbits */
427 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
428 /* Arguments to entry PITDEC (below) */
429 /* Parameters/constants */
430 /* Constants */
431 /* NF = Number of frames */
432 /* AF = Frame in which analysis is done */
433 /* OSLEN = Length of the onset buffer */
434 /* LTAU = Number of pitch lags */
435 /* SBUFL, SBUFH = Start and end index of speech buffers */
436 /* LBUFL, LBUFH = Start and end index of LPF speech buffer */
437 /* MINWIN, MAXWIN = Min and Max length of voicing (and analysis) windows
438 */
439 /* PWLEN, PWINH, PWINL = Length, upper and lower limits of pitch window
440 */
441 /* DVWINL, DVWINH = Default lower and upper limits of voicing window */
442 /* The tables TAU and BUFLIM, and the variable PRECOEF, are not */
443 /* Fortran PARAMETER's, but they are initialized with DATA */
444 /* statements, and never modified. Thus, they need not have SAVE */
445 /* statements for them to keep their values from one invocation to
446 */
447 /* the next. */
448 /* Local variables that need not be saved */
449 /* Local state */
450 /* Data Buffers */
451 /* INBUF Raw speech (with DC bias removed each frame) */
452 /* PEBUF Preemphasized speech */
453 /* LPBUF Low pass speech buffer */
454 /* IVBUF Inverse filtered speech */
455 /* OSBUF Indexes of onsets in speech buffers */
456 /* VWIN Voicing window indices */
457 /* AWIN Analysis window indices */
458 /* EWIN Energy window indices */
459 /* VOIBUF Voicing decisions on windows in VWIN */
460 /* RMSBUF RMS energy */
461 /* RCBUF Reflection Coefficients */
462
463 /* Pitch is handled separately from the above parameters. */
464 /* The following variables deal with pitch: */
465 /* MIDX Encoded initial pitch estimate for analysis frame */
466 /* IPITCH Initial pitch computed for frame AF (decoded from MIDX) */
467 /* PITCH The encoded pitch value (index into TAU) for the present */
468 /* frame (delayed and smoothed by Dyptrack) */
469 /* Parameter adjustments */
470 if (speech) {
471 --speech;
472 }
473 if (voice) {
474 --voice;
475 }
476 if (rc) {
477 --rc;
478 }
479
480 /* Function Body */
481
482 /* Calculations are done on future frame due to requirements */
483 /* of the pitch tracker. Delay RMS and RC's 2 frames to give */
484 /* current frame parameters on return. */
485 /* Update all buffers */
486
487 inbuf = &(st->inbuf[0]);
488 pebuf = &(st->pebuf[0]);
489 lpbuf = &(st->lpbuf[0]);
490 ivbuf = &(st->ivbuf[0]);
491 bias = &(st->bias);
492 osbuf = &(st->osbuf[0]);
493 osptr = &(st->osptr);
494 obound = &(st->obound[0]);
495 vwin = &(st->vwin[0]);
496 awin = &(st->awin[0]);
497 voibuf = &(st->voibuf[0]);
498 rmsbuf = &(st->rmsbuf[0]);
499 rcbuf = &(st->rcbuf[0]);
500 zpre = &(st->zpre);
501
502 i__1 = 720 - contrl_1.lframe;
503 for (i__ = 181; i__ <= i__1; ++i__) {
504 inbuf[i__ - 181] = inbuf[contrl_1.lframe + i__ - 181];
505 pebuf[i__ - 181] = pebuf[contrl_1.lframe + i__ - 181];
506 }
507 i__1 = 540 - contrl_1.lframe;
508 for (i__ = 229; i__ <= i__1; ++i__) {
509 ivbuf[i__ - 229] = ivbuf[contrl_1.lframe + i__ - 229];
510 }
511 i__1 = 720 - contrl_1.lframe;
512 for (i__ = 25; i__ <= i__1; ++i__) {
513 lpbuf[i__ - 25] = lpbuf[contrl_1.lframe + i__ - 25];
514 }
515 j = 1;
516 i__1 = (*osptr) - 1;
517 for (i__ = 1; i__ <= i__1; ++i__) {
518 if (osbuf[i__ - 1] > contrl_1.lframe) {
519 osbuf[j - 1] = osbuf[i__ - 1] - contrl_1.lframe;
520 ++j;
521 }
522 }
523 *osptr = j;
524 voibuf[0] = voibuf[2];
525 voibuf[1] = voibuf[3];
526 for (i__ = 1; i__ <= 2; ++i__) {
527 vwin[(i__ << 1) - 2] = vwin[(i__ + (1 << 1)) - 2] - contrl_1.lframe;
528 vwin[(i__ << 1) - 1] = vwin[(i__ + (1 << 1)) - 1] - contrl_1.lframe;
529 awin[(i__ << 1) - 2] = awin[(i__ + (1 << 1)) - 2] - contrl_1.lframe;
530 awin[(i__ << 1) - 1] = awin[(i__ + (1 << 1)) - 1] - contrl_1.lframe;
531 /* EWIN(*,J) is unused for J .NE. AF, so the following shift is
532 */
533 /* unnecessary. It also causes error messages when the C versio
534 n */
535 /* of the code created from this by f2c is run with Purify. It
536 */
537 /* correctly complains that uninitialized memory is being read.
538 */
539 /* EWIN(1,I) = EWIN(1,I+1) - LFRAME */
540 /* EWIN(2,I) = EWIN(2,I+1) - LFRAME */
541 obound[i__ - 1] = obound[i__];
542 voibuf[i__ * 2] = voibuf[(i__ + 1) * 2];
543 voibuf[(i__ << 1) + 1] = voibuf[(i__ + (1 << 1)) + 1];
544 rmsbuf[i__ - 1] = rmsbuf[i__];
545 i__1 = contrl_1.order;
546 for (j = 1; j <= i__1; ++j) {
547 rcbuf[j + i__ * 10 - 11] = rcbuf[j + (i__ + 1) * 10 - 11];
548 }
549 }
550 /* Copy input speech, scale to sign+12 bit integers */
551 /* Remove long term DC bias. */
552 /* If the average value in the frame was over 1/4096 (after current
553 */
554 /* BIAS correction), then subtract that much more from samples in */
555 /* next frame. If the average value in the frame was under */
556 /* -1/4096, add 1/4096 more to samples in next frame. In all other
557 */
558 /* cases, keep BIAS the same. */
559 temp = 0.f;
560 i__1 = contrl_1.lframe;
561 for (i__ = 1; i__ <= i__1; ++i__) {
562 inbuf[720 - contrl_1.lframe + i__ - 181] = speech[i__] * 4096.f -
563 (*bias);
564 temp += inbuf[720 - contrl_1.lframe + i__ - 181];
565 }
566 if (temp > (real) contrl_1.lframe) {
567 *bias += 1;
568 }
569 if (temp < (real) (-contrl_1.lframe)) {
570 *bias += -1;
571 }
572 /* Place Voicing Window */
573 i__ = 721 - contrl_1.lframe;
574 preemp_(&inbuf[i__ - 181], &pebuf[i__ - 181], &contrl_1.lframe, &precoef,
575 zpre);
576 onset_(pebuf, osbuf, osptr, &c__10, &c__181, &c__720, &contrl_1.lframe, st);
577
578 /* MAXOSP is just a debugging variable. */
579
580 /* MAXOSP = MAX( MAXOSP, OSPTR ) */
581
582 placev_(osbuf, osptr, &c__10, &obound[2], vwin, &c__3, &contrl_1.lframe,
583 &c__90, &c__156, &c__307, &c__462);
584 /* The Pitch Extraction algorithm estimates the pitch for a frame
585 */
586 /* of speech by locating the minimum of the average magnitude difference
587 */
588 /* function (AMDF). The AMDF operates on low-pass, inverse filtered */
589 /* speech. (The low-pass filter is an 800 Hz, 19 tap, equiripple, FIR
590 */
591 /* filter and the inverse filter is a 2nd-order LPC filter.) The pitch
592 */
593 /* estimate is later refined by dynamic programming (DYPTRK). However,
594 */
595 /* since some of DYPTRK's parameters are a function of the voicing */
596 /* decisions, a voicing decision must precede the final pitch estimation.
597 */
598 /* See subroutines LPFILT, IVFILT, and TBDM. */
599 /* LPFILT reads indices LBUFH-LFRAME-29 = 511 through LBUFH = 720 */
600 /* of INBUF, and writes indices LBUFH+1-LFRAME = 541 through LBUFH
601 */
602 /* = 720 of LPBUF. */
603 lpfilt_(&inbuf[228], &lpbuf[384], &c__312, &contrl_1.lframe);
604 /* IVFILT reads indices (PWINH-LFRAME-7) = 353 through PWINH = 540
605 */
606 /* of LPBUF, and writes indices (PWINH-LFRAME+1) = 361 through */
607 /* PWINH = 540 of IVBUF. */
608 ivfilt_(&lpbuf[204], ivbuf, &c__312, &contrl_1.lframe, ivrc);
609 /* TBDM reads indices PWINL = 229 through */
610 /* (PWINL-1)+MAXWIN+(TAU(LTAU)-TAU(1))/2 = 452 of IVBUF, and writes
611 */
612 /* indices 1 through LTAU = 60 of AMDF. */
613 tbdm_(ivbuf, &c__156, tau, &c__60, amdf, &minptr, &maxptr, &mintau);
614 /* Voicing decisions are made for each half frame of input speech.
615 */
616 /* An initial voicing classification is made for each half of the */
617 /* analysis frame, and the voicing decisions for the present frame */
618 /* are finalized. See subroutine VOICIN. */
619 /* The voicing detector (VOICIN) classifies the input signal as */
620 /* unvoiced (including silence) or voiced using the AMDF windowed */
621 /* maximum-to-minimum ratio, the zero crossing rate, energy measures, */
622 /* reflection coefficients, and prediction gains. */
623 /* The pitch and voicing rules apply smoothing and isolated */
624 /* corrections to the pitch and voicing estimates and, in the process,
625 */
626 /* introduce two frames of delay into the corrected pitch estimates and
627 */
628 /* voicing decisions. */
629 for (half = 1; half <= 2; ++half) {
630 voicin_(&vwin[4], inbuf, lpbuf, buflim, &half, &amdf[minptr - 1], &
631 amdf[maxptr - 1], &mintau, ivrc, obound, voibuf, &c__3, st);
632 }
633 /* Find the minimum cost pitch decision over several frames */
634 /* given the current voicing decision and the AMDF array */
635 dyptrk_(amdf, &c__60, &minptr, &voibuf[7], pitch, &midx, st);
636 ipitch = tau[midx - 1];
637 /* Place spectrum analysis and energy windows */
638 placea_(&ipitch, voibuf, &obound[2], &c__3, vwin, awin, ewin, &
639 contrl_1.lframe, &c__156);
640 /* Remove short term DC bias over the analysis window, Put result in ABUF
641 */
642 lanal = awin[5] + 1 - awin[4];
643 dcbias_(&lanal, &pebuf[awin[4] - 181], abuf);
644 /* ABUF(1:LANAL) is now defined. It is equal to */
645 /* PEBUF(AWIN(1,AF):AWIN(2,AF)) corrected for short term DC bias. */
646 /* Compute RMS over integer number of pitch periods within the */
647 /* analysis window. */
648 /* Note that in a hardware implementation this computation may be */
649 /* simplified by using diagonal elements of PHI computed by MLOAD. */
650 i__1 = ewin[5] - ewin[4] + 1;
651 energy_(&i__1, &abuf[ewin[4] - awin[4]], &rmsbuf[2]);
652 /* Matrix load and invert, check RC's for stability */
653 mload_(&contrl_1.order, &c__1, &lanal, abuf, phi, psi);
654 invert_(&contrl_1.order, phi, psi, &rcbuf[20]);
655 rcchk_(&contrl_1.order, &rcbuf[10], &rcbuf[20]);
656 /* Set return parameters */
657 voice[1] = voibuf[2];
658 voice[2] = voibuf[3];
659 *rms = rmsbuf[0];
660 i__1 = contrl_1.order;
661 for (i__ = 1; i__ <= i__1; ++i__) {
662 rc[i__] = rcbuf[i__ - 1];
663 }
664 return 0;
665 } /* analys_ */
666