📄 cpdr.c
字号:
/*-------------------------------------------------------------------------*
* *
* THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY *
* INFORMATION. IF PUBLICATION OCCURS, THE FOLLOWING NOTICE APPLIES: *
* "COPYRIGHT 2001 MIKET DSP SOLUTIONS, ALL RIGHTS RESERVED" *
* *
*-------------------------------------------------------------------------*/
#if ! defined (_dsp)
#include <stdlib.h> // abs()
#endif
#include "stddefs.h"
#include "cpdi.h"
/*--------------------- local defs ----------------------------------------*/
/*--------------------- public vars ---------------------------------------*/
/*--------------------- local vars ----------------------------------------*/
/*--------------------- local functions -----------------------------------*/
/*-------------------------------------------------------------------------*/
void cpd_get_lohi
/*-------------------------------------------------------------------------*/
(
CPD_tDb *pDb,
CPD_tSc *pSc
)
{
const ICPD_tCfg *pCfg = pDb->pCfg;
pSc->sLoIdx = pSc->sMaxIdx;
pSc->Lo.sEn = pSc->sMaxEn;
pSc->sHiIdx = pSc->sNextIdx;
pSc->Hi.sEn = pSc->sNextEn;
if ((pSc->sMaxEn - pSc->sNextEn) < (pCfg->sTwistThr<<1))
{
/* that's most probably not a single frequency */
if (pSc->sMaxIdx > pSc->sNextIdx)
{
pSc->sLoIdx = pSc->sNextIdx;
pSc->Lo.sEn = pSc->sNextEn;
pSc->sHiIdx = pSc->sMaxIdx;
pSc->Hi.sEn = pSc->sMaxEn;
}
pSc->sTestFailed = CPD_MASK_DUAL;
}
else
{
pSc->sTestFailed = 0;
}
}
/*-------------------------------------------------------------------------*/
void cpd_test
/*-------------------------------------------------------------------------*/
(
CPD_tDb *pDb,
CPD_tSc *pSc
)
{
const ICPD_tCfg *pCfg = pDb->pCfg;
S32 ac2;
S16 sTestFailed = pSc->sTestFailed;
ac2 = pSc->aOut[pSc->sMaxIdx].slEn;
ac2 += pSc->aOut[pSc->sNextIdx].slEn;
pSc->sSumEn = cpd_en2log(ac2, CPD_EN_PG);
/* test that frame energy is high enough. */
if (pSc->sMaxEn < pCfg->sMinEnThr)
sTestFailed |= CPD_MASK_MAX_EN;
/* test leading edge */
{
S16 sEn = pDb->v.asSumEn[CPD_EN_SZ-2];
if (sEn < pDb->v.asSumEn[CPD_EN_SZ-1])
sEn = pDb->v.asSumEn[CPD_EN_SZ-1];
if ((pSc->sSumEn - sEn) < pCfg->sNoiseThr)
sTestFailed |= CPD_MASK_RS_EDGE;
}
/* test falling edge */
if ((pDb->v.sAvrEn - pSc->sSumEn) < pCfg->sNoiseThr)
sTestFailed |= CPD_MASK_FL_EDGE;
/* test that frame energy is reasonably stable */
if (abs(pDb->Stts.sLoEn - pSc->Lo.sEn) > pCfg->sStableThr)
sTestFailed |= CPD_MASK_LO_STABLE;
if (abs(pDb->Stts.sHiEn - pSc->Hi.sEn) > pCfg->sStableThr)
sTestFailed |= CPD_MASK_HI_STABLE;
/* test that the spectrum is clean:
the highest of two dominant freqs shall be
much higher than the rest freqs */
{
S16 sDltEn = pSc->sMaxEn - pSc->sRestEn;
if (sDltEn < pCfg->sCleanThr)
sTestFailed |= CPD_MASK_CLEAN;
if (sDltEn < (pCfg->sCleanThr>>1))
sTestFailed |= CPD_MASK_CLEAN_MB;
}
/* test if the tone is single:
the highest freq shall be much higher than the next freq */
{
S16 sDltEn = pSc->sMaxEn - pSc->sNextEn;
if (sDltEn < pCfg->sCleanThr)
sTestFailed |= CPD_MASK_SINGLE;
if (sDltEn < (pCfg->sCleanThr>>1))
sTestFailed |= CPD_MASK_SINGLE_MB;
if (sDltEn > pCfg->sTwistThr)
sTestFailed |= CPD_MASK_TWIST;
}
/* test that "Lo" freq is in range */
{
if ((pSc->Lo.sEn - pSc->Lo.sDist) < pCfg->sMaxFreqDevThr)
sTestFailed |= CPD_MASK_LO_OK;
}
/* test that "Hi" freq is in range */
{
if ((pSc->Hi.sEn - pSc->Hi.sDist) < pCfg->sMaxFreqDevThr)
sTestFailed |= CPD_MASK_HI_OK;
}
pSc->sDigit = (1<<(pSc->sLoIdx));
if (pSc->sTestFailed & CPD_MASK_DUAL)
{
pSc->sDigit |= (1<<(pSc->sHiIdx));
}
/* test that the digit is the same */
if (pDb->v.sDigit != pSc->sDigit)
sTestFailed |= CPD_MASK_SAME_DGT;
pSc->sTestFailed = sTestFailed;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -