?? encoder.cpp
字號:
/* Serialize Control info */
Bsp = Par2Ser( Temp, Bsp, 2 ) ;
/* Check for Speech/NonSpeech case */
if ( Ftyp == 1 ) {
/* 24 bit LspId */
Temp = (*Line).LspId ;
Bsp = Par2Ser( Temp, Bsp, 24 ) ;
/*
* Do the part common to both rates
*/
/* Adaptive code book lags */
Temp = (int) (*Line).Olp[0] - (int) PitchMin ;
Bsp = Par2Ser( Temp, Bsp, 7 ) ;
Temp = (int) (*Line).Sfs[1].AcLg ;
Bsp = Par2Ser( Temp, Bsp, 2 ) ;
Temp = (int) (*Line).Olp[1] - (int) PitchMin ;
Bsp = Par2Ser( Temp, Bsp, 7 ) ;
Temp = (int) (*Line).Sfs[3].AcLg ;
Bsp = Par2Ser( Temp, Bsp, 2 ) ;
/* Write combined 12 bit index of all the gains */
for ( i = 0 ; i < SubFrames ; i ++ ) {
Temp = (*Line).Sfs[i].AcGn*NumOfGainLev + (*Line).Sfs[i].Mamp ;
if ( WrkRate == Rate63 )
Temp += (int) (*Line).Sfs[i].Tran << 11 ;
Bsp = Par2Ser( Temp, Bsp, 12 ) ;
}
/* Write all the Grid indices */
for ( i = 0 ; i < SubFrames ; i ++ )
*Bsp ++ = (short)(*Line).Sfs[i].Grid ;
/* High rate only part */
if ( WrkRate == Rate63 ) {
/* Write the reserved bit as 0 */
*Bsp ++ = (short) 0 ;
/* Write 13 bit combined position index */
Temp = (*Line).Sfs[0].Ppos >> 16 ;
Temp = Temp * 9 + ( (*Line).Sfs[1].Ppos >> 14) ;
Temp *= 90 ;
Temp += ((*Line).Sfs[2].Ppos >> 16) * 9 + ( (*Line).Sfs[3].Ppos >> 14 ) ;
Bsp = Par2Ser( Temp, Bsp, 13 ) ;
/* Write all the pulse positions */
Temp = (*Line).Sfs[0].Ppos & 0x0000ffffL ;
Bsp = Par2Ser( Temp, Bsp, 16 ) ;
Temp = (*Line).Sfs[1].Ppos & 0x00003fffL ;
Bsp = Par2Ser( Temp, Bsp, 14 ) ;
Temp = (*Line).Sfs[2].Ppos & 0x0000ffffL ;
Bsp = Par2Ser( Temp, Bsp, 16 ) ;
Temp = (*Line).Sfs[3].Ppos & 0x00003fffL ;
Bsp = Par2Ser( Temp, Bsp, 14 ) ;
/* Write pulse amplitudes */
Temp = (int) (*Line).Sfs[0].Pamp ;
Bsp = Par2Ser( Temp, Bsp, 6 ) ;
Temp = (int) (*Line).Sfs[1].Pamp ;
Bsp = Par2Ser( Temp, Bsp, 5 ) ;
Temp = (int) (*Line).Sfs[2].Pamp ;
Bsp = Par2Ser( Temp, Bsp, 6 ) ;
Temp = (int) (*Line).Sfs[3].Pamp ;
Bsp = Par2Ser( Temp, Bsp, 5 ) ;
}
/* Low rate only part */
else {
/* Write 12 bits of positions */
for ( i = 0 ; i < SubFrames ; i ++ ) {
Temp = (*Line).Sfs[i].Ppos ;
Bsp = Par2Ser( Temp, Bsp, 12 ) ;
}
/* Write 4 bit Pamps */
for ( i = 0 ; i < SubFrames ; i ++ ) {
Temp = (*Line).Sfs[i].Pamp ;
Bsp = Par2Ser( Temp, Bsp, 4 ) ;
}
}
}
else if (Ftyp == 2) { /* SID frame */
/* 24 bit LspId */
Temp = (*Line).LspId ;
Bsp = Par2Ser( Temp, Bsp, 24 ) ;
/* Do Sid frame gain */
Temp = (int)(*Line).Sfs[0].Mamp ;
Bsp = Par2Ser( Temp, Bsp, 6 ) ;
}
/* Write out active frames */
if (Ftyp == 1) {
if ( WrkRate == Rate63 )
BitCount = 192;
else
BitCount = 160;
}
/* Non active frames */
else if (Ftyp == 2)
BitCount = 32;
else
BitCount = 2;
for ( i = 0 ; i < BitCount ; i ++ )
Vout[i>>3] ^= BitStream[i] << (i & 0x0007) ;
}
/*
**
** Function: Find_Fcbk()
**
** Description: Fixed codebook excitation computation.
**
**
** Links to text: Sections 2.15 & 2.16
**
** Arguments:
**
** float *Dpnt Target vector
** float *ImpResp Impulse response of the synthesis filter
** LineDef *Line Excitation parameters for one subframe
** int Sfc Subframe index
**
** Outputs:
**
** float *Dpnt Excitation vector
** LINEDEF *Line Fixed codebook parameters for one subframe
**
** Return value: None
**
*/
void CLanAudioEncoder::Find_Fcbk(float *Dpnt, float *ImpResp, LINEDEF *Line, int Sfc)
{
int i;
int Srate, T0_acelp;
float gain_T0;
BESTDEF Best;
switch(WrkRate)
{
case Rate63:
Srate = Nb_puls[Sfc];
Best.MaxErr = (float)(-99999999.9);
Find_Best(&Best, Dpnt, ImpResp, Srate, SubFrLen);
if ((*Line).Olp[Sfc>>1] < SubFrLen-2)
Find_Best(&Best, Dpnt, ImpResp, Srate, (*Line).Olp[Sfc>>1]);
else
Find_Best(&Best, Dpnt, ImpResp, Srate, SubFrLen);
/* Reconstruct the excitation */
for (i=0; i < SubFrLen; i++)
Dpnt[i] = (float)0.0;
for (i=0; i < Srate; i++)
Dpnt[Best.Ploc[i]] = Best.Pamp[i];
/* Code the excitation */
Fcbk_Pack(Dpnt, &((*Line).Sfs[Sfc]), &Best, Srate);
if (Best.UseTrn == 1)
Gen_Trn(Dpnt, Dpnt, (*Line).Olp[Sfc>>1]);
break;
case Rate53:
T0_acelp = search_T0 ( (short) ((*Line).Olp[Sfc>>1]-1+(*Line).Sfs[Sfc].AcLg),
(*Line).Sfs[Sfc].AcGn, &gain_T0);
(*Line).Sfs[Sfc].Ppos = ACELP_LBC_code(Dpnt, ImpResp, T0_acelp, Dpnt,
&(*Line).Sfs[Sfc].Mamp,
&(*Line).Sfs[Sfc].Grid,
&(*Line).Sfs[Sfc].Pamp, gain_T0);
(*Line).Sfs[Sfc].Tran = 0;
break;
}
return;
}
/*
**
** Function: D4i64_LBC
**
** Description: Algebraic codebook for LBC.
** -> 17 bits; 4 pulses in a frame of 60 samples
**
** The code length is 60, containing 4 nonzero pulses
** i0, i1, i2, i3. Each pulse can have 8 possible
** positions (positive or negative):
**
** i0 (+-1) : 0, 8, 16, 24, 32, 40, 48, 56
** i1 (+-1) : 2, 10, 18, 26, 34, 42, 50, 58
** i2 (+-1) : 4, 12, 20, 28, 36, 44, 52, (60)
** i3 (+-1) : 6, 14, 22, 30, 38, 46, 54, (62)
**
** All the pulse can be shifted by one.
** The last position of the last 2 pulses falls outside the
** frame and signifies that the pulse is not present.
** The threshold controls if a section of the innovative
** codebook should be searched or not.
**
** Links to the text: Section 2.16
**
** Input arguments:
**
** float Dn[] Correlation between target vector & impulse resp h[]
** float rr[] Correlations of impulse response h[]
** float h[] Impulse response of filters
**
** Output arguments:
**
** float cod[] Selected algebraic codeword
** float y[] Filtered codeword
** int code_shift Shift of the codeword
** int sign Signs of the 4 pulses.
**
** Return value:
**
** int Index of selected codevector
**
*/
int CLanAudioEncoder::D4i64_LBC(float Dn[], float rr[], float h[], float cod[],
float y[], int *code_shift, int *sign)
{
int i0, i1, i2, i3, ip0, ip1, ip2, ip3;
int i, j, time;
int shif, shift;
float ps0, ps1, ps2, ps3;
float alp0, alp1, alp2, alp3;
float ps0a, ps1a, ps2a;
float ps3c, psc, alpha;
float means, max0, max1, max2, thres;
float *rri0i0,*rri1i1,*rri2i2,*rri3i3;
float *rri0i1,*rri0i2,*rri0i3;
float *rri1i2,*rri1i3,*rri2i3;
float *ptr_ri0i0,*ptr_ri1i1,*ptr_ri2i2,*ptr_ri3i3;
float *ptr_ri0i1,*ptr_ri0i2,*ptr_ri0i3;
float *ptr_ri1i2,*ptr_ri1i3,*ptr_ri2i3;
float temp1,temp2,apre;
int ii;
int p_sign[SubFrLen2/2],p_sign2[SubFrLen2/2];
/* Init pointers */
rri0i0 = rr;
rri1i1 = rri0i0 + NB_POS;
rri2i2 = rri1i1 + NB_POS;
rri3i3 = rri2i2 + NB_POS;
rri0i1 = rri3i3 + NB_POS;
rri0i2 = rri0i1 + MSIZE;
rri0i3 = rri0i2 + MSIZE;
rri1i2 = rri0i3 + MSIZE;
rri1i3 = rri1i2 + MSIZE;
rri2i3 = rri1i3 + MSIZE;
/* Extend the backward filtered target vector by zeros */
for (i=SubFrLen; i < SubFrLen2; i++)
Dn[i] = (float)0.0;
/* Chose the sign of the impulse. */
for (i=0; i<SubFrLen; i+=2)
{
if ((Dn[i] + Dn[i+1]) >= (float)0.0)
{
p_sign[i/2] = 1;
p_sign2[i/2] = 2;
}
else
{
p_sign[i/2] = -1;
p_sign2[i/2] = -2;
Dn[i] = -Dn[i];
Dn[i+1] = -Dn[i+1];
}
}
p_sign[30] = p_sign[31] = 1;
p_sign2[30] = p_sign2[31] = 2;
/* - Compute the search threshold after three pulses */
/* odd positions */
/* Find maximum of Dn[i0]+Dn[i1]+Dn[i2] */
max0 = Dn[0];
max1 = Dn[2];
max2 = Dn[4];
for (i=8; i < SubFrLen; i+=STEP)
{
if (Dn[i] > max0)
max0 = Dn[i];
if (Dn[i+2] > max1)
max1 = Dn[i+2];
if (Dn[i+4] > max2)
max2 = Dn[i+4];
}
max0 = max0 + max1 + max2;
/* Find means of Dn[i0]+Dn[i1]+Dn[i] */
means = (float)0.0;
for (i=0; i < SubFrLen; i+=STEP)
means += Dn[i+4] + Dn[i+2] + Dn[i];
means *= (float)0.125;
thres = means + (max0-means)*(float)0.5;
thres = (float)(thres *1.2);
/* even positions */
/* Find maximum of Dn[i0]+Dn[i1]+Dn[i2] */
/*max0 = Dn[1];
max1 = Dn[3];
max2 = Dn[5];
for (i=9; i < SubFrLen; i+=STEP)
{
if (Dn[i] > max0)
max0 = Dn[i];
if (Dn[i+2] > max1)
max1 = Dn[i+2];
if (Dn[i+4] > max2)
max2 = Dn[i+4];
}
max0 = max0 + max1 + max2;
/* Find means of Dn[i0]+Dn[i1]+Dn[i2] */
/* means = (float)0.0;
for (i=1; i < SubFrLen; i+=STEP)
means += Dn[i+4] + Dn[i+2] + Dn[i];
means *= (float)0.125;
max1 = means + (max0-means)*(float)0.5;
/* Keep maximum threshold between odd and even position */
/* if (max1 > thres)
thres = max1;
/* Modification of rrixiy[] to take signs into account. */
ptr_ri0i1 = rri0i1;
ptr_ri0i2 = rri0i2;
ptr_ri0i3 = rri0i3;
for (i0=0; i0<SubFrLen/2; i0+=STEP/2)
{
if(p_sign[i0]==-1)
{
for (i1=2/2; i1<SubFrLen/2; i1+=STEP/2)
{
*ptr_ri0i1++ *= - p_sign2[i1];
*ptr_ri0i2++ *= - p_sign2[i1+1];
*ptr_ri0i3++ *= - p_sign2[i1+2];
}
}
else
{
for (i1=2/2; i1<SubFrLen/2; i1+=STEP/2)
{
*ptr_ri0i1++ *= p_sign2[i1];
*ptr_ri0i2++ *= p_sign2[i1+1];
*ptr_ri0i3++ *= p_sign2[i1+2];
}
}
}
ptr_ri1i2 = rri1i2;
ptr_ri1i3 = rri1i3;
for (i1=2/2; i1<SubFrLen/2; i1+=STEP/2)
{
if(p_sign[i1]==-1)
{
for (i2=4/2; i2<SubFrLen2/2; i2+=STEP/2)
{
*ptr_ri1i2++ *= -p_sign2[i2];
*ptr_ri1i3++ *= -p_sign2[i2+1];
}
}
else
{
for (i2=4/2; i2<SubFrLen2/2; i2+=STEP/2)
{
*ptr_ri1i2++ *= p_sign2[i2];
*ptr_ri1i3++ *= p_sign2[i2+1];
}
}
}
ptr_ri2i3 = rri2i3;
for (i2=4/2; i2<SubFrLen2/2; i2+=STEP/2)
{
if(p_sign[i2]==-1)
{
for (i3=6/2; i3<SubFrLen2/2; i3+=STEP/2)
*ptr_ri2i3++ *= - p_sign2[i3];
}
else
{
for (i3=6/2; i3<SubFrLen2/2; i3+=STEP/2)
*ptr_ri2i3++ *= p_sign2[i3];
}
}
/*-------------------------------------------------------------------
* Search the optimum positions of the four pulses which maximize
* square(correlation) / energy
* The search is performed in four nested loops. At each loop, one
* pulse contribution is added to the correlation and energy.
*
* The fourth loop is entered only if the correlation due to the
* contribution of the first three pulses exceeds the preset
* threshold.
*/
/* Default values */
ip0 = 0;
ip1 = 2;
ip2 = 4;
ip3 = 6;
shif = 0;
psc = (float)0.0;
alpha = (float)1.0;
time = max_time + extra;
/* Four loops to search innovation code. */
/* Init. pointers that depend on first loop */
ptr_ri0i0 = rri0i0;
ptr_ri0i1 = rri0i1;
ptr_ri0i2 = rri0i2;
ptr_ri0i3 = rri0i3;
/* first pulse loop */
temp2=Dn[0]*Dn[0];
ii=0;
apre = *ptr_ri0i0++;
for(i0=8;i0<SubFrLen;i0+=STEP)
{
alp0 = *ptr_ri0i0++;
temp1=Dn[i0]*Dn[i0];
if(temp1*apre>temp2*alp0)
{
ii=i0;
apre=alp0;
temp2=temp1;
}
}
ptr_ri0i0 = rri0i0;
ii=ii-STEP;
if(ii<0) ii=0;
for (i0=ii; i0 <=ii+STEP; i0 +=STEP)
{
ps0 = Dn[i0];
ps0a = Dn[i0+1];
alp0 = *ptr_ri0i0++;
/* Init. pointers that depend on second loop */
ptr_ri1i1 = rri1i1;
ptr_ri1i2 = rri1i2;
ptr_ri1i3 = rri1i3;
/* second pulse loop */
for (i1=2; i1 < SubFrLen; i1 +=STEP)
{
ps1 = ps0 + Dn[i1];
ps1a = ps0a + Dn[i1+1];
alp1 = alp0 + *ptr_ri1i1++ + *ptr_ri0i1++;
/* Init. pointers that depend on third loop */
ptr_ri2i2 = rri2i2;
ptr_ri2i3 = rri2i3;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -