analys.c

Go to the documentation of this file.
00001 /*
00002 
00003 $Log$
00004 Revision 1.16  2004/06/26 03:50:14  markster
00005 Merge source cleanups (bug #1911)
00006 
00007 Revision 1.15  2003/09/19 01:20:22  markster
00008 Code cleanups (bug #66)
00009 
00010 Revision 1.2  2003/09/19 01:20:22  markster
00011 Code cleanups (bug #66)
00012 
00013 Revision 1.1.1.1  2003/02/12 13:59:14  matteo
00014 mer feb 12 14:56:57 CET 2003
00015 
00016 Revision 1.2  2000/01/05 08:20:39  markster
00017 Some OSS fixes and a few lpc changes to make it actually work
00018 
00019  * Revision 1.2  1996/08/20  20:16:01  jaf
00020  * Removed all static local variables that were SAVE'd in the Fortran
00021  * code, and put them in struct lpc10_encoder_state that is passed as an
00022  * argument.
00023  *
00024  * Removed init function, since all initialization is now done in
00025  * init_lpc10_encoder_state().
00026  *
00027  * Revision 1.1  1996/08/19  22:29:08  jaf
00028  * Initial revision
00029  *
00030 
00031 */
00032 
00033 #include "f2c.h"
00034 
00035 #ifdef P_R_O_T_O_T_Y_P_E_S
00036 extern int analys_(real *speech, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_encoder_state *st);
00037 /* comlen contrl_ 12 */
00038 /*:ref: preemp_ 14 5 6 6 4 6 6 */
00039 /*:ref: onset_ 14 7 6 4 4 4 4 4 4 */
00040 /*:ref: placev_ 14 11 4 4 4 4 4 4 4 4 4 4 4 */
00041 /*:ref: lpfilt_ 14 4 6 6 4 4 */
00042 /*:ref: ivfilt_ 14 5 6 6 4 4 6 */
00043 /*:ref: tbdm_ 14 8 6 4 4 4 6 4 4 4 */
00044 /*:ref: voicin_ 14 12 4 6 6 4 4 6 6 4 6 4 4 4 */
00045 /*:ref: dyptrk_ 14 6 6 4 4 4 4 4 */
00046 /*:ref: placea_ 14 9 4 4 4 4 4 4 4 4 4 */
00047 /*:ref: dcbias_ 14 3 4 6 6 */
00048 /*:ref: energy_ 14 3 4 6 6 */
00049 /*:ref: mload_ 14 6 4 4 4 6 6 6 */
00050 /*:ref: invert_ 14 4 4 6 6 6 */
00051 /*:ref: rcchk_ 14 3 4 6 6 */
00052 /*:ref: initonset_ 14 0 */
00053 /*:ref: initvoicin_ 14 0 */
00054 /*:ref: initdyptrk_ 14 0 */
00055 /* Rerunning f2c -P may change prototypes or declarations. */
00056 #endif
00057 
00058 /*  -- translated by f2c (version 19951025).
00059    You must link the resulting object file with the libraries:
00060    -lf2c -lm   (in that order)
00061 */
00062 
00063 /* Common Block Declarations */
00064 
00065 extern struct {
00066     integer order, lframe;
00067     logical corrp;
00068 } contrl_;
00069 
00070 #define contrl_1 contrl_
00071 
00072 /* Table of constant values */
00073 
00074 static integer c__10 = 10;
00075 static integer c__181 = 181;
00076 static integer c__720 = 720;
00077 static integer c__3 = 3;
00078 static integer c__90 = 90;
00079 static integer c__156 = 156;
00080 static integer c__307 = 307;
00081 static integer c__462 = 462;
00082 static integer c__312 = 312;
00083 static integer c__60 = 60;
00084 static integer c__1 = 1;
00085 
00086 /* ****************************************************************** */
00087 
00088 /*    ANALYS Version 55 */
00089 
00090 /* $Log$
00091  * Revision 1.16  2004/06/26 03:50:14  markster
00092  * Merge source cleanups (bug #1911)
00093  *
00094  * Revision 1.15  2003/09/19 01:20:22  markster
00095  * Code cleanups (bug #66)
00096  *
00097  * Revision 1.2  2003/09/19 01:20:22  markster
00098  * Code cleanups (bug #66)
00099  *
00100  * Revision 1.1.1.1  2003/02/12 13:59:14  matteo
00101  * mer feb 12 14:56:57 CET 2003
00102  *
00103  * Revision 1.2  2000/01/05 08:20:39  markster
00104  * Some OSS fixes and a few lpc changes to make it actually work
00105  *
00106  * Revision 1.2  1996/08/20  20:16:01  jaf
00107  * Removed all static local variables that were SAVE'd in the Fortran
00108  * code, and put them in struct lpc10_encoder_state that is passed as an
00109  * argument.
00110  *
00111  * Removed init function, since all initialization is now done in
00112  * init_lpc10_encoder_state().
00113  *
00114  * Revision 1.1  1996/08/19  22:29:08  jaf
00115  * Initial revision
00116  * */
00117 /* Revision 1.9  1996/05/23  19:41:07  jaf */
00118 /* Commented out some unnecessary lines that were reading uninitialized */
00119 /* values. */
00120 
00121 /* Revision 1.8  1996/03/27  23:57:55  jaf */
00122 /* Added some comments about which indices of the local buffers INBUF, */
00123 /* LPBUF, etc., get read or modified by some of the subroutine calls.  I */
00124 /* just did this while trying to figure out the discrepancy between the */
00125 /* embedded code compiled with all local variables implicitly saved, and */
00126 /* without. */
00127 
00128 /* I added some debugging write statements in hopes of finding a problem. */
00129 /* None of them ever printed anything while running with the long input */
00130 /* speech file dam9.spd provided in the distribution. */
00131 
00132 /* Revision 1.7  1996/03/27  18:06:20  jaf */
00133 /* Commented out access to MAXOSP, which is just a debugging variable */
00134 /* that was defined in the COMMON block CONTRL in contrl.fh. */
00135 
00136 /* Revision 1.6  1996/03/26  19:31:33  jaf */
00137 /* Commented out trace statements. */
00138 
00139 /* Revision 1.5  1996/03/21  15:19:35  jaf */
00140 /* Added comments for ENTRY PITDEC. */
00141 
00142 /* Revision 1.4  1996/03/19  20:54:27  jaf */
00143 /* Added a line to INITANALYS.  See comments there. */
00144 
00145 /* Revision 1.3  1996/03/19  20:52:49  jaf */
00146 /* Rearranged the order of the local variables quite a bit, to separate */
00147 /* them into groups of "constants", "locals that don't need to be saved */
00148 /* from one call to the next", and "local that do need to be saved from */
00149 /* one call to the next". */
00150 
00151 /* Several locals in the last set should have been given initial values, */
00152 /* but weren't.  I gave them all initial values of 0. */
00153 
00154 /* Added a separate ENTRY INITANALYS that initializes all local state */
00155 /* that should be, and also calls the corresponding entries of the */
00156 /* subroutines called by ANALYS that also have local state. */
00157 
00158 /* There used to be DATA statements in ANALYS.  I got rid of most of */
00159 /* them, and added a local logical variable FIRST that calls the entry */
00160 /* INITANALYS on the first call to ANALYS.  This is just so that one need */
00161 /* not remember to call INITANALYS first in order for the state to be */
00162 /* initialized. */
00163 
00164 /* Revision 1.2  1996/03/11  23:29:32  jaf */
00165 /* Added several comments with my own personal questions about the */
00166 /* Fortran 77 meaning of the parameters passed to the subroutine PREEMP. */
00167 
00168 /* Revision 1.1  1996/02/07  14:42:29  jaf */
00169 /* Initial revision */
00170 
00171 
00172 /* ****************************************************************** */
00173 
00174 /* SUBROUTINE ANALYS */
00175 
00176 /* Input: */
00177 /*  SPEECH */
00178 /*       Indices 1 through LFRAME read. */
00179 /* Output: */
00180 /*  VOICE */
00181 /*       Indices 1 through 2 written. */
00182 /*  PITCH */
00183 /*       Written in subroutine DYPTRK, and then perhaps read and written */
00184 /*       some more. */
00185 /*  RMS */
00186 /*       Written. */
00187 /*  RC */
00188 /*       Indices 1 through ORDER written (ORDER defined in contrl.fh). */
00189 
00190 /* This subroutine maintains local state from one call to the next.  If */
00191 /* you want to switch to using a new audio stream for this filter, or */
00192 /* reinitialize its state for any other reason, call the ENTRY */
00193 /* INITANALYS. */
00194 
00195 
00196 /* ENTRY PITDEC */
00197 
00198 /* Input: */
00199 /*  PITCH   - Encoded pitch index */
00200 /* Output: */
00201 /*  PTAU    - Decoded pitch period */
00202 
00203 /* This entry has no local state.  It accesses a "constant" array */
00204 /* declared in ANALYS. */
00205 
00206 /* Subroutine */ int analys_(real *speech, integer *voice, integer 
00207    *pitch, real *rms, real *rc, struct lpc10_encoder_state *st)
00208 {
00209     /* Initialized data */
00210 
00211     static integer tau[60] = { 20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,
00212        35,36,37,38,39,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,
00213        74,76,78,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,
00214        140,144,148,152,156 };
00215     static integer buflim[4] = { 181,720,25,720 };
00216     static real precoef = .9375f;
00217 
00218     /* System generated locals */
00219     integer i__1;
00220 
00221     /* Local variables */
00222     real amdf[60];
00223     integer half;
00224     real abuf[156];
00225     real *bias;
00226     extern /* Subroutine */ int tbdm_(real *, integer *, integer *, integer *,
00227         real *, integer *, integer *, integer *);
00228     integer *awin;
00229     integer midx, ewin[6]  /* was [2][3] */;
00230     real ivrc[2], temp;
00231     real *zpre;
00232     integer *vwin;
00233     integer i__, j, lanal;
00234     extern /* Subroutine */ int rcchk_(integer *, real *, real *), mload_(
00235        integer *, integer *, integer *, real *, real *, real *);
00236     real *inbuf, *pebuf;
00237     real *lpbuf, *ivbuf;
00238     real *rcbuf;
00239     integer *osbuf;
00240     extern /* Subroutine */ int onset_(real *, integer *, integer *, integer *
00241        , integer *, integer *, integer *, struct lpc10_encoder_state *);
00242     integer *osptr;
00243     extern int dcbias_(integer *, real *, real *);
00244     integer ipitch;
00245     integer *obound;
00246     extern /* Subroutine */ int preemp_(real *, real *, integer *, real *, 
00247        real *), voicin_(integer *, real *, real *, integer *, integer *, 
00248        real *, real *, integer *, real *, integer *, integer *, integer *,
00249        struct lpc10_encoder_state *);
00250     integer *voibuf;
00251     integer mintau;
00252     real *rmsbuf;
00253     extern /* Subroutine */ int lpfilt_(real *, real *, integer *, integer *),
00254         ivfilt_(real *, real *, integer *, integer *, real *), energy_(
00255        integer *, real *, real *), invert_(integer *, real *, real *, 
00256        real *);
00257     integer minptr, maxptr;
00258     extern /* Subroutine */ int dyptrk_(real *, integer *, integer *, integer 
00259        *, integer *, integer *, struct lpc10_encoder_state *);
00260     real phi[100] /* was [10][10] */, psi[10];
00261 
00262 /* $Log$
00263  * Revision 1.16  2004/06/26 03:50:14  markster
00264  * Merge source cleanups (bug #1911)
00265  *
00266  * Revision 1.15  2003/09/19 01:20:22  markster
00267  * Code cleanups (bug #66)
00268  *
00269  * Revision 1.2  2003/09/19 01:20:22  markster
00270  * Code cleanups (bug #66)
00271  *
00272  * Revision 1.1.1.1  2003/02/12 13:59:14  matteo
00273  * mer feb 12 14:56:57 CET 2003
00274  *
00275  * Revision 1.2  2000/01/05 08:20:39  markster
00276  * Some OSS fixes and a few lpc changes to make it actually work
00277  *
00278  * Revision 1.2  1996/08/20  20:16:01  jaf
00279  * Removed all static local variables that were SAVE'd in the Fortran
00280  * code, and put them in struct lpc10_encoder_state that is passed as an
00281  * argument.
00282  *
00283  * Removed init function, since all initialization is now done in
00284  * init_lpc10_encoder_state().
00285  *
00286  * Revision 1.1  1996/08/19  22:29:08  jaf
00287  * Initial revision
00288  * */
00289 /* Revision 1.3  1996/03/29  22:03:47  jaf */
00290 /* Removed definitions for any constants that were no longer used. */
00291 
00292 /* Revision 1.2  1996/03/26  19:34:33  jaf */
00293 /* Added comments indicating which constants are not needed in an */
00294 /* application that uses the LPC-10 coder. */
00295 
00296 /* Revision 1.1  1996/02/07  14:43:51  jaf */
00297 /* Initial revision */
00298 
00299 /*   LPC Configuration parameters: */
00300 /* Frame size, Prediction order, Pitch period */
00301 /*       Arguments to ANALYS */
00302 /* $Log$
00303  * Revision 1.16  2004/06/26 03:50:14  markster
00304  * Merge source cleanups (bug #1911)
00305  *
00306  * Revision 1.15  2003/09/19 01:20:22  markster
00307  * Code cleanups (bug #66)
00308  *
00309  * Revision 1.2  2003/09/19 01:20:22  markster
00310  * Code cleanups (bug #66)
00311  *
00312  * Revision 1.1.1.1  2003/02/12 13:59:14  matteo
00313  * mer feb 12 14:56:57 CET 2003
00314  *
00315  * Revision 1.2  2000/01/05 08:20:39  markster
00316  * Some OSS fixes and a few lpc changes to make it actually work
00317  *
00318  * Revision 1.2  1996/08/20  20:16:01  jaf
00319  * Removed all static local variables that were SAVE'd in the Fortran
00320  * code, and put them in struct lpc10_encoder_state that is passed as an
00321  * argument.
00322  *
00323  * Removed init function, since all initialization is now done in
00324  * init_lpc10_encoder_state().
00325  *
00326  * Revision 1.1  1996/08/19  22:29:08  jaf
00327  * Initial revision
00328  * */
00329 /* Revision 1.3  1996/03/29  22:05:55  jaf */
00330 /* Commented out the common block variables that are not needed by the */
00331 /* embedded version. */
00332 
00333 /* Revision 1.2  1996/03/26  19:34:50  jaf */
00334 /* Added comments indicating which constants are not needed in an */
00335 /* application that uses the LPC-10 coder. */
00336 
00337 /* Revision 1.1  1996/02/07  14:44:09  jaf */
00338 /* Initial revision */
00339 
00340 /*   LPC Processing control variables: */
00341 
00342 /* *** Read-only: initialized in setup */
00343 
00344 /*  Files for Speech, Parameter, and Bitstream Input & Output, */
00345 /*    and message and debug outputs. */
00346 
00347 /* Here are the only files which use these variables: */
00348 
00349 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
00350 
00351 /* Many files which use fdebug are not listed, since it is only used in */
00352 /* those other files conditionally, to print trace statements. */
00353 /*    integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
00354 /*  LPC order, Frame size, Quantization rate, Bits per frame, */
00355 /*    Error correction */
00356 /* Subroutine SETUP is the only place where order is assigned a value, */
00357 /* and that value is 10.  It could increase efficiency 1% or so to */
00358 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as 
00359 */
00360 /* a variable in a COMMON block, since it is used in many places in the */
00361 /* core of the coding and decoding routines.  Actually, I take that back. 
00362 */
00363 /* At least when compiling with f2c, the upper bound of DO loops is */
00364 /* stored in a local variable before the DO loop begins, and then that is 
00365 */
00366 /* compared against on each iteration. */
00367 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
00368 /* Similarly for quant, which is given a value of 2400 in SETUP.  quant */
00369 /* is used in only a few places, and never in the core coding and */
00370 /* decoding routines, so it could be eliminated entirely. */
00371 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
00372 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
00373 /* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */
00374 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is 
00375 */
00376 /* a constant or a variable, since it is only examined once per frame. */
00377 /* Leaving it as a variable that is set to .TRUE.  seems like a good */
00378 /* idea, since it does enable some error-correction capability for */
00379 /* unvoiced frames, with no change in the coding rate, and no noticeable 
00380 */
00381 /* quality difference in the decoded speech. */
00382 /*    integer quant, nbits */
00383 /* *** Read/write: variables for debugging, not needed for LPC algorithm 
00384 */
00385 
00386 /*  Current frame, Unstable frames, Output clip count, Max onset buffer, 
00387 */
00388 /*    Debug listing detail level, Line count on listing page */
00389 
00390 /* nframe is not needed for an embedded LPC10 at all. */
00391 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
00392 /* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */
00393 /* an application, I would recommend removing the call to ERROR in RCCHK, 
00394 */
00395 /* and remove ERROR and nunsfm completely. */
00396 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in 
00397 */
00398 /* sread.f.  When LPC10 is embedded into an application, one might want */
00399 /* to cause it to be incremented in a routine that takes the output of */
00400 /* SYNTHS and sends it to an audio device.  It could be optionally */
00401 /* displayed, for those that might want to know what it is. */
00402 /* maxosp is never initialized to 0 in SETUP, although it probably should 
00403 */
00404 /* be, and it is updated in subroutine ANALYS.  I doubt that its value */
00405 /* would be of much interest to an application in which LPC10 is */
00406 /* embedded. */
00407 /* listl and lincnt are not needed for an embedded LPC10 at all. */
00408 /*    integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
00409 /*    common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
00410 /*    common /contrl/ quant, nbits */
00411 /*    common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
00412 /*       Arguments to entry PITDEC (below) */
00413 /*    Parameters/constants */
00414 /*  Constants */
00415 /*    NF =     Number of frames */
00416 /*    AF =     Frame in which analysis is done */
00417 /*    OSLEN =  Length of the onset buffer */
00418 /*    LTAU =   Number of pitch lags */
00419 /*    SBUFL, SBUFH =   Start and end index of speech buffers */
00420 /*    LBUFL, LBUFH =   Start and end index of LPF speech buffer */
00421 /*   MINWIN, MAXWIN = Min and Max length of voicing (and analysis) windows
00422 */
00423 /*    PWLEN, PWINH, PWINL = Length, upper and lower limits of pitch window
00424  */
00425 /*    DVWINL, DVWINH = Default lower and upper limits of voicing window */
00426 /*       The tables TAU and BUFLIM, and the variable PRECOEF, are not */
00427 /*       Fortran PARAMETER's, but they are initialized with DATA */
00428 /*       statements, and never modified.  Thus, they need not have SAVE */
00429 /*       statements for them to keep their values from one invocation to 
00430 */
00431 /*       the next. */
00432 /*       Local variables that need not be saved */
00433 /*       Local state */
00434 /*  Data Buffers */
00435 /*    INBUF Raw speech (with DC bias removed each frame) */
00436 /*    PEBUF Preemphasized speech */
00437 /*    LPBUF Low pass speech buffer */
00438 /*    IVBUF Inverse filtered speech */
00439 /*    OSBUF Indexes of onsets in speech buffers */
00440 /*    VWIN  Voicing window indices */
00441 /*    AWIN  Analysis window indices */
00442 /*    EWIN  Energy window indices */
00443 /*    VOIBUF   Voicing decisions on windows in VWIN */
00444 /*    RMSBUF   RMS energy */
00445 /*    RCBUF Reflection Coefficients */
00446 
00447 /*  Pitch is handled separately from the above parameters. */
00448 /*  The following variables deal with pitch: */
00449 /*    MIDX  Encoded initial pitch estimate for analysis frame */
00450 /*    IPITCH   Initial pitch computed for frame AF (decoded from MIDX) */
00451 /*    PITCH    The encoded pitch value (index into TAU) for the present */
00452 /*       frame (delayed and smoothed by Dyptrack) */
00453     /* Parameter adjustments */
00454     if (speech) {
00455    --speech;
00456    }
00457     if (voice) {
00458    --voice;
00459    }
00460     if (rc) {
00461    --rc;
00462    }
00463 
00464     /* Function Body */
00465 
00466 /*   Calculations are done on future frame due to requirements */
00467 /*   of the pitch tracker.  Delay RMS and RC's 2 frames to give */
00468 /*   current frame parameters on return. */
00469 /*   Update all buffers */
00470 
00471     inbuf = &(st->inbuf[0]);
00472     pebuf = &(st->pebuf[0]);
00473     lpbuf = &(st->lpbuf[0]);
00474     ivbuf = &(st->ivbuf[0]);
00475     bias = &(st->bias);
00476     osbuf = &(st->osbuf[0]);
00477     osptr = &(st->osptr);
00478     obound = &(st->obound[0]);
00479     vwin = &(st->vwin[0]);
00480     awin = &(st->awin[0]);
00481     voibuf = &(st->voibuf[0]);
00482     rmsbuf = &(st->rmsbuf[0]);
00483     rcbuf = &(st->rcbuf[0]);
00484     zpre = &(st->zpre);
00485 
00486     i__1 = 720 - contrl_1.lframe;
00487     for (i__ = 181; i__ <= i__1; ++i__) {
00488    inbuf[i__ - 181] = inbuf[contrl_1.lframe + i__ - 181];
00489    pebuf[i__ - 181] = pebuf[contrl_1.lframe + i__ - 181];
00490     }
00491     i__1 = 540 - contrl_1.lframe;
00492     for (i__ = 229; i__ <= i__1; ++i__) {
00493    ivbuf[i__ - 229] = ivbuf[contrl_1.lframe + i__ - 229];
00494     }
00495     i__1 = 720 - contrl_1.lframe;
00496     for (i__ = 25; i__ <= i__1; ++i__) {
00497    lpbuf[i__ - 25] = lpbuf[contrl_1.lframe + i__ - 25];
00498     }
00499     j = 1;
00500     i__1 = (*osptr) - 1;
00501     for (i__ = 1; i__ <= i__1; ++i__) {
00502    if (osbuf[i__ - 1] > contrl_1.lframe) {
00503        osbuf[j - 1] = osbuf[i__ - 1] - contrl_1.lframe;
00504        ++j;
00505    }
00506     }
00507     *osptr = j;
00508     voibuf[0] = voibuf[2];
00509     voibuf[1] = voibuf[3];
00510     for (i__ = 1; i__ <= 2; ++i__) {
00511    vwin[(i__ << 1) - 2] = vwin[((i__ + 1) << 1) - 2] - contrl_1.lframe;
00512    vwin[(i__ << 1) - 1] = vwin[((i__ + 1) << 1) - 1] - contrl_1.lframe;
00513    awin[(i__ << 1) - 2] = awin[((i__ + 1) << 1) - 2] - contrl_1.lframe;
00514    awin[(i__ << 1) - 1] = awin[((i__ + 1) << 1) - 1] - contrl_1.lframe;
00515 /*       EWIN(*,J) is unused for J .NE. AF, so the following shift is 
00516 */
00517 /*       unnecessary.  It also causes error messages when the C versio
00518 n */
00519 /*       of the code created from this by f2c is run with Purify.  It 
00520 */
00521 /*       correctly complains that uninitialized memory is being read. 
00522 */
00523 /*       EWIN(1,I) = EWIN(1,I+1) - LFRAME */
00524 /*       EWIN(2,I) = EWIN(2,I+1) - LFRAME */
00525    obound[i__ - 1] = obound[i__];
00526    voibuf[i__ * 2] = voibuf[(i__ + 1) * 2];
00527    voibuf[(i__ << 1) + 1] = voibuf[((i__ + 1) << 1) + 1];
00528    rmsbuf[i__ - 1] = rmsbuf[i__];
00529    i__1 = contrl_1.order;
00530    for (j = 1; j <= i__1; ++j) {
00531        rcbuf[j + i__ * 10 - 11] = rcbuf[j + (i__ + 1) * 10 - 11];
00532    }
00533     }
00534 /*   Copy input speech, scale to sign+12 bit integers */
00535 /*   Remove long term DC bias. */
00536 /*       If the average value in the frame was over 1/4096 (after current 
00537 */
00538 /*       BIAS correction), then subtract that much more from samples in */
00539 /*       next frame.  If the average value in the frame was under */
00540 /*       -1/4096, add 1/4096 more to samples in next frame.  In all other 
00541 */
00542 /*       cases, keep BIAS the same. */
00543     temp = 0.f;
00544     i__1 = contrl_1.lframe;
00545     for (i__ = 1; i__ <= i__1; ++i__) {
00546    inbuf[720 - contrl_1.lframe + i__ - 181] = speech[i__] * 4096.f - 
00547       (*bias);
00548    temp += inbuf[720 - contrl_1.lframe + i__ - 181];
00549     }
00550     if (temp > (real) contrl_1.lframe) {
00551    *bias += 1;
00552     }
00553     if (temp < (real) (-contrl_1.lframe)) {
00554    *bias += -1;
00555     }
00556 /*   Place Voicing Window */
00557     i__ = 721 - contrl_1.lframe;
00558     preemp_(&inbuf[i__ - 181], &pebuf[i__ - 181], &contrl_1.lframe, &precoef, 
00559        zpre);
00560     onset_(pebuf, osbuf, osptr, &c__10, &c__181, &c__720, &contrl_1.lframe, st);
00561 
00562 /*       MAXOSP is just a debugging variable. */
00563 
00564 /*    MAXOSP = MAX( MAXOSP, OSPTR ) */
00565 
00566     placev_(osbuf, osptr, &c__10, &obound[2], vwin, &c__3, &contrl_1.lframe, 
00567        &c__90, &c__156, &c__307, &c__462);
00568 /*        The Pitch Extraction algorithm estimates the pitch for a frame 
00569 */
00570 /*   of speech by locating the minimum of the average magnitude difference
00571  */
00572 /*   function (AMDF).  The AMDF operates on low-pass, inverse filtered */
00573 /*   speech.  (The low-pass filter is an 800 Hz, 19 tap, equiripple, FIR 
00574 */
00575 /*   filter and the inverse filter is a 2nd-order LPC filter.)  The pitch 
00576 */
00577 /*   estimate is later refined by dynamic programming (DYPTRK).  However, 
00578 */
00579 /*   since some of DYPTRK's parameters are a function of the voicing */
00580 /*  decisions, a voicing decision must precede the final pitch estimation.
00581 */
00582 /*   See subroutines LPFILT, IVFILT, and TBDM. */
00583 /*       LPFILT reads indices LBUFH-LFRAME-29 = 511 through LBUFH = 720 */
00584 /*       of INBUF, and writes indices LBUFH+1-LFRAME = 541 through LBUFH 
00585 */
00586 /*       = 720 of LPBUF. */
00587     lpfilt_(&inbuf[228], &lpbuf[384], &c__312, &contrl_1.lframe);
00588 /*       IVFILT reads indices (PWINH-LFRAME-7) = 353 through PWINH = 540 
00589 */
00590 /*       of LPBUF, and writes indices (PWINH-LFRAME+1) = 361 through */
00591 /*       PWINH = 540 of IVBUF. */
00592     ivfilt_(&lpbuf[204], ivbuf, &c__312, &contrl_1.lframe, ivrc);
00593 /*       TBDM reads indices PWINL = 229 through */
00594 /*       (PWINL-1)+MAXWIN+(TAU(LTAU)-TAU(1))/2 = 452 of IVBUF, and writes 
00595 */
00596 /*       indices 1 through LTAU = 60 of AMDF. */
00597     tbdm_(ivbuf, &c__156, tau, &c__60, amdf, &minptr, &maxptr, &mintau);
00598 /*        Voicing decisions are made for each half frame of input speech. 
00599 */
00600 /*   An initial voicing classification is made for each half of the */
00601 /*   analysis frame, and the voicing decisions for the present frame */
00602 /*   are finalized.  See subroutine VOICIN. */
00603 /*        The voicing detector (VOICIN) classifies the input signal as */
00604 /*   unvoiced (including silence) or voiced using the AMDF windowed */
00605 /*   maximum-to-minimum ratio, the zero crossing rate, energy measures, */
00606 /*   reflection coefficients, and prediction gains. */
00607 /*        The pitch and voicing rules apply smoothing and isolated */
00608 /*   corrections to the pitch and voicing estimates and, in the process, 
00609 */
00610 /*   introduce two frames of delay into the corrected pitch estimates and 
00611 */
00612 /*   voicing decisions. */
00613     for (half = 1; half <= 2; ++half) {
00614    voicin_(&vwin[4], inbuf, lpbuf, buflim, &half, &amdf[minptr - 1], &
00615       amdf[maxptr - 1], &mintau, ivrc, obound, voibuf, &c__3, st);
00616     }
00617 /*   Find the minimum cost pitch decision over several frames */
00618 /*   given the current voicing decision and the AMDF array */
00619     dyptrk_(amdf, &c__60, &minptr, &voibuf[7], pitch, &midx, st);
00620     ipitch = tau[midx - 1];
00621 /*   Place spectrum analysis and energy windows */
00622     placea_(&ipitch, voibuf, &obound[2], &c__3, vwin, awin, ewin, &
00623        contrl_1.lframe, &c__156);
00624 /*  Remove short term DC bias over the analysis window, Put result in ABUF
00625 */
00626     lanal = awin[5] + 1 - awin[4];
00627     dcbias_(&lanal, &pebuf[awin[4] - 181], abuf);
00628 /*       ABUF(1:LANAL) is now defined.  It is equal to */
00629 /*       PEBUF(AWIN(1,AF):AWIN(2,AF)) corrected for short term DC bias. */
00630 /*   Compute RMS over integer number of pitch periods within the */
00631 /*   analysis window. */
00632 /*   Note that in a hardware implementation this computation may be */
00633 /*   simplified by using diagonal elements of PHI computed by MLOAD. */
00634     i__1 = ewin[5] - ewin[4] + 1;
00635     energy_(&i__1, &abuf[ewin[4] - awin[4]], &rmsbuf[2]);
00636 /*   Matrix load and invert, check RC's for stability */
00637     mload_(&contrl_1.order, &c__1, &lanal, abuf, phi, psi);
00638     invert_(&contrl_1.order, phi, psi, &rcbuf[20]);
00639     rcchk_(&contrl_1.order, &rcbuf[10], &rcbuf[20]);
00640 /*   Set return parameters */
00641     voice[1] = voibuf[2];
00642     voice[2] = voibuf[3];
00643     *rms = rmsbuf[0];
00644     i__1 = contrl_1.order;
00645     for (i__ = 1; i__ <= i__1; ++i__) {
00646    rc[i__] = rcbuf[i__ - 1];
00647     }
00648     return 0;
00649 } /* analys_ */

Generated on Thu Apr 16 06:27:06 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6