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

📄 gaecnrs.c

📁 TI公司DSP/tms320c55x/tms320c54x系列的声学回声消除代码
💻 C
字号:
/*-------------------------------------------------------------------------*
 *                                                                         *
 *   THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY   *
 *   INFORMATION.  IF PUBLICATION OCCURS, THE FOLLOWING NOTICE APPLIES:    *
 *      "COPYRIGHT 2003 MIKET DSP SOLUTIONS, ALL RIGHTS RESERVED"          *
 *                                                                         *
 *-------------------------------------------------------------------------*/

#include "gaeci.h"

/*--------------------- local defs ----------------------------------------*/


/*--------------------- public vars ---------------------------------------*/
/*--------------------- local vars ----------------------------------------*/
/*--------------------- local functions -----------------------------------*/
/*--------------------- public  functions ---------------------------------*/
/*-------------------------------------------------------------------------*/
#if !defined(_dsp)
void                        gaec_nr_nrg
#else
void                        gaec_nr_nrgC
#endif
/*-------------------------------------------------------------------------*/
(
GAEC_tDb *pDb,
GAEC_tSc *pSc
)
{
    GAEC_tScNr *pNr = pSc->u.aNr;

    int band;

    for (band = 0; band < GAEC_BANDS+1; band++)
    {
        S32 ac0, ac1;
        S16 sLevel, sNse; 

        sLevel = pSc->asErrEn[band] + GAEC_DB(25);
// prevent from overflow (on +18db)
        if (sLevel > GAEC_DB(15))
            sLevel = GAEC_DB(15);
        pNr->sSig = gaec_utl_exp(sLevel);
        sNse = gaec_utl_exp(pDb->asVadErrNse[band] + GAEC_DB(25));
        pNr->slSig = pNr->sSig * (S32) pNr->sSig;
        pNr->slNse = sNse * (S32) sNse;

        ac0 = pNr->slSig - pNr->slNse;
        if (ac0 < 0)
            ac0 = 0;
        ac1 = pDb->aslNrPrior[band];
        ac0 = ac0 - ac1;
        ac1 += ac0 >> 6;

        pNr->slEst = ac1; // expected signal burried in noise

        pNr++;
    }
}
/*-------------------------------------------------------------------------*/
#if !defined(_dsp)
void                        gaec_nr_coef
#else
void                        gaec_nr_coefC
#endif
/*-------------------------------------------------------------------------*/
(
GAEC_tDb *pDb,
GAEC_tSc *pSc
)
{
    GAEC_tScNr *pNr = pSc->u.aNr;
    int band;

    for (band = 0; band < GAEC_BANDS+1; band++)
    {
        S32 ac0;
        S16 s1, s2;

        s1 = gaec_utl_en2log(pNr->slEst) - gaec_utl_en2log(pNr->slEst+pNr->slNse);
        s2 = gaec_utl_en2log(pNr->slNse) - gaec_utl_en2log(pNr->slSig);

        if (s2 > GAEC_DB(8))
            s2 = GAEC_DB(8);

        s1 = gaec_utl_exp(s1 << 1);
        s2 = gaec_utl_exp(s2 << 1);
        ac0 = (s2+s1) * (S32) s1;
        ac0 = (ac0 + 2048) >> 12;

        // now let's take square root
        ac0 = gaec_utl_en2log(ac0) + GAEC_DB(52.21);
        if (ac0 > 0)
            ac0 = 0;
        pNr->sCoef = gaec_utl_exp((S16)ac0);
        pNr++;
    }
}
/*-------------------------------------------------------------------------*/
#if !defined(_dsp)
void                        gaec_nr_upd
#else
void                        gaec_nr_updC
#endif
/*-------------------------------------------------------------------------*/
(
GAEC_tDb *pDb,
GAEC_tSc *pSc
)
{
    GAEC_tScNr *pNr = pSc->u.aNr;
    int band;

    for (band = 0; band < GAEC_BANDS+1; band++)
    {
        S32 ac0;

        if (pNr->sCoef > 1024) // att < 12db
        {
            pDb->asNrCoef[band] = pNr->sCoef;
        }
        else if (pNr->sCoef > 720) // 12dB < att < 15 db
        {
            pDb->asNrCoef[band] += (pNr->sCoef - pDb->asNrCoef[band]) >> 1;
        }
        else if (pNr->sCoef > 410) // 15 db < att < 20 dB
        {
            pDb->asNrCoef[band] += (pNr->sCoef - pDb->asNrCoef[band]) >> 2;
        }
        else // att > 20 dB, clipped at 20 dB
        {
            pDb->asNrCoef[band] += (  410 - pDb->asNrCoef[band]) >> 3;
        }

        ac0 = pNr->sSig * (S32) pDb->asNrCoef[band];
        ac0 >>= 12;
        pDb->aslNrPrior[band] = ac0 * ac0;

        pNr++;

    }
}
/*-------------------------------------------------------------------------*/
#if !defined(_dsp)
void                        gaec_nr_att
#else
void                        gaec_nr_attC
#endif
/*-------------------------------------------------------------------------*/
(
GAEC_tDb *pDb,
GAEC_tSc *pSc
)
{
// asTmp use: GAEC_BANDS*2
    GAEC_tScNr *pNr = pSc->u.aNr;
    int band;

    for (band = 0; band < GAEC_BANDS+1; band++)
    {
        pSc->u.asTmp[band] = pDb->asNrCoef[band];
        pNr++;
    }
    for (band = 1; band < GAEC_BANDS; band ++)
    {
        pSc->u.asTmp[band + GAEC_BANDS] = pSc->u.asTmp[band];
    }
    for (band = 0; band < GAEC_BANDS*2; band++)
    {
        S16 sAtt = pSc->u.asTmp[band];
        S16 k;
        for (k = 0; k < GAEC_ERR_SZ; k ++)
        {
            S32 ac0 = pSc->aasErr0[band][k] * (S32) sAtt;
            pSc->aasErr0[band][k] = _Srnd(ac0, 3);
        }
    }
}

/*-------------------------------------------------------------------------*/

⌨️ 快捷键说明

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