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

📄 leci.h

📁 The line echo canceller (LEC) is designed to provide the maximum attainable transparent voice qualit
💻 H
字号:
/*---------------------------------------------------------------------*
 *                                                                     *
 * THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY *
 * INFORMATION.  IF PUBLICATION OCCURS, THE FOLLOWING NOTICE APPLIES:  *
 *     "COPYRIGHT 2001 MICHAEL TSIROULNIKOV, ALL RIGHTS RESERVED"      *
 *                                                                     *
 *---------------------------------------------------------------------*/
#ifndef _leci_h 
#define _leci_h 

#include "stddefs.h"
#include "lec_miket.h"

/*--------------------- local defs ------------------------------------*/

#define Q15(x)          ((S16)(32768.*x))

#define LEC_IO_FRAMES   2
/* number of frames used by filter */
#define LEC_FRAMES      4
/* there is a delay for a frame in each of RxIn/ TxOut devices.
	1 frame is compensated by update of the delay line after adaptation */
#define LEC_HST_FRAMES  (LEC_FRAMES + LEC_IO_FRAMES)
#define LEC_FLT_SZ      (LEC_FRAMES*ILEC_FR_SZ)
#define LEC_FLT2_SZ     ((LEC_FRAMES+1)*ILEC_FR_SZ)
#define LEC_HST_SZ      (LEC_HST_FRAMES*ILEC_FR_SZ)
#define LEC_SECTION_SZ	(4)

#define LEC_DB(x)       ((S16)(x*ILEC_1DB))

#define LEC_SLACC_MAX  (1L<<18)


#define LEC_BP_HSZ          (10)
#define LEC_BP_SSZ          (18)
#define LEC_BP_FSZ          (19)


#define LEC_VAD_ST_IDLE     (0)
#define LEC_VAD_ST_PRE      (1)
#define LEC_VAD_ST_ACTIVE   (2)
#define LEC_VAD_ST_HANGOVER (3)

#define LEC_FLAG_TONE       (0x0001)
#define LEC_FLAG_ADAPT      (0x0002)
#define LEC_FLAG_HITX       (0x0004)
#define LEC_FLAG_SINGULAR   (0x0008)
#define LEC_FLAG_ERROVERIDE (0x0010)
#define LEC_FLAG_ERL_OK     (0x0020)

typedef struct LEC_tVad
{
	S32 slEnergy;
	
	S16 sZc;
	S16 sZcNoise;
	S16 sEn;
	S16 sEnNoise;
	
	S16 sEnNoiseMax;
	S16 sCrit;
	S16 sState;
	S16 sFiller0;
			
} LEC_tVad;


typedef struct {

    S32 slAcc;
    
    S16 sERL;
    S16 sMSE;
    S16 sShift;
    S16 sNegShift;
    
    S16 sStabCnt;
    S16 sErlAveraged;
    S16 sErleAveraged;
    U16 uConverged;

} LEC_tAdf;

typedef struct LEC_tDb
{
    /* pointers */
    LEC_MIKET_tStts *pStts;
    S16 *psHst;
    S16 *psTxF;
    S16 *psFlt1;
    S16 *psFlt2;

	/* long word aligned data */
    LEC_tAdf    Adf1;
    LEC_tAdf    Adf2;
	LEC_tVad    VadTx;
    LEC_tVad    VadErr;
    S32         aslRk[6];
    S32         aslRkSav[6];
    
    S16         asBandPassSav[LEC_BP_SSZ];
    S16 		asLpSav[5];

    /* tx analisys */
	S16         asTxEnLog[7];
	S16         sTxMaxCnt;
    S16         sErlOkCnt;

    /* sout data */
	S16         sClipLevel;
    S16         sErrAvrEn;
    S16         sErrOverrideCnt;
	S16         sRxNoiseLevel;
	S16         sSeed;
	S16         asRand[4];

    /* dt */
	S16         sDtCriteria;

    /* flags */
    U16 uIsTone;
	U16 uIsDT;
    U16 uTest;

    ILEC_tCfg Cfg;

} LEC_tDb;

typedef struct LEC_tSc {

    S16 *psRx;
	S16 *psTx;

    S32 aslRk		[6];
    S32 aslRkTx		[6];
    S32 aslG		[6];
    S32 slEn;
    
    S16 asRk		[6];
    S16 asF			[6];
    S16 asK			[6];

    S16 asErr1      [ILEC_FR_SZ];
    S16 asErr2      [ILEC_FR_SZ];
    S16 asNormErr   [ILEC_FR_SZ];
    S16 asTmp		[ILEC_FR_SZ*2];

    S16 sStepSize;
    S16 sStepCorr;
    S16 sRxEn;
    S16 sExpectedErrorEn;
    S16 sAdaptThreshold;
    S16 sClipThreshold;

    S16 sErr1En;
    S16 sErr2En;
    S16 sErlEst;
    S16 sErl;
    S16 sErle;
    S16 sERL;
    S16 sMSE;

    S16 sRxNoiseAtt;
    S16 sJ0Tx;
    S16 sJ0;
    S16 sInvR0;
    
    U16 uFlags;
    U16 uNlpMode;
    U16 uAdaptMode;
    U16 uFltCpyMode;
    U16 uMseMode;

} LEC_tSc;


