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

📄 gaec.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 <string.h>
#include "gaeci.h"

/*--------------------- local defs ----------------------------------------*/
/*--------------------- public vars ---------------------------------------*/
#if defined(_dsp)
#pragma DATA_SECTION (GAEC_aasFBR, ".gaectab1");
#pragma DATA_SECTION (GAEC_aasFBS, ".gaectab2");
#pragma DATA_SECTION (GAEC_aasFBX, ".gaectab3");

#endif
#include "fb.c"

#if ! defined(_dsp)

#endif

#if (_DSK_VER)
S16 _asSoutEn[GAEC_BANDS+1]; // dbg
#endif

/*--------------------- local vars ----------------------------------------*/
/*--------------------- local functions -----------------------------------*/
/*-------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------*/
void                        _cfg_setup
/*-------------------------------------------------------------------------*/
(
GAEC_tDb *pDb,
IGAEC_tCfg *pCfg
)
{
    pDb->Cfg = *pCfg;
    pDb->Cfg.sDtThr *= 17;
    pDb->Cfg.sErlMin *= 17;
    pDb->Cfg.sTCLst *= 17;
    pDb->Cfg.sWhiteThr *= 17;
    pDb->Cfg.sTCLdt *= 17;
    pDb->Cfg.sRcvDistThr *= 17;
}
/*-------------------------------------------------------------------------*/
void                        _db_setup
/*-------------------------------------------------------------------------*/
(
GAEC_tDb *pDb
)
{
    int band;
    int k;

    for (band = 0; band < GAEC_BANDS+1; band++)
    {
        pDb->aslAdEn[band] = (S32)(GAEC_ADF_SZ * 3 * 3.);
		pDb->asErlAv[band] = pDb->Cfg.sErlMin;
        pDb->asVadErrNse[band] = GAEC_DB(-55.0);
        pDb->asVadRinNse[band] = GAEC_DB(-70.0);
        pDb->asExpectedErrEn[band] = GAEC_DB(-55.0);
    }
    pDb->sErlAv = pDb->Cfg.sErlMin;
    pDb->sVadErrNse = GAEC_DB(-50.0);
    pDb->sVadRinNse = GAEC_DB(-65.0);
    pDb->sExpectedErrEn = GAEC_DB(-50.0);

    for (k = 0; k < GAEC_ADF_FRS; k++)
    {
        pDb->asRoutEnHst[k] = GAEC_DB(-60);
        for (band = 0; band < GAEC_BANDS+1; band++)
        {
            pDb->aasRoutEnHst[band][k] = GAEC_DB(-65);
        }
    }
    for (k = 0; k < GAEC_FLATEN_SZ; k++)
    {
		pDb->asFlatRoutEnHst[k] = GAEC_DB(-60.0);
	}
}
/*-------------------------------------------------------------------------*/
void                        _stts_update
/*-------------------------------------------------------------------------*/
(
GAEC_tDb *pDb,
GAEC_tSc *pSc
)
{
	GAEC_MIKET_tStts *pStts = &(pDb->Stts);
	
    pStts->sRcvNoise = _by17(pDb->sVadRinNse);
    pStts->sSndNoise = _by17(pDb->sVadErrNse);
    pStts->sErl  = _by17(pDb->sErlAv);
    pStts->sErle = _by17(pDb->sErleAv);
	pStts->sMaxCoef = pDb->sMaxCoefAv;

	{
		int band = 0;
		S16 sWorstErl = GAEC_DB(20);
		for (band = 0; band < GAEC_BANDS; band++)
		{
			if (sWorstErl > pDb->asErlAv[band])
				sWorstErl = pDb->asErlAv[band];
		}
		pStts->sWorstErl = _by17(sWorstErl);
	}
    
}

/*--------------------- public  functions ---------------------------------*/
 
/*-------------------------------------------------------------------------*/
void                        GAEC_MIKET_init_db
/*-------------------------------------------------------------------------*/
(
void *p,
IGAEC_tCfg *pCfg,
S16 *psRcv,
S16 *psAdf,
S16 *psAdfM
)
{
    GAEC_tDb *pDb = (GAEC_tDb *)p;

    memclr (p, sizeof(GAEC_tDb));

    pDb->psRcv = psRcv;
    pDb->psAdf = psAdf;
    pDb->psAdfM = psAdfM;
    memclr(pDb->psRcv, GAEC_RCV_SZ*2*GAEC_BANDS);
    memclr(pDb->psAdf, GAEC_ADF_SZ*2*GAEC_BANDS);
    memclr(pDb->psAdfM, GAEC_ADF_SZ*2*GAEC_BANDS);
    _cfg_setup(pDb, pCfg);
    _db_setup(pDb);
}
/*-------------------------------------------------------------------------*/
void                        GAEC_MIKET_control
/*-------------------------------------------------------------------------*/
(
void *pdb,
IALG_Cmd Cmd,
IGAEC_Status *pStatus
)
{
    GAEC_tDb *pDb = (GAEC_tDb *)pdb;
    U16 uMask = IGAEC_CMD_CFG | IGAEC_CMD_RESET | IGAEC_CMD_PRESERVE_FLT | IGAEC_CMD_VOLUME;
    
    
	if (Cmd & IGAEC_CMD_CFG)
	{
		_cfg_setup(pDb, pStatus->pCfg);
	}

	if (Cmd & IGAEC_CMD_RESET)
	{
		S16 *p1 = (S16 *)pDb;
		S16 *p2 = (S16 *)&(pDb->Cfg);
		p1 += sizeof(p1)*3; // pass psRcv flt;
		memclr(p1, p2-p1);
        memclr(pDb->psRcv, GAEC_RCV_SZ*2*GAEC_BANDS);
		if (!(Cmd & IGAEC_CMD_PRESERVE_FLT))
		{
            memclr(pDb->psAdf, GAEC_ADF_SZ*2*GAEC_BANDS);
            memclr(pDb->psAdfM, GAEC_ADF_SZ*2*GAEC_BANDS);
		}
        _db_setup(pDb);
	}

	if (Cmd & IGAEC_CMD_VOLUME)
	{
        int band;
        S16 sDiff = pStatus->sVolume * 17 - pDb->sVolume;
        for (band = 0; band < GAEC_BANDS+1; band++)
        {
            pDb->asVadRinNse[band] += sDiff;
        }
		pDb->sVolume += sDiff;
	}


    pDb->uControl &= ~uMask;
    Cmd 		  &= ~uMask;
    pDb->uControl = (pDb->uControl & (~pStatus->uCmdMask)) | 
    				(Cmd           & ( pStatus->uCmdMask));
}

