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

📄 g7231_lpc.c

📁 G723.1语音压缩解压在tms320c54系列上的实现代码,本人已在CCS上仿真通过. 包含全部源代码,主函数请自已写(本人的就不奉送了:
💻 C
📖 第 1 页 / 共 2 页
字号:
 /*
  * Perceptual weighting filter
  */

        /* FIR part */
        for ( j = 0 ; j < G7231LpcOrder ; j ++ )
            Acc0 = G7231L_msu( Acc0, PerLpc[j], FirDl[j] ) ;
                                Acc0 = G7231L_shl( Acc0, (Word16) 1 ) ;
        for ( j = G7231LpcOrder-1 ; j > 0 ; j -- )
            FirDl[j] = FirDl[j-1] ;
        FirDl[0] = G7231round( Acc1 ) ;

        /* Iir part */
        for ( j = 0 ; j < G7231LpcOrder ; j++ )
            Acc0 = G7231L_mac( Acc0, PerLpc[G7231LpcOrder+j], IirDl[j] ) ;
        for ( j = G7231LpcOrder-1 ; j > 0 ; j -- )
            IirDl[j] = IirDl[j-1] ;
        Acc0 = G7231L_shl( Acc0, (Word16) 2 ) ;
        IirDl[0] = G7231round( Acc0 ) ;
        Temp[G7231PitchMax+i] = IirDl[0] ;

 /*
  * Harmonic noise shaping filter
  */

        Acc0 = G7231L_deposit_h( IirDl[0] ) ;
        Acc0 = G7231L_msu( Acc0, Pw.Gain, Temp[G7231PitchMax-Pw.Indx+i] ) ;
        ImpResp[i] = G7231round( Acc0 ) ;

        Acc0 = (Word32) 0 ;
    }
}

void  G7231Sub_Ring( Word16 *Dpnt, Word16 *QntLpc, Word16 *PerLpc, Word16
*PrevErr, G7231PWDEF Pw )
{
    int   i,j   ;
    Word32   Acc0,Acc1 ;

    Word16   FirDl[G7231LpcOrder] ;
    Word16   IirDl[G7231LpcOrder] ;
    Word16   Temp[G7231PitchMax+G7231SubFrLen] ;


 /*
  * Initialize the memory
  */
    for ( i = 0 ; i < G7231PitchMax ; i ++ )
        Temp[i] = PrevErr[i] ;

    for ( i = 0 ; i < G7231LpcOrder ; i ++ ) {
        FirDl[i] = G7231CodStat.RingFirDl[i] ;
        IirDl[i] = G7231CodStat.RingIirDl[i] ;
    }

 /*
  * Do for all elements in a subframe
  */
    for ( i = 0 ; i < G7231SubFrLen ; i ++ ) {

 /*
  * Input zero
  */
        Acc0 = (Word32) 0 ;

 /*
  * Synthesis filter
  */
        for ( j = 0 ; j < G7231LpcOrder ; j ++ )
            Acc0 = G7231L_mac( Acc0, QntLpc[j], FirDl[j] ) ;
        Acc1 = G7231L_shl( Acc0, (Word16) 2 ) ;

 /*
  * Perceptual weighting filter
  */

        /* Fir part */
        for ( j = 0 ; j < G7231LpcOrder ; j ++ )
            Acc0 = G7231L_msu( Acc0, PerLpc[j], FirDl[j] ) ;
        for ( j = G7231LpcOrder-1 ; j > 0 ; j -- )
            FirDl[j] = FirDl[j-1] ;
        FirDl[0] = G7231round( Acc1 ) ;

        /* Iir part */
        for ( j = 0 ; j < G7231LpcOrder ; j ++ )
            Acc0 = G7231L_mac( Acc0, PerLpc[G7231LpcOrder+j], IirDl[j] ) ;
        Acc0 = G7231L_shl( Acc0, (Word16) 2 ) ;
        for ( j = G7231LpcOrder-1 ; j > 0 ; j -- )
            IirDl[j] = IirDl[j-1] ;
        IirDl[0] = G7231round( Acc0 ) ;
        Temp[G7231PitchMax+i] = IirDl[0] ;

 /*
  * Do the harmonic noise shaping filter and subtract the result
  * from the harmonic noise weighted vector.
  */
        Acc0 = G7231L_deposit_h( G7231sub( Dpnt[i], IirDl[0] ) ) ;
        Acc0 = G7231L_mac( Acc0, Pw.Gain, Temp[G7231PitchMax-(int)Pw.Indx+i] ) ;
        Dpnt[i] = G7231round ( Acc0 ) ;
    }
}