/*--------------------- public vars- ----------------------------------*/

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

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

extern void lec_vad_logic           (LEC_tVad *pDb);

/* to be asm, lecns.c */
extern void lec_dt_start            (LEC_tDb *pDb, LEC_tSc *pSc);
extern void lec_dt_end              (LEC_tDb *pDb, LEC_tSc *pSc);
extern void lec_double_talk_detector(LEC_tDb *pDb, LEC_tSc *pSc);
extern void lec_non_linear_processor(LEC_tDb *pDb, LEC_tSc *pSc);
extern void lec_adapt_fast          (LEC_tDb *pDb, LEC_tSc *pSc);
extern void lec_adapt_slow          (LEC_tDb *pDb, LEC_tSc *pSc);

/* signal analysis routines from lecpa.s5x */
extern void lec_band_pass_rx        (LEC_tDb *p, LEC_tSc *pSc);
extern S16  lec_durbin              (LEC_tDb *pDb, LEC_tSc *pSc);
extern void lec_normalise_rk        (LEC_tDb *pDb, LEC_tSc *pSc, S16 sShift, S16 sAdd);
extern void lec_tx_moments          (LEC_tDb *pDb, LEC_tSc *pSc);
extern void lec_gs_moments          (LEC_tDb *pDb, LEC_tSc *pSc);
extern void lec_ts_moments          (LEC_tDb *pDb, LEC_tSc *pSc);
extern void lec_gs_filter           (LEC_tDb *pDb, LEC_tSc *pSc);
extern void lec_lp_residual_error	(LEC_tDb *pDb, LEC_tSc *pSc, const S16 *psCoeff);

/* adapt routines, lecaa.s5x */
extern void lec_cancel_pkt          (LEC_tDb *pDb, LEC_tSc *pSc);
extern S16  lec_cancel_shifted		(S16 *psHst, S16 *psFlt, S16 sRxIn, S16 sShift);
extern S32  lec_get_xz_slow			(S16 *psX, S16 *pxZ);
extern void lec_shift_adf2          (LEC_tDb *pDb, LEC_tSc *pSc);
extern S16  lec_step_size			(S32 slEn, S16 *psStepSize);
extern void lec_adapt_slow_high     (LEC_tDb *pDb, LEC_tSc *pSc, S16 base, S16 sStep);
extern void lec_adapt_slow_low      (LEC_tDb *pDb, LEC_tSc *pSc, S16 base, S16 sStep);
extern void lec_shift_err2          (LEC_tDb *pDb, LEC_tSc *pSc);
extern S16  lec_step_size_corr_slow (LEC_tDb *pDb, LEC_tSc *pSc, S16 base);

/* utilities, lecua.s5x */
extern void lec_pkt_rand            (S16 *psSeed, S16 *psData);
extern S32  lec_pkt_energy          (S16 *psData);
extern S16  lec_en2log              (S32 slEn, S16 sCorr);
extern S16  lec_exp                 (S16 sdB);
extern S16  lec_pkt_zc              (S16 *psData);
extern S16  lec_pkt_peak            (S16 *psData);
extern S16  lec_pkt_excess          (S16 *pError, S16 ClipThreshold);
extern void lec_make_noise          (S16 *pTo, S16 *pFrom, S16 Level);
extern void lec_central_clipping    (S16 *pTo, S16 *pFrom, S16 Threshold);

#define lec_pkts_cpy(x,y,z) memcpy((x),(y),((z)*ILEC_FR_SZ*sizeof(S16)))

/* ------------------------------------------------------------------------ */
static inline void               lec_avrg
/* ------------------------------------------------------------------------ */
(
S16 *psVal, 
S16 sNew,
S16 sCoeff
)
/* Vk+1 = Vk + (y - Vk) * coeff/32768; */
{
    S32 acc;

    acc = (sNew - *psVal);
    acc *= sCoeff;
    acc += ((S32)(*psVal))<<15;
    acc += 0x4000;
    acc >>= 15;
    *psVal = (S16)acc;
}
/*--------------------- public  functions -----------------------------*/


/*---------------------------------------------------------------------*/

#endif  /* _leci_h */

⌨️ 快捷键说明

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