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

📄 lpc.c

📁 G.723加解码程序
💻 C
📖 第 1 页 / 共 2 页
字号:
 /*  * Input a single impulse  */    Acc0 = (Word32) 0x04000000L ; /*  * Do for all elements in a subframe  */    for ( i = 0 ; i < SubFrLen ; i ++ ) { /*  * Synthesis filter  */        for ( j = 0 ; j < LpcOrder ; j ++ )            Acc0 = L_mac( Acc0, QntLpc[j], FirDl[j] ) ;        Acc1 = L_shl( Acc0, (Word16) 2 ) ; /*  * Perceptual weighting filter  */        /* FIR part */        for ( j = 0 ; j < LpcOrder ; j ++ )            Acc0 = L_msu( Acc0, PerLpc[j], FirDl[j] ) ;                                Acc0 = L_shl( Acc0, (Word16) 1 ) ;        for ( j = LpcOrder-1 ; j > 0 ; j -- )            FirDl[j] = FirDl[j-1] ;        FirDl[0] = round( Acc1 ) ;        /* Iir part */        for ( j = 0 ; j < LpcOrder ; j ++ )            Acc0 = L_mac( Acc0, PerLpc[LpcOrder+j], IirDl[j] ) ;        for ( j = LpcOrder-1 ; j > 0 ; j -- )            IirDl[j] = IirDl[j-1] ;        Acc0 = L_shl( Acc0, (Word16) 2 ) ;        IirDl[0] = round( Acc0 ) ;        Temp[PitchMax+i] = IirDl[0] ; /*  * Harmonic noise shaping filter  */        Acc0 = L_deposit_h( IirDl[0] ) ;        Acc0 = L_msu( Acc0, Pw.Gain, Temp[PitchMax-Pw.Indx+i] ) ;        ImpResp[i] = round( Acc0 ) ;        Acc0 = (Word32) 0 ;    }}/***** Function:        Sub_Ring()**** Description:     Computes the zero-input response of the**          combined formant perceptual weighting filter,**          harmonic noise shaping filter, and synthesis**          filter for a subframe.  Subtracts the**          zero-input response from the harmonic noise**          weighted speech vector to produce the target **          speech vector.**** Links to text:   Section 2.13**** Arguments:       ****  Word16 Dpnt[]       Harmonic noise weighted vector w[n] (60 words)**  Word16 QntLpc[]     Quantized LPC coefficients (10 words)**  Word16 PerLpc[]     Perceptual filter coefficients (20 words)**  Word16 PrevErr[]    Harmonic noise shaping filter memory (145 words)**  PWDEF Pw        Harmonic noise shaping filter parameters**  ** Inputs:****  CodStat.RingFirDl[] Perceptual weighting filter FIR memory from **               previous subframe (10 words)**  CodStat.RingIirDl[] Perceptual weighting filter IIR memory from **               previous subframe (10 words)**** Outputs:     ****  Word16 Dpnt[]       Target vector t[n] (60 words)**** Return value:    None***/void  Sub_Ring( Word16 *Dpnt, Word16 *QntLpc, Word16 *PerLpc, Word16*PrevErr, PWDEF Pw ){    int   i,j   ;    Word32   Acc0,Acc1 ;    Word16   FirDl[LpcOrder] ;    Word16   IirDl[LpcOrder] ;    Word16   Temp[PitchMax+SubFrLen] ; /*  * Initialize the memory  */    for ( i = 0 ; i < PitchMax ; i ++ )        Temp[i] = PrevErr[i] ;    for ( i = 0 ; i < LpcOrder ; i ++ ) {        FirDl[i] = CodStat.RingFirDl[i] ;        IirDl[i] = CodStat.RingIirDl[i] ;    } /*  * Do for all elements in a subframe  */    for ( i = 0 ; i < SubFrLen ; i ++ ) { /*  * Input zero  */        Acc0 = (Word32) 0 ; /*  * Synthesis filter  */        for ( j = 0 ; j < LpcOrder ; j ++ )            Acc0 = L_mac( Acc0, QntLpc[j], FirDl[j] ) ;        Acc1 = L_shl( Acc0, (Word16) 2 ) ; /*  * Perceptual weighting filter  */        /* Fir part */        for ( j = 0 ; j < LpcOrder ; j ++ )            Acc0 = L_msu( Acc0, PerLpc[j], FirDl[j] ) ;        for ( j = LpcOrder-1 ; j > 0 ; j -- )            FirDl[j] = FirDl[j-1] ;        FirDl[0] = round( Acc1 ) ;        /* Iir part */        for ( j = 0 ; j < LpcOrder ; j ++ )            Acc0 = L_mac( Acc0, PerLpc[LpcOrder+j], IirDl[j] ) ;        Acc0 = L_shl( Acc0, (Word16) 2 ) ;        for ( j = LpcOrder-1 ; j > 0 ; j -- )            IirDl[j] = IirDl[j-1] ;        IirDl[0] = round( Acc0 ) ;        Temp[PitchMax+i] = IirDl[0] ; /*  * Do the harmonic noise shaping filter and subtract the result  * from the harmonic noise weighted vector.  */        Acc0 = L_deposit_h( sub( Dpnt[i], IirDl[0] ) ) ;        Acc0 = L_mac( Acc0, Pw.Gain, Temp[PitchMax-(int)Pw.Indx+i] ) ;        Dpnt[i] = round ( Acc0 ) ;    }}/***** Function:        Upd_Ring()**** Description:     Updates the memory of the combined formant**          perceptual weighting filter, harmonic noise**          shaping filter, and synthesis filter for a**          subframe.  The update is done by passing the**          current subframe's excitation through the**          combined filter.**** Links to text:   Section 2.19**** Arguments:       ****  Word16 Dpnt[]       Decoded excitation for the current subframe e[n] **               (60 words)**  Word16 QntLpc[]     Quantized LPC coefficients (10 words)**  Word16 PerLpc[]     Perceptual filter coefficients (20 words)**  Word16 PrevErr[]    Harmonic noise shaping filter memory (145 words)**  ** Inputs:****  CodStat.RingFirDl[] Perceptual weighting filter FIR memory from **               previous subframe (10 words)**  CodStat.RingIirDl[] Perceptual weighting filter IIR memory from **               previous subframe (10 words)**** Outputs:     ****  Word16 PrevErr[]    Updated harmonic noise shaping filter memory **  CodStat.RingFirDl[] Updated perceptual weighting filter FIR memory **  CodStat.RingIirDl[] Updated perceptual weighting filter IIR memory **** Return value:    None***/void  Upd_Ring( Word16 *Dpnt, Word16 *QntLpc, Word16 *PerLpc, Word16*PrevErr ){    int   i,j   ;    Word32   Acc0,Acc1   ; /*  * Shift the harmonic noise shaping filter memory  */    for ( i = SubFrLen ; i < PitchMax ; i ++ )        PrevErr[i-SubFrLen] = PrevErr[i] ; /*  * Do for all elements in the subframe  */    for ( i = 0 ; i < SubFrLen ; i ++ ) { /*  * Input the current subframe's excitation  */        Acc0 = L_deposit_h( Dpnt[i] ) ;        Acc0 = L_shr( Acc0, (Word16) 3 ) ; /*  * Synthesis filter  */        for ( j = 0 ; j < LpcOrder ; j ++ )            Acc0 = L_mac( Acc0, QntLpc[j], CodStat.RingFirDl[j] ) ;        Acc1 = L_shl( Acc0, (Word16) 2 ) ;        Dpnt[i] = shl( round( Acc1 ), (Word16) 1 ) ; /*  * Perceptual weighting filter  */        /* FIR part */        for ( j = 0 ; j < LpcOrder ; j ++ )            Acc0 = L_msu( Acc0, PerLpc[j], CodStat.RingFirDl[j] ) ;        /* Update FIR memory */        for ( j = LpcOrder-1 ; j > 0 ; j -- )            CodStat.RingFirDl[j] = CodStat.RingFirDl[j-1] ;        CodStat.RingFirDl[0] = round( Acc1 ) ;        /* IIR part */        for ( j = 0 ; j < LpcOrder ; j ++ )            Acc0 = L_mac( Acc0, PerLpc[LpcOrder+j], CodStat.RingIirDl[j] ) ;        Acc0 = L_shl( Acc0, (Word16) 2 ) ;        /* Update IIR memory */        for ( j = LpcOrder-1 ; j > 0 ; j -- )            CodStat.RingIirDl[j] = CodStat.RingIirDl[j-1] ;        CodStat.RingIirDl[0] = round( Acc0 ) ;        /* Update harmonic noise shaping memory */        PrevErr[PitchMax-SubFrLen+i] = CodStat.RingIirDl[0] ;    }}/***** Function:        Synt()**** Description:     Implements the decoder synthesis filter for a**          subframe.  This is a tenth-order IIR filter.**** Links to text:   Section 3.7**** Arguments:       ****  Word16 Dpnt[]       Pitch-postfiltered excitation for the current**               subframe ppf[n] (60 words)**  Word16 Lpc[]        Quantized LPC coefficients (10 words)**  ** Inputs:****  DecStat.SyntIirDl[] Synthesis filter memory from previoussubframe (10 words)**** Outputs:     ****  Word16 Dpnt[]       Synthesized speech vector sy[n]**  DecStat.SyntIirDl[] Updated synthesis filter memory **** Return value:    None***/void     Synt( Word16 *Dpnt, Word16 *Lpc ){    int   i,j   ;    Word32   Acc0  ; /*  * Do for all elements in the subframe  */    for ( i = 0 ; i < SubFrLen ; i ++ ) { /*  * Input the current subframe's excitation  */        Acc0 = L_deposit_h( Dpnt[i] ) ;        Acc0 = L_shr( Acc0, (Word16) 3 ) ; /*  * Synthesis  */        /* Filter */        for ( j = 0 ; j < LpcOrder ; j ++ )            Acc0 = L_mac( Acc0, Lpc[j], DecStat.SyntIirDl[j] ) ;        /* Update memory */        for ( j = LpcOrder-1 ; j > 0 ; j -- )            DecStat.SyntIirDl[j] = DecStat.SyntIirDl[j-1] ;        Acc0 = L_shl( Acc0, (Word16) 2 ) ;        DecStat.SyntIirDl[0] = round( Acc0 ) ; /*  * Scale output if postfilter is off.  (Otherwise output is  * scaled by the gain scaling unit.)  */        if ( UsePf )            Dpnt[i] = DecStat.SyntIirDl[0] ;        else            Dpnt[i] = shl( DecStat.SyntIirDl[0], (Word16) 1 ) ;    }}/***** Function:        Spf()**** Description:     Implements the formant postfilter for a**          subframe.  The formant postfilter is a**          10-pole, 10-zero ARMA filter followed by a**          single-tap tilt compensation filter.**** Links to text:   Section 3.8**** Arguments:****  Word16 Tv[]     Synthesized speech vector sy[n] (60 words)**  Word16 Lpc[]        Quantized LPC coefficients (10 words)**** Inputs:****  DecStat.PostIirDl[] Postfilter IIR memory from previoussubframe (10 words)**  DecStat.PostFirDl[] Postfilter FIR memory from previoussubframe (10 words)**  DecStat.Park        Previous value of compensation filter parameter**** Outputs:****  Word16 Tv[]     Postfiltered speech vector pf[n] (60 words)**  DecStat.PostIirDl[] Updated postfilter IIR memory**  DecStat.PostFirDl[] Updated postfilter FIR memory**  DecStat.Park        Updated compensation filter parameter**** Return value: Input vector energy***/Word32  Spf( Word16 *Tv, Word16 *Lpc ){    int   i,j   ;    Word32   Acc0,Acc1   ;    Word32   Sen ;    Word16   Tmp ;    Word16   Exp ;    Word16   FirCoef[LpcOrder] ;    Word16   IirCoef[LpcOrder] ;    Word16   TmpVect[SubFrLen] ; /*  * 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 < LpcOrder ; i ++ ) {        FirCoef[i] = mult_r( Lpc[i], PostFiltZeroTable[i] ) ;        IirCoef[i] = mult_r( Lpc[i], PostFiltPoleTable[i] ) ;    } /*  * Normalize the speech vector.  */    for ( i = 0 ; i < SubFrLen ; i ++ )        TmpVect[i] = Tv[i] ;    Exp = Vec_Norm( TmpVect, (Word16) SubFrLen ) ; /*  * Compute the first two autocorrelation coefficients R[0] and R[1]  */    Acc0 = (Word32) 0 ;    Acc1 = L_mult( TmpVect[0], TmpVect[0] ) ;    for ( i = 1 ; i < SubFrLen ; i ++ ) {        Acc0 = L_mac( Acc0, TmpVect[i], TmpVect[i-1] ) ;        Acc1 = L_mac( Acc1, TmpVect[i], TmpVect[i] ) ;    } /*  * Scale the energy for the later use.  */    Sen = L_shr( Acc1, (Word16)(2*Exp + 4) ) ; /*  * Compute the first-order partial correlation coefficient of the  * input speech vector.  */    Tmp = extract_h( Acc1 ) ;    if ( Tmp != (Word16) 0 ) {        /* Compute first parkor */        Acc0 = L_shr( Acc0, (Word16) 1 ) ;        Acc1 = Acc0 ;        Acc0 = L_abs( Acc0 ) ;        Tmp = div_l( Acc0, Tmp ) ;        if ( Acc1 < (Word32) 0 )            Tmp = negate( Tmp ) ;    }    else        Tmp = (Word16) 0 ; /*  * Compute the compensation filter parameter and update the memory  */    Acc0 = L_deposit_h( DecStat.Park ) ;    Acc0 = L_msu( Acc0, DecStat.Park, (Word16) 0x2000 ) ;    Acc0 = L_mac( Acc0, Tmp, (Word16) 0x2000 ) ;    DecStat.Park = round( Acc0 ) ;    Tmp  = mult( DecStat.Park, PreCoef ) ;    Tmp &= (Word16) 0xfffc ; /*  *  Do for all elements in the subframe  */    for ( i = 0 ; i < SubFrLen ; i ++ ) { /*  * Input the speech vector  */        Acc0 = L_deposit_h( Tv[i] ) ;        Acc0 = L_shr( Acc0, (Word16) 2 ) ; /*  * Formant postfilter  */        /* FIR part */        for ( j = 0 ; j < LpcOrder ; j ++ )            Acc0 = L_msu( Acc0, FirCoef[j], DecStat.PostFirDl[j] ) ;        /* Update FIR memory */        for ( j = LpcOrder-1 ; j > 0 ; j -- )            DecStat.PostFirDl[j] = DecStat.PostFirDl[j-1] ;        DecStat.PostFirDl[0] = Tv[i] ;        /* IIR part */        for ( j = 0 ; j < LpcOrder ; j ++ )            Acc0 = L_mac( Acc0, IirCoef[j], DecStat.PostIirDl[j] ) ;        /* Update IIR memory */        for ( j = LpcOrder-1 ; j > 0 ; j -- )            DecStat.PostIirDl[j] = DecStat.PostIirDl[j-1] ;        Acc0 = L_shl( Acc0, (Word16) 2 ) ;        Acc1 = Acc0 ;        DecStat.PostIirDl[0] = round( Acc0 ) ; /*  * Compensation filter  */        Acc1 = L_mac( Acc1, DecStat.PostIirDl[1], Tmp ) ;        Tv[i] = round( Acc1 ) ;    }    return Sen ;}

⌨️ 快捷键说明

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