1 /*
2 
3  * Revision 1.2  1996/08/20  20:45:00  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  * Removed init function, since all initialization is now done in
9  * init_lpc10_encoder_state().
10  *
11  * Revision 1.1  1996/08/19  22:30:14  jaf
12  * Initial revision
13  *
14 
15 */
16 
17 /*  -- translated by f2c (version 19951025).
18    You must link the resulting object file with the libraries:
19 	-lf2c -lm   (in that order)
20 */
21 
22 #include "f2c.h"
23 
24 extern 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);
25 
26 /* Common Block Declarations */
27 
28 extern struct {
29     integer order, lframe;
30     logical corrp;
31 } contrl_;
32 
33 #define contrl_1 contrl_
34 
35 /****************************************************************************/
36 
37 /* 	VOICIN Version 52 */
38 
39 /*
40  * Revision 1.2  1996/08/20  20:45:00  jaf
41  * Removed all static local variables that were SAVE'd in the Fortran
42  * code, and put them in struct lpc10_encoder_state that is passed as an
43  * argument.
44  *
45  * Removed init function, since all initialization is now done in
46  * init_lpc10_encoder_state().
47  *
48  * Revision 1.1  1996/08/19  22:30:14  jaf
49  * Initial revision
50  * */
51 /* Revision 1.10  1996/03/29  17:59:14  jaf */
52 /* Avoided using VALUE(9), although it shouldn't affect the function of */
53 /* the code at all, because it was always multiplied by VDC(9,SNRL), */
54 /* which is 0 for all values of SNRL.  Still, if VALUE(9) had an initial */
55 /* value of IEEE NaN, it might cause trouble (I don't know how IEEE */
56 /* defines Nan * 0.  It should either be NaN or 0.) */
57 
58 /* Revision 1.9  1996/03/29  17:54:46  jaf */
59 /* Added a few comments about the accesses made to argument array VOIBUF */
60 /* and the local saved array VOICE. */
61 
62 /* Revision 1.8  1996/03/27  18:19:54  jaf */
63 /* Added an assignment to VSTATE that does not affect the function of the */
64 /* program at all.  The only reason I put it in was so that the tracing */
65 /* statements at the end, when enabled, will print a consistent value for */
66 /* VSTATE when HALF .EQ. 1, rather than a garbage value that could change */
67 /* from one call to the next. */
68 
69 /* Revision 1.7  1996/03/26  20:00:06  jaf */
70 /* Removed the inclusion of the file "vcomm.fh", and put its contents */
71 /* into this file.  It was included nowhere else but here. */
72 
73 /* Revision 1.6  1996/03/26  19:38:09  jaf */
74 /* Commented out trace statements. */
75 
76 /* Revision 1.5  1996/03/19  20:43:45  jaf */
77 /* Added comments about which indices of OBOUND and VOIBUF can be */
78 /* accessed, and whether they are read or written.  VOIBUF is fairly */
79 /* messy. */
80 
81 /* Revision 1.4  1996/03/19  15:00:58  jaf */
82 /* Moved the DATA statements for the *VDC* variables later, as it is */
83 /* apparently illegal to have DATA statements before local variable */
84 /* declarations. */
85 
86 /* Revision 1.3  1996/03/19  00:10:49  jaf */
87 /* Heavily commented the local variables that are saved from one */
88 /* invocation to the next, and how the local variable FIRST is used to */
89 /* avoid the need to assign most of them initial values with DATA */
90 /* statements. */
91 
92 /* A few should be initialized, but aren't.  I've guessed initial values */
93 /* for two of these, SFBUE and SLBUE, and I've convinced myself that for */
94 /* VOICE, the effects of uninitialized values will die out after 2 or 3 */
95 /* frame times.  It would still be good to choose initial values for */
96 /* these, but I don't know what reasonable values would be (0 comes to */
97 /* mind). */
98 
99 /* Revision 1.2  1996/03/13  16:09:28  jaf */
100 /* Comments added explaining which of the local variables of this */
101 /* subroutine need to be saved from one invocation to the next, and which */
102 /* do not. */
103 
104 /* WARNING!  Some of them that should are never given initial values in */
105 /* this code.  Hopefully, Fortran 77 defines initial values for them, but */
106 /* even so, giving them explicit initial values is preferable. */
107 
108 /* WARNING!  VALUE(9) is used, but never assigned a value.  It should */
109 /* probably be eliminated from the code. */
110 
111 /* Revision 1.1  1996/02/07 14:50:28  jaf */
112 /* Initial revision */
113 
114 
115 /****************************************************************************/
116 
117 /*        Voicing Detection (VOICIN) makes voicing decisions for each half */
118 /*  frame of input speech.  Tentative voicing decisions are made two frames*/
119 /*   in the future (2F) for each half frame.  These decisions are carried */
120 /*   through one frame in the future (1F) to the present (P) frame where */
121 /*   they are examined and smoothed, resulting in the final voicing */
122 /*   decisions for each half frame. */
123 /*        The voicing parameter (signal measurement) column vector (VALUE) */
124 /*   is based on a rectangular window of speech samples determined by the */
125 /*  window placement algorithm.  The voicing parameter vector contains the*/
126 /*  AMDF windowed maximum-to-minimum ratio, the zero crossing rate, energy*/
127 /*   measures, reflection coefficients, and prediction gains.  The voicing */
128 /*  window is placed to avoid contamination of the voicing parameter vector*/
129 /*   with speech onsets. */
130 /*        The input signal is then classified as unvoiced (including */
131 /*   silence) or voiced.  This decision is made by a linear discriminant */
132 /*   function consisting of a dot product of the voicing decision */
133 /*   coefficient (VDC) row vector with the measurement column vector */
134 /*  (VALUE).  The VDC vector is 2-dimensional, each row vector is optimized*/
135 /*   for a particular signal-to-noise ratio (SNR).  So, before the dot */
136 /*   product is performed, the SNR is estimated to select the appropriate */
137 /*   VDC vector. */
138 /*        The smoothing algorithm is a modified median smoother.  The */
139 /*  voicing discriminant function is used by the smoother to determine how*/
140 /*   strongly voiced or unvoiced a signal is.  The smoothing is further */
141 /*   modified if a speech onset and a voicing decision transition occur */
142 /*   within one half frame.  In this case, the voicing decision transition */
143 /*  is extended to the speech onset.  For transmission purposes, there are*/
144 /*   constraints on the duration and transition of voicing decisions.  The */
145 /*   smoother takes these constraints into account. */
146 /*        Finally, the energy estimates are updated along with the dither */
147 /*   threshold used to calculate the zero crossing rate (ZC). */
148 
149 /* Inputs: */
150 /*  VWIN      - Voicing window limits */
151 /*              The indices read of arrays VWIN, INBUF, LPBUF, and BUFLIM */
152 /*              are the same as those read by subroutine VPARMS. */
153 /*  INBUF     - Input speech buffer */
154 /*  LPBUF     - Low-pass filtered speech buffer */
155 /*  BUFLIM    - INBUF and LPBUF limits */
156 /*  HALF      - Present analysis half frame number */
157 /*  MINAMD    - Minimum value of the AMDF */
158 /*  MAXAMD    - Maximum value of the AMDF */
159 /*  MINTAU    - Pointer to the lag of the minimum AMDF value */
160 /*  IVRC(2)   - Inverse filter's RC's */
161 /*              Only index 2 of array IVRC read under normal operation. */
162 /*              (Index 1 is also read when debugging is turned on.) */
163 /*  OBOUND    - Onset boundary descriptions */
164 /*             Indices 1 through 3 read if (HALF .NE. 1), otherwise untouched.
165 */
166 /*  AF        - The analysis frame number */
167 /* Output: */
168 /*  VOIBUF(2,0:AF) - Buffer of voicing decisions */
169 /*              Index (HALF,3) written. */
170 /*              If (HALF .EQ. 1), skip down to "Read (HALF,3)" below. */
171 /*              Indices (1,2), (2,1), (1,2), and (2,2) read. */
172 /*              One of the following is then done: */
173 /*                 read (1,3) and possibly write (1,2) */
174 /*                 read (1,3) and write (1,2) or (2,2) */
175 /*                 write (2,1) */
176 /*                 write (2,1) or (1,2) */
177 /*                 read (1,0) and (1,3) and then write (2,2) or (1,1) */
178 /*                 no reads or writes on VOIBUF */
179 /*              Finally, read (HALF,3) */
180 /* Internal: */
181 /*  QS        - Ratio of preemphasized to full-band energies */
182 /*  RC1       - First reflection coefficient */
183 /* AR_B      - Product of the causal forward and reverse pitch prediction gain
184 s*/
185 /* AR_F      - Product of the noncausal forward and rev. pitch prediction gain
186 s*/
187 /*  ZC        - Zero crossing rate */
188 /*  DITHER    - Zero crossing threshold level */
189 /*  MAXMIN    - AMDF's 1 octave windowed maximum-to-minimum ratio */
190 /*  MINPTR    - Location  of minimum AMDF value */
191 /*  NVDC      - Number of elements in each VDC vector */
192 /*  NVDCL     - Number of VDC vectors */
193 /*  VDCL      - SNR values corresponding to the set of VDC's */
194 /*  VDC       - 2-D voicing decision coefficient vector */
195 /*  VALUE(9)  - Voicing Parameters */
196 /*  VOICE(2,3)- History of LDA results */
197 /*              On every call when (HALF .EQ. 1), VOICE(*,I+1) is */
198 /*              shifted back to VOICE(*,I), for I=1,2. */
199 /*              VOICE(HALF,3) is written on every call. */
200 /*              Depending on several conditions, one or more of */
201 /*              (1,1), (1,2), (2,1), and (2,2) might then be read. */
202 /*  LBE       - Ratio of low-band instantaneous to average energies */
203 /*  FBE       - Ratio of full-band instantaneous to average energies */
204 /*  LBVE      - Low band voiced energy */
205 /*  LBUE      - Low band unvoiced energy */
206 /*  FBVE      - Full band voiced energy */
207 /*  FBUE      - Full band unvoiced energy */
208 /*  OFBUE     - Previous full-band unvoiced energy */
209 /*  OLBUE     - Previous low-band unvoiced energy */
210 /*  REF       - Reference energy for initialization and DITHER threshold */
211 /*  SNR       - Estimate of signal-to-noise ratio */
212 /*  SNR2      - Estimate of low-band signal-to-noise ratio */
213 /*  SNRL      - SNR level number */
214 /*  OT        - Onset transition present */
215 /*  VSTATE    - Decimal interpretation of binary voicing classifications */
216 /*  FIRST     - First call flag */
217 
218 /* This subroutine maintains local state from one call to the next.  If */
219 /* you want to switch to using a new audio stream for this filter, or */
220 /* reinitialize its state for any other reason, call the ENTRY */
221 /* INITVOICIN. */
222 
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)223 /* Subroutine */ int voicin_(integer *vwin, real *inbuf, real *
224 	lpbuf, integer *buflim, integer *half, real *minamd, real *maxamd,
225 	integer *mintau, real *ivrc, integer *obound, integer *voibuf,
226 	integer *af, struct lpc10_encoder_state *st)
227 {
228     /* Initialized data */
229 
230     real *dither;
231     static real vdc[100]	/* was [10][10] */ = { 0.f,1714.f,-110.f,
232 	    334.f,-4096.f,-654.f,3752.f,3769.f,0.f,1181.f,0.f,874.f,-97.f,
233 	    300.f,-4096.f,-1021.f,2451.f,2527.f,0.f,-500.f,0.f,510.f,-70.f,
234 	    250.f,-4096.f,-1270.f,2194.f,2491.f,0.f,-1500.f,0.f,500.f,-10.f,
235 	    200.f,-4096.f,-1300.f,2e3f,2e3f,0.f,-2e3f,0.f,500.f,0.f,0.f,
236 	    -4096.f,-1300.f,2e3f,2e3f,0.f,-2500.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,
237 	    0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,
238 	    0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,
239 	    0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f };
240     static integer nvdcl = 5;
241     static real vdcl[10] = { 600.f,450.f,300.f,200.f,0.f,0.f,0.f,0.f,0.f,0.f }
242 	    ;
243 
244     /* System generated locals */
245     integer inbuf_offset = 0, lpbuf_offset = 0, i__1, i__2;
246     real r__1, r__2;
247 
248     /* Builtin functions */
249     integer i_nint(real *);
250     double sqrt(doublereal);
251 
252     /* Local variables */
253     real ar_b__, ar_f__;
254     integer *lbve, *lbue, *fbve, *fbue;
255     integer snrl, i__;
256     integer *ofbue, *sfbue;
257     real *voice;
258     integer *olbue, *slbue;
259     real value[9];
260     integer zc;
261     logical ot;
262     real qs;
263     real *maxmin;
264     integer vstate;
265     real rc1;
266     extern /* Subroutine */ int vparms_(integer *, real *, real *, integer *,
267 	    integer *, real *, integer *, integer *, integer *, integer *,
268 	    real *, real *, real *, real *);
269     integer fbe, lbe;
270     real *snr;
271     real snr2;
272 
273     (void)af;
274 /* 	Global Variables: */
275 /*       Arguments */
276 
277 /*   LPC Processing control variables: */
278 
279 /* *** Read-only: initialized in setup */
280 
281 /*  Files for Speech, Parameter, and Bitstream Input & Output, */
282 /*    and message and debug outputs. */
283 
284 /* Here are the only files which use these variables: */
285 
286 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
287 
288 /* Many files which use fdebug are not listed, since it is only used in */
289 /* those other files conditionally, to print trace statements. */
290 /* 	integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
291 /*  LPC order, Frame size, Quantization rate, Bits per frame, */
292 /*    Error correction */
293 /* Subroutine SETUP is the only place where order is assigned a value, */
294 /* and that value is 10.  It could increase efficiency 1% or so to */
295 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
296 */
297 /* a variable in a COMMON block, since it is used in many places in the */
298 /* core of the coding and decoding routines.  Actually, I take that back.
299 */
300 /* At least when compiling with f2c, the upper bound of DO loops is */
301 /* stored in a local variable before the DO loop begins, and then that is
302 */
303 /* compared against on each iteration. */
304 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
305 /* Similarly for quant, which is given a value of 2400 in SETUP.  quant */
306 /* is used in only a few places, and never in the core coding and */
307 /* decoding routines, so it could be eliminated entirely. */
308 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
309 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
310 /* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */
311 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
312 */
313 /* a constant or a variable, since it is only examined once per frame. */
314 /* Leaving it as a variable that is set to .TRUE.  seems like a good */
315 /* idea, since it does enable some error-correction capability for */
316 /* unvoiced frames, with no change in the coding rate, and no noticeable
317 */
318 /* quality difference in the decoded speech. */
319 /* 	integer quant, nbits */
320 /* *** Read/write: variables for debugging, not needed for LPC algorithm
321 */
322 
323 /*  Current frame, Unstable frames, Output clip count, Max onset buffer,
324 */
325 /*    Debug listing detail level, Line count on listing page */
326 
327 /* nframe is not needed for an embedded LPC10 at all. */
328 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
329 /* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */
330 /* an application, I would recommend removing the call to ERROR in RCCHK,
331 */
332 /* and remove ERROR and nunsfm completely. */
333 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
334 */
335 /* sread.f.  When LPC10 is embedded into an application, one might want */
336 /* to cause it to be incremented in a routine that takes the output of */
337 /* SYNTHS and sends it to an audio device.  It could be optionally */
338 /* displayed, for those that might want to know what it is. */
339 /* maxosp is never initialized to 0 in SETUP, although it probably should
340 */
341 /* be, and it is updated in subroutine ANALYS.  I doubt that its value */
342 /* would be of much interest to an application in which LPC10 is */
343 /* embedded. */
344 /* listl and lincnt are not needed for an embedded LPC10 at all. */
345 /* 	integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
346 /* 	common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
347 /* 	common /contrl/ quant, nbits */
348 /* 	common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
349 /* 	Parameters/constants */
350 /*       Voicing coefficient and Linear Discriminant Analysis variables:
351 */
352 /*       Max number of VDC's and VDC levels */
353 /*       The following are not Fortran PARAMETER's, but they are */
354 /*       initialized with DATA statements, and never modified. */
355 /*       Actual number of VDC's and levels */
356 /*       Local variables that need not be saved */
357 /*       Note: */
358 
359 /*       VALUE(1) through VALUE(8) are assigned values, but VALUE(9) */
360 /*       never is.  Yet VALUE(9) is read in the loop that begins "DO I =
361 */
362 /*       1, 9" below.  I believe that this doesn't cause any problems in
363 */
364 /*       this subroutine, because all VDC(9,*) array elements are 0, and
365 */
366 /*       this is what is multiplied by VALUE(9) in all cases.  Still, it
367 */
368 /*       would save a multiplication to change the loop to "DO I = 1, 8".
369 */
370 /*       Local state */
371 /*       WARNING! */
372 
373 /*       VOICE, SFBUE, and SLBUE should be saved from one invocation to */
374 /*       the next, but they are never given an initial value. */
375 
376 /*       Does Fortran 77 specify some default initial value, like 0, or */
377 /*       is it undefined?  If it is undefined, then this code should be */
378 /*       corrected to specify an initial value. */
379 
380 /*       For VOICE, note that it is "shifted" in the statement that */
381 /*       begins "IF (HALF .EQ. 1) THEN" below.  Also, uninitialized */
382 /*       values in the VOICE array can only affect entries in the VOIBUF
383 */
384 /*       array that are for the same frame, or for an older frame.  Thus
385 */
386 /*       the effects of uninitialized values in VOICE cannot linger on */
387 /*       for more than 2 or 3 frame times. */
388 
389 /*       For SFBUE and SLBUE, the effects of uninitialized values can */
390 /*       linger on for many frame times, because their previous values */
391 /*       are exponentially decayed.  Thus it is more important to choose
392 */
393 /*       initial values for these variables.  I would guess that a */
394 /*       reasonable initial value for SFBUE is REF/16, the same as used */
395 /*       for FBUE and OFBUE.  Similarly, SLBUE can be initialized to */
396 /*       REF/32, the same as for LBUE and OLBUE. */
397 
398 /*       These guessed initial values should be validated by re-running */
399 /*       the modified program on some audio samples. */
400 
401 /*   Declare and initialize filters: */
402 
403     dither = (&st->dither);
404     snr = (&st->snr);
405     maxmin = (&st->maxmin);
406     voice = (&st->voice[0]);
407     lbve = (&st->lbve);
408     lbue = (&st->lbue);
409     fbve = (&st->fbve);
410     fbue = (&st->fbue);
411     ofbue = (&st->ofbue);
412     olbue = (&st->olbue);
413     sfbue = (&st->sfbue);
414     slbue = (&st->slbue);
415 
416     /* Parameter adjustments */
417     if (vwin) {
418 	--vwin;
419 	}
420     if (buflim) {
421 	--buflim;
422 	}
423     if (inbuf) {
424 	inbuf_offset = buflim[1];
425 	inbuf -= inbuf_offset;
426 	}
427     if (lpbuf) {
428 	lpbuf_offset = buflim[3];
429 	lpbuf -= lpbuf_offset;
430 	}
431     if (ivrc) {
432 	--ivrc;
433 	}
434     if (obound) {
435 	--obound;
436 	}
437     if (voibuf) {
438 	--voibuf;
439 	}
440 
441     /* Function Body */
442 
443 /*       The following variables are saved from one invocation to the */
444 /*       next, but are not initialized with DATA statements.  This is */
445 /*       acceptable, because FIRST is initialized ot .TRUE., and the */
446 /*       first time that this subroutine is then called, they are all */
447 /*       given initial values. */
448 
449 /*       SNR */
450 /*       LBVE, LBUE, FBVE, FBUE, OFBUE, OLBUE */
451 
452 /*       MAXMIN is initialized on the first call, assuming that HALF */
453 /*       .EQ. 1 on first call.  This is how ANALYS calls this subroutine.
454 */
455 
456 /*   Voicing Decision Parameter vector (* denotes zero coefficient): */
457 
458 /* 	* MAXMIN */
459 /* 	  LBE/LBVE */
460 /* 	  ZC */
461 /* 	  RC1 */
462 /* 	  QS */
463 /* 	  IVRC2 */
464 /* 	  aR_B */
465 /* 	  aR_F */
466 /* 	* LOG(LBE/LBVE) */
467 /*  Define 2-D voicing decision coefficient vector according to the voicin
468 g*/
469 /*  parameter order above.  Each row (VDC vector) is optimized for a speci
470 fic*/
471 /*   SNR.  The last element of the vector is the constant. */
472 /* 	         E    ZC    RC1    Qs   IVRC2  aRb   aRf        c */
473 
474 /*  The VOICE array contains the result of the linear discriminant functio
475 n*/
476 /*   (analog values).  The VOIBUF array contains the hard-limited binary
477 */
478 /*   voicing decisions.  The VOICE and VOIBUF arrays, according to FORTRAN
479  */
480 /*   memory allocation, are addressed as: */
481 
482 /* 	   (half-frame number, future-frame number) */
483 
484 /* 	   |   Past    |  Present  |  Future1  |  Future2  | */
485 /* 	   | 1,0 | 2,0 | 1,1 | 2,1 | 1,2 | 2,2 | 1,3 | 2,3 |  --->  time */
486 
487 /*   Update linear discriminant function history each frame: */
488     if (*half == 1) {
489 	voice[0] = voice[2];
490 	voice[1] = voice[3];
491 	voice[2] = voice[4];
492 	voice[3] = voice[5];
493 	*maxmin = *maxamd / max(*minamd,1.f);
494     }
495 /*   Calculate voicing parameters twice per frame: */
496     vparms_(&vwin[1], &inbuf[inbuf_offset], &lpbuf[lpbuf_offset], &buflim[1],
497 	    half, dither, mintau, &zc, &lbe, &fbe, &qs, &rc1, &ar_b__, &
498 	    ar_f__);
499 /*   Estimate signal-to-noise ratio to select the appropriate VDC vector.
500 */
501 /*   The SNR is estimated as the running average of the ratio of the */
502 /*   running average full-band voiced energy to the running average */
503 /*   full-band unvoiced energy. SNR filter has gain of 63. */
504     r__1 = (*snr + *fbve / (real) max(*fbue,1)) * 63 / 64.f;
505     *snr = (real) i_nint(&r__1);
506     snr2 = *snr * *fbue / max(*lbue,1);
507 /*   Quantize SNR to SNRL according to VDCL thresholds. */
508     snrl = 1;
509     i__1 = nvdcl - 1;
510     for (snrl = 1; snrl <= i__1; ++snrl) {
511 	if (snr2 > vdcl[snrl - 1]) {
512 	    goto L69;
513 	}
514     }
515 /*   	(Note:  SNRL = NVDCL here) */
516 L69:
517 /*   Linear discriminant voicing parameters: */
518     value[0] = *maxmin;
519     value[1] = (real) lbe / max(*lbve,1);
520     value[2] = (real) zc;
521     value[3] = rc1;
522     value[4] = qs;
523     value[5] = ivrc[2];
524     value[6] = ar_b__;
525     value[7] = ar_f__;
526 /*   Evaluation of linear discriminant function: */
527     voice[*half + 3] = vdc[snrl * 10 - 1];
528     for (i__ = 1; i__ <= 8; ++i__) {
529 	voice[*half + 3] += vdc[i__ + snrl * 10 - 11] * value[i__ - 1];
530     }
531 /*   Classify as voiced if discriminant > 0, otherwise unvoiced */
532 /*   Voicing decision for current half-frame:  1 = Voiced; 0 = Unvoiced */
533     if (voice[*half + 3] > 0.f) {
534 	voibuf[*half + 6] = 1;
535     } else {
536 	voibuf[*half + 6] = 0;
537     }
538 /*   Skip voicing decision smoothing in first half-frame: */
539 /*     Give a value to VSTATE, so that trace statements below will print
540 */
541 /*     a consistent value from one call to the next when HALF .EQ. 1. */
542 /*     The value of VSTATE is not used for any other purpose when this is
543 */
544 /*     true. */
545     vstate = -1;
546     if (*half == 1) {
547 	goto L99;
548     }
549 /*   Voicing decision smoothing rules (override of linear combination): */
550 
551 /* 	Unvoiced half-frames:  At least two in a row. */
552 /* 	-------------------- */
553 
554 /* 	Voiced half-frames:    At least two in a row in one frame. */
555 /* 	-------------------    Otherwise at least three in a row. */
556 /* 			       (Due to the way transition frames are encoded) */
557 
558 /* 	In many cases, the discriminant function determines how to smooth. */
559 /*	In the following chart, the decisions marked with a * may be overridden
560 .*/
561 
562 /*   Voicing override of transitions at onsets: */
563 /* 	If a V/UV or UV/V voicing decision transition occurs within one-half
564 */
565 /* 	frame of an onset bounding a voicing window, then the transition is */
566 /* 	moved to occur at the onset. */
567 
568 /* 	P	1F */
569 /* 	-----	----- */
570 /* 	0   0   0   0 */
571 /* 	0   0   0*  1	(If there is an onset there) */
572 /* 	0   0   1*  0*	(Based on 2F and discriminant distance) */
573 /* 	0   0   1   1 */
574 /* 	0   1*  0   0	(Always) */
575 /* 	0   1*  0*  1	(Based on discriminant distance) */
576 /* 	0*  1   1   0*	(Based on past, 2F, and discriminant distance) */
577 /* 	0   1*  1   1	(If there is an onset there) */
578 /* 	1   0*  0   0	(If there is an onset there) */
579 /* 	1   0   0   1 */
580 /* 	1   0*  1*  0	(Based on discriminant distance) */
581 /* 	1   0*  1   1	(Always) */
582 /* 	1   1   0   0 */
583 /* 	1   1   0*  1*	(Based on 2F and discriminant distance) */
584 /* 	1   1   1*  0	(If there is an onset there) */
585 /* 	1   1   1   1 */
586 
587 /*   Determine if there is an onset transition between P and 1F. */
588 /*   OT (Onset Transition) is true if there is an onset between */
589 /*   P and 1F but not after 1F. */
590     ot = ((obound[1] & 2) != 0 || obound[2] == 1) && (obound[3] & 1) == 0;
591 /*   Multi-way dispatch on voicing decision history: */
592     vstate = (voibuf[3] << 3) + (voibuf[4] << 2) + (voibuf[5] << 1) + voibuf[
593 	    6];
594     switch (vstate + 1) {
595 	case 1:  goto L99;
596 	case 2:  goto L1;
597 	case 3:  goto L2;
598 	case 4:  goto L99;
599 	case 5:  goto L4;
600 	case 6:  goto L5;
601 	case 7:  goto L6;
602 	case 8:  goto L7;
603 	case 9:  goto L8;
604 	case 10:  goto L99;
605 	case 11:  goto L10;
606 	case 12:  goto L11;
607 	case 13:  goto L99;
608 	case 14:  goto L13;
609 	case 15:  goto L14;
610 	case 16:  goto L99;
611     }
612 L1:
613     if (ot && voibuf[7] == 1) {
614 	voibuf[5] = 1;
615     }
616     goto L99;
617 L2:
618     if (voibuf[7] == 0 || voice[2] < -voice[3]) {
619 	voibuf[5] = 0;
620     } else {
621 	voibuf[6] = 1;
622     }
623     goto L99;
624 L4:
625     voibuf[4] = 0;
626     goto L99;
627 L5:
628     if (voice[1] < -voice[2]) {
629 	voibuf[4] = 0;
630     } else {
631 	voibuf[5] = 1;
632     }
633     goto L99;
634 /*   VOIBUF(2,0) must be 0 */
635 L6:
636     if (voibuf[1] == 1 || voibuf[7] == 1 || voice[3] > voice[0]) {
637 	voibuf[6] = 1;
638     } else {
639 	voibuf[3] = 1;
640     }
641     goto L99;
642 L7:
643     if (ot) {
644 	voibuf[4] = 0;
645     }
646     goto L99;
647 L8:
648     if (ot) {
649 	voibuf[4] = 1;
650     }
651     goto L99;
652 L10:
653     if (voice[2] < -voice[1]) {
654 	voibuf[5] = 0;
655     } else {
656 	voibuf[4] = 1;
657     }
658     goto L99;
659 L11:
660     voibuf[4] = 1;
661     goto L99;
662 L13:
663     if (voibuf[7] == 0 && voice[3] < -voice[2]) {
664 	voibuf[6] = 0;
665     } else {
666 	voibuf[5] = 1;
667     }
668     goto L99;
669 L14:
670     if (ot && voibuf[7] == 0) {
671 	voibuf[5] = 0;
672     }
673 /* 	GOTO 99 */
674 L99:
675 /*   Now update parameters: */
676 /*   ---------------------- */
677 
678 /*  During unvoiced half-frames, update the low band and full band unvoice
679 d*/
680 /*   energy estimates (LBUE and FBUE) and also the zero crossing */
681 /*   threshold (DITHER).  (The input to the unvoiced energy filters is */
682 /*   restricted to be less than 10dB above the previous inputs of the */
683 /*   filters.) */
684 /*   During voiced half-frames, update the low-pass (LBVE) and all-pass */
685 /*   (FBVE) voiced energy estimates. */
686     if (voibuf[*half + 6] == 0) {
687 /* Computing MIN */
688 	i__1 = fbe, i__2 = *ofbue * 3;
689 	r__1 = (*sfbue * 63 + (min(i__1,i__2) << 3)) / 64.f;
690 	*sfbue = i_nint(&r__1);
691 	*fbue = *sfbue / 8;
692 	*ofbue = fbe;
693 /* Computing MIN */
694 	i__1 = lbe, i__2 = *olbue * 3;
695 	r__1 = (*slbue * 63 + (min(i__1,i__2) << 3)) / 64.f;
696 	*slbue = i_nint(&r__1);
697 	*lbue = *slbue / 8;
698 	*olbue = lbe;
699     } else {
700 	r__1 = (*lbve * 63 + lbe) / 64.f;
701 	*lbve = i_nint(&r__1);
702 	r__1 = (*fbve * 63 + fbe) / 64.f;
703 	*fbve = i_nint(&r__1);
704     }
705 /*   Set dither threshold to yield proper zero crossing rates in the */
706 /*   presence of low frequency noise and low level signal input. */
707 /*   NOTE: The divisor is a function of REF, the expected energies. */
708 /* Computing MIN */
709 /* Computing MAX */
710     r__2 = sqrt((real) (*lbue * *lbve)) * 64 / 3000;
711     r__1 = max(r__2,1.f);
712     *dither = min(r__1,20.f);
713 /*   Voicing decisions are returned in VOIBUF. */
714     return 0;
715 } /* voicin_ */
716