void  G7231Upd_Ring( Word16 *Dpnt, Word16 *QntLpc, Word16 *PerLpc, Word16
*PrevErr )
{
    int   i,j   ;

    Word32   Acc0,Acc1   ;


 /*
  * Shift the harmonic noise shaping filter memory
  */
    for ( i = G7231SubFrLen ; i < G7231PitchMax ; i ++ )
        PrevErr[i-G7231SubFrLen] = PrevErr[i] ;


 /*
  * Do for all elements in the subframe
  */
    for ( i = 0 ; i < G7231SubFrLen ; i ++ ) {

 /*
  * Input the current subframe's excitation
  */
        Acc0 = G7231L_deposit_h( Dpnt[i] ) ;
        Acc0 = G7231L_shr( Acc0, (Word16) 3 ) ;

 /*
  * Synthesis filter
  */
        for ( j = 0 ; j < G7231LpcOrder ; j ++ )
            Acc0 = G7231L_mac( Acc0, QntLpc[j], G7231CodStat.RingFirDl[j] ) ;
        Acc1 = G7231L_shl( Acc0, (Word16) 2 ) ;

        Dpnt[i] = G7231shl( G7231round( Acc1 ), (Word16) 1 ) ;

 /*
  * Perceptual weighting filter
  */

        /* FIR part */
        for ( j = 0 ; j < G7231LpcOrder ; j ++ )
            Acc0 = G7231L_msu( Acc0, PerLpc[j], G7231CodStat.RingFirDl[j] ) ;

        /* Update FIR memory */
        for ( j = G7231LpcOrder-1 ; j > 0 ; j -- )
            G7231CodStat.RingFirDl[j] = G7231CodStat.RingFirDl[j-1] ;
        G7231CodStat.RingFirDl[0] = G7231round( Acc1 ) ;

        /* IIR part */
        for ( j = 0 ; j < G7231LpcOrder ; j ++ )
            Acc0 = G7231L_mac( Acc0, PerLpc[G7231LpcOrder+j], G7231CodStat.RingIirDl[j] ) ;
        Acc0 = G7231L_shl( Acc0, (Word16) 2 ) ;

        /* Update IIR memory */
        for ( j = G7231LpcOrder-1 ; j > 0 ; j -- )
            G7231CodStat.RingIirDl[j] = G7231CodStat.RingIirDl[j-1] ;
        G7231CodStat.RingIirDl[0] = G7231round( Acc0 ) ;

        /* Update harmonic noise shaping memory */
        PrevErr[G7231PitchMax-G7231SubFrLen+i] = G7231CodStat.RingIirDl[0] ;
    }
}

void     G7231Synt( Word16 *Dpnt, Word16 *Lpc )
{
    int   i,j   ;

    Word32   Acc0  ;


 /*
  * Do for all elements in the subframe
  */
    for ( i = 0 ; i < G7231SubFrLen ; i ++ ) {

 /*
  * Input the current subframe's excitation
  */
        Acc0 = G7231L_deposit_h( Dpnt[i] ) ;
        Acc0 = G7231L_shr( Acc0, (Word16) 3 ) ;

 /*
  * Synthesis
  */

        /* Filter */
        for ( j = 0 ; j < G7231LpcOrder ; j ++ )
            Acc0 = G7231L_mac( Acc0, Lpc[j], G7231DecStat.SyntIirDl[j] ) ;

        /* Update memory */
        for ( j = G7231LpcOrder-1 ; j > 0 ; j -- )
            G7231DecStat.SyntIirDl[j] = G7231DecStat.SyntIirDl[j-1] ;

        Acc0 = G7231L_shl( Acc0, (Word16) 2 ) ;

        G7231DecStat.SyntIirDl[0] = G7231round( Acc0 ) ;

 /*
  * Scale output if postfilter is off.  (Otherwise output is
  * scaled by the gain scaling unit.)
  */
        if ( G7231UsePf )
            Dpnt[i] = G7231DecStat.SyntIirDl[0] ;
        else
            Dpnt[i] = G7231shl( G7231DecStat.SyntIirDl[0], (Word16) 1 ) ;

    }

}

