lpc10/decode.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:22:39  jaf
00020  * Removed all static local variables that were SAVE'd in the Fortran
00021  * code, and put them in struct lpc10_decoder_state that is passed as an
00022  * argument.
00023  *
00024  * Removed init function, since all initialization is now done in
00025  * init_lpc10_decoder_state().
00026  *
00027  * Revision 1.1  1996/08/19  22:32:38  jaf
00028  * Initial revision
00029  *
00030 
00031 */
00032 
00033 /*  -- translated by f2c (version 19951025).
00034    You must link the resulting object file with the libraries:
00035    -lf2c -lm   (in that order)
00036 */
00037 
00038 #include "f2c.h"
00039 
00040 #ifdef P_R_O_T_O_T_Y_P_E_S
00041 extern int decode_(integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc, struct lpc10_decoder_state *st);
00042 /* comlen contrl_ 12 */
00043 /*:ref: ham84_ 14 3 4 4 4 */
00044 /*:ref: median_ 4 3 4 4 4 */
00045 #endif
00046 
00047 /* Common Block Declarations */
00048 
00049 extern struct {
00050     integer order, lframe;
00051     logical corrp;
00052 } contrl_;
00053 
00054 #define contrl_1 contrl_
00055 
00056 /* Table of constant values */
00057 
00058 static integer c__2 = 2;
00059 
00060 /* ***************************************************************** */
00061 
00062 /*    DECODE Version 54 */
00063 
00064 /* $Log$
00065  * Revision 1.16  2004/06/26 03:50:14  markster
00066  * Merge source cleanups (bug #1911)
00067  *
00068  * Revision 1.15  2003/09/19 01:20:22  markster
00069  * Code cleanups (bug #66)
00070  * 
00071  * Revision 1.2  2003/09/19 01:20:22  markster
00072  * Code cleanups (bug #66)
00073  *
00074  * Revision 1.1.1.1  2003/02/12 13:59:14  matteo
00075  * mer feb 12 14:56:57 CET 2003
00076  *
00077  * Revision 1.2  2000/01/05 08:20:39  markster
00078  * Some OSS fixes and a few lpc changes to make it actually work
00079  *
00080  * Revision 1.2  1996/08/20  20:22:39  jaf
00081  * Removed all static local variables that were SAVE'd in the Fortran
00082  * code, and put them in struct lpc10_decoder_state that is passed as an
00083  * argument.
00084  *
00085  * Removed init function, since all initialization is now done in
00086  * init_lpc10_decoder_state().
00087  *
00088  * Revision 1.1  1996/08/19  22:32:38  jaf
00089  * Initial revision
00090  * */
00091 /* Revision 1.5  1996/05/23  20:06:03  jaf */
00092 /* Assigned PITCH a "default" value on the first call, since otherwise it */
00093 /* would be left uninitialized. */
00094 
00095 /* Revision 1.4  1996/03/26  19:35:18  jaf */
00096 /* Commented out trace statements. */
00097 
00098 /* Revision 1.3  1996/03/21  21:10:50  jaf */
00099 /* Added entry INITDECODE to reinitialize the local state of subroutine */
00100 /* DECODE. */
00101 
00102 /* Revision 1.2  1996/03/21  21:04:50  jaf */
00103 /* Determined which local variables should be saved from one invocation */
00104 /* to the next, and guessed initial values for some that should have been */
00105 /* saved, but weren't given initial values.  Many of the arrays are */
00106 /* "constants", and many local variables are only used if the "global" */
00107 /* variable CORRP is .TRUE. */
00108 
00109 /* Added comments explaining which indices of array arguments are read or */
00110 /* written. */
00111 
00112 /* Revision 1.1  1996/02/12 03:21:10  jaf */
00113 /* Initial revision */
00114 
00115 
00116 /* ***************************************************************** */
00117 
00118 /*   This subroutine provides error correction and decoding */
00119 /*   for all LPC parameters */
00120 
00121 /* Input: */
00122 /*  IPITV  - Index value of pitch */
00123 /*  IRMS   - Coded Energy */
00124 /*  CORRP  - Error correction: */
00125 /*    If FALSE, parameters are decoded directly with no delay.  If TRUE, */
00126 /*    most important parameter bits are protected by Hamming code and */
00127 /*    median smoothed.  This requires an additional frame of delay. */
00128 /* Input/Output: */
00129 /*  IRC    - Coded Reflection Coefficients */
00130 /*           Indices 1 through ORDER always read, then written. */
00131 /* Output: */
00132 /*  VOICE  - Half frame voicing decisions */
00133 /*           Indices 1 through 2 written. */
00134 /*  PITCH  - Decoded pitch */
00135 /*  RMS    - Energy */
00136 /*  RC     - Reflection coefficients */
00137 /*           Indices 1 through ORDER written. */
00138 
00139 /*  NOTE: Zero RC's should be done more directly, but this would affect */
00140 /*   coded parameter printout. */
00141 
00142 /* This subroutine maintains local state from one call to the next.  If */
00143 /* you want to switch to using a new audio stream for this filter, or */
00144 /* reinitialize its state for any other reason, call the ENTRY */
00145 /* INITDECODE. */
00146 
00147 /* Subroutine */ int decode_(integer *ipitv, integer *irms, 
00148    integer *irc, integer *voice, integer *pitch, real *rms, real *rc,
00149               struct lpc10_decoder_state *st)
00150 {
00151     /* Initialized data */
00152 
00153     logical *first;
00154     static integer ethrs = 2048;
00155     static integer ethrs1 = 128;
00156     static integer ethrs2 = 1024;
00157     static integer ethrs3 = 2048;
00158     static integer ivtab[32] = { 24960,24960,24960,24960,25480,25480,25483,
00159        25480,16640,1560,1560,1560,16640,1816,1563,1560,24960,24960,24859,
00160        24856,26001,25881,25915,25913,1560,1560,7800,3640,1561,1561,3643,
00161        3641 };
00162     static real corth[32]  /* was [4][8] */ = { 32767.f,10.f,5.f,0.f,
00163        32767.f,8.f,4.f,0.f,32.f,6.4f,3.2f,0.f,32.f,6.4f,3.2f,0.f,32.f,
00164        11.2f,6.4f,0.f,32.f,11.2f,6.4f,0.f,16.f,5.6f,3.2f,0.f,16.f,5.6f,
00165        3.2f,0.f };
00166     static integer detau[128] = { 0,0,0,3,0,3,3,31,0,3,3,21,3,3,29,30,0,3,3,
00167        20,3,25,27,26,3,23,58,22,3,24,28,3,0,3,3,3,3,39,33,32,3,37,35,36,
00168        3,38,34,3,3,42,46,44,50,40,48,3,54,3,56,3,52,3,3,1,0,3,3,108,3,78,
00169        100,104,3,84,92,88,156,80,96,3,3,74,70,72,66,76,68,3,62,3,60,3,64,
00170        3,3,1,3,116,132,112,148,152,3,3,140,3,136,3,144,3,3,1,124,120,128,
00171        3,3,3,3,1,3,3,3,1,3,1,1,1 };
00172     static integer rmst[64] = { 1024,936,856,784,718,656,600,550,502,460,420,
00173        384,352,328,294,270,246,226,206,188,172,158,144,132,120,110,102,
00174        92,84,78,70,64,60,54,50,46,42,38,34,32,30,26,24,22,20,18,17,16,15,
00175        14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 };
00176     static integer detab7[32] = { 4,11,18,25,32,39,46,53,60,66,72,77,82,87,92,
00177        96,101,104,108,111,114,115,117,119,121,122,123,124,125,126,127,
00178        127 };
00179     static real descl[8] = { .6953f,.625f,.5781f,.5469f,.5312f,.5391f,.4688f,
00180        .3828f };
00181     integer *ivp2h;
00182     static integer deadd[8] = { 1152,-2816,-1536,-3584,-1280,-2432,768,-1920 }
00183        ;
00184     static integer qb[8] = { 511,511,1023,1023,1023,1023,2047,4095 };
00185     static integer nbit[10] = { 8,8,5,5,4,4,4,4,3,2 };
00186     static integer zrc[10] = { 0,0,0,0,0,3,0,2,0,0 };
00187     static integer bit[5] = { 2,4,8,16,32 };
00188     integer *iovoic;
00189     integer *iavgp;
00190     integer *iptold;
00191     integer *erate;
00192     integer *drc;
00193     integer *dpit;
00194     integer *drms;
00195 
00196     /* System generated locals */
00197     integer i__1, i__2;
00198 
00199     /* Builtin functions */
00200     integer pow_ii(integer *, integer *);
00201 
00202     /* Local variables */
00203     extern /* Subroutine */ int ham84_(integer *, integer *, integer *);
00204     integer ipit, iout, i__, icorf, index, ivoic, ixcor, i1, i2, i4;
00205     extern integer median_(integer *, integer *, integer *);
00206     integer ishift, errcnt, lsb;
00207 
00208 /* $Log$
00209  * Revision 1.16  2004/06/26 03:50:14  markster
00210  * Merge source cleanups (bug #1911)
00211  *
00212  * Revision 1.15  2003/09/19 01:20:22  markster
00213  * Code cleanups (bug #66)
00214  *
00215  * Revision 1.2  2003/09/19 01:20:22  markster
00216  * Code cleanups (bug #66)
00217  *
00218  * Revision 1.1.1.1  2003/02/12 13:59:14  matteo
00219  * mer feb 12 14:56:57 CET 2003
00220  *
00221  * Revision 1.2  2000/01/05 08:20:39  markster
00222  * Some OSS fixes and a few lpc changes to make it actually work
00223  *
00224  * Revision 1.2  1996/08/20  20:22:39  jaf
00225  * Removed all static local variables that were SAVE'd in the Fortran
00226  * code, and put them in struct lpc10_decoder_state that is passed as an
00227  * argument.
00228  *
00229  * Removed init function, since all initialization is now done in
00230  * init_lpc10_decoder_state().
00231  *
00232  * Revision 1.1  1996/08/19  22:32:38  jaf
00233  * Initial revision
00234  * */
00235 /* Revision 1.3  1996/03/29  22:03:47  jaf */
00236 /* Removed definitions for any constants that were no longer used. */
00237 
00238 /* Revision 1.2  1996/03/26  19:34:33  jaf */
00239 /* Added comments indicating which constants are not needed in an */
00240 /* application that uses the LPC-10 coder. */
00241 
00242 /* Revision 1.1  1996/02/07  14:43:51  jaf */
00243 /* Initial revision */
00244 
00245 /*   LPC Configuration parameters: */
00246 /* Frame size, Prediction order, Pitch period */
00247 /*       Arguments */
00248 /* $Log$
00249  * Revision 1.16  2004/06/26 03:50:14  markster
00250  * Merge source cleanups (bug #1911)
00251  *
00252  * Revision 1.15  2003/09/19 01:20:22  markster
00253  * Code cleanups (bug #66)
00254  *
00255  * Revision 1.2  2003/09/19 01:20:22  markster
00256  * Code cleanups (bug #66)
00257  *
00258  * Revision 1.1.1.1  2003/02/12 13:59:14  matteo
00259  * mer feb 12 14:56:57 CET 2003
00260  *
00261  * Revision 1.2  2000/01/05 08:20:39  markster
00262  * Some OSS fixes and a few lpc changes to make it actually work
00263  *
00264  * Revision 1.2  1996/08/20  20:22:39  jaf
00265  * Removed all static local variables that were SAVE'd in the Fortran
00266  * code, and put them in struct lpc10_decoder_state that is passed as an
00267  * argument.
00268  *
00269  * Removed init function, since all initialization is now done in
00270  * init_lpc10_decoder_state().
00271  *
00272  * Revision 1.1  1996/08/19  22:32:38  jaf
00273  * Initial revision
00274  * */
00275 /* Revision 1.3  1996/03/29  22:05:55  jaf */
00276 /* Commented out the common block variables that are not needed by the */
00277 /* embedded version. */
00278 
00279 /* Revision 1.2  1996/03/26  19:34:50  jaf */
00280 /* Added comments indicating which constants are not needed in an */
00281 /* application that uses the LPC-10 coder. */
00282 
00283 /* Revision 1.1  1996/02/07  14:44:09  jaf */
00284 /* Initial revision */
00285 
00286 /*   LPC Processing control variables: */
00287 
00288 /* *** Read-only: initialized in setup */
00289 
00290 /*  Files for Speech, Parameter, and Bitstream Input & Output, */
00291 /*    and message and debug outputs. */
00292 
00293 /* Here are the only files which use these variables: */
00294 
00295 /* lpcsim.f setup.f trans.f error.f vqsetup.f */
00296 
00297 /* Many files which use fdebug are not listed, since it is only used in */
00298 /* those other files conditionally, to print trace statements. */
00299 /*    integer fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
00300 /*  LPC order, Frame size, Quantization rate, Bits per frame, */
00301 /*    Error correction */
00302 /* Subroutine SETUP is the only place where order is assigned a value, */
00303 /* and that value is 10.  It could increase efficiency 1% or so to */
00304 /* declare order as a constant (i.e., a Fortran PARAMETER) instead of as 
00305 */
00306 /* a variable in a COMMON block, since it is used in many places in the */
00307 /* core of the coding and decoding routines.  Actually, I take that back. 
00308 */
00309 /* At least when compiling with f2c, the upper bound of DO loops is */
00310 /* stored in a local variable before the DO loop begins, and then that is 
00311 */
00312 /* compared against on each iteration. */
00313 /* Similarly for lframe, which is given a value of MAXFRM in SETUP. */
00314 /* Similarly for quant, which is given a value of 2400 in SETUP.  quant */
00315 /* is used in only a few places, and never in the core coding and */
00316 /* decoding routines, so it could be eliminated entirely. */
00317 /* nbits is similar to quant, and is given a value of 54 in SETUP. */
00318 /* corrp is given a value of .TRUE. in SETUP, and is only used in the */
00319 /* subroutines ENCODE and DECODE.  It doesn't affect the speed of the */
00320 /* coder significantly whether it is .TRUE. or .FALSE., or whether it is 
00321 */
00322 /* a constant or a variable, since it is only examined once per frame. */
00323 /* Leaving it as a variable that is set to .TRUE.  seems like a good */
00324 /* idea, since it does enable some error-correction capability for */
00325 /* unvoiced frames, with no change in the coding rate, and no noticeable 
00326 */
00327 /* quality difference in the decoded speech. */
00328 /*    integer quant, nbits */
00329 /* *** Read/write: variables for debugging, not needed for LPC algorithm 
00330 */
00331 
00332 /*  Current frame, Unstable frames, Output clip count, Max onset buffer, 
00333 */
00334 /*    Debug listing detail level, Line count on listing page */
00335 
00336 /* nframe is not needed for an embedded LPC10 at all. */
00337 /* nunsfm is initialized to 0 in SETUP, and incremented in subroutine */
00338 /* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */
00339 /* an application, I would recommend removing the call to ERROR in RCCHK, 
00340 */
00341 /* and remove ERROR and nunsfm completely. */
00342 /* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in 
00343 */
00344 /* sread.f.  When LPC10 is embedded into an application, one might want */
00345 /* to cause it to be incremented in a routine that takes the output of */
00346 /* SYNTHS and sends it to an audio device.  It could be optionally */
00347 /* displayed, for those that might want to know what it is. */
00348 /* maxosp is never initialized to 0 in SETUP, although it probably should 
00349 */
00350 /* be, and it is updated in subroutine ANALYS.  I doubt that its value */
00351 /* would be of much interest to an application in which LPC10 is */
00352 /* embedded. */
00353 /* listl and lincnt are not needed for an embedded LPC10 at all. */
00354 /*    integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
00355 /*    common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
00356 /*    common /contrl/ quant, nbits */
00357 /*    common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
00358 /*       Function return value definitions */
00359 
00360 /*       Parameters/constants */
00361 
00362 /*       The variables below that are not Fortran PARAMETER's are */
00363 /*       initialized with DATA statements, and then never modified. */
00364 /*       The following are used regardless of CORRP's value. */
00365 
00366 /*       DETAU, NBIT, QB, DEADD, DETAB7, RMST, DESCL */
00367 
00368 /*       The following are used only if CORRP is .TRUE. */
00369 
00370 /*       ETHRS, ETHRS1, ETHRS2, ETHRS3, IVTAB, BIT, CORTH, ZRC */
00371 
00372 /*       Local variables that need not be saved */
00373 
00374 /*       The following are used regardless of CORRP's value */
00375 /*       The following are used only if CORRP is .TRUE. */
00376 
00377 /*       Local state */
00378 
00379 /*       The following are used regardless of CORRP's value */
00380 /*       The following are used only if CORRP is .TRUE. */
00381 /*       I am guessing the initial values for IVP2H, IOVOIC, DRC, DPIT, */
00382 /*       and DRMS.  They should be checked to see if they are reasonable. 
00383 */
00384 /*       I'm also guessing for ERATE, but I think 0 is the right initial 
00385 */
00386 /*       value. */
00387     /* Parameter adjustments */
00388     if (irc) {
00389    --irc;
00390    }
00391     if (voice) {
00392    --voice;
00393    }
00394     if (rc) {
00395    --rc;
00396    }
00397 
00398     /* Function Body */
00399 
00400     iptold = &(st->iptold);
00401     first = &(st->first);
00402     ivp2h = &(st->ivp2h);
00403     iovoic = &(st->iovoic);
00404     iavgp = &(st->iavgp);
00405     erate = &(st->erate);
00406     drc = &(st->drc[0]);
00407     dpit = &(st->dpit[0]);
00408     drms = &(st->drms[0]);
00409 
00410 /* DATA statements for "constants" defined above. */
00411 /*    IF (LISTL.GE.3) WRITE(FDEBUG,800) IPITV,IRMS,(IRC(J),J=1,ORDER) */
00412 /* 800   FORMAT(1X,' <<ERRCOR IN>>',T32,6X,I6,I5,T50,10I8) */
00413 /*  If no error correction, do pitch and voicing then jump to decode */
00414     i4 = detau[*ipitv];
00415     if (! contrl_1.corrp) {
00416    voice[1] = 1;
00417    voice[2] = 1;
00418    if (*ipitv <= 1) {
00419        voice[1] = 0;
00420    }
00421    if (*ipitv == 0 || *ipitv == 2) {
00422        voice[2] = 0;
00423    }
00424    *pitch = i4;
00425    if (*pitch <= 4) {
00426        *pitch = *iptold;
00427    }
00428    if (voice[1] == 1 && voice[2] == 1) {
00429        *iptold = *pitch;
00430    }
00431    if (voice[1] != voice[2]) {
00432        *pitch = *iptold;
00433    }
00434    goto L900;
00435     }
00436 /*  Do error correction pitch and voicing */
00437     if (i4 > 4) {
00438    dpit[0] = i4;
00439    ivoic = 2;
00440    *iavgp = (*iavgp * 15 + i4 + 8) / 16;
00441     } else {
00442    ivoic = i4;
00443    dpit[0] = *iavgp;
00444     }
00445     drms[0] = *irms;
00446     i__1 = contrl_1.order;
00447     for (i__ = 1; i__ <= i__1; ++i__) {
00448    drc[i__ * 3 - 3] = irc[i__];
00449     }
00450 /*  Determine index to IVTAB from V/UV decision */
00451 /*  If error rate is high then use alternate table */
00452     index = (*ivp2h << 4) + (*iovoic << 2) + ivoic + 1;
00453     i1 = ivtab[index - 1];
00454     ipit = i1 & 3;
00455     icorf = i1 / 8;
00456     if (*erate < ethrs) {
00457    icorf /= 64;
00458     }
00459 /*  Determine error rate:  4=high    1=low */
00460     ixcor = 4;
00461     if (*erate < ethrs3) {
00462    ixcor = 3;
00463     }
00464     if (*erate < ethrs2) {
00465    ixcor = 2;
00466     }
00467     if (*erate < ethrs1) {
00468    ixcor = 1;
00469     }
00470 /*  Voice/unvoice decision determined from bits 0 and 1 of IVTAB */
00471     voice[1] = icorf / 2 & 1;
00472     voice[2] = icorf & 1;
00473 /*  Skip decoding on first frame because present data not yet available */
00474     if (*first) {
00475    *first = FALSE_;
00476 /*          Assign PITCH a "default" value on the first call, since */
00477 /*          otherwise it would be left uninitialized.  The two lines 
00478 */
00479 /*          below were copied from above, since it seemed like a */
00480 /*          reasonable thing to do for the first call. */
00481    *pitch = i4;
00482    if (*pitch <= 4) {
00483        *pitch = *iptold;
00484    }
00485    goto L500;
00486     }
00487 /*  If bit 4 of ICORF is set then correct RMS and RC(1) - RC(4). */
00488 /*    Determine error rate and correct errors using a Hamming 8,4 code */
00489 /*    during transition or unvoiced frame.  If IOUT is negative, */
00490 /*    more than 1 error occurred, use previous frame's parameters. */
00491     if ((icorf & bit[3]) != 0) {
00492    errcnt = 0;
00493    lsb = drms[1] & 1;
00494    index = (drc[22] << 4) + drms[1] / 2;
00495    ham84_(&index, &iout, &errcnt);
00496    drms[1] = drms[2];
00497    if (iout >= 0) {
00498        drms[1] = (iout << 1) + lsb;
00499    }
00500    for (i__ = 1; i__ <= 4; ++i__) {
00501        if (i__ == 1) {
00502       i1 = ((drc[25] & 7) << 1) + (drc[28] & 1);
00503        } else {
00504       i1 = drc[(9 - i__) * 3 - 2] & 15;
00505        }
00506        i2 = drc[(5 - i__) * 3 - 2] & 31;
00507        lsb = i2 & 1;
00508        index = (i1 << 4) + i2 / 2;
00509        ham84_(&index, &iout, &errcnt);
00510        if (iout >= 0) {
00511       iout = (iout << 1) + lsb;
00512       if ((iout & 16) == 16) {
00513           iout += -32;
00514       }
00515        } else {
00516       iout = drc[(5 - i__) * 3 - 1];
00517        }
00518        drc[(5 - i__) * 3 - 2] = iout;
00519    }
00520 /*  Determine error rate */
00521    *erate = (integer)(*erate * .96875f + errcnt * 102);
00522     }
00523 /*  Get unsmoothed RMS, RC's, and PITCH */
00524     *irms = drms[1];
00525     i__1 = contrl_1.order;
00526     for (i__ = 1; i__ <= i__1; ++i__) {
00527    irc[i__] = drc[i__ * 3 - 2];
00528     }
00529     if (ipit == 1) {
00530    dpit[1] = dpit[2];
00531     }
00532     if (ipit == 3) {
00533    dpit[1] = dpit[0];
00534     }
00535     *pitch = dpit[1];
00536 /*  If bit 2 of ICORF is set then smooth RMS and RC's, */
00537     if ((icorf & bit[1]) != 0) {
00538    if ((i__1 = drms[1] - drms[0], (real) abs(i__1)) >= corth[ixcor + 3] 
00539       && (i__2 = drms[1] - drms[2], (real) abs(i__2)) >= corth[
00540       ixcor + 3]) {
00541        *irms = median_(&drms[2], &drms[1], drms);
00542    }
00543    for (i__ = 1; i__ <= 6; ++i__) {
00544        if ((i__1 = drc[i__ * 3 - 2] - drc[i__ * 3 - 3], (real) abs(i__1))
00545            >= corth[ixcor + ((i__ + 2) << 2) - 5] && (i__2 = drc[i__ *
00546            3 - 2] - drc[i__ * 3 - 1], (real) abs(i__2)) >= corth[
00547           ixcor + ((i__ + 2) << 2) - 5]) {
00548       irc[i__] = median_(&drc[i__ * 3 - 1], &drc[i__ * 3 - 2], &drc[
00549          i__ * 3 - 3]);
00550        }
00551    }
00552     }
00553 /*  If bit 3 of ICORF is set then smooth pitch */
00554     if ((icorf & bit[2]) != 0) {
00555    if ((i__1 = dpit[1] - dpit[0], (real) abs(i__1)) >= corth[ixcor - 1] 
00556       && (i__2 = dpit[1] - dpit[2], (real) abs(i__2)) >= corth[
00557       ixcor - 1]) {
00558        *pitch = median_(&dpit[2], &dpit[1], dpit);
00559    }
00560     }
00561 /*  If bit 5 of ICORF is set then RC(5) - RC(10) are loaded with */
00562 /*  values so that after quantization bias is removed in decode */
00563 /*  the values will be zero. */
00564 L500:
00565     if ((icorf & bit[4]) != 0) {
00566    i__1 = contrl_1.order;
00567    for (i__ = 5; i__ <= i__1; ++i__) {
00568        irc[i__] = zrc[i__ - 1];
00569    }
00570     }
00571 /*  House keeping  - one frame delay */
00572     *iovoic = ivoic;
00573     *ivp2h = voice[2];
00574     dpit[2] = dpit[1];
00575     dpit[1] = dpit[0];
00576     drms[2] = drms[1];
00577     drms[1] = drms[0];
00578     i__1 = contrl_1.order;
00579     for (i__ = 1; i__ <= i__1; ++i__) {
00580    drc[i__ * 3 - 1] = drc[i__ * 3 - 2];
00581    drc[i__ * 3 - 2] = drc[i__ * 3 - 3];
00582     }
00583 L900:
00584 /*    IF (LISTL.GE.3)WRITE(FDEBUG,801)VOICE,PITCH,IRMS,(IRC(J),J=1,ORDER) */
00585 /* 801   FORMAT(1X,'<<ERRCOR OUT>>',T32,2I3,I6,I5,T50,10I8) */
00586 /*   Decode RMS */
00587     *irms = rmst[(31 - *irms) * 2];
00588 /*  Decode RC(1) and RC(2) from log-area-ratios */
00589 /*  Protect from illegal coded value (-16) caused by bit errors */
00590     for (i__ = 1; i__ <= 2; ++i__) {
00591    i2 = irc[i__];
00592    i1 = 0;
00593    if (i2 < 0) {
00594        i1 = 1;
00595        i2 = -i2;
00596        if (i2 > 15) {
00597       i2 = 0;
00598        }
00599    }
00600    i2 = detab7[i2 * 2];
00601    if (i1 == 1) {
00602        i2 = -i2;
00603    }
00604    ishift = 15 - nbit[i__ - 1];
00605    irc[i__] = i2 * pow_ii(&c__2, &ishift);
00606     }
00607 /*  Decode RC(3)-RC(10) to sign plus 14 bits */
00608     i__1 = contrl_1.order;
00609     for (i__ = 3; i__ <= i__1; ++i__) {
00610    i2 = irc[i__];
00611    ishift = 15 - nbit[i__ - 1];
00612    i2 *= pow_ii(&c__2, &ishift);
00613    i2 += qb[i__ - 3];
00614    irc[i__] = (integer)(i2 * descl[i__ - 3] + deadd[i__ - 3]);
00615     }
00616 /*    IF (LISTL.GE.3) WRITE(FDEBUG,811) IRMS, (IRC(I),I=1,ORDER) */
00617 /* 811   FORMAT(1X,'<<DECODE OUT>>',T45,I4,1X,10I8) */
00618 /*  Scale RMS and RC's to reals */
00619     *rms = (real) (*irms);
00620     i__1 = contrl_1.order;
00621     for (i__ = 1; i__ <= i__1; ++i__) {
00622    rc[i__] = irc[i__] / 16384.f;
00623     }
00624     return 0;
00625 } /* decode_ */

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