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

📄 exc_lbc.c

📁 嵌入式linux系统的网络编程(C++) 在ARM上实现视频会议 此程序获得全国研究生电子大赛一等奖 压缩包内为全部源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    Exp = norm_l( Acc1 ) ;    for ( i = 0 ; i < 5 ; i ++ ) {        Acc0 = L_shl( Lcr[i], Exp ) ;        Scr[i] = extract_h( Acc0 ) ;    }    /* Select the best pair */    if ( (Bindx != (Word16) 0) && ( Findx == (Word16) 0) )        Pf = Get_Ind( Bindx, Scr[0], Scr[1], Scr[2] ) ;    if ( (Bindx == (Word16) 0) && ( Findx != (Word16) 0) )        Pf = Get_Ind( Findx, Scr[0], Scr[3], Scr[4] ) ;    if ( (Bindx != (Word16) 0) && ( Findx != (Word16) 0) ) {        Exp = mult_r( Scr[1], Scr[1] ) ;        Acc0 = L_mult( Exp, Scr[4] ) ;        Exp = mult_r( Scr[3], Scr[3] ) ;        Acc1 = L_mult( Exp, Scr[2] ) ;        if ( Acc0 > Acc1 )            Pf = Get_Ind( Bindx, Scr[0], Scr[1], Scr[2] ) ;        else            Pf = Get_Ind( Findx, Scr[0], Scr[3], Scr[4] ) ;    }    return Pf ;}/***** Function:        Find_B()**** Description:     Computes best pitch postfilter backward lag by**                  backward cross correlation maximization around the**                  decoded pitch lag**                  of the subframe 0 (for subframes 0 & 1)**                  of the subframe 2 (for subframes 2 & 3)**** Links to text:   Section 3.6**** Arguments:****  Word16 *Buff    decoded excitation**  Word16 Olp      Decoded pitch lag**  Word16 Sfc      Subframe index**** Outputs:     None**** Return value:****  Word16   Pitch postfilter backward lag*/Word16   Find_B( Word16 *Buff, Word16 Olp, Word16 Sfc ){    int   i,j   ;    Word16   Indx = 0 ;    Word32   Acc0,Acc1 ;    if ( Olp > (Word16) (PitchMax-3) )        Olp = (Word16) (PitchMax-3) ;    Acc1 = (Word32) 0 ;    for ( i = (int)Olp-3 ; i <= (int)Olp+3 ; i ++ ) {        Acc0 = (Word32) 0 ;        for ( j = 0 ; j < SubFrLen ; j ++ )            Acc0 = L_mac( Acc0, Buff[PitchMax+(int)Sfc*SubFrLen+j],                                    Buff[PitchMax+(int)Sfc*SubFrLen-i+j] ) ;        if ( Acc0 > Acc1 ) {            Acc1 = Acc0 ;            Indx = -(Word16) i ;        }    }    return Indx ;}/***** Function:        Find_F()**** Description:     Computes best pitch postfilter forward lag by**                  forward cross correlation maximization around the**                  decoded pitch lag**                  of the subframe 0 (for subframes 0 & 1)**                  of the subframe 2 (for subframes 2 & 3)**** Links to text:   Section 3.6**** Arguments:****  Word16 *Buff    decoded excitation**  Word16 Olp      Decoded pitch lag**  Word16 Sfc      Subframe index**** Outputs:     None**** Return value:****  Word16    Pitch postfilter forward lag*/Word16   Find_F( Word16 *Buff, Word16 Olp, Word16 Sfc ){    int   i,j   ;    Word16   Indx = 0 ;    Word32   Acc0,Acc1 ;    if ( Olp > (Word16) (PitchMax-3) )        Olp = (Word16) (PitchMax-3) ;    Acc1 = (Word32) 0 ;    for ( i = Olp-3 ; i <= Olp+3 ; i ++ ) {        Acc0 = (Word32) 0 ;        if ( ((int)Sfc*SubFrLen+SubFrLen+i) <= Frame ) {            for ( j = 0 ; j < SubFrLen ; j ++ )                Acc0 = L_mac( Acc0, Buff[PitchMax+(int)Sfc*SubFrLen+j],                            Buff[PitchMax+(int)Sfc*SubFrLen+i+j] ) ;        }        if ( Acc0 > Acc1 ) {            Acc1 = Acc0 ;            Indx = (Word16) i ;        }    }    return Indx ;}/***** Function:        Get_Ind()**** Description:     Computes gains of the pitch postfilter.**                  The gains are calculated using the cross correlation**                  (forward or backward, the one with the greatest contribution)**                  and the energy of the signal. Also, a test is performed on**                  the prediction gain to see whether the pitch postfilter**                  should be used or not.******** Links to text:   Section 3.6**** Arguments:****  Word16 Ind      Pitch postfilter lag**  Word16 Ten      energy of the current subframe excitation vector**  Word16 Ccr      Crosscorrelation of the excitation**  Word16 Enr      Energy of the (backward or forward) "delayed" excitation**** Outputs:     None**** Return value:****  PFDEF**         Word16   Indx    Pitch postfilter lag**         Word16   Gain    Pitch postfilter gain**         Word16   ScGn    Pitch postfilter scaling gain***/PFDEF Get_Ind( Word16 Ind, Word16 Ten, Word16 Ccr, Word16 Enr ){    Word32   Acc0,Acc1 ;    Word16   Exp   ;    PFDEF Pf ;    Pf.Indx = Ind ;    /* Check valid gain */    Acc0 = L_mult( Ten, Enr ) ;    Acc0 = L_shr( Acc0, (Word16) 2 ) ;    Acc1 = L_mult( Ccr, Ccr ) ;    if ( Acc1 > Acc0 ) {        if ( Ccr >= Enr )            Pf.Gain = LpfConstTable[(int)WrkRate] ;        else {            Pf.Gain = div_s( Ccr, Enr ) ;            Pf.Gain = mult( Pf.Gain, LpfConstTable[(int)WrkRate] ) ;        }        /* Compute scaling gain */        Acc0 = L_deposit_h( Ten ) ;        Acc0 = L_shr( Acc0, (Word16) 1 ) ;        Acc0 = L_mac( Acc0, Ccr, Pf.Gain ) ;        Exp  = mult( Pf.Gain, Pf.Gain ) ;        Acc1 = L_mult( Enr, Exp ) ;        Acc1 = L_shr( Acc1, (Word16) 1 ) ;        Acc0 = L_add( Acc0, Acc1 ) ;        Exp = round( Acc0 ) ;        Acc1 = L_deposit_h( Ten ) ;        Acc0 = L_deposit_h( Exp ) ;        Acc1 = L_shr( Acc1, (Word16) 1 ) ;        if ( Acc1 >= Acc0 )            Exp = (Word16) 0x7fff ;        else            Exp = div_l( Acc1, Exp ) ;        Acc0 = L_deposit_h( Exp ) ;        Pf.ScGn = Sqrt_lbc( Acc0 ) ;    }    else {        Pf.Gain = (Word16) 0 ;        Pf.ScGn = (Word16) 0x7fff ;    }    Pf.Gain = mult( Pf.Gain, Pf.ScGn ) ;    return Pf ;}/***** Function:        Filt_Lpf()**** Description:     Applies the pitch postfilter for each subframe.**** Links to text:   Section 3.6**** Arguments:****  Word16 *Tv      Pitch postfiltered excitation**  Word16 *Buff    decoded excitation**  PFDEF Pf        Pitch postfilter parameters**  Word16 Sfc      Subframe index**** Outputs:****  Word16 *Tv      Pitch postfiltered excitation**** Return value: None***/void  Filt_Lpf( Word16 *Tv, Word16 *Buff, PFDEF Pf, Word16 Sfc ){    int   i  ;    Word32   Acc0 ;    for ( i = 0 ; i < SubFrLen ; i ++ ) {        Acc0 = L_mult( Buff[PitchMax+(int)Sfc*SubFrLen+i], Pf.ScGn ) ;        //2*e(n)*scaleGain        Acc0 = L_mac( Acc0, Buff[PitchMax+(int)Sfc*SubFrLen+(int)Pf.Indx+i],Pf.Gain ) ;//2*e(n)*scaleGain+2*e(n-delay)*gain        Tv[(int)Sfc*SubFrLen+i] = round( Acc0 ) ;                              // extract high 16 bits to output    }    return;}/***** Function:        ACELP_LBC_code()**** Description:     Find Algebraic codebook for low bit rate LBC encoder**** Links to text:   Section 2.16**** Arguments:****   Word16 X[]              Target vector.     (in Q0)**   Word16 h[]              Impulse response.  (in Q12)**   Word16 T0               Pitch period.**   Word16 code[]           Innovative vector.        (in Q12)**   Word16 gain             Innovative vector gain.   (in Q0)**   Word16 sign             Signs of the 4 pulses.**   Word16 shift            Shift of the innovative vector**   Word16 gain_T0          Gain for pitch synchronous fiter**** Inputs :****   Word16 X[]              Target vector.     (in Q0)**   Word16 h[]              Impulse response.  (in Q12)**   Word16 T0               Pitch period.**   Word16 gain_T0          Gain for pitch synchronous fiter**** Outputs:****   Word16 code[]           Innovative vector.        (in Q12)**   Word16 gain             Innovative vector gain.   (in Q0)**   Word16 sign             Signs of the 4 pulses.**   Word16 shift            Shift of the innovative vector.**** Return value:****   Word16 index            Innovative codebook index***/Word16  ACELP_LBC_code(Word16 X[], Word16 h[], Word16 T0, Word16 code[],        Word16 *ind_gain, Word16 *shift, Word16 *sign, Word16 gain_T0){    Word16 i, index, gain_q;    Word16 Dn[SubFrLen2], tmp_code[SubFrLen2];    Word16 rr[DIM_RR]; /*  * Include fixed-gain pitch contribution into impulse resp. h[]  * Find correlations of h[] needed for the codebook search. */    for (i = 0; i < SubFrLen; i++)    /* Q13 -->  Q12*/        h[i] = shr(h[i], 1);    if (T0 < SubFrLen-2) {        for (i = T0; i < SubFrLen; i++)    /* h[i] += gain_T0*h[i-T0] */        h[i] = add(h[i], mult(h[i-T0], gain_T0));    }    Cor_h(h, rr); /*  * Compute correlation of target vector with impulse response.  */    Cor_h_X(h, X, Dn); /*  * Find innovative codebook.  * rr input matrix autocorrelation  *    output filtered codeword  */    index = D4i64_LBC(Dn, rr, h, tmp_code, rr, shift, sign); /*  * Compute innovation vector gain.  * Include fixed-gain pitch contribution into code[].  */    *ind_gain = G_code(X, rr, &gain_q);    for (i = 0; i < SubFrLen; i++)   {        code[i] = i_mult(tmp_code[i], gain_q);    }    if(T0 < SubFrLen-2)        for (i = T0; i < SubFrLen; i++)    /* code[i] += gain_T0*code[i-T0] */            code[i] = add(code[i], mult(code[i-T0], gain_T0));    return index;}/***** Function:        Cor_h()**** Description:     Compute correlations of h[] needed for the codebook search.**** Links to text:   Section 2.16**** Arguments:****  Word16 h[]              Impulse response.**  Word16 rr[]             Correlations.****  Outputs:****  Word16 rr[]             Correlations.****  Return value :          None*/void Cor_h(Word16 *H, Word16 *rr){    Word16 *rri0i0, *rri1i1, *rri2i2, *rri3i3;    Word16 *rri0i1, *rri0i2, *rri0i3;    Word16 *rri1i2, *rri1i3, *rri2i3;    Word16 *p0, *p1, *p2, *p3;    Word16 *ptr_hd, *ptr_hf, *ptr_h1, *ptr_h2;    Word32 cor;    Word16 i, k, ldec, l_fin_sup, l_fin_inf;    Word16 h[SubFrLen2];    /* Scaling for maximum precision */    cor = 0;    for(i=0; i<SubFrLen; i++)        cor = L_mac(cor, H[i], H[i]);    if(extract_h(cor) > 32000 ) {        for(i=0; i<SubFrLen; i++) h[i+4] = shr(H[i], 1);    }    else {        k = norm_l(cor);        k = shr(k, 1);        for(i=0; i<SubFrLen; i++) h[i+4] = shl(H[i], k);    }    for(i=0; i<4; i++) h[i] = 0;    /* 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; /*  * Compute rri0i0[], rri1i1[], rri2i2[] and rri3i3[]  */    p0 = rri0i0 + NB_POS-1;   /* Init pointers to last position of rrixix[] */    p1 = rri1i1 + NB_POS-1;    p2 = rri2i2 + NB_POS-1;    p3 = rri3i3 + NB_POS-1;    ptr_h1 = h;    cor    = 0;    for(i=0;  i<NB_POS; i++) {        cor = L_mac(cor, *ptr_h1, *ptr_h1); ptr_h1++;        cor = L_mac(cor, *ptr_h1, *ptr_h1); ptr_h1++;        *p3-- = extract_h(cor);        cor = L_mac(cor, *ptr_h1, *ptr_h1); ptr_h1++;        cor = L_mac(cor, *ptr_h1, *ptr_h1); ptr_h1++;        *p2-- = extract_h(cor);        cor = L_mac(cor, *ptr_h1, *ptr_h1); ptr_h1++;        cor = L_mac(cor, *ptr_h1, *ptr_h1); ptr_h1++;        *p1-- = extract_h(cor);        cor = L_mac(cor, *ptr_h1, *ptr_h1); ptr_h1++;        cor = L_mac(cor, *ptr_h1, *ptr_h1); ptr_h1++;        *p0-- = extract_h(cor);    } /*  * Compute elements of: rri0i1[], rri0i3[], rri1i2[] and rri2i3[]  */    l_fin_sup = MSIZE-1;    l_fin_inf = l_fin_sup-(Word16)1;    ldec = NB_POS+1;    ptr_hd = h;    ptr_hf = ptr_hd + 2;    for(k=0; k<NB_POS; k++) {        p3 = rri2i3 + l_fin_sup;        p2 = rri1i2 + l_fin_sup;        p1 = rri0i1 + l_fin_sup;        p0 = rri0i3 + l_fin_inf;        cor = 0;        ptr_h1 = ptr_hd;        ptr_h2 =  ptr_hf;        for(i=k+(Word16)1; i<NB_POS; i++ ) {            cor = L_mac(cor, *ptr_h1, *ptr_h2); ptr_h1++; ptr_h2++;            cor = L_mac(cor, *ptr_h1, *ptr_h2); ptr_h1++; ptr_h2++;            *p3 = extract_h(cor);            cor = L_mac(cor, *ptr_h1, *ptr_h2); ptr_h1++; ptr_h2++;            cor = L_mac(cor, *ptr_h1, *ptr_h2); ptr_h1++; ptr_h2++;            *p2 = extract_h(cor);            cor = L_mac(cor, *ptr_h1, *ptr_h2); ptr_h1++; ptr_h2++;            cor = L_mac(cor, *ptr_h1, *ptr_h2); ptr_h1++; ptr_h2++;            *p1 = extract_h(cor);            cor = L_mac(cor, *ptr_h1, *ptr_h2); ptr_h1++; ptr_h2++;            cor = L_mac(cor, *ptr_h1, *ptr_h2); ptr_h1++; ptr_h2++;            *p0 = extract_h(cor);            p3 -= ldec;            p2 -= ldec;

⌨️ 快捷键说明

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