📄 autocorr.c
字号:
b1_h = b0_h;
t0 = (b1_h*xmid +( b1_l*xmid >>15 ))<< 2 ;
t0 -= (b2_h<<16) + (b2_l<<1);
t0 += coef[4]<<14;
b0_h = (Word16)(t0 >>16);
b0_l = (t0 - (b0_h<<16))>>1;
b2_l = b1_l;
b2_h = b1_h;
b1_l = b0_l;
b1_h = b0_h;
t0 = (b1_h*xmid+ ( b1_l*xmid >>15 ))<<1;
t0 -= (b2_h<<16) + (b2_l<<1);
t0 += coef[5] << 13;
t0 = ( t0 > (Word32)0x1ffffff) ? MAX_32: (t0 < (Word32)0xfe000000 ? MIN_32: t0 << 6);
ymid = (Word16)(t0 >>16);
if (ylow* ymid <= 0L)
{
yhigh = ymid;
xhigh = xmid;
}
else
{
ylow = ymid;
xlow = xmid;
}
}
/*-------------------------------------------------------------*
* Linear interpolation *
* xint = xlow - ylow*(xhigh-xlow)/(yhigh-ylow); *
*-------------------------------------------------------------*/
x = (xhigh-xlow);
y = (yhigh- ylow);
if (y == 0)
{
xint = xlow;
}
else
{
sign = y;
y = y>0 ? y : -y;
// exp = norm_s (y);
temp = y;
for (exp = 0; temp < 0x4000; exp++)
temp <<= 1;
y <<= exp ;
// y = div_s ((Word16) 16383, y);
if (16383 == y)
{
y = MAX_16;
}
else
{
temp = 0;
L_num = (Word32) 16383;
L_denom = (Word32)y;
for (k = 0; k < 15; k++)
{
temp <<= 1;
L_num <<= 1;
temp = L_num >= L_denom ? temp+1 : temp;
L_num = L_num >= L_denom ?L_num -L_denom : L_num;
}
y = temp;
}
t0 = (x* y<<1);
t0 = t0>> (20- exp) ;
y = (Word16)t0 ; /* y= (xhigh-xlow)/(yhigh-ylow) */
if (sign < 0)
y = (y == MIN_16) ? MAX_16:-y;
t0 = (ylow* y <<1 );
t0 = (t0>> 11);
xint = (xlow - (Word16) t0); /* xint = xlow - ylow*y */
}
plsp[nf] = xint;
xlow = xint;
nf++;
coef = (ip== 0)? f2 :f1;
ip = (ip== 0);
//ylow = Chebps (xlow, coef, NC);
b2_h = 256;
b2_l = 0;
t0 = (xlow<<10);
t0 += coef[1]<<14 ;
b1_h = (Word16)(t0>>16);
b1_l = (t0 - (b1_h<<16))>>1;
t0 = (b1_h*xlow +( b1_l*xlow>>15 ))<< 2 ;
t0 -= (b2_h<<16) + (b2_l<<1);
t0 += coef[2]<<14;
b0_h = (Word16)(t0 >>16);
b0_l = (t0 - (b0_h<<16))>>1;
b2_l = b1_l;
b2_h = b1_h;
b1_l = b0_l;
b1_h = b0_h;
t0 = (b1_h*xlow +( b1_l*xlow>>15 ))<< 2 ;
t0 -= (b2_h<<16) + (b2_l<<1);
t0 += coef[3]<<14;
b0_h = (Word16)(t0 >>16);
b0_l = (t0 - (b0_h<<16))>>1;
b2_l = b1_l;
b2_h = b1_h;
b1_l = b0_l;
b1_h = b0_h;
t0 = (b1_h*xlow +( b1_l*xlow >>15 ))<< 2 ;
t0 -= (b2_h<<16) + (b2_l<<1);
t0 += coef[4]<<14;
b0_h = (Word16)(t0 >>16);
b0_l = (t0 - (b0_h<<16))>>1;
b2_l = b1_l;
b2_h = b1_h;
b1_l = b0_l;
b1_h = b0_h;
t0 = (b1_h*xlow+ ( b1_l*xlow >>15 ))<<1;
t0 -= (b2_h<<16) + (b2_l<<1);
t0 += coef[5] << 13;
t0 = ( t0 > (Word32)0x1ffffff) ? MAX_32: (t0 < (Word32)0xfe000000 ? MIN_32: t0 << 6);
ylow = (Word16)(t0 >>16);
}
}
/* Check if M roots found */
if ((nf < M))
{
memcpy(plsp, pold_lsp, 20);
}
return;
}
/*************************************************************************
Function : cor_h_x2()
Purpose : Computes correlation between target signal "x[]" andimpulse response"h[]".
Description :
See cor_h_x, d[n] can be normalized regards to sum of the
five MR122 maxima or the four MR102 maxima.
Input:
h[] : impulse response of weighted synthesis filter
x[] : target
sf : scaling factor: 2 for 12.2, 1 for others
nb_track : the number of ACB tracks
step : step size from one pulse position to the next in one track
Output:
dn[] : correlation between target and h[]
Return:
*************************************************************************/void cor_h_x2 ( Word16 h[], Word16 x[], Word16 dn[],Word16 sf,Word16 nb_track, Word16 step)
{
Word16 i, j, k; Word32 s, y32[L_CODE], max, tot; Word16 *px,*ph,*pdn;
px = x;ph =h;pdn =dn;
/* first keep the result on 32 bits and find absolute maximum */
tot = 5; for (k = 0; k < nb_track; k++) { max = 0; for (i = k; i < L_CODE; i += step) { s = 0; for (j = i; j < L_CODE; j++)
s += px[j]*ph[j - i] << 1;
y32[i] = s; s = s < 0 ? -s : s; if (s > max ) max = s; } tot += max>> 1; } j = norm_l (tot) -sf; for (i = 0; i < L_CODE; i+=4 )
{ y32[i] = j>0 ? y32[i] << j : y32[i] >>( -j);
y32[i+1] = j>0 ? y32[i+1] << j : y32[i+1] >>( -j);
y32[i+2] = j>0 ? y32[i+2] << j : y32[i+2] >>( -j);
y32[i+3] = j>0 ? y32[i+3] << j : y32[i+3] >>( -j);
pdn[i] = (y32[i] + 0x00008000) >> 16 ;
pdn[i+1] = (y32[i+1] + 0x00008000) >> 16 ;
pdn[i+2] = (y32[i+2] + 0x00008000) >> 16 ;
pdn[i+3] = (y32[i+3] + 0x00008000) >> 16 ;
}
}/*************************************************************************
Function : cor_h()
Purpose: Computes correlations of h[] needed for the codebook search;
and includes the sign information into the correlations.
Description: The correlations are given by
rr[i][j] = sum_{n=i}^{L-1} h[n-i] h[n-j]; i>=j; i,j=0,...,L-1
and the sign information is included by
rr[i][j] = rr[i][j]*sign[i]*sign[j]
Input:
h[] : impulse response of weighted synthesis filter
sign[] : sign of d[n]
Output:
rr[][L_CODE] : matrix of autocorrelation
Retrun:
*************************************************************************/void cor_h ( Word16 h[], Word16 sign[], Word16 rr[][L_CODE])
{
Word16 i, j, k,h2[L_CODE];
Word32 s;
Word16 *ph = h, *psign = sign;
/* Scaling for maximum precision */ s = 2;
for (i = 0; i < L_CODE; i++)
{
s += ph[i]* ph[i]<< 1;
if(s < 0) break;
}
if (s < 0) {
h2[0] = ph[0]>>1; h2[1] = ph[1]>>1; h2[2] = ph[2]>>1; h2[3] = ph[3]>>1; h2[4] = ph[4]>>1;
h2[5] = ph[5]>>1; h2[6] = ph[6]>>1; h2[7] = ph[7]>>1; h2[8] = ph[8]>>1; h2[9] = ph[9]>>1;
h2[10] = ph[10]>>1; h2[11] = ph[11]>>1; h2[12] = ph[12]>>1; h2[13] = ph[13]>>1; h2[14] = ph[14]>>1;
h2[15] = ph[15]>>1; h2[16] = ph[16]>>1; h2[17] = ph[17]>>1; h2[18] = ph[18]>>1; h2[19] = ph[19]>>1;
h2[20] = ph[20]>>1; h2[21] = ph[21]>>1; h2[22] = ph[22]>>1; h2[23] = ph[23]>>1; h2[24] = ph[24]>>1;
h2[25] = ph[25]>>1; h2[26] = ph[26]>>1; h2[27] = ph[27]>>1; h2[28] = ph[28]>>1; h2[29] = ph[29]>>1;
h2[30] = ph[30]>>1; h2[31] = ph[31]>>1; h2[32] = ph[32]>>1; h2[33] = ph[33]>>1; h2[34] = ph[34]>>1;
h2[35] = ph[35]>>1; h2[36] = ph[36]>>1; h2[37] = ph[37]>>1; h2[38] = ph[38]>>1; h2[39] = ph[39]>>1;
} else { s >>= 1 ;
k = (Word16)(Inv_sqrt (s)>> 9 );
k = ( k* 32440 >> 15 ) ;
h2[0] = ((ph[0]* k << 10 ) + 0x00008000) >> 16 ; h2[1] = ((ph[1]* k << 10 ) + 0x00008000) >> 16 ;
h2[2] = ((ph[2]* k << 10 ) + 0x00008000) >> 16 ; h2[3] = ((ph[3]* k << 10 ) + 0x00008000) >> 16 ;
h2[4] = ((ph[4]* k << 10 ) + 0x00008000) >> 16 ; h2[5] = ((ph[5]* k << 10 ) + 0x00008000) >> 16 ;
h2[6] = ((ph[6]* k << 10 ) + 0x00008000) >> 16 ; h2[7] = ((ph[7]* k << 10 ) + 0x00008000) >> 16 ;
h2[8] = ((ph[8]* k << 10 ) + 0x00008000) >> 16 ; h2[9] = ((ph[9]* k << 10 ) + 0x00008000) >> 16 ;
h2[10] = ((ph[10]* k << 10 ) + 0x00008000) >> 16 ; h2[11] = ((ph[11]* k << 10 ) + 0x00008000) >> 16 ;
h2[12] = ((ph[12]* k << 10 ) + 0x00008000) >> 16 ; h2[13] = ((ph[13]* k << 10 ) + 0x00008000) >> 16 ;
h2[14] = ((ph[14]* k << 10 ) + 0x00008000) >> 16 ; h2[15] = ((ph[15]* k << 10 ) + 0x00008000) >> 16 ;
h2[16] = ((ph[16]* k << 10 ) + 0x00008000) >> 16 ; h2[17] = ((ph[17]* k << 10 ) + 0x00008000) >> 16 ;
h2[18] = ((ph[18]* k << 10 ) + 0x00008000) >> 16 ; h2[19] = ((ph[19]* k << 10 ) + 0x00008000) >> 16 ;
h2[20] = ((ph[20]* k << 10 ) + 0x00008000) >> 16 ; h2[21] = ((ph[21]* k << 10 ) + 0x00008000) >> 16 ;
h2[22] = ((ph[22]* k << 10 ) + 0x00008000) >> 16 ; h2[23] = ((ph[23]* k << 10 ) + 0x00008000) >> 16 ;
h2[24] = ((ph[24]* k << 10 ) + 0x00008000) >> 16 ; h2[25] = ((ph[25]* k << 10 ) + 0x00008000) >> 16 ;
h2[26] = ((ph[26]* k << 10 ) + 0x00008000) >> 16 ; h2[27] = ((ph[27]* k << 10 ) + 0x00008000) >> 16 ;
h2[28] = ((ph[28]* k << 10 ) + 0x00008000) >> 16 ; h2[29] = ((ph[29]* k << 10 ) + 0x00008000) >> 16 ;
h2[30] = ((ph[30]* k << 10 ) + 0x00008000) >> 16 ; h2[31] = ((ph[31]* k << 10 ) + 0x00008000) >> 16 ;
h2[32] = ((ph[32]* k << 10 ) + 0x00008000) >> 16 ; h2[33] = ((ph[33]* k << 10 ) + 0x00008000) >> 16 ;
h2[34] = ((ph[34]* k << 10 ) + 0x00008000) >> 16 ; h2[35] = ((ph[35]* k << 10 ) + 0x00008000) >> 16 ;
h2[36] = ((ph[36]* k << 10 ) + 0x00008000) >> 16 ; h2[37] = ((ph[37]* k << 10 ) + 0x00008000) >> 16 ;
h2[38] = ((ph[38]* k << 10 ) + 0x00008000) >> 16 ; h2[39] = ((ph[39]* k << 10 ) + 0x00008000) >> 16 ;
} /* build matrix rr[] */
s = 0;
s += h2[0]*h2[0]; rr[39][39] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[1]*h2[1]; rr[38][38] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[2]*h2[2]; rr[37][37] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[3]*h2[3]; rr[36][36] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[4]*h2[4]; rr[35][35] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[5]*h2[5]; rr[34][34] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[6]*h2[6]; rr[33][33] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[7]*h2[7]; rr[32][32] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[8]*h2[8]; rr[31][31] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[9]*h2[9]; rr[30][30] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[10]*h2[10]; rr[29][29] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[11]*h2[11]; rr[28][28] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[12]*h2[12]; rr[27][27] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[13]*h2[13]; rr[26][26] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[14]*h2[14]; rr[25][25] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[15]*h2[15]; rr[24][24] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[16]*h2[16]; rr[23][23] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[17]*h2[17]; rr[22][22] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[18]*h2[18]; rr[21][21] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[19]*h2[19]; rr[20][20] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[20]*h2[20]; rr[19][19] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[21]*h2[21]; rr[18][18] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[22]*h2[22]; rr[17][17] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[23]*h2[23]; rr[16][16] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[24]*h2[24]; rr[15][15] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[25]*h2[25]; rr[14][14] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[26]*h2[26]; rr[13][13] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[27]*h2[27]; rr[12][12] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[28]*h2[28]; rr[11][11] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[29]*h2[29]; rr[10][10] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[30]*h2[30]; rr[9][9] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[31]*h2[31]; rr[8][8] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[32]*h2[32]; rr[7][7] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[33]*h2[33]; rr[6][6] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[34]*h2[34]; rr[5][5] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[35]*h2[35]; rr[4][4] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[36]*h2[36]; rr[3][3] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[37]*h2[37]; rr[2][2] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[38]*h2[38]; rr[1][1] = ((s<<1) + 0x00008000) >> 16 ;
s += h2[39]*h2[39]; rr[0][0] = ((s<<1) + 0x00008000) >> 16 ;
s = 0;
j = 39;
i =38 ;
for (k = 0; k < 39; k++, i--, j--)
{
s += h2[k]*h2[k + 1] << 1;
rr[i][j] = rr[j][i] = ((s+ 0x00008000)>> 16 ) * (psign[i]*psign[j] >> 15 ) >> 15 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -