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

📄 autocorr.c

📁 AMR-NB 的编码实现,纯C, VC下建立工程即可用.
💻 C
📖 第 1 页 / 共 4 页
字号:
	{                       
		s += h2[k]*h2[k + 38] << 1;	 
		rr[i][j] = rr[j][i] = ((s+ 0x00008000)>> 16 ) * (psign[i]*psign[j] >> 15 ) >> 15 ;

	}

	s = 0;                                 
	j = 39;
	i = 0 ;
	for (k = 0; k < 1; k++, i--, j--)
	{                       
		s += h2[k]*h2[k + 39] << 1;	 
		rr[i][j] = rr[j][i] = ((s+ 0x00008000)>> 16 ) * (psign[i]*psign[j] >> 15 ) >> 15 ;

	}


}


/************************************************************************* 
   Function     :  comp_corr 
   Purpose      : Calculate all correlations of scal_sig[] in a given delay  range.
   Description :
                       The correlation is given by cor[t] = <scal_sig[n],scal_sig[n-t]>,  t=lag_min,...,lag_max
                       The functions outputs the all correlations 

  Input:		  
           scal_sig[]   :  scaled signal.                        
           L_frame     :   length of frame to compute pitch      
           lag_max     :  maximum lag                            
           lag_min      :  minimum lag     
           
  Output:
          corr[]          : correlation of selected lag          
  Return:
 
 *************************************************************************/void comp_corr ( Word16 scal_sig[],  Word16 L_frame, Word16 lag_max, Word16 lag_min, Word32 corr[]) 
{
    Word16 i;    Word16 *p, *p1;    Word32 t0,t1,t2,t3,t4,t5,t6,t7,t8, t9, t10;
    Word16* pScalsig;
    Word32 *pCorr;

    pScalsig = scal_sig;
    pCorr    = corr;

	
    for (i = lag_max; i >= lag_min; i--)    {	p   = pScalsig;          
	p1 = &pScalsig[-i];     
	t0  = 0;           


	t1 = p[0]*p1[0];   t2 = p[1]*p1[1];   t3 = p[2]*p1[2];  t4 = p[3]*p1[3]; t5   = p[4]*p1[4];
	t6 = p[5]*p1[5];   t7 = p[6]*p1[6];   t8 = p[7]*p1[7];  t9 = p[8]*p1[8]; t10 = p[9]*p1[9];	   
	t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

	t1 = p[10]*p1[10];   t2 = p[11]*p1[11];   t3 = p[12]*p1[12];  t4 = p[13]*p1[13]; t5   = p[14]*p1[14];
	t6 = p[15]*p1[15];   t7 = p[16]*p1[16];   t8 = p[17]*p1[17];  t9 = p[18]*p1[18]; t10 = p[19]*p1[19];	   
	t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

	t1 = p[20]*p1[20];   t2 = p[21]*p1[21];   t3 = p[22]*p1[22];  t4 = p[23]*p1[23]; t5   = p[24]*p1[24];
	t6 = p[25]*p1[25];   t7 = p[26]*p1[26];   t8 = p[27]*p1[27];  t9 = p[28]*p1[28]; t10 = p[29]*p1[29];	   
	t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

	t1 = p[30]*p1[30];   t2 = p[31]*p1[31];   t3 = p[32]*p1[32];  t4 = p[33]*p1[33]; t5   = p[34]*p1[34];
	t6 = p[35]*p1[35];   t7 = p[36]*p1[36];   t8 = p[37]*p1[37];  t9 = p[38]*p1[38]; t10 = p[39]*p1[39];	   
	t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

	t1 = p[40]*p1[40];   t2 = p[41]*p1[41];   t3 = p[42]*p1[42];  t4 = p[43]*p1[43]; t5   = p[44]*p1[44];
	t6 = p[45]*p1[45];   t7 = p[46]*p1[46];   t8 = p[47]*p1[47];  t9 = p[48]*p1[48]; t10 = p[49]*p1[49];	   
	t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

	t1 = p[50]*p1[50];   t2 = p[51]*p1[51];   t3 = p[52]*p1[52];  t4 = p[53]*p1[53]; t5   = p[54]*p1[54];
	t6 = p[55]*p1[55];   t7 = p[56]*p1[56];   t8 = p[57]*p1[57];  t9 = p[58]*p1[58]; t10 = p[59]*p1[59];	   
	t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

	t1 = p[60]*p1[60];   t2 = p[61]*p1[61];   t3 = p[62]*p1[62];  t4 = p[63]*p1[63]; t5   = p[64]*p1[64];
	t6 = p[65]*p1[65];   t7 = p[66]*p1[66];   t8 = p[67]*p1[67];  t9 = p[68]*p1[68]; t10 = p[69]*p1[69];	   
	t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

	t1 = p[70]*p1[70];   t2 = p[71]*p1[71];   t3 = p[72]*p1[72];  t4 = p[73]*p1[73]; t5   = p[74]*p1[74];
	t6 = p[75]*p1[75];   t7 = p[76]*p1[76];   t8 = p[77]*p1[77];  t9 = p[78]*p1[78]; t10 = p[79]*p1[79];	   
	t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

	if( 160 == L_frame)
	{
		p += 80; p1+= 80;

		t1 = p[0]*p1[0];   t2 = p[1]*p1[1];   t3 = p[2]*p1[2];  t4 = p[3]*p1[3]; t5   = p[4]*p1[4];
		t6 = p[5]*p1[5];   t7 = p[6]*p1[6];   t8 = p[7]*p1[7];  t9 = p[8]*p1[8]; t10 = p[9]*p1[9];	   
		t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

		t1 = p[10]*p1[10];   t2 = p[11]*p1[11];   t3 = p[12]*p1[12];  t4 = p[13]*p1[13]; t5   = p[14]*p1[14];
		t6 = p[15]*p1[15];   t7 = p[16]*p1[16];   t8 = p[17]*p1[17];  t9 = p[18]*p1[18]; t10 = p[19]*p1[19];	   
		t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

		t1 = p[20]*p1[20];   t2 = p[21]*p1[21];   t3 = p[22]*p1[22];  t4 = p[23]*p1[23]; t5   = p[24]*p1[24];
		t6 = p[25]*p1[25];   t7 = p[26]*p1[26];   t8 = p[27]*p1[27];  t9 = p[28]*p1[28]; t10 = p[29]*p1[29];	   
		t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

		t1 = p[30]*p1[30];   t2 = p[31]*p1[31];   t3 = p[32]*p1[32];  t4 = p[33]*p1[33]; t5   = p[34]*p1[34];
		t6 = p[35]*p1[35];   t7 = p[36]*p1[36];   t8 = p[37]*p1[37];  t9 = p[38]*p1[38]; t10 = p[39]*p1[39];	   
		t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

		t1 = p[40]*p1[40];   t2 = p[41]*p1[41];   t3 = p[42]*p1[42];  t4 = p[43]*p1[43]; t5   = p[44]*p1[44];
		t6 = p[45]*p1[45];   t7 = p[46]*p1[46];   t8 = p[47]*p1[47];  t9 = p[48]*p1[48]; t10 = p[49]*p1[49];	   
		t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

		t1 = p[50]*p1[50];   t2 = p[51]*p1[51];   t3 = p[52]*p1[52];  t4 = p[53]*p1[53]; t5   = p[54]*p1[54];
		t6 = p[55]*p1[55];   t7 = p[56]*p1[56];   t8 = p[57]*p1[57];  t9 = p[58]*p1[58]; t10 = p[59]*p1[59];	   
		t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

		t1 = p[60]*p1[60];   t2 = p[61]*p1[61];   t3 = p[62]*p1[62];  t4 = p[63]*p1[63]; t5   = p[64]*p1[64];
		t6 = p[65]*p1[65];   t7 = p[66]*p1[66];   t8 = p[67]*p1[67];  t9 = p[68]*p1[68]; t10 = p[69]*p1[69];	   
		t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

		t1 = p[70]*p1[70];   t2 = p[71]*p1[71];   t3 = p[72]*p1[72];  t4 = p[73]*p1[73]; t5   = p[74]*p1[74];
		t6 = p[75]*p1[75];   t7 = p[76]*p1[76];   t8 = p[77]*p1[77];  t9 = p[78]*p1[78]; t10 = p[79]*p1[79];	   
		t0 +=  t1 + t2 + t3 + t4 + t5+t6+t7+t8+t9+t10;

	}


		pCorr[-i] = t0<<1;       
	}

    return;}


/*************************************************************************
 Function:   Convolve
 Purpose:
                 Perform the convolution between two vectors x[] and h[] and
                 write the result in the vector y[]. All vectors are of length L
                  and only the first L samples of the convolution are computed.
 
   Description:   The convolution is given byy[n] = sum_{i=0}^{n} x[i] h[n-i],        n=0,...,L-1
   Input:  
             x[] : input vector                       
             h[] : impulse response                 
             L    : vector size   
   Output:
            y[]  : output vector     
   Return:
 
 *************************************************************************/void Convolve (Word16 x[], Word16 h[],Word16 y[], Word16 L)
{
	Word16 i, n;
	Word32 s;
	Word16 *px = x, *ph = h, *py = y;

	for (n = 0; n < L; n++)
	{
		s = 0;           
		for (i = 0; i <= n; i++)
		{
			s += px[i]*ph[n-i];
		}      
		py[n] = (Word16)(s>>12);
	}
	return;
}
/*************************************************************************
   Function:   pre_big
   Purpose:    
   Description:
   Input:  
                 Mode mode           : coder mode                   
                 gamma1[]             : spectral exp. factor 1                
                 gamma1_12k2[]  : spectral exp. factor 1 for EFR    
                 gamma2[]             : spectral exp. factor 2              
                 frameOffset          : Start position in speech vector,   Q0 
                 speech[]                : speech,                            Q0  
                 mem_w[]              : synthesis filter memory state,     Q0  
   Output:
                 mem_w[]              : synthesis filter memory state,     Q0 
                 wsp[]                    : weighted speech                    Q0 
   Return:
 
 *************************************************************************/
