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

📄 lpc2.c

📁 symbian 系统下的g.723 g.723_24实现, 本源码在 series60 sdk fp2下调试通过
💻 C
📖 第 1 页 / 共 2 页
字号:
     * Clear all memory.  Impulse response calculation requires
     * an all-zero initial state.
     */

    /* Perceptual weighting filter */

    for (i=0; i < LpcOrder; i++)
        FirDl[i] = IirDl[i] = (FLOAT)0.0;

    /* Harmonic noise shaping filter */

    for (i=0; i < PitchMax+SubFrLen; i++)
        Temp[i] = (FLOAT)0.0;

    /*  Input a single impulse  */

    Acc0 = (FLOAT)1.0;

    /*  Do for all elements in a subframe  */

    for (i=0; i < SubFrLen; i++)
    {
        /*  Synthesis filter  */

        Acc1 = Acc0 = Acc0 + DotProd(QntLpc,FirDl,LpcOrder);

        /*  Perceptual weighting filter  */

        /*  FIR part */

        Acc0 -= DotProd(PerLpc,FirDl,LpcOrder);
        for (j=LpcOrder-1; j > 0; j--)
            FirDl[j] = FirDl[j-1];

        FirDl[0] = Acc1;

        /*  IIR part */

        Acc0 += DotProd(&PerLpc[LpcOrder],IirDl,LpcOrder);
        for (j=LpcOrder-1; j > 0; j--)
            IirDl[j] = IirDl[j-1];

        Temp[PitchMax+i] = IirDl[0] = Acc0;

        /*  Harmonic noise shaping filter  */

        ImpResp[i] = Acc0 - Pw.Gain*Temp[PitchMax-Pw.Indx+i];

        Acc0 = (FLOAT)0.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:
**
**  FLOAT Dpnt[]       Harmonic noise weighted vector w[n] (60 words)
**  FLOAT QntLpc[]     Quantized LPC coefficients (10 words)
**  FLOAT PerLpc[]     Perceptual filter coefficients (20 words)
**  FLOAT 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:
**
**  FLOAT Dpnt[]       Target vector t[n] (60 words)
**
** Return value:    None
**
*/
void  Sub_Ring(FLOAT *Dpnt, FLOAT *QntLpc, FLOAT *PerLpc, FLOAT *PrevErr,
               PWDEF Pw)
{
    int    i,j;
    FLOAT  Acc0,Acc1;

    FLOAT  FirDl[LpcOrder];
    FLOAT  IirDl[LpcOrder];
    FLOAT  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++)
    {
        /*  Synthesis filter  */

        Acc1 = Acc0 = DotProd(QntLpc,FirDl,LpcOrder);

        /*  Perceptual weighting filter  */

        /*  FIR part */

        Acc0 -= DotProd(PerLpc,FirDl,LpcOrder);

        for (j=LpcOrder-1; j > 0; j--)
            FirDl[j] = FirDl[j-1];

        FirDl[0] = Acc1;

        /*  IIR part */

        Acc0 += DotProd(&PerLpc[LpcOrder],IirDl,LpcOrder);

        for (j=LpcOrder-1; j > 0; j--)
            IirDl[j] = IirDl[j-1];

        Temp[PitchMax+i] = IirDl[0] = Acc0;
        /*
         * Do the harmonic noise shaping filter and subtract the result
         * from the harmonic noise weighted vector.
         */
        Dpnt[i] -= Acc0 - Pw.Gain*Temp[PitchMax-Pw.Indx+i];
    }
}


/*
**
** 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:
**
**  FLOAT  Dpnt[]       Decoded excitation for the current subframe e[n]
**               (60 words)
**  FLOAT  QntLpc[]     Quantized LPC coefficients (10 words)
**  FLOAT  PerLpc[]     Perceptual filter coefficients (20 words)
**  FLOAT  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:
**
**  FLOAT  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(FLOAT *Dpnt, FLOAT *QntLpc, FLOAT *PerLpc, FLOAT *PrevErr)
{
    int    i,j;
    FLOAT  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++)
    {
        /*  Synthesis filter  */

        Acc0 = Dpnt[i] + DotProd(QntLpc,CodStat.RingFirDl,LpcOrder);

        Dpnt[i] = Acc0;
        Acc1 = Acc0;

        /*  Perceptual weighting filter  */
        /*  FIR part */

        Acc0 -= DotProd(PerLpc,CodStat.RingFirDl,LpcOrder);

        for (j=LpcOrder-1; j > 0; j--)
            CodStat.RingFirDl[j] = CodStat.RingFirDl[j-1];
        CodStat.RingFirDl[0] = Acc1;

        /*  IIR part */

        Acc0 += DotProd(&PerLpc[LpcOrder],CodStat.RingIirDl,LpcOrder);

        /* Update IIR memory */
        for (j=LpcOrder-1; j > 0; j--)
            CodStat.RingIirDl[j] = CodStat.RingIirDl[j-1];

        CodStat.RingIirDl[0] = Acc0;
        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:
**
**  FLOAT  Dpnt[]       Pitch-postfiltered excitation for the current
**               subframe ppf[n] (60 words)
**  FLOAT  Lpc[]        Quantized LPC coefficients (10 words)
**
** Inputs:
**
**  DecStat.SyntIirDl[] Synthesis filter memory from previous
**               subframe (10 words)
**
** Outputs:
**
**  FLOAT  Dpnt[]       Synthesized speech vector sy[n]
**  DecStat.SyntIirDl[] Updated synthesis filter memory
**
** Return value:    None
**
*/
void Synt(FLOAT *Dpnt, FLOAT *Lpc)
{
    int     i,j;
    FLOAT   Acc0;

    for (i=0 ; i < SubFrLen ; i++)
    {
        Acc0 = Dpnt[i] + DotProd(Lpc,DecStat.SyntIirDl,LpcOrder);

        for (j=LpcOrder-1 ; j > 0 ; j--)
            DecStat.SyntIirDl[j] = DecStat.SyntIirDl[j-1];

        Dpnt[i] = DecStat.SyntIirDl[0] = Acc0;
    }
}


/*
**
** 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:
**
**  FLOAT Tv[]     Synthesized speech vector sy[n] (60 words)
**  FLOAT Lpc[]        Quantized LPC coefficients (10 words)
**  FLOAT Sen      Input speech vector energy
**
** Inputs:
**
**  DecStat.PostIirDl[] Postfilter IIR memory from previous subframe (10 words)
**  DecStat.PostFirDl[] Postfilter FIR memory from previous subframe (10 words)
**  DecStat.Park        Previous value of compensation filter parameter
**
** Outputs:
**
**  FLOAT 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:    None
**
*/
FLOAT  Spf(FLOAT *Tv, FLOAT *Lpc)
{
    int    i,j;

    FLOAT  Acc0, Acc1;
    FLOAT  Sen;
    FLOAT  Tmp;
    FLOAT  FirCoef[LpcOrder];
    FLOAT  IirCoef[LpcOrder];

    /*
     * 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] = Lpc[i]*PostFiltZeroTable[i];
        IirCoef[i] = Lpc[i]*PostFiltPoleTable[i];
    }

    /* Compute the first two autocorrelation coefficients R[0] and R[1] */

    Acc0 = DotProd(Tv,&Tv[1],SubFrLen-1);
    Acc1 = DotProd(Tv,Tv,SubFrLen);

    /* energy */
    Sen = Acc1;

    /*
     * Compute the first-order partial correlation coefficient of the
     * input speech vector.
     */

    if (Acc1 > (FLOAT) FLT_MIN)
        Tmp = Acc0/Acc1;
    else
        Tmp = (FLOAT)0.0;

    /* Update the parkor memory */

    DecStat.Park = (((FLOAT)0.75)*DecStat.Park + ((FLOAT)0.25)*Tmp);
    Tmp = DecStat.Park*PreCoef;

    /* Do the formant post filter */

    for (i=0; i<SubFrLen; i++)
    {
        /* FIR Filter */

        Acc0 = Tv[i] - DotProd(FirCoef,DecStat.PostFirDl,LpcOrder);

        for (j=LpcOrder-1; j > 0; j--)
            DecStat.PostFirDl[j] = DecStat.PostFirDl[j-1];

        DecStat.PostFirDl[0] = Tv[i];

        /* IIR Filter */

        Acc0 += DotProd(IirCoef,DecStat.PostIirDl,LpcOrder);

        for (j=LpcOrder-1; j > 0; j--)
            DecStat.PostIirDl[j] = DecStat.PostIirDl[j-1];

        DecStat.PostIirDl[0] = Acc0;

        /* Preemphasis */

        Tv[i] = Acc0 + DecStat.PostIirDl[1] * Tmp;

    }
    return Sen;
}

⌨️ 快捷键说明

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