⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decode.c

📁 局域网ICQ的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ERROR, which is only called from RCCHK.  When LPC10 is embedded into */
/* an application, I would recommend removing the call to ERROR in RCCHK, 
*/
/* and remove ERROR and nunsfm completely. */
/* iclip is initialized to 0 in SETUP, and incremented in entry SWRITE in 
*/
/* sread.f.  When LPC10 is embedded into an application, one might want */
/* to cause it to be incremented in a routine that takes the output of */
/* SYNTHS and sends it to an audio device.  It could be optionally */
/* displayed, for those that might want to know what it is. */
/* maxosp is never initialized to 0 in SETUP, although it probably should 
*/
/* be, and it is updated in subroutine ANALYS.  I doubt that its value */
/* would be of much interest to an application in which LPC10 is */
/* embedded. */
/* listl and lincnt are not needed for an embedded LPC10 at all. */
/* 	integer nframe, nunsfm, iclip, maxosp, listl, lincnt */
/* 	common /contrl/ fsi, fso, fpi, fpo, fbi, fbo, pbin, fmsg, fdebug */
/* 	common /contrl/ quant, nbits */
/* 	common /contrl/ nframe, nunsfm, iclip, maxosp, listl, lincnt */
/*       Function return value definitions */

/*       Parameters/constants */

/*       The variables below that are not Fortran PARAMETER's are */
/*       initialized with DATA statements, and then never modified. */
/*       The following are used regardless of CORRP's value. */

/*       DETAU, NBIT, QB, DEADD, DETAB7, RMST, DESCL */

/*       The following are used only if CORRP is .TRUE. */

/*       ETHRS, ETHRS1, ETHRS2, ETHRS3, IVTAB, BIT, CORTH, ZRC */

/*       Local variables that need not be saved */

/*       The following are used regardless of CORRP's value */
/*       The following are used only if CORRP is .TRUE. */

/*       Local state */

/*       The following are used regardless of CORRP's value */
/*       The following are used only if CORRP is .TRUE. */
/*       I am guessing the initial values for IVP2H, IOVOIC, DRC, DPIT, */
/*       and DRMS.  They should be checked to see if they are reasonable. 
*/
/*       I'm also guessing for ERATE, but I think 0 is the right initial 
*/
/*       value. */
    /* Parameter adjustments */
    if (irc) {
	--irc;
	}
    if (voice) {
	--voice;
	}
    if (rc) {
	--rc;
	}

    /* Function Body */

    iptold = &(st->iptold);
    first = &(st->first);
    ivp2h = &(st->ivp2h);
    iovoic = &(st->iovoic);
    iavgp = &(st->iavgp);
    erate = &(st->erate);
    drc = &(st->drc[0]);
    dpit = &(st->dpit[0]);
    drms = &(st->drms[0]);

/* 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_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -