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