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

📄 gaecdtd.c

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

#include "gaeci.h"

/*--------------------- local defs ----------------------------------------*/
/*--------------------- public vars ---------------------------------------*/
/*--------------------- local vars ----------------------------------------*/
/*--------------------- local functions -----------------------------------*/

/*-------------------------------------------------------------------------*/
void                        _avrg_erle_fb
/*-------------------------------------------------------------------------*/
(
GAEC_tDb *pDb,
GAEC_tSc *pSc
)
{
	
    if (((pSc->sSinEn - pDb->sErleAv) > pDb->sVadErrNse) &&
        ((pSc->sRoutEn - pDb->sErleAv - pDb->sErlAv) > pDb->sVadErrNse) &&
         (pDb->sDtCrit < 0))
    {
	    S16 sCoef = Q15(1./64.);
    	if (pDb->uAdfMode > 2)
        	sCoef >>= 1;
    	if (pDb->uAdfMode > 3)
        	sCoef >>= 1;
        	
        gaec_utl_avrg(&(pDb->sErleAv), pSc->sErle, sCoef);
        if (pDb->sErleAv < 0)
            pDb->sErleAv = 0;
            
        sCoef >>= 1;
        
        gaec_utl_avrg(&(pDb->sErlAv ), pSc->sErl,  sCoef);
        if (pDb->sErlAv < pDb->Cfg.sErlMin)
            pDb->sErlAv = pDb->Cfg.sErlMin;
    }
}
/*--------------------- public  functions ---------------------------------*/
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
void                        _erle_max
/*-------------------------------------------------------------------------*/
(
GAEC_tDb *pDb, 
GAEC_tSc *pSc 
)
{
    int k;
    // let's test if the tx energy is not excessive,
    // so the loudspeaker isn't in non-linear zone
    S16 sEn = pDb->asFlatRoutEnHst[0];

    // max of some of the most recent frames
    for (k = 1; k < GAEC_FLATEN_SZ-1; k++)
    {
        S16 x = pDb->asFlatRoutEnHst[k];
        if (sEn < x)
            sEn = x;
    }

    // let's assume that the distortions are due to the 3rd harmonics
    // dis = alpha*x^3.
    // then if the signal strength is x, the distortions are x*2
    // the relative is dis/x = alpha*x^2;
    // if we know the level when distortions are 1% (-40 dB) , then 
    // they will grow to 10% (-20 dB) when signal is 3 times (-10dB)
    // stronger

    sEn -= pDb->Cfg.sRcvDistThr;
    if (sEn < GAEC_DB(-35))
        sEn = GAEC_DB(-35);
    pSc->sErleMax = GAEC_ERLE_MAX - sEn*2;
}
/*-------------------------------------------------------------------------*/
void						gaec_dtd_update_rout_flat
/*-------------------------------------------------------------------------*/
(
GAEC_tDb *pDb, 
S16 *psRcv
)
{
	int k;

	for (k = 0; k < GAEC_FLATEN_SZ-1; k++)
	{
		pDb->asFlatRoutEnHst[k] = pDb->asFlatRoutEnHst[k+1];
	}
	pDb->asFlatRoutEnHst[GAEC_FLATEN_SZ-1] = gaec_utl_pkt_energy(psRcv) + GAEC_DB(0);
}

/*-------------------------------------------------------------------------*/
void                        gaec_dtd_update_exp_err
/*-------------------------------------------------------------------------*/
(
GAEC_tDb *pDb,
GAEC_tSc *pSc
)
{
    _erle_max(pDb, pSc);

    pSc->sRoutEn = gaec_utl_pkt_energy
		(pDb->asRbuf + (GAEC_RBUF_SZ-GAEC_FR_SZ)/2);
    gaec_dtd_exp_err(pDb, pSc);
    gaec_dtd_exp_err_sb(pDb, pSc);
}

/*-------------------------------------------------------------------------*/
void                        gaec_dtd
/*-------------------------------------------------------------------------*/
(
GAEC_tDb *pDb,
GAEC_tSc *pSc
)
{
    gaec_dtd_vad_err(pDb, pSc);
    gaec_dtd_vad_err_sb(pDb, pSc);
	gaec_dtd_criteria(pDb, pSc);
	gaec_dtd_criteria_sb(pDb, pSc);

    if (pDb->uIsTone) // tone on Rcv
    {
        gaec_dtd_dec_criteria(pDb, pSc); // if any

        pSc->uNlpMode = GAEC_NLP_MODE_CLEAR;
    }
    else // normal call 
    {
        if (pDb->uIsDT == FALSE)
        {
            if (pDb->sDtCrit > GAEC_CRIT_MRGN)
            {
                pDb->uIsDT = TRUE;

                gaec_adf_dt_start(pDb, pSc);
            }
        }
        else
        {
            if (pDb->sDtCrit < 0)
            {
                pDb->uIsDT = FALSE;

                gaec_adf_dt_end(pDb, pSc);
            }
        }

        // if Snd is most probably an echo
    	gaec_dtd_avrg_erle_sb(pDb, pSc);
        _avrg_erle_fb(pDb, pSc);

        pSc->uNlpMode = GAEC_NLP_MODE_MODIFY;
    }

    if (pDb->uControl & IGAEC_CMD_NLP_OFF)
    {
        pSc->uNlpMode = GAEC_NLP_MODE_PASS;
    }

}

⌨️ 快捷键说明

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