
#ifndef	DiamondVoiceTx_H
#define DiamondVoiceTx_H

/****************************************************************************************
*  HEADER FILE
****************************************************************************************/
#include "samsungTxHPF.h"
#include "samsungTxGain.h"
#include "samsungTxHPF.h"
#include "samsungTxWiseVoice.h"
#include "samsungTxFIRFilter.h"
#include "samsungTxAGC.h"
#include "samsungTxLimiter.h"
#include "samsungTxCNG.h"
#include "samsungHOWLTx.h"

/*   DiamondVoice Mode Config   */
#define	SAMSUNGHPF_TX_ON							(1<<0)
#define	SAMSUNGWiseVoice_TX_ON						(1<<1)
#define	SAMSUNG_TX_ON								(1<<2)
#define SAMSUNGCNG_TX_ON							(1<<3)
#define SAMSUNGCNG_HOWLTX_ON						(1<<4)

#define	SAMSUNGHPF_TX_OFF							0x0
#define	SAMSUNGWiseVoice_TX_OFF						0x0
#define	SAMSUNG_TX_OFF								0x0
#define SAMSUNGCNG_TX_OFF							0x0
#define SAMSUNGCNG_HOWLTX_OFF						0x0

#define	SAMSUNGDIAMONDVOICE_TX_ENABLE				1
#define	SAMSUNGDIAMONDVOICE_TX_DISABLE				0

#define SAMSUNGDIAMONDVOICESUPERWIDEBAND_TX			640
#define	SAMSUNGDIAMONDVOICEWIDEBAND_TX				320
#define	SAMSUNGDIAMONDVOICENARROWBAND_TX			160

#define	TX_MIX_SWB							320
#define	TX_MIX_WB							160
#define	TX_MIX_NB							80


/******************************************************************************
*  TYPEDEFS AND STRUCTURES
*****************************************************************************/

#ifndef	_DiamondVoiceTxEngine_HPF_Cfg_t_H
#define	_DiamondVoiceTxEngine_HPF_Cfg_t_H

#define	TX_FIRFILTERNUM						63
#define	TX_FIRFILTER_CENTER					31
#define	TX_FIRFILTER_BYPASS					16384

typedef struct {
	int coeff[5];
	int	state[5];
} HPFIIRstruct;

typedef struct {	
	short *Speech;
	short *OutSignal;
	short Bandwidth;
	short HPF_mode;
	HPFIIRstruct Hpf;

	short HPF_cutoff;
	short HPF_gain;

} DiamondVoiceTxEngine_HPF_Cfg_t;

#endif


#ifndef _DiamondVoiceTxEngine_WiseVoice_Cfg_t_H_
#define _DiamondVoiceTxEngine_WiseVoice_Cfg_t_H_

typedef struct {
	short monitor1;
	short monitor2;
	short monitor3;
	short monitor4;
	short monitor5;
	short monitor6;
	short monitor7;
	short monitor8;
	short monitor9;
} WiseVoiceState_type;

typedef struct {
	short x_d1;
	short x_d2;
	short y_d1;
	short y_d2;
	long err_h;
} WiseIIR;

typedef struct {
	short latt;				// level attack
	short lrlt;				// level release
	short gat;				// gain attack time
	short grt;				// gain release time
	short thd1;
	short thd2;
	short thd3;
	short thd4;				// reserved
	short slop1;
	short slop2;
	short slop3;
	short slop4;				// reserved
	short slop5;				// reserved
	short maxboost1;
	short maxboost2;
	short xd_level;			// fast rms value
	short G_old;
	short maxboost2_old;// past Gain
} WiseVoiceStatus;

typedef struct {
	short latt;			// level attack
	short lrlt;			// level release
	short gat;			// gain attack time
	short grt;			// gain release time	
	short thd1;
	short thd2;
	short slop1;
	short slop2;
	short maxboost1;
	short maxboost2;
	short xd_level;		// fast rms value
	short G_old;		// past Gain
} WiseVoiceNGStatus;

typedef struct {
	short *Speech;
	short *OutSignal;
	short Bandwidth;
	short WiseVoice_mode;	
	short WiseVoice_device_mode;
	short WiseVoice_InGain;
	short WiseVoice_OutGain;	
	short WiseVoice_InGain_old;
	short WiseVoice_OutGain_old;
	short WiseVoice_Init_Vol;
	short WiseVoice_ngmode;
	WiseVoiceState_type WiseVoiceMonitor_v;
	WiseVoiceStatus comp_api;
	WiseVoiceNGStatus pre_ng_api;
	WiseVoiceNGStatus post_ng_api;
} DiamondVoiceTxEngine_WiseVoice_Cfg_t;
#endif 

#ifndef	_DiamondVoiceTxEngine_CNG_Cfg_t_H
#define	_DiamondVoiceTxEngine_CNG_Cfg_t_H

typedef struct {
	short monitor1;				// CNG Gain
	short monitor2;
	short monitor3;
	short monitor4;
	short monitor5;
} TxCNGState_type;

typedef struct {
	short *Speech;
	short *OutSignal;
	short CNG_mode;
	short CNG_bandwidth;
	short CNG_gain_offset;
	short CNG_gain;
	short CNG_sample;
	short CNG_seed;
	short CNG_pre_value;
	TxCNGState_type CNGMonitor_v;
} DiamondVoiceTxEngine_CNG_Cfg_t;
#endif 

#ifndef	_DiamondVoiceTxEngine_Cfg_t_H
#define	_DiamondVoiceTxEngine_Cfg_t_H

#define	TX_FIRFILTERNUM						63
#define	TX_FIRFILTER_CENTER					31
#define	TX_FIRFILTER_BYPASS					16384


typedef struct {
	short latt;			// level attack
	short lrlt;			// level release
	short gat;			// gain attack time
	short grt;			// gain release time	
	short compthd;
	short expthd;
	short compslop;
	short expslop;
	short maxboost1;
	short maxboost2;
	short xd_level;		// fast rms value
	short G_old;		// past Gain
} AGCStatus;

typedef struct {
	short latt;			// level attack
	short lrel;			// level release
	short xd_level;		// fast rms value
	short G_old;			// past Gain
	short THDCOM;
	short SLOPCOM;
	short GAINCOM;
	short GAINCOM_DEC;
} Limitstruct;


typedef struct {
	short *Speech;
	short *OutSignal;
	short Bandwidth;
	short Mode;
	//FIR Filter	
	short FIRCoefBuff[SAMSUNGDIAMONDVOICESUPERWIDEBAND_TX + TX_FIRFILTERNUM - 1];
	short FIRCoef[TX_FIRFILTERNUM+1];
	//AGC	
	AGCStatus comp_api;
	//Limiter
	Limitstruct PBoost;
	short Limiter_delay_x[SAMSUNGDIAMONDVOICESUPERWIDEBAND_TX + 50];
	short Limiter_Idx;
	short Limiter_lah;
	//gain
	short Gain_level;
	// mix
	short AGC_Mix[TX_MIX_SWB];
} DiamondVoiceTxEngine_Cfg_t;


#if	!defined(_DiamondVoiceTxEngine_HOWLTx_Cfg_t_H)
#define	_DiamondVoiceTxEngine_HOWLTx_Cfg_t_H

#define HOWLTx_LPC_ORDER		10
#define HOWLTx_NUM_CH_WB		14
#define HOWLTx_Half_Nfft_WB		128

typedef struct{
	short howl_lowthd;			/* minmax threshold in lowband */
	short howl_highthd;			/* minmax threshold in highband */
	short howl_bandthd1;		/* minmax threshold in band1 */
	short howl_bandthd2;		/* minmax threshold in band2 */
	short howl_bandthd3;		/* minmax threshold in band3 */
	short howl_bandthd4;		/* minmax threshold in band4 */
	short howl_bandthd5;		/* minmax threshold in band5 */
	short howl_bandthd6;		/* minmax threshold in band6 */
	short howl_bandthd7;		/* minmax threshold in band7 */
	short howl_bandthd8;		/* minmax threshold in band8 */
	short howl_bandthd9;		/* minmax threshold in band9 */
	short howl_bandthd10;		/* minmax threshold in band10 */
	short howl_bandthd11;		/* minmax threshold in band11 */
	short howl_bandthd12;		/* minmax threshold in band12 */
	short howl_bandthd13;		/* minmax threshold in band13 */
	short howl_bandthd14;		/* minmax threshold in band14 */
	short howl_weak_gain;		/* suppression gain for weak howiling */
	short howl_strong_gain;		/* suppression gain for strong howiling */
	short howl_global_gain;		/* suppression gain for globak howiling */
	short howl_frm_cnt;			/* howling suppresion frame count */
	short reserved1;
	short reserved2;
	short reserved3;
	short reserved4;
} HowlTx_parameter;

typedef struct {
	long  Xpsd[128];

	short CHMinMaxRto[14];
	short HowlHangoverCnt[14];
	short CHHowlFlag[14];
	short CHHowlThreshold[14];

	short FreqHowlFlag[128];
	short FreqGain[128];

	short FirstFrmFlag;

	short HowlThrLowBand;
	short HowlThrHighBand;

	short FrmBuff[256];
	long  Xs[128];
	long  Xsavg[128];
	short TempFreqGain[128];
	short TempFreqGainAvg[128];

	short Gain_Band_low_Howl;
	short Gain_Band_high_Howl;
	short Gain_low_Howl;
	short Gain_high_Howl;

	short last_normb_shift;
	long L_EEBin[128];
	short S_DRCGain[128];
	short window_overlap[96];
	short overlap[256 - 160];
	short pre_emp_mem;
	short de_emp_mem;

	short HOWL_oldgain;
	short HOWL_count;

	short HOWL_gainGlobal;
	short HOWL_gainNomIndex;
	short HOWL_gainCur;
	short HOWL_gainNorm;

	short HOWL_lpc[HOWLTx_LPC_ORDER + 1];
	short HOWL_lsp[HOWLTx_LPC_ORDER];
	short HOWL_old_lsp[HOWLTx_LPC_ORDER];
	short HOWL_lsf[HOWLTx_LPC_ORDER];
	short HOWL_lsf_delta[HOWLTx_LPC_ORDER];
	short HOWL_lsf_bin[HOWLTx_LPC_ORDER];
	float HOWL_lsf_freq[HOWLTx_LPC_ORDER];
	short HOWL_lsf_band[HOWLTx_NUM_CH_WB];
	short HOWL_lsf_pband[HOWLTx_NUM_CH_WB];
	short HOWL_lsf_E[HOWLTx_Half_Nfft_WB];
	short HOWL_lsf_HOCnt[HOWLTx_NUM_CH_WB];
	short HOWL_THD_width;
	short HOWL_THD_power;
	short HOWL_howl_cnt;
	short HOWL_reserved;
} HOWLTx_STFT_type;

typedef struct {
	short monitor1;
	short monitor2;
	short monitor3;
	short monitor4;
	short monitor5[14];
} HOWLTxState_type;

typedef struct {
	short *Speech;
	short *OutSignal;
	short HOWLTx_mode;
	short HOWLTx_bandwidth;
	HOWLTx_STFT_type howl_STFTOLA;
	HOWLTxState_type HOWLMonitor_v;
} DiamondVoiceTxEngine_HOWLTx_Cfg_t;

#endif //_DiamondVoiceEngine_HOWLTx_Cfg_t_H

#endif

typedef struct {
	short mode;
	//HPF
	short hpf_cutoff;
	short hpf_gain;
	
	//WISE VOICE
	short wisevoice_device_mode;
	short wisevoice_att_time;
	short wisevoice_rel_time;
	short wisevoice_thd[4];
	short wisevoice_slp_high;
	short wisevoice_slp_low;
	short wisevoice_gain;
	short wisevoice_InGain;
	short wisevoice_OutGain;
	short wisevoice_ngmode;
	short wisevoice_ngpara[2];
	short wisevoice_ComThd;
	short wisevoice_ComSlope;
	short wisevoice_ExpThd;
	short wisevoice_ExpSlope;	
	
	//ETC
	short firFilter[32];
	short agc_comThd;
	short agc_comSlope;
	short agc_expThd;
	short agc_expSlope;	
	short gain;	
	short limit_thd;
	//CNG
	short cng_level;
	//Howling Reduction
	HowlTx_parameter howl_param;

}SamsungDiamondVoiceTxParam;

