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

📄 g722.cpp

📁 G722语音压缩算法
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	{ 
	/* PROCESS PCM THROUGH THE QMF FILTER                               */

nexttwodata:
	xp = x + 23; xp_2 = x +21;

	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;
	*xp-- = *xp_2--;

	*xp = *datap++;
	*--xp = *datap++;

/* DISCARD EVERY OTHER QMF OUTPUT                                   */

		sumeven = *xp++ * 3;	
		sumodd = *xp++ * (-11);	
		sumeven += *xp++ * (-11);	
		sumodd += *xp++ * 53;	
		sumeven += *xp++ * 12;	
		sumodd += *xp++ * (-156);	
		sumeven += *xp++ * 32;	
		sumodd += *xp++ * 362;	
		sumeven += *xp++ * (-210);	
		sumodd += *xp++ * (-805);	
		sumeven += *xp++ * 951;	
		sumodd += *xp++ * 3876;	
		sumeven += *xp++ * 3876;	
		sumodd += *xp++ * 951;	
		sumeven += *xp++ * (-805);	
		sumodd += *xp++ * (-210);	
		sumeven += *xp++ * 362;	
		sumodd += *xp++ * 32;	
		sumeven += *xp++ * (-156);	
		sumodd += *xp++ * 12;	
		sumeven += *xp++ * 53;	
		sumodd += *xp++ * (-11);	
		sumeven += *xp++ * (-11);	
		sumodd += *xp++ * 3;	

	test->rlow = (sumeven + sumodd) >>13;
	test->rhigh = (sumeven - sumodd) >>13;

/*************************************** BLOCK 1L, SUBTRA ************/

	el = test->rlow - test->slow ;

        if ( el > 32767 ) el = 32767;
        else if ( el < -32768 ) el = -32768;

/*************************************** BLOCK 1L, QUANTL ************/

	wd= (el>= 0 ) ?  el: -(el+1) ;
	
	q6p = q6;

	mil = 1;
                for (i=0;i<29;i++)
	     {        
	       wd1 = (*++q6p * test->detlow) >>12 ;		
		   if (wd >= wd1)  mil++;
		   else 
                        break;	
            }
 
	test->ilowr = ( el < 0 ) ? iln[mil] : ilp[mil];

/************************************** BLOCK 2L, INVQAL ************/

	ril = test->ilowr >> 2 ;
	wd2 = qm4[ril] ;
	test->dlowt = (test->detlow * wd2) >> 15 ;

/************************************** BLOCK 3L, LOGSCL *************/

	il4 = rl42[ril] ;

	wd = (nbl * 127) >> 7 ;
	
	nbl = wd + wl[il4] ;

	if (nbl <     0) nbl = 0 ;
	else if (nbl > 18432) nbl = 18432 ;

/************************************** BLOCK 3L, SCALEL *************/
	wd1 =  (nbl >> 6) & 31 ;
	wd2 = nbl >> 11 ;
	wd3=((8 - wd2) < 0) ? ilb[wd1]<<(wd2 - 8) : ilb[wd1]>>(8 - wd2); 
	test->detlow  = wd3 << 2 ;
/************************************** BLOCK 3L, DELAYA *************/

	test->slow = encoder_block4l (test->dlowt) ;


/*************************************** BLOCK 1H, SUBTRA ************/

	eh = test->rhigh - test->shigh ;
/*
        if ( eh > 32767 ) eh = 32767;
        else if ( eh < -32768 ) eh = -32768;
*/
/*************************************** BLOCK 1H, QUANTH ************/

	wd = (eh>= 0 )? eh : -( eh +1 ) ;
	
	hdu = 564 * test->dethigh; 
	wd1 = hdu >> 12 ;
	mih = (wd >= wd1)? 2: 1 ;
	test->ihigh = (eh<0) ? ihn[mih] : ihp[mih] ;

/************************************** BLOCK 2H, INVQAH ************/

	wd2 = qm2[test->ihigh] ;
	test->dhigh = (test->dethigh * wd2) >> 15 ;


/************************************** BLOCK 3H, LOGSCH *************/

	ih2 = rh2[test->ihigh] ;
	wd = (nbh * 127) >> 7 ;
	nbh = wd + wh[ih2] ;

	if (nbh <     0) nbh = 0 ;
	else if (nbh > 22528) nbh = 22528 ;

/************************************** BLOCK 3H, SCALEH *************/
	wd1 =  (nbh >> 6) & 31 ;
	wd2 = nbh >> 11 ;
	wd3=((10-wd2) < 0)? ilb[wd1] << (wd2-10): ilb[wd1] >> (10-wd2) ;
	test->dethigh = wd3 << 2 ;
/************************************** BLOCK 3L, DELAYA *************/

	test->shigh = encoder_block4h (test->dhigh) ;
	/*
        if(k>0){
                outdata[j] = test->ilowr;
                outdata[j] = (outdata[j]<<2) + test->ihigh;
                k = -k;

                goto nexttwodata;

	}
        else {
                outdata[j] = (outdata[j]<<6) + test->ilowr;
                outdata[j] = (outdata[j]<<2) + test->ihigh;
                k = -k;
		}
        */ //06.6.9
        *outdata++ = test->ilowr;
        *outdata++ = test->ihigh;
	j++;
	}
     //   P=(&(*outdata))-P
        return 1;//P/sizeof(UINT3216);
}
INT32 g722_decoder(pG722_Handle test, UINT16 *pdecdata, short *pcmout, INT32 samplesRead)
	{	INT32 j,k=1;
           //     UINT3232 P= (&(*pcmout));
		static INT32 nbl = 0;
		static INT32 nbh = 0;
		INT32 wd1, wd2, wd3;
		INT32 *xdp, *xsp, *xdp_1, *xsp_1, xout;
		for(j=0; j < samplesRead;)
	{	
                /*
                test->ilowr = *pdecdata >> 10;
		test->ihigh = (*pdecdata >> 8) & 3;
                */ //06.6.9
                test->ilowr = *pdecdata++;
                test->ihigh = *pdecdata++;
nexttwodata:
	/*********************** BLOCK 5L, LOW BAND INVQBL ****************/
	
	wd2 = qm6[test->ilowr] ;
	wd2 = (test->detlow * wd2 ) >> 15 ;
	/******************************** BLOCK 5L, RECONS ****************/
	test->rlow = test->slow + wd2 ;
	/*
	  if (test->rlow > 32767) test->rlow = 32767;
	  if (test->rlow < -32768) test->rlow = -32768;
	*/
	/******************************** BLOCK 6L, LIMIT ******************/
	/*
	  if (test->rlow > 16383 ) test->rlow = 16383;
	  if (test->rlow < -16383 ) test->rlow = -16383;
	*/
	/************************************** BLOCK 2L, INVQAL ************/
	
	wd1 = test->ilowr >> 2 ;
	wd2 = qm4[wd1] ;
	test->dlowt = (test->detlow * wd2) >> 15 ;
	/************************************** BLOCK 3L, LOGSCL *************/
	
        wd2 = rl42[wd1] ;
        wd1 = (nbl * 127) >> 7 ;
        nbl = wd1 + wl[wd2] ;
        if (nbl < 0)
	    nbl = 0 ;
        else if (nbl > 18432)
	    nbl = 18432 ;
	/************************************** BLOCK 3L, SCALEL *************/
	
        wd1 =  (nbl >> 6) & 31 ;
        wd2 = nbl >> 11 ;
        wd3= ((8 - wd2) < 0)? ilb[wd1] << (wd2 - 8) : ilb[wd1] >> (8 - wd2) ;
        test->detlow = wd3 << 2 ;
	
	test->slow = decoder_block4l (test->dlowt) ;
	/************************************** BLOCK 2H, INVQAH ************/
	
	wd2 = qm2[test->ihigh] ;
	test->dhigh  = (test->dethigh * wd2) >> 15 ;
	
        test->rhigh  = test->dhigh + test->shigh ;
	/*
	  if (test->rhigh >  16383 )  test->rhigh =  16383 ;
	  if (test->rhigh < -16384 )  test->rhigh = -16384 ;
	  */
	/************************************** BLOCK 2H, INVQAH ************/
	
        wd2 = rh2[test->ihigh] ;
        wd1 = (nbh * 127) >> 7 ;
        nbh = wd1 + wh[wd2] ;
	if (nbh <     0)
	    nbh = 0 ;
	else if (nbh > 22528)
	    nbh = 22528 ;
	/************************************** BLOCK 3H, SCALEH *************/
	
        wd1 =  (nbh >> 6) & 31 ;
        wd2 = nbh >> 11 ;
        wd3= ((10 - wd2) < 0)? ilb[wd1] << (wd2 - 10) : ilb[wd1] >> (10 - wd2) ;
        test->dethigh = wd3 << 2 ;
	
	test->shigh = decoder_block4h (test->dhigh) ;
	/******************************* RECIEVE QMF ************************/

		xdp=xd+11, xsp=xs+11, xdp_1=xd+10, xsp_1=xs+10;
		*xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
		*xdp-- = *xdp_1--; *xsp-- = *xsp_1--; 
		*xdp-- = *xdp_1--; *xsp-- = *xsp_1--; 
		*xdp-- = *xdp_1--; *xsp-- = *xsp_1--; 
		*xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
		*xdp-- = *xdp_1--; *xsp-- = *xsp_1--; 
		*xdp-- = *xdp_1--; *xsp-- = *xsp_1--; 
		*xdp-- = *xdp_1--; *xsp-- = *xsp_1--; 
		*xdp-- = *xdp_1--; *xsp-- = *xsp_1--; 
		*xdp-- = *xdp_1--; *xsp-- = *xsp_1--; 
		*xdp-- = *xdp_1--; *xsp-- = *xsp_1--; 
	/************************************* RECA ***************************/
	*xdp  = test->rlow - test->rhigh ;
        /*
	  if (*xdp > 16383) *xdp = 16383;
	  if (*xdp < -16384) *xdp = -16384;
        */
/************************************* RECA ***************************/
	*xsp  = test->rlow + test->rhigh ;
        /*
	  if (*xsp > 16383) *xsp = 16383;
	  if (*xsp < -16384) *xsp = -16384;
        */
	/************************************* ACCUM C&D *************************/
					/*	qmf tap coefficients	*/
/*      pmf=&tap[0];
		while(*++pmf)
		xout+=*xdp++ * *(pmf);		*/
		xout = *xdp++ * 3;
		xout += *xdp++ * -11;
		xout += *xdp++ * 12;
		xout += *xdp++ * 32;
		xout += *xdp++ * -210;
		xout += *xdp++ * 951;
		xout += *xdp++ * 3876;
		xout += *xdp++ * -805;
		xout += *xdp++ * 362;
		xout += *xdp++ * -156;
		xout += *xdp++ * 53;
		xout += *xdp++ * -11;
                /*
                wd1=xout>>12;
                if(wd1>32767)   wd1=32767;
                else if(wd1<-32768)     wd1=-32768;

		*pcmout++ = wd1 ;
                */
                wd1=xout>>12;
                if(wd1>32767)
                *pcmout++=32767;
                else if(wd1<-32768)
                *pcmout++=-32768;
                else *pcmout++=wd1;

/*        fprINT32f (stdout, "%5d\n", xout);  output pcm */
//			xout=0;
//			while(*--pmf)
//			xout+=*xsp++ * *(pmf);
		xout = *xsp++ * -11;
		xout += *xsp++ * 53;
		xout += *xsp++ * -156;
		xout += *xsp++ * 362;
		xout += *xsp++ * -805;
		xout += *xsp++ * 3876;
		xout += *xsp++ * 951;
		xout += *xsp++ * -210;
		xout += *xsp++ * 32;
		xout += *xsp++ * 12;
		xout += *xsp++ * -11;
		xout += *xsp++ * 3;
                /*
		wd1=xout>>12;
                if(wd1>32767)   wd1=32767;
                else if(wd1<-32768)     wd1=-32768;

		*pcmout++ = wd1 ;
                */
                wd1=xout>>12;
                if(wd1>32767)
                *pcmout++=32767;
                else if(wd1<-32768)
                *pcmout++=-32768;
                else *pcmout++=wd1;

/*       fprINT32f (stdout, "%5d\n", xout1);  output pcm */

	j++, j++;

	k=-k;
	/*
	  if (xout1 >  16383)  xout1 =  16383 ;
	  if (xout1 < -16384)  xout1 = -16384 ;
	  if (xout1 >  16383)  xout1 =  16383 ;
	  if (xout1 < -16384)  xout1 = -16384 ;
	  */
        /*
	if(k<0)
	{	test->ilowr = (*pdecdata >> 2) & 63;
		test->ihigh = (*pdecdata++) & 3;
		goto nexttwodata;
	}
        */ //06.6.9
    }
//    P=(&(*pcmout))-P;
    return 1; //P/sizeof(short);
}

⌨️ 快捷键说明

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