Word32  G7231Spf( Word16 *Tv, Word16 *Lpc )
{
    int   i,j   ;

    Word32   Acc0,Acc1   ;
    Word32   Sen ;
    Word16   Tmp ;
    Word16   Exp ;

    Word16   FirCoef[G7231LpcOrder] ;
    Word16   IirCoef[G7231LpcOrder] ;

    Word16   TmpVect[G7231SubFrLen] ;

 /*
  * Compute ARMA coefficients.  Compute the jth FIR coefficient by
  * multiplying the jth quantized LPC coefficient by (0.65)^j.
  * Compute the jth IIR coefficient by multiplying the jth quantized
  * LPC coefficient by (0.75)^j.  This emphasizes the formants in
  * the frequency response.
  */
    for ( i = 0 ; i < G7231LpcOrder ; i ++ ) {
        FirCoef[i] = G7231mult_r( Lpc[i], G7231PostFiltZeroTable[i] ) ;
        IirCoef[i] = G7231mult_r( Lpc[i], G7231PostFiltPoleTable[i] ) ;
    }

 /*
  * Normalize the speech vector.
  */
    for ( i = 0 ; i < G7231SubFrLen ; i ++ )
        TmpVect[i] = Tv[i] ;
    Exp = G7231Vec_Norm( TmpVect, (Word16) G7231SubFrLen ) ;

 /*
  * Compute the first two autocorrelation coefficients R[0] and R[1]
  */
    Acc0 = (Word32) 0 ;
    Acc1 = G7231L_mult( TmpVect[0], TmpVect[0] ) ;
    for ( i = 1 ; i < G7231SubFrLen ; i ++ ) {
        Acc0 = G7231L_mac( Acc0, TmpVect[i], TmpVect[i-1] ) ;
        Acc1 = G7231L_mac( Acc1, TmpVect[i], TmpVect[i] ) ;
    }

 /*
  * Scale the energy for the later use.
  */
    Sen = G7231L_shr( Acc1, (Word16)(2*Exp + 4) ) ;

 /*
  * Compute the first-order partial correlation coefficient of the
  * input speech vector.
  */
    Tmp = G7231extract_h( Acc1 ) ;
    if ( Tmp != (Word16) 0 ) {

        /* Compute first parkor */
        Acc0 = G7231L_shr( Acc0, (Word16) 1 ) ;
        Acc1 = Acc0 ;
        Acc0 = G7231L_abs( Acc0 ) ;

        Tmp = G7231div_l( Acc0, Tmp ) ;

        if ( Acc1 < (Word32) 0 )
            Tmp = G7231negate( Tmp ) ;
    }
    else
        Tmp = (Word16) 0 ;

 /*
  * Compute the compensation filter parameter and update the memory
  */
    Acc0 = G7231L_deposit_h( G7231DecStat.Park ) ;
    Acc0 = G7231L_msu( Acc0, G7231DecStat.Park, (Word16) 0x2000 ) ;
    Acc0 = G7231L_mac( Acc0, Tmp, (Word16) 0x2000 ) ;
    G7231DecStat.Park = G7231round( Acc0 ) ;

    Tmp  = G7231mult( G7231DecStat.Park, G7231PreCoef ) ;
    Tmp &= (Word16) 0xfffc ;


 /*
  *  Do for all elements in the subframe
  */
    for ( i = 0 ; i < G7231SubFrLen ; i ++ ) {

 /*
  * Input the speech vector
  */
        Acc0 = G7231L_deposit_h( Tv[i] ) ;
        Acc0 = G7231L_shr( Acc0, (Word16) 2 ) ;

 /*
  * Formant postfilter
  */

        /* FIR part */
        for ( j = 0 ; j < G7231LpcOrder ; j ++ )
            Acc0 = G7231L_msu( Acc0, FirCoef[j], G7231DecStat.PostFirDl[j] ) ;

        /* Update FIR memory */
        for ( j = G7231LpcOrder-1 ; j > 0 ; j -- )
            G7231DecStat.PostFirDl[j] = G7231DecStat.PostFirDl[j-1] ;
        G7231DecStat.PostFirDl[0] = Tv[i] ;

        /* IIR part */
        for ( j = 0 ; j < G7231LpcOrder ; j ++ )
            Acc0 = G7231L_mac( Acc0, IirCoef[j], G7231DecStat.PostIirDl[j] ) ;

        /* Update IIR memory */
        for ( j = G7231LpcOrder-1 ; j > 0 ; j -- )
            G7231DecStat.PostIirDl[j] = G7231DecStat.PostIirDl[j-1] ;

        Acc0 = G7231L_shl( Acc0, (Word16) 2 ) ;
        Acc1 = Acc0 ;

        G7231DecStat.PostIirDl[0] = G7231round( Acc0 ) ;

 /*
  * Compensation filter
  */
        Acc1 = G7231L_mac( Acc1, G7231DecStat.PostIirDl[1], Tmp ) ;

        Tv[i] = G7231round( Acc1 ) ;
    }
    return Sen ;
}

⌨️ 快捷键说明

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