📄 decode.c,v
字号:
/* DATA statements for "constants" defined above. *//* IF (LISTL.GE.3) WRITE(FDEBUG,800) IPITV,IRMS,(IRC(J),J=1,ORDER) *//* 800 FORMAT(1X,' <<ERRCOR IN>>',T32,6X,I6,I5,T50,10I8) *//* If no error correction, do pitch and voicing then jump to decode */ i4 = detau[*ipitv]; if (! contrl_1.corrp) { voice[1] = 1; voice[2] = 1; if (*ipitv <= 1) { voice[1] = 0; } if (*ipitv == 0 || *ipitv == 2) { voice[2] = 0; } *pitch = i4; if (*pitch <= 4) { *pitch = *iptold; } if (voice[1] == 1 && voice[2] == 1) { *iptold = *pitch; } if (voice[1] != voice[2]) { *pitch = *iptold; } goto L900; }/* Do error correction pitch and voicing */ if (i4 > 4) { dpit[0] = i4; ivoic = 2; *iavgp = (*iavgp * 15 + i4 + 8) / 16; } else { ivoic = i4; dpit[0] = *iavgp; } drms[0] = *irms; i__1 = contrl_1.order; for (i__ = 1; i__ <= i__1; ++i__) { drc[i__ * 3 - 3] = irc[i__]; }/* Determine index to IVTAB from V/UV decision *//* If error rate is high then use alternate table */ index = (*ivp2h << 4) + (*iovoic << 2) + ivoic + 1; i1 = ivtab[index - 1]; ipit = i1 & 3; icorf = i1 / 8; if (*erate < ethrs) { icorf /= 64; }/* Determine error rate: 4=high 1=low */ ixcor = 4; if (*erate < ethrs3) { ixcor = 3; } if (*erate < ethrs2) { ixcor = 2; } if (*erate < ethrs1) { ixcor = 1; }/* Voice/unvoice decision determined from bits 0 and 1 of IVTAB */ voice[1] = icorf / 2 & 1; voice[2] = icorf & 1;/* Skip decoding on first frame because present data not yet available */ if (*first) { *first = FALSE_;/* Assign PITCH a "default" value on the first call, since *//* otherwise it would be left uninitialized. The two lines *//* below were copied from above, since it seemed like a *//* reasonable thing to do for the first call. */ *pitch = i4; if (*pitch <= 4) { *pitch = *iptold; } goto L500; }/* If bit 4 of ICORF is set then correct RMS and RC(1) - RC(4). *//* Determine error rate and correct errors using a Hamming 8,4 code *//* during transition or unvoiced frame. If IOUT is negative, *//* more than 1 error occurred, use previous frame's parameters. */ if ((icorf & bit[3]) != 0) { errcnt = 0; lsb = drms[1] & 1; index = (drc[22] << 4) + drms[1] / 2; ham84_(&index, &iout, &errcnt); drms[1] = drms[2]; if (iout >= 0) { drms[1] = (iout << 1) + lsb; } for (i__ = 1; i__ <= 4; ++i__) { if (i__ == 1) { i1 = ((drc[25] & 7) << 1) + (drc[28] & 1); } else { i1 = drc[(9 - i__) * 3 - 2] & 15; } i2 = drc[(5 - i__) * 3 - 2] & 31; lsb = i2 & 1; index = (i1 << 4) + i2 / 2; ham84_(&index, &iout, &errcnt); if (iout >= 0) { iout = (iout << 1) + lsb; if ((iout & 16) == 16) { iout += -32; } } else { iout = drc[(5 - i__) * 3 - 1]; } drc[(5 - i__) * 3 - 2] = iout; }/* Determine error rate */ *erate = *erate * .96875f + errcnt * 102; }/* Get unsmoothed RMS, RC's, and PITCH */ *irms = drms[1]; i__1 = contrl_1.order; for (i__ = 1; i__ <= i__1; ++i__) { irc[i__] = drc[i__ * 3 - 2]; } if (ipit == 1) { dpit[1] = dpit[2]; } if (ipit == 3) { dpit[1] = dpit[0]; } *pitch = dpit[1];/* If bit 2 of ICORF is set then smooth RMS and RC's, */ if ((icorf & bit[1]) != 0) { if ((i__1 = drms[1] - drms[0], (real) abs(i__1)) >= corth[ixcor + 3] && (i__2 = drms[1] - drms[2], (real) abs(i__2)) >= corth[ ixcor + 3]) { *irms = median_(&drms[2], &drms[1], drms); } for (i__ = 1; i__ <= 6; ++i__) { if ((i__1 = drc[i__ * 3 - 2] - drc[i__ * 3 - 3], (real) abs(i__1)) >= corth[ixcor + (i__ + 2 << 2) - 5] && (i__2 = drc[i__ * 3 - 2] - drc[i__ * 3 - 1], (real) abs(i__2)) >= corth[ ixcor + (i__ + 2 << 2) - 5]) { irc[i__] = median_(&drc[i__ * 3 - 1], &drc[i__ * 3 - 2], &drc[ i__ * 3 - 3]); } } }/* If bit 3 of ICORF is set then smooth pitch */ if ((icorf & bit[2]) != 0) { if ((i__1 = dpit[1] - dpit[0], (real) abs(i__1)) >= corth[ixcor - 1] && (i__2 = dpit[1] - dpit[2], (real) abs(i__2)) >= corth[ ixcor - 1]) { *pitch = median_(&dpit[2], &dpit[1], dpit); } }/* If bit 5 of ICORF is set then RC(5) - RC(10) are loaded with *//* values so that after quantization bias is removed in decode *//* the values will be zero. */L500: if ((icorf & bit[4]) != 0) { i__1 = contrl_1.order; for (i__ = 5; i__ <= i__1; ++i__) { irc[i__] = zrc[i__ - 1]; } }/* House keeping - one frame delay */ *iovoic = ivoic; *ivp2h = voice[2]; dpit[2] = dpit[1]; dpit[1] = dpit[0]; drms[2] = drms[1]; drms[1] = drms[0]; i__1 = contrl_1.order; for (i__ = 1; i__ <= i__1; ++i__) { drc[i__ * 3 - 1] = drc[i__ * 3 - 2]; drc[i__ * 3 - 2] = drc[i__ * 3 - 3]; }L900:/* IF (LISTL.GE.3)WRITE(FDEBUG,801)VOICE,PITCH,IRMS,(IRC(J),J=1,ORDER) *//* 801 FORMAT(1X,'<<ERRCOR OUT>>',T32,2I3,I6,I5,T50,10I8) *//* Decode RMS */ *irms = rmst[(31 - *irms) * 2];/* Decode RC(1) and RC(2) from log-area-ratios *//* Protect from illegal coded value (-16) caused by bit errors */ for (i__ = 1; i__ <= 2; ++i__) { i2 = irc[i__]; i1 = 0; if (i2 < 0) { i1 = 1; i2 = -i2; if (i2 > 15) { i2 = 0; } } i2 = detab7[i2 * 2]; if (i1 == 1) { i2 = -i2; } ishift = 15 - nbit[i__ - 1]; irc[i__] = i2 * pow_ii(&c__2, &ishift); }/* Decode RC(3)-RC(10) to sign plus 14 bits */ i__1 = contrl_1.order; for (i__ = 3; i__ <= i__1; ++i__) { i2 = irc[i__]; ishift = 15 - nbit[i__ - 1]; i2 *= pow_ii(&c__2, &ishift); i2 += qb[i__ - 3]; irc[i__] = i2 * descl[i__ - 3] + deadd[i__ - 3]; }/* IF (LISTL.GE.3) WRITE(FDEBUG,811) IRMS, (IRC(I),I=1,ORDER) *//* 811 FORMAT(1X,'<<DECODE OUT>>',T45,I4,1X,10I8) *//* Scale RMS and RC's to reals */ *rms = (real) (*irms); i__1 = contrl_1.order; for (i__ = 1; i__ <= i__1; ++i__) { rc[i__] = irc[i__] / 16384.f; } return 0;} /* decode_ */@1.1log@Initial revision@text@d3 4a6 1$Log$d11 1a11 2extern int decode_(integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc);extern int initdecode_(void);d41 4a44 1/* $Log: decode.f,v $ */d101 3a103 2/* Subroutine */ int decode_0_(int n__, integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc)d107 1a107 1 static logical first = TRUE_;d135 1a135 1 static integer ivp2h = 0;d142 7a148 8 static integer iovoic = 0; static integer iavgp = 60; static integer iptold = 60; static integer erate = 0; static integer drc[30] /* was [3][10] */ = { 0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; static integer dpit[3] = { 0,0,0 }; static integer drms[3] = { 0,0,0 };d158 1a158 1 integer ipit, iout, i__, j, icorf, index, ivoic, ixcor, i1, i2, i4;d162 4a165 1/* $Log: config.fh,v $ */d179 4a182 1/* $Log: contrl.fh,v $ */d307 10a316 3 switch(n__) { case 1: goto L_initdecode; }d334 1a334 1 *pitch = iptold;d337 1a337 1 iptold = *pitch;d340 1a340 1 *pitch = iptold;d348 1a348 1 iavgp = (iavgp * 15 + i4 + 8) / 16;d351 1a351 1 dpit[0] = iavgp;d360 1a360 1 index = (ivp2h << 4) + (iovoic << 2) + ivoic + 1;d364 1a364 1 if (erate < ethrs) {d369 1a369 1 if (erate < ethrs3) {d372 1a372 1 if (erate < ethrs2) {d375 1a375 1 if (erate < ethrs1) {d382 2a383 2 if (first) { first = FALSE_;d391 1a391 1 *pitch = iptold;d429 1a429 4 erate = erate * .96875f + errcnt * 102;/* IF (ERATE.NE.0 .AND. LISTL.GE.3) WRITE(FDEBUG,987) ERATE,ERRCNT *//* 987 FORMAT(' ERATE=',I6,' ERRCNT=',I6) */d480 2a481 2 iovoic = ivoic; ivp2h = voice[2];a532 16L_initdecode: first = TRUE_; ivp2h = 0; iovoic = 0; iavgp = 60; iptold = 60; erate = 0; for (j = 1; j <= 3; ++j) { for (i__ = 1; i__ <= 10; ++i__) { drc[j + i__ * 3 - 4] = 0; } dpit[j - 1] = 0; drms[j - 1] = 0; } return 0;a533 13/* Subroutine */ int decode_(integer *ipitv, integer *irms, integer *irc, integer *voice, integer *pitch, real *rms, real *rc){ return decode_0_(0, ipitv, irms, irc, voice, pitch, rms, rc); }/* Subroutine */ int initdecode_(void){ return decode_0_(1, (integer *)0, (integer *)0, (integer *)0, (integer *) 0, (integer *)0, (real *)0, (real *)0); }@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -