demo.cpp

来自「Express DSP compliant C55x DTMF detector」· C++ 代码 · 共 1,667 行 · 第 1/4 页

CPP
1,667
字号
            val_out(XT4, YT1, CYAN,       "DBad   %d", pDb->v.sBad);

            val_out(XT6, YT1, WHITE,      "D2kDlt %8.2f", pSc->s2kEnDlt/170.1);
            val_out(XT7, YT1, GREEN,      "Ddial  %8.2f", dtmf_en2log(pDb->v.slDialEn)/170.1);

            val_out(XT8, YT1, WHITE,      "dTwstM %8.2f", 
                (pSc->sHiMaxFreqEn - pSc->sLoMaxFreqEn)/170.1);
        }
        /* row 2 --------------------------------------------- */
        bar(XT0, YT2, XTM, YT2+YTD);
        {
    	    for(k=0;k<6;k++)
	        {
	    	    val_out(XT0+k*XTD, YT2, WHITE,
                                           "%DEn[%d] %8.2f", k, pDb->v.asSumEn[k]/170.1);
    	    }
            val_out(XT6, YT2, __aiColor[0],"DLoEn  %8.2f", pSc->sLoBpEn/170.1);
            val_out(XT7, YT2, __aiColor[1],"DHiEn  %8.2f", pSc->sHiBpEn/170.1);
            val_out(XT8, YT2, WHITE,       "dTwstB %8.2f", 
                (pSc->sHiBpEn-pSc->sLoBpEn)/170.1);
        }
        /* row 3 --------------------------------------------- */
        bar(XT0, YT3, XTM, YT3+YTD);
        {
            extern S16 DBG_sFrameEn;
            val_out(XT0, YT3, LIGHTGREEN, "GState %d", __TgDb.sState);
            val_out(XT1, YT3, LIGHTRED,   "GLoAmp %d", __TgDb.Lo.sAmp);
            val_out(XT2, YT3, LIGHTBLUE,  "GHiAmp %d", __TgDb.Hi.sAmp);
            val_out(XT3, YT3, WHITE,      "Gsame  %d", __Gen.iSameCntr);

            val_out(XT4, YT3, DARKGRAY  , "Dframe %8.2f", dtmf_en2log(pSc->slFrameEn)/170.1);
            val_out(XT5, YT3, WHITE,      "Dprev  %8.2f", DBG_sFrameEn/170.1);
            val_out(XT6, YT3, LIGHTGREEN, "Dsumdl %8.2f", pSc->sSumDialEn/170.1);
            val_out(XT7, YT3, LIGHTGREEN, "Dsum   %8.2f", pSc->sSumEn/170.1);
            val_out(XT8, YT3, WHITE,      "DClHi  %8.2f",
                (pSc->sHiMaxFreqEn - pSc->sHiNextEn)/170.1);

        }

        /* row 4 --------------------------------------------- */
        bar(XT0, YT4, XTM, YT4+YTD);
        {
	        val_out(XT0, YT4, LIGHTRED,   "GLoIdx %d", __Gen.iLoIdx);
	        val_out(XT1, YT4, LIGHTBLUE,  "GHiIdx %d", __Gen.iHiIdx);
            val_out(XT2, YT4, LIGHTRED,   "GLoPh  %d", __TgDb.Lo.sPhase);
            val_out(XT3, YT4, LIGHTBLUE,  "GHiPh  %d", __TgDb.Hi.sPhase);
            val_out(XT4, YT4, LIGHTGRAY,  "GtoneC %d", __Gen.iToneCntr);
            val_out(XT5, YT4, LIGHTGRAY,  "GfreqC %d", __Gen.iFreqCntr);
            val_out(XT6, YT4, LIGHTRED,   "GLoStp %d", __TgDb.Lo.sFreq);
            val_out(XT7, YT4, LIGHTBLUE,  "GHiStp %d", __TgDb.Hi.sFreq);

            val_out(XT8, YT4, WHITE,      "DClLo  %8.2f",
                (pSc->sLoMaxFreqEn - pSc->sLoNextEn)/170.1);
        }
        /* row 7 --------------------------------------------- */
        bar(XT0, YT7, XTM, YT7+YTD);
        {
	        val_out(XT0, YT7, LIGHTRED,   "DLoDv %8.2f", pSc->sLoFreqDev/170.);
	        val_out(XT1, YT7, __aiColor[4],"DLoDS %8.2f", pDb->v.Stat.sLoFreqDev/170.);
	        val_out(XT2, YT7, LIGHTRED,   "DLoPl %8.2f", 
                (pSc->sLoMaxFreqEn - pSc->asLoMainEn[pSc->sLoFreqNo])/170.);
	        val_out(XT3, YT7, RED,        "DLoES %8.2f", pDb->v.Stat.sLoEn/170.);

            val_out(XT4, YT7, LIGHTBLUE,  "DHiDv %8.2f", pSc->sHiFreqDev/170.);
            val_out(XT5, YT7, __aiColor[8],"DHiDv %8.2f", pDb->v.Stat.sHiFreqDev/170.);
	        val_out(XT6, YT7, LIGHTBLUE,  "DHiPl %8.2f", 
                (pSc->sHiMaxFreqEn - pSc->asHiMainEn[pSc->sHiFreqNo])/170.);
	        val_out(XT7, YT7, BLUE,       "DHiES %8.2f", pDb->v.Stat.sHiEn/170.);
	        val_out(XT8, YT7, WHITE,      "DEn %8.2f", pDb->v.Stat.sEn/170.);
        }
        /* row 8 --------------------------------------------- */
        bar(XT0, YT8, XTM, YT8+YTD);
        {
        }
    }
}

/*--------------------- public  functions ---------------------------------*/
/*-------------------------------------------------------------------------*/
void                    indicate_start
/*-------------------------------------------------------------------------*/
(
)
{
    __lStartFrame = __Frame;
}
/*-------------------------------------------------------------------------*/
void                    indicate_end
/*-------------------------------------------------------------------------*/
(
)
{
}

/*-------------------------------------------------------------------------*/
void                    dump_val
/*-------------------------------------------------------------------------*/
(
S16 s1, 
S16 s2
)
{
    if(__Control.pTmpFile)
        fprintf(__Control.pTmpFile, "%6d %6d\n", s1, s2);
}
/*-------------------------------------------------------------------------*/
int                     demo_ind_tone
/*-------------------------------------------------------------------------*/
(
S16 toneId,
S16 IsOn
)
{
    if (IsOn) // start
    {
        __Stat.sStart++;
        if (__Control.iCatchCntr > 0)
        {
            __Control.iCatchCntr = -1;
        }

        if (__Control.pDbgFile)
        {
            static int cntr = 0;
            cntr++;
            fprintf(__Control.pDbgFile, 
                "start    %2d [%05d] frame %ld\n",
                toneId,    cntr,  __Frame);
        }
    }
    else
    {
        __Stat.sEnd++;
        if (__Control.pDbgFile)
        {
            DTMF_tDb *pDb = &__DtmfDb;
            static int cntr = 0;
            cntr++;
            fprintf(__Control.pDbgFile, 
                "end      %2d [%05d] frame %ld\n",
                toneId,    cntr,  __Frame);
            fprintf(__Control.pDbgFile, 
                "stats LO: en %7.2fdBm dev %7.2f%% HI: en %7.2fdBm dev %7.2f%% \n",
                pDb->v.Stat.sLoEn/170.1,
                pDb->v.Stat.sLoFreqDev/170.1,
                pDb->v.Stat.sHiEn/170.1,
                pDb->v.Stat.sHiFreqDev/170.1
                );
        }
    }
    return 0;
}

/*-------------------------------------------------------------------------*/
int                     demo_ind_abort
/*-------------------------------------------------------------------------*/
(
S16 toneId,
S16 IsOn
)
{
    __Stat.sAbort++;
    if (__Control.pDbgFile)
    {
        static int cntr = 0;
        cntr++;
        fprintf(__Control.pDbgFile, 
                "abort    %2d [%05d] frame %ld\n",
            toneId,    cntr,  __Frame);
    }
    return 0;
}

/*-------------------------------------------------------------------------*/
int                     demo_ind_early
/*-------------------------------------------------------------------------*/
(
S16 toneId,
S16 IsOn
)
{
    if (IsOn)
    {
        __Stat.sEarlyOn++;
        if (__Control.pDbgFile)
        {
            static int cntr = 0;
            cntr++;
            fprintf(__Control.pDbgFile, 
                "earlyon  %2d [%05d] frame %ld\n",
                toneId,    cntr,  __Frame);
        }
//        if(__Control.pTmpFile) fprintf(__Control.pTmpFile, "%6d\n", int(__Frame - __lStartFrame));
    }
    else
    {
        __Stat.sEarlyOff++;
        if (__Control.pDbgFile)
        {
            static int cntr = 0;
            cntr++;
            fprintf(__Control.pDbgFile, 
                "earlyoff %2d [%05d] frame %ld\n",
                toneId,    cntr,  __Frame);
        }
    }
    return 0;
}
/*-------------------------------------------------------------------------*/
void                    demo_init
/*-------------------------------------------------------------------------*/
(
int Err
)
{
    if(fabs(__Control.fRxCorr) < 0.001)
            __Control.fRxCorr = 1.0;

    TG_create(&__TgDb);
    TG_init(&__TgDb);
    TG_create(&__DialDb);
    TG_init(&__DialDb);

	DTMF_create(&__DtmfDb);

    __DtmfCfg.sFwdTwistThr  = dbs(4.0);
    __DtmfCfg.sRevTwistThr  = dbs(8.0);
    __DtmfCfg.sMinEnThr     = dbs(-40.0);
    __DtmfCfg.sNoiseThr     = dbs(10.25-1.25);
    __DtmfCfg.sSumEnThr     = dbs(2.75+0);
    __DtmfCfg.sVarThr       = dbs(2.0+1);
    __DtmfCfg.s2kUpThr      = dbs(11.0-3);
    __DtmfCfg.sPartThr      = dbs(2.0+0);
    __DtmfCfg.sCleanThr     = dbs(10.75-3.75);
    __DtmfCfg.sMaxFreqDevThr = dbs(2+0.5);
    __DtmfCfg.sMinToneDuration = 4-2;
    __DtmfCfg.sMinPostSilenceDuration = 4;
    __DtmfCfg.sAbortTimeout = 4;

    DTMF_init(&__DtmfDb, &__DtmfCfg);

    tg_config();
    
    dial_config();

    graphic_init(Err);
}

/*-------------------------------------------------------------------------*/
void                        demo_run
/*-------------------------------------------------------------------------*/
(
)
{
    S16 sRc;
    __Frame++;
    S16 k;

//    if(__Frame == 1240) DEMO_StepMode = TRUE;
//    if(__Frame == 5963) DEMO_StepMode = TRUE;
//    if(__Frame == 6624) DEMO_StepMode = TRUE;

    for(k=0; k < RX_DELAY; k++) __aRx[k] = __aRx[k+STD_FR_SZ];
	fill_input(&__aRx[RX_DELAY]);
	sRc = DTMF_process(&__DtmfDb, &__DtmfSc, &__aRx[0]);
//    for(k=0; k < STD_FR_SZ; k++) dump_val(__aRx[k],0);

    switch(sRc&0xff00)
    {
    case DTMF_EV_NONE:
        break;
    case DTMF_EV_EARLY_ON:
        demo_ind_early(sRc & 0xff, TRUE);
        break;
    case DTMF_EV_EARLY_OFF:
        demo_ind_early(sRc & 0xff, FALSE);
        break;
    case DTMF_EV_START:
        demo_ind_tone (sRc & 0xff, TRUE);
        break;
    case DTMF_EV_END:
        {
            DTMF_tStats Stats;
            DTMF_get_stats(&__DtmfDb, &Stats);
            dump_val(Stats.sLoFreqDev, Stats.sHiFreqDev);
//            dump_val(Stats.sLoEn, Stats.sHiEn);
//            dump_val(Stats.sEn, 0);
        }
        demo_ind_tone (sRc & 0xff, FALSE);
        break;
    case DTMF_EV_ABORT:
        demo_ind_abort(sRc & 0xff, TRUE);
//        DEMO_StepMode = TRUE;
        break;
    }

    if (--__Control.iCatchCntr == 0)
    {
        if ((__Control.iCatch) && (__Gen.iSameCntr < __Gen.iSameCntrMax))

        {
            DEMO_StepMode = TRUE;
        }
    }

	plot_results();
}