typedef struct {
	short *Speech;
	short *OutSignal;
	short Mode;
	short BandWidth;
	short Buff[SAMSUNGDIAMONDVOICESUPERWIDEBAND_TX];
	DiamondVoiceTxEngine_HPF_Cfg_t DiamondVoiceEngine_HPF_vars;
	DiamondVoiceTxEngine_Cfg_t DiamondVoiceEngine_Tx_vars;	
	DiamondVoiceTxEngine_CNG_Cfg_t DiamondVoiceEngine_CNG_vars;
	DiamondVoiceTxEngine_WiseVoice_Cfg_t DiamondVoiceEngine_WiseVoice_vars;
	DiamondVoiceTxEngine_HOWLTx_Cfg_t DiamondVoiceEngine_HOWLTx_vars;
} SamsungDiamondVoiceTxEngine_Handle_t;



/******************************************************************************
*  FUNCTION PROTOTYPES
*****************************************************************************/

extern int SamsungTxHPFState(DiamondVoiceTxEngine_HPF_Cfg_t* DiamondVoiceEngine_HPF_vars);
extern int SamsungTxWiseVoiceState(DiamondVoiceTxEngine_WiseVoice_Cfg_t* DiamondVoiceEngine_WiseVoice_vars);
extern int SamsungTxState(DiamondVoiceTxEngine_Cfg_t* DiamondVoiceEngine_Tx_vars);
extern int SamsungTxCNGState(DiamondVoiceTxEngine_CNG_Cfg_t* DiamondVoiceEngine_CNG_vars);

extern int SamsungDiamondVoiceTxEngineInit(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceEngine_vars_Tx, short  bandwidth);
extern int SamsungDiamondVoiceTxEngineInOutConfig(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceEngine_vars_Tx, short *Speech, short *OutSignal);
extern int SamsungDiamondVoiceTxEngineModeConfig(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceEngine_vars_Tx, SamsungDiamondVoiceTxParam *SamsungDiamondParam_varsTx);

extern int SamsungDiamondVoiceTxEngineHPFConfig(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceEngine_vars_Tx, SamsungDiamondVoiceTxParam *SamsungDiamondParam_varsTx);
extern int SamsungDiamondVoiceTxEngineGain1Config(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceEngine_vars_Tx, SamsungDiamondVoiceTxParam *SamsungDiamondParam_varsTx);
extern int SamsungDiamondVoiceTxEngineWiseVoiceConfig(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceEngine_vars_Tx, SamsungDiamondVoiceTxParam *SamsungDiamondParam_varsTx);
extern int SamsungDiamondVoiceTxEngineConfig(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceEngine_vars_Tx, SamsungDiamondVoiceTxParam *SamsungDiamondParam_varsTx);
extern int SamsungDiamondVoiceTxEngineAGCConfig(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceEngine_vars_Tx, SamsungDiamondVoiceTxParam *SamsungDiamondParam_varsTx);
extern int SamsungDiamondVoiceTxEngineGain2Config(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceEngine_vars_Tx, SamsungDiamondVoiceTxParam *SamsungDiamondParam_varsTx);
extern int SamsungDiamondVoiceTxEngineLimiterConfig(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceEngine_vars_Tx, SamsungDiamondVoiceTxParam *SamsungDiamondParam_varsTx);
extern int SamsungDiamondVoiceTxEngineCNGConfig(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceEngine_vars, SamsungDiamondVoiceTxParam *SamsungDiamondParam_vars);
extern int SamsungDiamondVoiceTxEngineHOWLTxConfig(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceTxEngine_vars, SamsungDiamondVoiceTxParam *SamsungDiamondParam_vars);

extern int SamsungDiamondVoiceTxEngineExe(SamsungDiamondVoiceTxEngine_Handle_t* SamsungDiamondVoiceEngine_vars_Tx, SamsungDiamondVoiceTxParam *SamsungDiamondParam_varsTx, short *output, short *input);

#endif
