Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
voicin.c File Reference
#include "f2c.h"
Include dependency graph for voicin.c:

Go to the source code of this file.

Macros

#define contrl_1   contrl_
 

Functions

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)
 

Variables

struct {
   logical   corrp
 
   integer   lframe
 
   integer   order
 
contrl_
 

Macro Definition Documentation

◆ contrl_1

#define contrl_1   contrl_

Definition at line 53 of file voicin.c.

Function Documentation

◆ voicin_()

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 at line 258 of file voicin.c.

References lpc10_encoder_state::dither, lpc10_encoder_state::fbue, lpc10_encoder_state::fbve, i_nint(), L1, L2, lpc10_encoder_state::lbue, lpc10_encoder_state::lbve, max, lpc10_encoder_state::maxmin, min, lpc10_encoder_state::ofbue, lpc10_encoder_state::olbue, lpc10_encoder_state::sfbue, lpc10_encoder_state::slbue, lpc10_encoder_state::snr, value, lpc10_encoder_state::voice, and vparms_().

Referenced by analys_().

262 {
263  /* Initialized data */
264 
265  real *dither;
266  static real vdc[100] /* was [10][10] */ = { 0.f,1714.f,-110.f,
267  334.f,-4096.f,-654.f,3752.f,3769.f,0.f,1181.f,0.f,874.f,-97.f,
268  300.f,-4096.f,-1021.f,2451.f,2527.f,0.f,-500.f,0.f,510.f,-70.f,
269  250.f,-4096.f,-1270.f,2194.f,2491.f,0.f,-1500.f,0.f,500.f,-10.f,
270  200.f,-4096.f,-1300.f,2e3f,2e3f,0.f,-2e3f,0.f,500.f,0.f,0.f,
271  -4096.f,-1300.f,2e3f,2e3f,0.f,-2500.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,
272  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,
273  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,
274  0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f,0.f };
275  static integer nvdcl = 5;
276  static real vdcl[10] = { 600.f,450.f,300.f,200.f,0.f,0.f,0.f,0.f,0.f,0.f }
277  ;
278 
279  /* System generated locals */
280  integer inbuf_offset = 0, lpbuf_offset = 0, i__1, i__2;
281  real r__1, r__2;
282 
283  /* Builtin functions */
284  integer i_nint(real *);
285  double sqrt(doublereal);
286 
287  /* Local variables */
288  real ar_b__, ar_f__;
289  integer *lbve, *lbue, *fbve, *fbue;
290  integer snrl, i__;
291  integer *ofbue, *sfbue;
292  real *voice;
293  integer *olbue, *slbue;
294  real value[9];
295  integer zc;
296  logical ot;
297  real qs;
298  real *maxmin;
299  integer vstate;
300  real rc1;
301  extern /* Subroutine */ int vparms_(integer *, real *, real *, integer *,
302  integer *, real *, integer *, integer *, integer *, integer *,
303  real *, real *, real *, real *);
304  integer fbe, lbe;
305  real *snr;
306  real snr2;
307 
308 /* Global Variables: */
309 /* Arguments */
310 /* $Log$
311  * Revision 1.16 2004/06/26 03:50:14 markster
312  * Merge source cleanups (bug #1911)
313  *
314  * Revision 1.15 2003/11/23 22:14:32 markster
315  * Various warning cleanups
316  *
317  * Revision 1.14 2003/02/12 13:59:15 matteo
318  * mer feb 12 14:56:57 CET 2003
319  *
320  * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
321  * mer feb 12 14:56:57 CET 2003
322  *
323  * Revision 1.2 2000/01/05 08:20:40 markster
324  * Some OSS fixes and a few lpc changes to make it actually work
325  *
326  * Revision 1.2 1996/08/20 20:45:00 jaf
327  * Removed all static local variables that were SAVE'd in the Fortran
328  * code, and put them in struct lpc10_encoder_state that is passed as an
329  * argument.
330  *
331  * Removed init function, since all initialization is now done in
332  * init_lpc10_encoder_state().
333  *
334  * Revision 1.1 1996/08/19 22:30:14 jaf
335  * Initial revision
336  * */
337 /* Revision 1.3 1996/03/29 22:05:55 jaf */
338 /* Commented out the common block variables that are not needed by the */
339 /* embedded version. */
340 
341 /* Revision 1.2 1996/03/26 19:34:50 jaf */
342 /* Added comments indicating which constants are not needed in an */
343 /* application that uses the LPC-10 coder. */
344 
345 /* Revision 1.1 1996/02/07 14:44:09 jaf */
346 /* Initial revision */
347 
348 /* LPC Processing control variables: */
349 
350 /* *** Read-only: initialized in setup */
351 
352 /* Files for Speech, Parameter, and Bitstream Input & Output, */
353 /* and message and debug outputs. */
354 
355 /* Here are the only files which use these variables: */
356 
357 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
358 
359 /* Many files which use fdebug are not listed, since it is only used in */
360 /* those other files conditionally, to print trace statements. */
361 /* integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
362 /* LPC order, Frame size, Quantization rate, Bits per frame, */
363 /* Error correction */
364 /* Subroutine SETUP is the only place where order is assigned a value, */
365 /* and that value is 10. It could increase efficiency 1% or so to */
366 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as
367 */
368 /* a variable in a COMMON block, since it is used in many places in the */
369 /* core of the coding and decoding routines. Actually, I take that back.
370 */
371 /* At least when compiling with f2c, the upper bound of DO loops is */
372 /* stored in a local variable before the DO loop begins, and then that is
373 */
374 /* compared against on each iteration. */
375 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
376 /* Similarly for quant, which is given a value of 2400 in SETUP. quant */
377 /* is used in only a few places, and never in the core coding and */
378 /* decoding routines, so it could be eliminated entirely. */
379 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
380 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
381 /* subroutines ENCODE and DECODE. It doesn't affect the speed of the */
382 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is
383 */
384 /* a constant or a variable, since it is only examined once per frame. */
385 /* Leaving it as a variable that is set to .TRUE. seems like a good */
386 /* idea, since it does enable some error-correction capability for */
387 /* unvoiced frames, with no change in the coding rate, and no noticeable
388 */
389 /* quality difference in the decoded speech. */
390 /* integer quant, nbits */
391 /* *** Read/write: variables for debugging, not needed for LPC algorithm
392 */
393 
394 /* Current frame, Unstable frames, Output clip count, Max onset buffer,
395 */
396 /* Debug listing detail level, Line count on listing page */
397 
398 /* nframe is not needed for an embedded LPC10 at all. */
399 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
400 /* ERROR, which is only called from RCCHK. When LPC10 is embedded into */
401 /* an application, I would recommend removing the call to ERROR in RCCHK,
402 */
403 /* and remove ERROR and nunsfm completely. */
404 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in
405 */
406 /* sread.f. When LPC10 is embedded into an application, one might want */
407 /* to cause it to be incremented in a routine that takes the output of */
408 /* SYNTHS and sends it to an audio device. It could be optionally */
409 /* displayed, for those that might want to know what it is. */
410 /* maxosp is never initialized to 0 in SETUP, although it probably should
411 */
412 /* be, and it is updated in subroutine ANALYS. I doubt that its value */
413 /* would be of much interest to an application in which LPC10 is */
414 /* embedded. */
415 /* listl and lincnt are not needed for an embedded LPC10 at all. */
416 /* integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
417 /* common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
418 /* common /contrl/ quant, nbits */
419 /* common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
420 /* Parameters/constants */
421 /* Voicing coefficient and Linear Discriminant Analysis variables:
422 */
423 /* Max number of VDC's and VDC levels */
424 /* The following are not Fortran PARAMETER's, but they are */
425 /* initialized with DATA statements, and never modified. */
426 /* Actual number of VDC's and levels */
427 /* Local variables that need not be saved */
428 /* Note: */
429 
430 /* VALUE(1) through VALUE(8) are assigned values, but VALUE(9) */
431 /* never is. Yet VALUE(9) is read in the loop that begins "DO I =
432 */
433 /* 1, 9" below. I believe that this doesn't cause any problems in
434 */
435 /* this subroutine, because all VDC(9,*) array elements are 0, and
436 */
437 /* this is what is multiplied by VALUE(9) in all cases. Still, it
438 */
439 /* would save a multiplication to change the loop to "DO I = 1, 8".
440 */
441 /* Local state */
442 /* WARNING! */
443 
444 /* VOICE, SFBUE, and SLBUE should be saved from one invocation to */
445 /* the next, but they are never given an initial value. */
446 
447 /* Does Fortran 77 specify some default initial value, like 0, or */
448 /* is it undefined? If it is undefined, then this code should be */
449 /* corrected to specify an initial value. */
450 
451 /* For VOICE, note that it is "shifted" in the statement that */
452 /* begins "IF (HALF .EQ. 1) THEN" below. Also, uninitialized */
453 /* values in the VOICE array can only affect entries in the VOIBUF
454 */
455 /* array that are for the same frame, or for an older frame. Thus
456 */
457 /* the effects of uninitialized values in VOICE cannot linger on */
458 /* for more than 2 or 3 frame times. */
459 
460 /* For SFBUE and SLBUE, the effects of uninitialized values can */
461 /* linger on for many frame times, because their previous values */
462 /* are exponentially decayed. Thus it is more important to choose
463 */
464 /* initial values for these variables. I would guess that a */
465 /* reasonable initial value for SFBUE is REF/16, the same as used */
466 /* for FBUE and OFBUE. Similarly, SLBUE can be initialized to */
467 /* REF/32, the same as for LBUE and OLBUE. */
468 
469 /* These guessed initial values should be validated by re-running */
470 /* the modified program on some audio samples. */
471 
472 /* Declare and initialize filters: */
473 
474  dither = (&st->dither);
475  snr = (&st->snr);
476  maxmin = (&st->maxmin);
477  voice = (&st->voice[0]);
478  lbve = (&st->lbve);
479  lbue = (&st->lbue);
480  fbve = (&st->fbve);
481  fbue = (&st->fbue);
482  ofbue = (&st->ofbue);
483  olbue = (&st->olbue);
484  sfbue = (&st->sfbue);
485  slbue = (&st->slbue);
486 
487  /* Parameter adjustments */
488  if (vwin) {
489  --vwin;
490  }
491  if (buflim) {
492  --buflim;
493  }
494  if (inbuf) {
495  inbuf_offset = buflim[1];
496  inbuf -= inbuf_offset;
497  }
498  if (lpbuf) {
499  lpbuf_offset = buflim[3];
500  lpbuf -= lpbuf_offset;
501  }
502  if (ivrc) {
503  --ivrc;
504  }
505  if (obound) {
506  --obound;
507  }
508  if (voibuf) {
509  --voibuf;
510  }
511 
512  /* Function Body */
513 
514 /* The following variables are saved from one invocation to the */
515 /* next, but are not initialized with DATA statements. This is */
516 /* acceptable, because FIRST is initialized ot .TRUE., and the */
517 /* first time that this subroutine is then called, they are all */
518 /* given initial values. */
519 
520 /* SNR */
521 /* LBVE, LBUE, FBVE, FBUE, OFBUE, OLBUE */
522 
523 /* MAXMIN is initialized on the first call, assuming that HALF */
524 /* .EQ. 1 on first call. This is how ANALYS calls this subroutine.
525 */
526 
527 /* Voicing Decision Parameter vector (* denotes zero coefficient): */
528 
529 /* * MAXMIN */
530 /* LBE/LBVE */
531 /* ZC */
532 /* RC1 */
533 /* QS */
534 /* IVRC2 */
535 /* aR_B */
536 /* aR_F */
537 /* * LOG(LBE/LBVE) */
538 /* Define 2-D voicing decision coefficient vector according to the voicin
539 g*/
540 /* parameter order above. Each row (VDC vector) is optimized for a speci
541 fic*/
542 /* SNR. The last element of the vector is the constant. */
543 /* E ZC RC1 Qs IVRC2 aRb aRf c */
544 
545 /* The VOICE array contains the result of the linear discriminant functio
546 n*/
547 /* (analog values). The VOIBUF array contains the hard-limited binary
548 */
549 /* voicing decisions. The VOICE and VOIBUF arrays, according to FORTRAN
550  */
551 /* memory allocation, are addressed as: */
552 
553 /* (half-frame number, future-frame number) */
554 
555 /* | Past | Present | Future1 | Future2 | */
556 /* | 1,0 | 2,0 | 1,1 | 2,1 | 1,2 | 2,2 | 1,3 | 2,3 | ---> time */
557 
558 /* Update linear discriminant function history each frame: */
559  if (*half == 1) {
560  voice[0] = voice[2];
561  voice[1] = voice[3];
562  voice[2] = voice[4];
563  voice[3] = voice[5];
564  *maxmin = *maxamd / max(*minamd,1.f);
565  }
566 /* Calculate voicing parameters twice per frame: */
567  vparms_(&vwin[1], &inbuf[inbuf_offset], &lpbuf[lpbuf_offset], &buflim[1],
568  half, dither, mintau, &zc, &lbe, &fbe, &qs, &rc1, &ar_b__, &
569  ar_f__);
570 /* Estimate signal-to-noise ratio to select the appropriate VDC vector.
571 */
572 /* The SNR is estimated as the running average of the ratio of the */
573 /* running average full-band voiced energy to the running average */
574 /* full-band unvoiced energy. SNR filter has gain of 63. */
575  r__1 = (*snr + *fbve / (real) max(*fbue,1)) * 63 / 64.f;
576  *snr = (real) i_nint(&r__1);
577  snr2 = *snr * *fbue / max(*lbue,1);
578 /* Quantize SNR to SNRL according to VDCL thresholds. */
579  snrl = 1;
580  i__1 = nvdcl - 1;
581  for (snrl = 1; snrl <= i__1; ++snrl) {
582  if (snr2 > vdcl[snrl - 1]) {
583  goto L69;
584  }
585  }
586 /* (Note: SNRL = NVDCL here) */
587 L69:
588 /* Linear discriminant voicing parameters: */
589  value[0] = *maxmin;
590  value[1] = (real) lbe / max(*lbve,1);
591  value[2] = (real) zc;
592  value[3] = rc1;
593  value[4] = qs;
594  value[5] = ivrc[2];
595  value[6] = ar_b__;
596  value[7] = ar_f__;
597 /* Evaluation of linear discriminant function: */
598  voice[*half + 3] = vdc[snrl * 10 - 1];
599  for (i__ = 1; i__ <= 8; ++i__) {
600  voice[*half + 3] += vdc[i__ + snrl * 10 - 11] * value[i__ - 1];
601  }
602 /* Classify as voiced if discriminant > 0, otherwise unvoiced */
603 /* Voicing decision for current half-frame: 1 = Voiced; 0 = Unvoiced */
604  if (voice[*half + 3] > 0.f) {
605  voibuf[*half + 6] = 1;
606  } else {
607  voibuf[*half + 6] = 0;
608  }
609 /* Skip voicing decision smoothing in first half-frame: */
610 /* Give a value to VSTATE, so that trace statements below will print
611 */
612 /* a consistent value from one call to the next when HALF .EQ. 1. */
613 /* The value of VSTATE is not used for any other purpose when this is
614 */
615 /* true. */
616  vstate = -1;
617  if (*half == 1) {
618  goto L99;
619  }
620 /* Voicing decision smoothing rules (override of linear combination): */
621 
622 /* Unvoiced half-frames: At least two in a row. */
623 /* -------------------- */
624 
625 /* Voiced half-frames: At least two in a row in one frame. */
626 /* ------------------- Otherwise at least three in a row. */
627 /* (Due to the way transition frames are encoded) */
628 
629 /* In many cases, the discriminant function determines how to smooth. */
630 /* In the following chart, the decisions marked with a * may be overridden
631 .*/
632 
633 /* Voicing override of transitions at onsets: */
634 /* If a V/UV or UV/V voicing decision transition occurs within one-half
635 */
636 /* frame of an onset bounding a voicing window, then the transition is */
637 /* moved to occur at the onset. */
638 
639 /* P 1F */
640 /* ----- ----- */
641 /* 0 0 0 0 */
642 /* 0 0 0* 1 (If there is an onset there) */
643 /* 0 0 1* 0* (Based on 2F and discriminant distance) */
644 /* 0 0 1 1 */
645 /* 0 1* 0 0 (Always) */
646 /* 0 1* 0* 1 (Based on discriminant distance) */
647 /* 0* 1 1 0* (Based on past, 2F, and discriminant distance) */
648 /* 0 1* 1 1 (If there is an onset there) */
649 /* 1 0* 0 0 (If there is an onset there) */
650 /* 1 0 0 1 */
651 /* 1 0* 1* 0 (Based on discriminant distance) */
652 /* 1 0* 1 1 (Always) */
653 /* 1 1 0 0 */
654 /* 1 1 0* 1* (Based on 2F and discriminant distance) */
655 /* 1 1 1* 0 (If there is an onset there) */
656 /* 1 1 1 1 */
657 
658 /* Determine if there is an onset transition between P and 1F. */
659 /* OT (Onset Transition) is true if there is an onset between */
660 /* P and 1F but not after 1F. */
661  ot = ((obound[1] & 2) != 0 || obound[2] == 1) && (obound[3] & 1) == 0;
662 /* Multi-way dispatch on voicing decision history: */
663  vstate = (voibuf[3] << 3) + (voibuf[4] << 2) + (voibuf[5] << 1) + voibuf[
664  6];
665  switch (vstate + 1) {
666  case 1: goto L99;
667  case 2: goto L1;
668  case 3: goto L2;
669  case 4: goto L99;
670  case 5: goto L4;
671  case 6: goto L5;
672  case 7: goto L6;
673  case 8: goto L7;
674  case 9: goto L8;
675  case 10: goto L99;
676  case 11: goto L10;
677  case 12: goto L11;
678  case 13: goto L99;
679  case 14: goto L13;
680  case 15: goto L14;
681  case 16: goto L99;
682  }
683 L1:
684  if (ot && voibuf[7] == 1) {
685  voibuf[5] = 1;
686  }
687  goto L99;
688 L2:
689  if (voibuf[7] == 0 || voice[2] < -voice[3]) {
690  voibuf[5] = 0;
691  } else {
692  voibuf[6] = 1;
693  }
694  goto L99;
695 L4:
696  voibuf[4] = 0;
697  goto L99;
698 L5:
699  if (voice[1] < -voice[2]) {
700  voibuf[4] = 0;
701  } else {
702  voibuf[5] = 1;
703  }
704  goto L99;
705 /* VOIBUF(2,0) must be 0 */
706 L6:
707  if (voibuf[1] == 1 || voibuf[7] == 1 || voice[3] > voice[0]) {
708  voibuf[6] = 1;
709  } else {
710  voibuf[3] = 1;
711  }
712  goto L99;
713 L7:
714  if (ot) {
715  voibuf[4] = 0;
716  }
717  goto L99;
718 L8:
719  if (ot) {
720  voibuf[4] = 1;
721  }
722  goto L99;
723 L10:
724  if (voice[2] < -voice[1]) {
725  voibuf[5] = 0;
726  } else {
727  voibuf[4] = 1;
728  }
729  goto L99;
730 L11:
731  voibuf[4] = 1;
732  goto L99;
733 L13:
734  if (voibuf[7] == 0 && voice[3] < -voice[2]) {
735  voibuf[6] = 0;
736  } else {
737  voibuf[5] = 1;
738  }
739  goto L99;
740 L14:
741  if (ot && voibuf[7] == 0) {
742  voibuf[5] = 0;
743  }
744 /* GOTO 99 */
745 L99:
746 /* Now update parameters: */
747 /* ---------------------- */
748 
749 /* During unvoiced half-frames, update the low band and full band unvoice
750 d*/
751 /* energy estimates (LBUE and FBUE) and also the zero crossing */
752 /* threshold (DITHER). (The input to the unvoiced energy filters is */
753 /* restricted to be less than 10dB above the previous inputs of the */
754 /* filters.) */
755 /* During voiced half-frames, update the low-pass (LBVE) and all-pass */
756 /* (FBVE) voiced energy estimates. */
757  if (voibuf[*half + 6] == 0) {
758 /* Computing MIN */
759  i__1 = fbe, i__2 = *ofbue * 3;
760  r__1 = (*sfbue * 63 + (min(i__1,i__2) << 3)) / 64.f;
761  *sfbue = i_nint(&r__1);
762  *fbue = *sfbue / 8;
763  *ofbue = fbe;
764 /* Computing MIN */
765  i__1 = lbe, i__2 = *olbue * 3;
766  r__1 = (*slbue * 63 + (min(i__1,i__2) << 3)) / 64.f;
767  *slbue = i_nint(&r__1);
768  *lbue = *slbue / 8;
769  *olbue = lbe;
770  } else {
771  r__1 = (*lbve * 63 + lbe) / 64.f;
772  *lbve = i_nint(&r__1);
773  r__1 = (*fbve * 63 + fbe) / 64.f;
774  *fbve = i_nint(&r__1);
775  }
776 /* Set dither threshold to yield proper zero crossing rates in the */
777 /* presence of low frequency noise and low level signal input. */
778 /* NOTE: The divisor is a function of REF, the expected energies. */
779 /* Computing MIN */
780 /* Computing MAX */
781  r__2 = (real)(sqrt((real) (*lbue * *lbve)) * 64 / 3000);
782  r__1 = max(r__2,1.f);
783  *dither = min(r__1,20.f);
784 /* Voicing decisions are returned in VOIBUF. */
785  return 0;
786 } /* voicin_ */
integer i_nint(real *x)
Definition: f2clib.c:80
integer fbve
Definition: lpc10.h:122
integer fbue
Definition: lpc10.h:122
integer olbue
Definition: lpc10.h:124
integer lbve
Definition: lpc10.h:122
static int inbuf(struct baseio *bio, FILE *fi)
utility used by inchar(), for base_encode()
int value
Definition: syslog.c:37
integer slbue
Definition: lpc10.h:124
int vparms_(integer *vwin, real *inbuf, real *lpbuf, integer *buflim, integer *half, real *dither, integer *mintau, integer *zc, integer *lbe, integer *fbe, real *qs, real *rc1, real *ar_b__, real *ar_f__)
Definition: vparms.c:134
integer sfbue
Definition: lpc10.h:123
Definition: isdn_lib.h:241
Definition: isdn_lib.h:240
double doublereal
Definition: f2c.h:50
float real
Definition: lpc10.h:79
integer lbue
Definition: lpc10.h:122
real voice[6]
Definition: lpc10.h:121
integer ofbue
Definition: lpc10.h:123
INT32 logical
Definition: lpc10.h:81
#define min(a, b)
Definition: f2c.h:197
INT32 integer
Definition: lpc10.h:80
#define max(a, b)
Definition: f2c.h:198

Variable Documentation

◆ contrl_

struct { ... } contrl_

◆ corrp

logical corrp

Definition at line 50 of file voicin.c.

◆ lframe

integer lframe

Definition at line 49 of file voicin.c.

◆ order

integer order

Definition at line 49 of file voicin.c.