/*-------------------------------------------------------------------------*/
void                    demo_exit
/*-------------------------------------------------------------------------*/
(
)
{
	// close all files
	if (__Control.pDbgFile) fclose(__Control.pDbgFile);
	if (__Control.pInFile)  fclose(__Control.pInFile);
	if (__Control.pOutFile) fclose(__Control.pOutFile);
	if (__Control.pTmpFile) fclose(__Control.pTmpFile);
}

/*-------------------------------------------------------------------------*/
int                     demo_get_cfg
/*-------------------------------------------------------------------------*/
(
)
{
    int Err = 0;
	FILE *pCfgFile = fopen("sim.cfg", "r");
    int Line;

	if ( pCfgFile == NULL )
	{
        Err = 99;
		__err(Err, 0, "opening config file SIM.CFG ");
	}
	else
	{
		for ( Line = 1;; Line++)
		{
			int i;
			char *p = fgets(__aBuff, 80, pCfgFile);
			if ( p == NULL )	// EOF
			{
				break;
			} /* end-of-if */
			for ( i = 0; i < 80; i++ )
			{
				if ( iscntrl(__aBuff[i]))
				{
					__aBuff[i] = 0;
					break;
				} /* end-of-if */
			}  /* end-of-for */

			if (strlen(__aBuff))
			{
				Err = get_cfg_line(__aBuff);
				if(Err)
				{
                    __err(Err, Line, " processing sim.cfg file at ");
					break;
				}
			}
		}  /* end-of-for */
		fclose(pCfgFile);
	}
    return Err;
}
#if 0
            static const double aKdevLo[4] = {
                1.765, 1.4142, 1.1186, 0.8876
            };
            static const double aKdevHi[4] = {
                1.879, 1.5101, 1.2024, 0.9482
            };
            static const double coef[4] = {
                -0.15, -0.2, 0.2, 0.15
            };
            static const double dlev = 0.32;
            int k;
            double accLo = 0;
            double accHi = 0;

            for (k = 0; k < 4; k++)
            {
                accLo += afNew[2+k]*coef[k];
                accHi += afNew[6+k]*coef[k];
            }

            accLo *= -aKdevLo[iLo];
            accHi *= -aKdevHi[iHi]*0.75;
	        val_out(XT0, YT7, LIGHTRED,   "DLoDev %8.2f", accLo);
	        val_out(XT1, YT7, LIGHTBLUE,  "DHiDev %8.2f", accHi);

            if ((__Control.pOutFile != NULL) &&
                ((pDb->v.sState == 2) ||
                (pDb->v.sState == 3)))
                fprintf(__Control.pOutFile, "%d %8.3f %8.3f\n", pDb->v.sState, accLo, accHi);
            val_out(XT2, YT7, LIGHTRED,   "DLoPl %8.2f", accLo*accLo*dlev/aKdevLo[iLo]);
	        val_out(XT3, YT7, LIGHTBLUE,  "DHiPl %8.2f", accHi*accHi*dlev/aKdevHi[iHi]);
/*-------------------------------------------------------------------------*/
double                   L2dB_oldf
/*-------------------------------------------------------------------------*/
(
S32 energy
)
#define EN1 (4096.0*4096.0*STD_FR_SZ/8.0)
{
    double en = 10.0*log10(energy/EN1 + 1e-12);
    if (en < YEDBMIN) en = YEDBMIN;
    if (en > YEDBMAX) en = YEDBMAX;
    return (-en);
}
#endif

⌨️ 快捷键说明

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