int pre_big(Mode mode, const Word16 gamma1[], const Word16 gamma1_12k2[],const Word16 gamma2[], 
                    Word16 A_t[], Word16 frameOffset,  Word16 speech[],Word16 mem_w[], Word16 wsp[] )
{
	Word16 Ap1[MP1];            /* A(z) with spectral expansion              */
	Word16 Ap2[MP1];            /* A(z) with spectral expansion              */
	const Word16 *g1;           /* Pointer to correct gammma1 vector    */
	Word16 aOffset;


	Word16*pA_t = A_t,*pspeech = speech;
	Word16* pmem_w = mem_w, *pwsp = wsp;
	const Word16 * pgamma1 =gamma1, *pgamma2 = gamma2, *pgamma1_12k2 =  gamma1_12k2;

	g1        = ( mode<=  MR795) ? gamma1 : gamma1_12k2;     
	aOffset = (frameOffset > 0) ? 22 : 0;

	/* process two subframes (which form the "big" subframe) */

	Ap1[0] = pA_t[aOffset];                                  
	Ap1[1] = (Word16)(( (pA_t[1+aOffset]*g1[0] << 1) + 0x00008000L) >> 16) ;  
	Ap1[2] = (Word16)(( (pA_t[2+aOffset]*g1[1] << 1) + 0x00008000L) >> 16) ; 
	Ap1[3] = (Word16)(( (pA_t[3+aOffset]*g1[2] << 1) + 0x00008000L) >> 16) ; 
	Ap1[4] = (Word16)(( (pA_t[4+aOffset]*g1[3] << 1) + 0x00008000L) >> 16) ; 
	Ap1[5] = (Word16)(( (pA_t[5+aOffset]*g1[4] << 1) + 0x00008000L) >> 16) ; 
	Ap1[6] = (Word16)(( (pA_t[6+aOffset]*g1[5] << 1) + 0x00008000L) >> 16) ; 
	Ap1[7] = (Word16)(( (pA_t[7+aOffset]*g1[6] << 1) + 0x00008000L) >> 16) ; 
	Ap1[8] = (Word16)(( (pA_t[8+aOffset]*g1[7] << 1) + 0x00008000L) >> 16) ; 
	Ap1[9] = (Word16)(( (pA_t[9+aOffset]*g1[8] << 1) + 0x00008000L) >> 16) ; 
	Ap1[10] = (Word16)(( (pA_t[10+aOffset]*g1[9] << 1) + 0x00008000L) >> 16) ; 


	// Weight_Ai(&pA_t[aOffset], pgamma2, Ap2);
	Ap2[0] = pA_t[aOffset];                                  
	Ap2[1] = (Word16)(( (pA_t[1+aOffset]    *pgamma2[0] << 1) + 0x00008000L) >> 16) ;  
	Ap2[2] = (Word16)(( (pA_t[2+aOffset]    *pgamma2[1] << 1) + 0x00008000L) >> 16) ; 
	Ap2[3] = (Word16)(( (pA_t[3+aOffset]    *pgamma2[2] << 1) + 0x00008000L) >> 16) ; 
	Ap2[4] = (Word16)(( (pA_t[4+aOffset]    *pgamma2[3] << 1) + 0x00008000L) >> 16) ; 
	Ap2[5] = (Word16)(( (pA_t[5+aOffset]    *pgamma2[4] << 1) + 0x00008000L) >> 16) ; 
	Ap2[6] = (Word16)(( (pA_t[6+aOffset]    *pgamma2[5] << 1) + 0x00008000L) >> 16) ; 
	Ap2[7] = (Word16)(( (pA_t[7+aOffset]    *pgamma2[6] << 1) + 0x00008000L) >> 16) ; 
	Ap2[8] = (Word16)(( (pA_t[8+aOffset]    *pgamma2[7] << 1) + 0x00008000L) >> 16) ; 
	Ap2[9] = (Word16)(( (pA_t[9+aOffset]    *pgamma2[8] << 1) + 0x00008000L) >> 16) ; 
	Ap2[10] = (Word16)(( (pA_t[10+aOffset]*pgamma2[9] << 1) + 0x00008000L) >> 16) ; 

	Residu(Ap1, &pspeech[frameOffset], &pwsp[frameOffset], L_SUBFR);
	Syn_filt(Ap2, &pwsp[frameOffset], &pwsp[frameOffset], L_SUBFR, pmem_w, 1);


	//Weight_Ai(&A_t[aOffset+11], g1, Ap1);	  
	aOffset += 11;
	Ap1[0] = pA_t[aOffset];                                  
	Ap1[1] = (Word16)(( (pA_t[1+aOffset]*g1[0] << 1) + 0x00008000L) >> 16) ;  
	Ap1[2] = (Word16)(( (pA_t[2+aOffset]*g1[1] << 1) + 0x00008000L) >> 16) ; 
	Ap1[3] = (Word16)(( (pA_t[3+aOffset]*g1[2] << 1) + 0x00008000L) >> 16) ; 
	Ap1[4] = (Word16)(( (pA_t[4+aOffset]*g1[3] << 1) + 0x00008000L) >> 16) ; 
	Ap1[5] = (Word16)(( (pA_t[5+aOffset]*g1[4] << 1) + 0x00008000L) >> 16) ; 
	Ap1[6] = (Word16)(( (pA_t[6+aOffset]*g1[5] << 1) + 0x00008000L) >> 16) ; 
	Ap1[7] = (Word16)(( (pA_t[7+aOffset]*g1[6] << 1) + 0x00008000L) >> 16) ; 
	Ap1[8] = (Word16)(( (pA_t[8+aOffset]*g1[7] << 1) + 0x00008000L) >> 16) ; 
	Ap1[9] = (Word16)(( (pA_t[9+aOffset]*g1[8] << 1) + 0x00008000L) >> 16) ; 
	Ap1[10] = (Word16)(( (pA_t[10+aOffset]*g1[9] << 1) + 0x00008000L) >> 16) ; 


	// Weight_Ai(&A_t[aOffset+11], gamma2, Ap2); 
	Ap2[0] = pA_t[aOffset];                                  
	Ap2[1] = (Word16)(( (pA_t[1+aOffset]    *pgamma2[0] << 1) + 0x00008000L) >> 16) ;  
	Ap2[2] = (Word16)(( (pA_t[2+aOffset]    *pgamma2[1] << 1) + 0x00008000L) >> 16) ; 
	Ap2[3] = (Word16)(( (pA_t[3+aOffset]    *pgamma2[2] << 1) + 0x00008000L) >> 16) ; 
	Ap2[4] = (Word16)(( (pA_t[4+aOffset]    *pgamma2[3] << 1) + 0x00008000L) >> 16) ; 
	Ap2[5] = (Word16)(( (pA_t[5+aOffset]    *pgamma2[4] << 1) + 0x00008000L) >> 16) ; 
	Ap2[6] = (Word16)(( (pA_t[6+aOffset]    *pgamma2[5] << 1) + 0x00008000L) >> 16) ; 
	Ap2[7] = (Word16)(( (pA_t[7+aOffset]    *pgamma2[6] << 1) + 0x00008000L) >> 16) ; 
	Ap2[8] = (Word16)(( (pA_t[8+aOffset]    *pgamma2[7] << 1) + 0x00008000L) >> 16) ; 
	Ap2[9] = (Word16)(( (pA_t[9+aOffset]    *pgamma2[8] << 1) + 0x00008000L) >> 16) ; 
	Ap2[10] = (Word16)(( (pA_t[10+aOffset]*pgamma2[9] << 1) + 0x00008000L) >> 16) ; 

	Residu(Ap1, &pspeech[frameOffset+40], &pwsp[frameOffset+40], L_SUBFR);
	Syn_filt(Ap2, &pwsp[frameOffset+40], &pwsp[frameOffset+40], L_SUBFR, pmem_w, 1);
	return 0;
}

/*************************************************************************
   Function:   Residual
   Purpose:   comput residual signal 
   Description:
   Input:  
             a[] : prediction coefficients                    
             x[] : speech signal                              
             lg   : size of filtering                       
   Output:
             y[] : residual signal                     
   Return:
 
 *************************************************************************/
void Residu (Word16 a[],  Word16 x[], Word16 y[], Word16 lg )
{
	Word16 i;
	Word32 s1,s2;
	Word16 *pa = a, *px = x, *py = y;

	for (i = 0; i < 40; i++ )
	{
		s1 = px[i]*pa[0] + pa[1]*px[i - 1]+ pa[2]*px[i - 2]+ pa[3]*px[i - 3]+ pa[4]*px[i - 4]+ pa[5]*px[i - 5];
		s2 = pa[6]*px[i - 6]+ pa[7]*px[i - 7]+ pa[8]*px[i -8]+ pa[9]*px[i - 9]+ pa[10]*px[i - 10];	
		py[i]     = (Word16)((((s1+s2)<<4) + 0x00008000L) >> 16) ;  
	}
	return;
}/*************************************************************************
   Function:     syn_filt
   Purpose:     synthsis filting 
   Description:
   Input:  
           a[]         :   a[M+1] prediction coefficients   (M=10) 
           x[]         :   input signal                           
           lg           :   size of filtering                
           mem[]   :   memory associated with this filtering.
           update   :   0=no update, 1=update of memory.  
   Output:
             y[]       :   output signal                    
             mem[] :   memory associated with this filtering.
   Return:
 
 *************************************************************************/
void Syn_filt (Word16 a[], Word16 x[],   Word16 y[], Word16 lg,Word16 mem[], Word16 update  )
{
	Word16 i;
	Word32 s,temp1,temp2;
	Word16 tmp[80];              /* This is usually done by memory allocation (lg+M) */
	Word16 *yy;
	Word16 *pmem = mem, *pa =a, *px =x, *py = y;

	/* Copy mem[] to yy[] */
	yy = tmp;   
	yy[0] = pmem[0];     yy[1] = pmem[1];  yy[2] = pmem[2];  yy[3] = pmem[3];  yy[4] = pmem[4]; 
	yy[5] = pmem[5];     yy[6] = pmem[6];  yy[7] = pmem[7];  yy[8] = pmem[8];  yy[9] = pmem[9]; 
	yy+= 10;

	for (i = 0; i < 40; i++)
	{

		s = px[i]* pa[0];
		temp1 =  pa[1]*yy[-1] + pa[2]*yy[-2]+ pa[3]*yy[-3]+ pa[4]*yy[-4] +pa[5]*yy[-5];
		temp2 =  pa[6]*yy[-6] + pa[7]*yy[-7]+ pa[8]*yy[-8]+ pa[9]*yy[-9] + pa[10]*yy[-10];
		s -= temp1+temp2;
		*yy++ =  (Word16)(((s<<4) + 0x00008000L ) >> 16) ;       
	}
	memcpy(py, &tmp[10], 80 );
	
	/* Update of memory if update==1 */
	if (update != 0)
	{
		memcpy(pmem, &py[30], 20 );
	}
	return;
}


⌨️ 快捷键说明

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