/*-------------------------------------------------------------------------*/
GAEC_MIKET_tStts *          GAEC_MIKET_stts
/*-------------------------------------------------------------------------*/
(
void *pdb
)
{
	
    GAEC_tDb *pDb = (GAEC_tDb *)pdb;
    return &(pDb->Stts);
}
/*-------------------------------------------------------------------------*/
void                        GAEC_MIKET_process
/*-------------------------------------------------------------------------*/
(
void *pdb,
void *psc,
S16 *psRcv,
S16 *psSnd
)
{
    GAEC_tDb *pDb = (GAEC_tDb *)pdb;
    GAEC_tSc *pSc = (GAEC_tSc *)psc;

    if (pDb->uControl & IGAEC_CMD_ALL_OFF)
    {
    	return;
    }

    memclr(pSc, sizeof(GAEC_tSc));
#if _DSK_LIM
	{
		pDb->ulLimCnt++;
		if (pDb->ulLimCnt > (200*60*30L))
			return;
	}
#endif

    gaec_rcv_detect_tone (pDb, pSc, psRcv);
    gaec_in_corr(&pDb->sSinSav, psSnd);

    if (pDb->uControl & IGAEC_CMD_LOOPBACK)
    {
    	gaec_loopback(pDb, psSnd);
    }

    gaec_fb_snd_analysis(pDb, pSc, psSnd);
    gaec_nrg_blk(&pSc->aasSin[0][0], pSc->asSinEn);
    gaec_nrg_rcv(pDb, pSc);

    gaec_adf_cancel(pDb, pSc); // on both active and mirror filters
    gaec_nrg_blk(&pSc->aasErr[0][0], pSc->asErrEn);
    gaec_nrg_blk(&pSc->aasErrM[0][0], pSc->asErrMEn);

    gaec_dtd_update_exp_err(pDb, pSc);
    gaec_adf_stepsize(pDb, pSc);
    gaec_adf_adapt(pDb, pSc);

    gaec_nrg_blk(&pSc->aasErr[0][0], pSc->asErrEn);

    gaec_adf_epc_control(pDb, pSc);
    gaec_update_err_sav(pDb, pSc);
    gaec_fb_synthesis (pDb->aasErrSav, psSnd);

    gaec_erle(pDb, pSc, psSnd);
    gaec_erle_sb(pDb, pSc);
    gaec_erl(pDb, pSc);
    gaec_erl_sb(pDb, pSc);

#if (_DSK_VER)//!defined(_dsp)
    {
        extern void gaec_cnl_corr(S16*);
        gaec_cnl_corr(psSnd);
    }
#endif

	// rcv,snd xcorrelation is done on non-flattented signals
    gaec_out_corr(&pDb->slSepcSav, psSnd);
    gaec_epc_xcorrelation(pDb, pSc, psRcv, psSnd);

    gaec_dtd(pDb, pSc);

    gaec_adf_control(pDb, pSc);

    gaec_nlp(pDb, pSc);

#if !defined (_dsp)
    {
		extern S16 _asNr[GAEC_FR_SZ];
        extern void gaec_err0_energy(GAEC_tSc *pSc);
        extern void gaec_nr_corr(void);
        gaec_err0_energy(pSc);
        gaec_fb_synthesis(pSc->aasErr0, _asNr);
        gaec_nr_corr();
    }
#endif

// end of Snd processing
    gaec_nr(pDb, pSc); // noise reduction
#if (_DSK_VER)    
    gaec_nrg_err(pSc->aasErr0, _asSoutEn); // dbg
#endif    
    gaec_fb_synthesis(pSc->aasErr0, psSnd);
    gaec_out_corr(&pDb->slSoutSav, psSnd);

// end of Rcv processing
    pSc->sRinEn = gaec_utl_pkt_energy(psRcv);
    gaec_tx_vad_fb(pDb, pSc);

    gaec_in_corr(&pDb->sRinSav, psRcv);

    gaec_tx_process(pDb, pSc, psRcv);
    gaec_update_rbuf(pDb, psRcv);
    gaec_shift_rcv(pDb);
    gaec_fb_rcv_analysis(pDb, pSc);

    gaec_out_corr(&pDb->slRoutSav, psRcv);

	gaec_dtd_update_rout_flat(pDb, psRcv);

//	stts
	gaec_max_coef(pDb, pSc);
	gaec_adf_scale(pDb, pSc);
    _stts_update(pDb, pSc);
}

⌨️ 快捷键说明

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