📄 demo.cpp
字号:
/*-------------------------------------------------------------------------*
* *
* THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY *
* INFORMATION. IF PUBLICATION OCCURS, THE FOLLOWING NOTICE APPLIES: *
* "COPYRIGHT 2001 MICHAEL TSIROULNIKOV, ALL RIGHTS RESERVED" *
* *
*-------------------------------------------------------------------------*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define M_PI 3.14159265
#include "sim.h"
#include "stddefs.h"
#include "leci.h"
#include "spbpf.h"
#include "stdafx.h"
#include <mmsystem.h>
#include "ilec.cpp"
/*--------------------- local defs ----------------------------------------*/
#define _GR_FR (200*0)
#define IN_MODE 0
#define LEV0 (4096.0)
#define ECHO_SZ (ILEC_FR_SZ*5)
#define ADF_SZ (LEC_FLT_SZ)
#define ADF2_SZ (LEC_FLT2_SZ)
#define EPS (1.0e-8)
#define X0 (20)
#define DX (1)
#define FR_MAX (200*3)
#define XM (X0+FR_MAX*DX)
#define YCC (619)
#define YCM (80)
#define XADF (XM+10)
#define YADF (100)
#define YADFA (75)
#define XT (XADF+210)
#define YTA 75
#define YDBMAX (+6.0)
#define YDBMIN (-80.0)
#define YG (260)
#define YV (86*3)
#define YDHMAX (+6.0)
#define YDHMIN (-50.0)
#define YGH (10)
#define YVH (56*3)
#define XTD (120)
#define XT0 (X0)
#define XT1 (XT0+XTD)
#define XT2 (XT1+XTD)
#define XT3 (XT2+XTD)
#define XT4 (XT3+XTD)
#define XT5 (XT4+XTD)
#define XT6 (XT5+XTD)
#define XT7 (XT6+XTD)
#define XT8 (XT7+XTD)
#define XTM (XT8+XTD)
#define YTD (20)
#define YT0 (700)
#define YT1 (YT0+YTD)
#define YT2 (YT1+YTD)
#define YT3 (YT2+YTD)
#define YT4 (YT3+YTD)
#define YT5 (YT4+YTD)
#define YT6 (YT5+YTD)
#define YT7 (YT6+YTD)
#define YT8 (YT7+YTD)
typedef struct tControl
{
double fBypass;
int iGmode;
double fRxCorr;
double fTxCorr;
int iRxDelay;
int iTxDelay;
int iReplaceRx;
int iAddReflections;
FILE *pInTrxFile;
FILE *pInTxFile;
FILE *pInTxBin;
FILE *pInRxBin;
FILE *pAdfFile;
FILE *pPcmFile;
FILE *pTmpFile;
FILE *pRespFile;
FILE *pNlpWavFile;
FILE *pCnlWavFile;
FILE *pTxWavFile;
FILE *pRxWavFile;
} tControl;
typedef struct tGen {
double fRxNoise;
double fRxLevel;
double fTxNoise;
double fTxLevel;
double fWordLen;
double fPauseLen;
double fDoubleTalk;
long liSentenceLen;
int iBeginFrom;
int iState;
long liStateCntr;
long liCurrWord;
int iDirection;
} tGen;
typedef struct {
char acRiff[4];
U32 ulLen1;
char acWave[4];
char acFmt[4];
U32 ulLen2;
U16 uMode;
U16 uNumber;
U32 ulFs;
U32 ulBps;
U16 uBytes;
U16 uBits;
char acData[4];
U32 ulLen3;
} tWavHdr;
/*--------------------- public vars ---------------------------------------*/
U16 DEMO_StepMode;
/*--------------------- local vars ----------------------------------------*/
U16 _uIsSeriaOver;
static char _aBuff[81];
tGen _Gen;
tControl _Control;
tWavHdr _WavHdr;
static int _aiColor[10] =
{
RED, GREEN,
3 , 3 +(2<<2), 3 +(3<<2), 3 +(3<<2) + 0x20,
48, 48+(2<<2), 48+(3<<2), 48+(3<<2) + 0x02,
};
long _Frame;
long _lStartFrame;
double _fReflection;
S16 _asReadTmp[ILEC_FR_SZ];
S16 _asRxInHst [LEC_HST_SZ];
S16 _asRxOutHst[LEC_HST_SZ];
S16 _asRxIn[ILEC_FR_SZ];
S16 _asRx[ILEC_FR_SZ];
S16 _asTx[ILEC_FR_SZ];
S16 _asRxOut[ILEC_FR_SZ];
S16 _asCnl[ILEC_FR_SZ];
S16 _asEchoTx[ECHO_SZ+3*ILEC_FR_SZ];
float _afEcho[ECHO_SZ];
S16 _asEchoS16[ECHO_SZ];
S16 _asAdf1Diff[ADF_SZ];
S16 _asAdf2Diff[ADF_SZ];
S16 _asAdfOld[ADF_SZ];
S16 _asAdf[LEC_FLT2_SZ*2];
S16 _asHst[LEC_HST_SZ*2];
LEC_MIKET_tStts _LecStts;
LEC_tDb _LecDb;
LEC_tSc _LecSc;
//ILEC_tCfg _LecCfg;
ILEC_Status _LEC_Status;
SPBPF_tDb _SpBpfDb;
SPBPF_tSc _SpBpfSc;
char *_acOn[] =
{
"off",
"on"
};
char *aVad[] =
{
"IDLE",
"PRE",
"ACTIVE",
"HANGOVER"
};
int st_x;
/*--------------------- local functions -----------------------------------*/
void dump_results(void);
/*-------------------------------------------------------------------------*/
static void _err
/*-------------------------------------------------------------------------*/
(
int no,
int line,
char *pStr
)
{
val_out(400, 0, LIGHTRED, "ERR %d : %s (line %d)", no, pStr, line);
}
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/* I N P U T , G E N E R A T O R */
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
void _read_tx_bin
/*-------------------------------------------------------------------------*/
(
)
{
int k;
int Read;
int Tries = 0;
Read = fread(_asReadTmp, sizeof(S16), ILEC_FR_SZ, _Control.pInTxBin);
if (Read != ILEC_FR_SZ)
{
DEMO_StepMode = TRUE;
rewind(_Control.pInTxBin);
}
else
{
for (k = 0; k < ILEC_FR_SZ; k++)
{
double fTx = _asReadTmp[k] * _Control.fTxCorr;
if (fTx > 8159) fTx = 8159;
if (fTx < -8159) fTx = -8159;
_asTx[k] = (S16)fTx;
}
}
}
/*-------------------------------------------------------------------------*/
void _read_rx_bin
/*-------------------------------------------------------------------------*/
(
)
{
int k;
int Read;
int Tries = 0;
Read = fread(_asReadTmp, sizeof(S16), ILEC_FR_SZ, _Control.pInRxBin);
if (Read != ILEC_FR_SZ)
{
DEMO_StepMode = TRUE;
rewind(_Control.pInRxBin);
}
else
{
for (k = 0; k < ILEC_FR_SZ; k++)
{
double fRx = _asReadTmp[k] * _Control.fRxCorr;
if (fRx > 8159) fRx = 8159;
if (fRx < -8159) fRx = -8159;
_asRx[k] = (S16)fRx;
}
}
}
/*-------------------------------------------------------------------------*/
void _read_intx_file
/*-------------------------------------------------------------------------*/
(
)
{
int k;
for (k = 0; k < ILEC_FR_SZ; k++)
{
int Read;
int Tries = 0;
do
{
int iTx;
Read = fscanf(_Control.pInTxFile, "%d", &iTx);
if (Read != EOF)
{
double fTx = iTx * _Control.fTxCorr;
if (fTx > 8159) fTx = 8159;
if (fTx < -8159) fTx = -8159;
_asTx[k] = (S16)fTx;
}
else /* end of file, rewind */
{
rewind(_Control.pInTxFile);
}
if (++Tries == 5)
{
exit(15);
}
}
while (Read != 1);
}
}
/*-------------------------------------------------------------------------*/
void _read_intrx_file
/*-------------------------------------------------------------------------*/
(
)
{
static S16 aRxDelay[1000];
static S16 aTxDelay[1000];
static int Cntr = 0;
static char aBuffer[81];
if (Cntr == 0)
{
int k;
for (k = 0; k < ILEC_FR_SZ; k++)
{
int iRx, iTx;
double f;
int Tries = 0;
char *p = fgets(aBuffer, 80, _Control.pInTrxFile);
if (p != NULL)
{
sscanf(aBuffer, "%d %d", &iTx, &iRx);
f = iTx * _Control.fTxCorr;
if (f > 8159) f = 8159;
if (f < -8159) f = -8159;
iTx = (S16)f;
if (_Control.iTxDelay == 0)
{
_asTx[k] = iTx;
}
else
{
_asTx[k] = S16(/*Tx + */1.0 * aTxDelay[_Control.iTxDelay]);
for (int i = _Control.iTxDelay; i > 0; i--)
{
aTxDelay[i] = aTxDelay[i-1];
}
aTxDelay[0] = iTx;
}
f = iRx * _Control.fRxCorr;
if (f > 8159) f = 8159;
if (f < -8159) f = -8159;
iRx = (S16)f;
if (_Control.iRxDelay == 0)
{
_asRx[k] = iRx;
}
else
{
_asRx[k] = S16(/*Rx + */1.0 * aRxDelay[_Control.iRxDelay]);
for (int i = _Control.iRxDelay; i > 0; i--)
{
aRxDelay[i] = aRxDelay[i-1];
}
aRxDelay[0] = iRx;
}
}
else /* end of file, rewind */
{
rewind(_Control.pInTrxFile);
DEMO_StepMode = TRUE;
Cntr = 30;
}
if (++Tries == 5)
{
exit(15);
}
}
}
else
{
Cntr--;
}
}
/*-------------------------------------------------------------------------*/
S16 _gen_rand
/*-------------------------------------------------------------------------*/
(
double fNorma
)
{
double f = 0;
S16 n;
for (n = 0; n < 12; n++)
{
f += rand();
}
f = ((f - 6.0*RAND_MAX)* fNorma)/RAND_MAX;
return (S16)f;
}
/*-------------------------------------------------------------------------*/
void _generate_input
/*-------------------------------------------------------------------------*/
(
S16 *pRx,
S16 *pTx
)
{
S16 Rx;
S16 Tx;
if (_Gen.liStateCntr-- == 0)
{
/* change state*/
switch(_Gen.iState)
{
case 0: /* silence */
{
if (rand() < RAND_MAX * _Gen.fDoubleTalk)
{
_Gen.iState = 3;
_Gen.liStateCntr = long(_Gen.fWordLen * (16000.0/RAND_MAX) * rand()+1);
}
else
{
if (--_Gen.liCurrWord < 0) /* change direction */
{
if (_Gen.iDirection == 2)
{
_Gen.iState = 1;
_Gen.iDirection = 1;
}
else
{
_Gen.iState = 2;
_Gen.iDirection = 2;
}
_Gen.liCurrWord = _Gen.liSentenceLen;
}
else /* go on with the sentence */
{
_Gen.iState = _Gen.iDirection;
}
_Gen.liStateCntr = long(_Gen.fWordLen * (16000.0/RAND_MAX) * rand());
}
break;
}
case 1: /* tx */
case 2: /* rx */
{
if (rand() < RAND_MAX * _Gen.fDoubleTalk)
{
_Gen.iState = 3;
_Gen.liStateCntr = long(_Gen.fWordLen * (16000.0/RAND_MAX) * rand() + 1);
}
else
{
_Gen.iState = 0;
_Gen.liStateCntr = long(_Gen.fPauseLen * (16000.0/RAND_MAX) * rand() +1);
}
break;
}
case 3: /* double talk */
{
_Gen.iState = 0;
_Gen.liStateCntr = long(_Gen.fPauseLen * (16000.0/RAND_MAX) * rand() +1);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -