#define _CRT_SECURE_NO_WARNINGS
#if defined(__arm__)
#if (__ARMCC_VERSION >= 6000000)
#pragma clang section data = "SE_SOL_DSRW" text = "SE_SOL_CODE" bss = "SE_SOL_DSZI" rodata = "SE_SOL_DSCONST"
#elif (__ARMCC_VERSION >= 5000000)
#pragma arm section rwdata = "SE_DMV_DSRW", rodata = "SE_DMV_DSCONST", code = "SE_DMV_CODE", zidata = "SE_DMV_DSZI"
#else
// to do
#endif
#endif

/*--------------------------------------------------------------*\
* 				Samsung Electnoics co, LTD.                              		*
*                                                              							*
*				    DiamondVoice (Fixed-point)						*
*                                                              							*
*                         	 	   main.c                       						*
*                                                           								*
\*--------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>


double start, end;
double duration;
long max_iter = 10000;
long k;

static int flag = 0;


//#define  _DV_RX_

#ifdef  _DV_RX_

#include "samsungDiamondVoice.h"


#define	DIAMONDVOICE_FRAME				SAMSUNGDIAMONDVOICEWIDEBAND		// SAMSUNGDIAMONDVOICESUPERWIDEBAND,	SAMSUNGDIAMONDVOICEWIDEBAND, SAMSUNGDIAMONDVOICENARROWBAND
#define	FIRFILTERTEMP					32
#define	FIRFILTERTEMP_QF				17

short DiamondVoice_Mode_v = 0;

short dhaHearingLevel[12]		= {10,5,10,10,15,30,10,5,10,10,15,30};


/* FIR Filter for NBquality */
short NBQualityCoef[FIRFILTERTEMP_QF] = { 104, -157, -354, -346, -105, 250, 508, 476, 106, -445, -861, -808, -107, 1151, 2604, 3762, 4204 };	// 33 Tap FIR for SWB
//short NBQualityCoef[FIRFILTERTEMP_QF] = { 91, -332, -91, 388, 92, -462, -93, 570, 93, -737, -93, 1038, 93, -1735, -93, 5214, 8286 };	// 33 Tap FIR for WB


SamsungDiamondVoiceParam				DiamondVoice_DVConfig = { 0, };
SamsungDiamondVoiceEngine_Handle_t		SamsungDiamondVoiceEngine_var;

void setMode(int flag);


FILE *dfp[20];
char *debug_description[20] = { "_DIFF_RMS", "_NOISE_RMS", "_NOISE_THD", "_GAIN", "_TX_VAD", "_NoiseClass", "_NoiseClass1", "_NoiseClass2", "_NONSTAT", "_IDLE_CNT",
"_FILTER_CNT", "_ADRC_CNT", "_SVI_CNT", "_STATUS", "_NS_IN_FRM", "_NS_OUT_FRM", "_NS_IN_RMS", "_NS_OUT_RMS", "_DETECT_NOISE", "_DETECT_IDLE" };
int  nDebugFiles = 20;

FILE *fp_adrc;


FILE  *fp_spectro, *fp_fq_para, *fp_ch_minmax, *fp_ch_howl_flag, *fp_freq_howl_flag, *fp_freq_howl_gain, *fp_lsf_eng, *fp_lsf_band; // for howl debug

int main(int argc, char *argv[])
{

	// for howl debug
	fp_spectro = fopen("howl_spectro.txt", "w");
	fp_fq_para = fopen("howl_para.txt", "w");
	fp_ch_minmax = fopen("howl_band_minmax.txt", "w");
	fp_ch_howl_flag = fopen("howl_band_flag.txt", "w");
	fp_freq_howl_flag = fopen("howl_freq_flag.txt", "w");
	fp_freq_howl_gain = fopen("howl_freq_gain.txt", "w");


	FILE *ifp1, *ifp2, *ifp3, *ifp4, *ofp, *ofp2;

	short counter = 0;
	long FrmCnt = 0;
	short i = 0;
	short big_rx_silence;
	short big_tx_state;
	short big_tx1_var, big_tx1_rms, big_tx2_var, big_tx2_rms;
	short big_tx_cnt;
	short big_mbd_state;
	short big_mbd_maxtime;
	short n = 0;

	for (int i = 0; i < nDebugFiles; i++)
	{
		char debug_filename[100] = "\0";
		strcat(debug_filename, "DEBUG_");
		debug_filename[6] = i / 10 + '0';
		debug_filename[7] = i % 10 + '0';
		strcat(debug_filename, debug_description[i]);
		strcat(debug_filename, ".pcm");
		dfp[i] = fopen(debug_filename, "wb");
	}

	fp_adrc = fopen("adrc_rms.pcm", "wb");

	short Speech_buf[640], Noise_buf_bot[640], Noise_buf_top[640], Noise_buf_after[640], Output_buf[640], Output_buf_ds[640];


	FILE* fp_bigstatus;
	FILE* fp_bigrms1;
	FILE* fp_bigvar1;
	FILE* fp_bigrms2;
	FILE* fp_bigvar2;
	FILE* fp_bigcnt;
	FILE* fp_mbdstatus;

	fp_bigstatus = fopen("big_tx_status.txt", "wb");
	fp_bigrms1 = fopen("big_tx1_rms.txt", "wb");
	fp_bigvar1 = fopen("big_tx1_var.txt", "wb");
	fp_bigrms2 = fopen("big_tx2_rms.txt", "wb");
	fp_bigvar2 = fopen("big_tx2_var.txt", "wb");
	fp_bigcnt = fopen("big_tx_cnt.txt", "wb");
	fp_mbdstatus = fopen("big_mbs_status.txt", "wb");
	fp_lsf_eng = fopen("howl_lsf_eng.txt", "wb");
	fp_lsf_band = fopen("howl_lsf_band.txt", "wb");



	if ((ifp1 = fopen(argv[1], "rb")) == (FILE *)NULL)
		exit(fprintf(stderr, "input file error..\n"));

	if ((ifp2 = fopen(argv[2], "rb")) == (FILE *)NULL)
		exit(fprintf(stderr, "input file error..\n"));

	if ((ifp3 = fopen(argv[3], "rb")) == (FILE *)NULL)
		exit(fprintf(stderr, "input file error..\n"));

	if ((ifp4 = fopen(argv[4], "rb")) == (FILE *)NULL)
		exit(fprintf(stderr, "input file error..\n"));

	if ((ofp = fopen(argv[5], "wb")) == (FILE *)NULL)
		exit(fprintf(stderr, "output file error..\n"));

	if ((ofp2 = fopen(argv[6], "wb")) == (FILE *)NULL)
		exit(fprintf(stderr, "output file error..\n"));

#if	defined(__DV_NEON_OPT)
	if (testBand == 0)
		DIAMONDVOICE_FRAME = 160;
	else if (testBand == 1)
		DIAMONDVOICE_FRAME = 320;
	else if (testBand == 2)
		DIAMONDVOICE_FRAME = 640;
	else{
		printf("error(teatBand)\n");
	}

	if (testBand == 0) {
		if ((ofp = fopen("D:\\00_Temp\\neonout\\NEON_Rxout_8k.pcm", "wb")) == (FILE *)NULL)
		{
			fprintf(stderr, "output file error..\n"); return 0;
		}
		if ((ofp2 = fopen("D:\\00_Temp\\neonout\\NEON_Rxout_8k_ds.pcm", "wb")) == (FILE *)NULL)
		{
			fprintf(stderr, "output file error..\n"); return 0;
		}
	}
	if (testBand == 1) {
		if ((ofp = fopen("D:\\00_Temp\\neonout\\NEON_Rxout_16k.pcm", "wb")) == (FILE *)NULL)
		{
			fprintf(stderr, "output file error..\n"); return 0;
		}
		if ((ofp2 = fopen("D:\\00_Temp\\neonout\\NEON_Rxout_16k_ds.pcm", "wb")) == (FILE *)NULL)
		{
			fprintf(stderr, "output file error..\n"); return 0;
		}
	}
	if (testBand == 2) {
		if ((ofp = fopen("D:\\00_Temp\\neonout\\NEON_Rxout_32k.pcm", "wb")) == (FILE *)NULL)
		{
			fprintf(stderr, "output file error..\n"); return 0;
		}
		if ((ofp2 = fopen("D:\\00_Temp\\neonout\\NEON_Rxout_32k_ds.pcm", "wb")) == (FILE *)NULL)
		{
			fprintf(stderr, "output file error..\n"); return 0;
		}
	}
#elif	defined(__DV_ARM_OPT)

	if (testBand == 0)
		DIAMONDVOICE_FRAME = 160;
	else if (testBand == 1)
		DIAMONDVOICE_FRAME = 320;
	else if (testBand == 2)
		DIAMONDVOICE_FRAME = 640;
	else{
		printf("error(teatBand)\n");
	}

	if (testBand == 0) {
		if ((ofp = fopen("D:\\00_Temp\\neonout\\ARM_Rxout_8k.pcm", "wb")) == (FILE *)NULL)
		{
			fprintf(stderr, "output file error..\n"); return 0;
		}
		if ((ofp2 = fopen("D:\\00_Temp\\neonout\\ARM_Rxout_8k_ds.pcm", "wb")) == (FILE *)NULL)
		{
			fprintf(stderr, "output file error..\n"); return 0;
		}
	}
	if (testBand == 1) {
		if ((ofp = fopen("D:\\00_Temp\\neonout\\ARM_Rxout_16k.pcm", "wb")) == (FILE *)NULL)
		{
			fprintf(stderr, "output file error..\n"); return 0;
		}
		if ((ofp2 = fopen("D:\\00_Temp\\neonout\\ARM_Rxout_16k_ds.pcm", "wb")) == (FILE *)NULL)
		{
			fprintf(stderr, "output file error..\n"); return 0;
		}
	}
	if (testBand == 2) {
		if ((ofp = fopen("D:\\00_Temp\\neonout\\ARM_Rxout_32k.pcm", "wb")) == (FILE *)NULL)
		{
			fprintf(stderr, "output file error..\n"); return 0;
		}
		if ((ofp2 = fopen("D:\\00_Temp\\neonout\\ARM_Rxout_32k_ds.pcm", "wb")) == (FILE *)NULL)
		{
			fprintf(stderr, "output file error..\n"); return 0;
		}
	}
#else

#endif

	//	Initialization for NarrowBand or Wideband
	SamsungDiamondVoiceEngineInit(&SamsungDiamondVoiceEngine_var, DIAMONDVOICE_FRAME);


	printf("framesize : %d !! \n", DIAMONDVOICE_FRAME);

	setMode(1);

	FrmCnt = 0;

	while ((fread(Speech_buf, sizeof(short), DIAMONDVOICE_FRAME, ifp1) == (unsigned)DIAMONDVOICE_FRAME)
		&& (fread(Noise_buf_bot, sizeof(short), DIAMONDVOICE_FRAME, ifp2) == (unsigned)DIAMONDVOICE_FRAME)
		&& (fread(Noise_buf_top, sizeof(short), DIAMONDVOICE_FRAME, ifp3) == (unsigned)DIAMONDVOICE_FRAME)
		&& (fread(Noise_buf_after, sizeof(short), DIAMONDVOICE_FRAME, ifp4) == (unsigned)DIAMONDVOICE_FRAME))
	{
		SamsungDiamondVoiceEngineExe(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig, Output_buf, Output_buf_ds, Speech_buf, Noise_buf_bot, Noise_buf_top, Noise_buf_after);

		FrmCnt++;


		if ((FrmCnt % 100) == 0)
		{
			printf("%d\n", FrmCnt);
			printf("%d\n", DyVEMonitor_v.monitor4);
		}

		fwrite(Output_buf, sizeof(short), DIAMONDVOICE_FRAME, ofp);
		fwrite(Output_buf_ds, sizeof(short), DIAMONDVOICE_FRAME, ofp2);
	}

	fclose(ifp1);
	fclose(ifp2);
	fclose(ifp3);
	fclose(ifp4);
	fclose(ofp);
	fclose(ofp2);

	fclose(fp_bigstatus);
	fclose(fp_bigrms1);
	fclose(fp_bigvar1);
	fclose(fp_bigrms2);
	fclose(fp_bigvar2);
	fclose(fp_bigcnt);
	fclose(fp_mbdstatus);

	// for howl debug file close
	fclose(fp_spectro);
	fclose(fp_fq_para);
	fclose(fp_ch_minmax);
	fclose(fp_ch_howl_flag);
	fclose(fp_freq_howl_flag);
	fclose(fp_freq_howl_gain);
	fclose(fp_lsf_eng);
	fclose(fp_lsf_band);

	for (int i = 0; i < nDebugFiles; i++)
	{
		fclose(dfp[i]);
	}
	fclose(fp_adrc);

	return 0;
}

void setMode(int flag)
{
	if (flag == 0)  //NB
	{
		short sf_step_maxgain_m[11] = { 0xFFEE,	0xFFF2,	0xFFF6,	0xFFFA,	0xFFFD,	0x0,0x03,0x06,0x0,0x0,0x0};
		short SF_HIGH_FIRCoef_m[FIRFILTERTEMP] = { 0x82, 0x60, 0xA1, 0xA0, 0xBF, 0xA5, 0xAC, 0x39, 0x8D, 0x50, 0x50, 0x2B, 0x09, 0xFFCD, 0xFFB1, 0xFF02, 0xFF7A, 0xFF7F, 0xFF8F, 0xFF43, 0xFF79, 0xFF9A, 0xFF48, 0xFEBC, 0xFF2C, 0xFFF5, 0x030C, 0x01F4, 0x02ED, 0x0533, 0x1A, 0x258A };
		short SF_MIDH_FIRCoef_m[FIRFILTERTEMP] = { 0x82, 0x60, 0xA1, 0xA0, 0xBF, 0xA5, 0xAC, 0x39, 0x8D, 0x50, 0x50, 0x2B, 0x09, 0xFFCD, 0xFFB1, 0xFF02, 0xFF7A, 0xFF7F, 0xFF8F, 0xFF43, 0xFF79, 0xFF9A, 0xFF48, 0xFEBC, 0xFF2C, 0xFFF5, 0x030C, 0x01F4, 0x02ED, 0x0533, 0x1A, 0x258A };
		short SF_MIDL_FIRCoef_m[FIRFILTERTEMP] = { 0x82, 0x60, 0xA1, 0xA0, 0xBF, 0xA5, 0xAC, 0x39, 0x8D, 0x50, 0x50, 0x2B, 0x09, 0xFFCD, 0xFFB1, 0xFF02, 0xFF7A, 0xFF7F, 0xFF8F, 0xFF43, 0xFF79, 0xFF9A, 0xFF48, 0xFEBC, 0xFF2C, 0xFFF5, 0x030C, 0x01F4, 0x02ED, 0x0533, 0x1A, 0x258A };
		short SF_LOW_FIRCoef_m[FIRFILTERTEMP] = { 0x82, 0x60, 0xA1, 0xA0, 0xBF, 0xA5, 0xAC, 0x39, 0x8D, 0x50, 0x50, 0x2B, 0x09, 0xFFCD, 0xFFB1, 0xFF02, 0xFF7A, 0xFF7F, 0xFF8F, 0xFF43, 0xFF79, 0xFF9A, 0xFF48, 0xFEBC, 0xFF2C, 0xFFF5, 0x030C, 0x01F4, 0x02ED, 0x0533, 0x1A, 0x258A };

		short sf_step_maxgain_s[11] = { -20, -16, -12, -8, -4, 0, 0, 0, 0, 0, 0 };
		short SF_HIGH_FIRCoef_s[FIRFILTERTEMP] = { -27, -35, -11, -48, -37, -41, 8, -16, -36, -83, -26, 4, 37, -1, -1, -77, -111, -50, 99, 12, -148, -155, 335, 1056, 1142, 345, -330, -266, 663, 1038, -1037, 11720 };
		short SF_MIDH_FIRCoef_s[FIRFILTERTEMP] = { -27, -35, -11, -48, -37, -41, 8, -16, -36, -83, -26, 4, 37, -1, -1, -77, -111, -50, 99, 12, -148, -155, 335, 1056, 1142, 345, -330, -266, 663, 1038, -1037, 11720 };
		short SF_MIDL_FIRCoef_s[FIRFILTERTEMP] = { -27, -35, -11, -48, -37, -41, 8, -16, -36, -83, -26, 4, 37, -1, -1, -77, -111, -50, 99, 12, -148, -155, 335, 1056, 1142, 345, -330, -266, 663, 1038, -1037, 11720 };
		short SF_LOW_FIRCoef_s[FIRFILTERTEMP] = { -27, -35, -11, -48, -37, -41, 8, -16, -36, -83, -26, 4, 37, -1, -1, -77, -111, -50, 99, 12, -148, -155, 335, 1056, 1142, 345, -330, -266, 663, 1038, -1037, 11720 };

		
		VBParam_type VB_HIGH_Param_m = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 3, 0, 0, 0 };		// WB (voice)
		VBParam_type VB_MIDH_Param_m = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 3, 0, 0, 0 };		// WB (voice)
		VBParam_type VB_MIDL_Param_m = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 3, 0, 0, 0 };		// WB (voice)
		VBParam_type VB_LOW_Param_m = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 3, 0, 0, 0 };		// WB (voice)

		VBParam_type VB_HIGH_Param_s = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 3, 0, 0, 0 };		// WB (voice)
		VBParam_type VB_MIDH_Param_s = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 3, 0, 0, 0 };		// WB (voice)
		VBParam_type VB_MIDL_Param_s = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 3, 0, 0, 0 };		// WB (voice)
		VBParam_type VB_LOW_Param_s = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 3, 0, 0, 0 };		// WB (voice)

		short CNG_HIGH_Level_m = 32;
		short CNG_MIDH_Level_m = 32;
		short CNG_MIDL_Level_m = 32;
		short CNG_LOW_Level_m = 32;

		short CNG_HIGH_Level_s = 32;
		short CNG_MIDH_Level_s = 32;
		short CNG_MIDL_Level_s = 32;
		short CNG_LOW_Level_s = 32;

		/* FIR Filter for DyVE */
		short DyVERXFIRCoef_Max[7] = { 0, 0, 0, 0, 0, 0, 0x4C10};
		short DyVERXFIRCoef_Nom[7] = { 0, 0, 0, 0, 0, 0, 0x4000};

		DyVEStepGain_type step_maxgain = {
			0x0,
			0x0,
			0x0,
			0x0,
			0x0,
			0x0,
			0x0,
			0x04,
			0x0,
			0x0,
			0x0
		};
		
		//	DiamondVoice Mode
		DiamondVoice_DVConfig.dvMode = (SAMSUNGSF_OFF| SAMSUNGVB_OFF | SAMSUNGASF_OFF | SAMSUNGDYVERCV_OFF | SAMSUNGDYVESPK_OFF | SAMSUNGCNG_OFF | SAMSUNGBIGDATARCV_OFF | SAMSUNGBIGDATASPK_OFF  | SAMSUNGHOWL_ON);
		DiamondVoice_DVConfig.dvDualMode = SAMSUNGDIAMONDVOICE_DUALSPK_DISABLE; // SAMSUNGDIAMONDVOICE_DUALSPK_ENABLE , SAMSUNGDIAMONDVOICE_DUALSPK_DISABLE
		SamsungDiamondVoiceEngineModeConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);

		//	Static Params Setting
		{
			
			/********************************************************************************************************/
			/*  SwingFree */
			/********************************************************************************************************/
			//	SF Function Common Parameter
			DiamondVoice_DVConfig.dvVolStep_Midh2High = 0;		// vol 6 ~ vol max		; high
			DiamondVoice_DVConfig.dvVolStep_Midl2Midh = 0;		// vol 4, vol5			; mid_high
			DiamondVoice_DVConfig.dvVolStep_Low2Midl = 0;		// vol 2, vol3			; mid_low

			DiamondVoice_DVConfig.sfWNLevel = 0x06;
			DiamondVoice_DVConfig.sfComThd = 0x0F;
			DiamondVoice_DVConfig.sfComSlope = 0x64;
			DiamondVoice_DVConfig.sfExpThd = 0;
			DiamondVoice_DVConfig.sfExpSlope = 0;

			// Main
			DiamondVoice_DVConfig.sfHpfCutoff_m = 0xC8;
			DiamondVoice_DVConfig.sfPeakLimiter_m = 0x1A;
			DiamondVoice_DVConfig.sfPeakLimiterLPF_m = 0;
			DiamondVoice_DVConfig.sfStepGain_m[0] = sf_step_maxgain_m[0];
			DiamondVoice_DVConfig.sfStepGain_m[1] = sf_step_maxgain_m[1];
			DiamondVoice_DVConfig.sfStepGain_m[2] = sf_step_maxgain_m[2];
			DiamondVoice_DVConfig.sfStepGain_m[3] = sf_step_maxgain_m[3];
			DiamondVoice_DVConfig.sfStepGain_m[4] = sf_step_maxgain_m[4];
			DiamondVoice_DVConfig.sfStepGain_m[5] = sf_step_maxgain_m[5];
			DiamondVoice_DVConfig.sfStepGain_m[6] = sf_step_maxgain_m[6];
			DiamondVoice_DVConfig.sfStepGain_m[7] = sf_step_maxgain_m[7];
			DiamondVoice_DVConfig.sfStepGain_m[8] = sf_step_maxgain_m[8];
			DiamondVoice_DVConfig.sfStepGain_m[9] = sf_step_maxgain_m[9];
			DiamondVoice_DVConfig.sfStepGain_m[10] = sf_step_maxgain_m[10];

			memcpy(DiamondVoice_DVConfig.sfStepHigh_m.sfRxFilter, SF_HIGH_FIRCoef_m, sizeof(SF_HIGH_FIRCoef_m));
			memcpy(DiamondVoice_DVConfig.sfStepMidh_m.sfRxFilter, SF_MIDH_FIRCoef_m, sizeof(SF_MIDH_FIRCoef_m));
			memcpy(DiamondVoice_DVConfig.sfStepMidl_m.sfRxFilter, SF_MIDL_FIRCoef_m, sizeof(SF_MIDL_FIRCoef_m));
			memcpy(DiamondVoice_DVConfig.sfStepLow_m.sfRxFilter, SF_LOW_FIRCoef_m, sizeof(SF_LOW_FIRCoef_m));


			// Sub
			DiamondVoice_DVConfig.sfHpfCutoff_s = 0;
			DiamondVoice_DVConfig.sfPeakLimiter_s = 10;
			DiamondVoice_DVConfig.sfPeakLimiterLPF_s = 7000;
			DiamondVoice_DVConfig.sfStepGain_s[0] = sf_step_maxgain_s[0];
			DiamondVoice_DVConfig.sfStepGain_s[1] = sf_step_maxgain_s[1];
			DiamondVoice_DVConfig.sfStepGain_s[2] = sf_step_maxgain_s[2];
			DiamondVoice_DVConfig.sfStepGain_s[3] = sf_step_maxgain_s[3];
			DiamondVoice_DVConfig.sfStepGain_s[4] = sf_step_maxgain_s[4];
			DiamondVoice_DVConfig.sfStepGain_s[5] = sf_step_maxgain_s[5];
			DiamondVoice_DVConfig.sfStepGain_s[6] = sf_step_maxgain_s[6];
			DiamondVoice_DVConfig.sfStepGain_s[7] = sf_step_maxgain_s[7];
			DiamondVoice_DVConfig.sfStepGain_s[8] = sf_step_maxgain_s[8];
			DiamondVoice_DVConfig.sfStepGain_s[9] = sf_step_maxgain_s[9];
			DiamondVoice_DVConfig.sfStepGain_s[10] = sf_step_maxgain_s[10];

			memcpy(DiamondVoice_DVConfig.sfStepHigh_s.sfRxFilter, SF_HIGH_FIRCoef_s, sizeof(SF_HIGH_FIRCoef_s));
			memcpy(DiamondVoice_DVConfig.sfStepMidh_s.sfRxFilter, SF_MIDH_FIRCoef_s, sizeof(SF_MIDH_FIRCoef_s));
			memcpy(DiamondVoice_DVConfig.sfStepMidl_s.sfRxFilter, SF_MIDL_FIRCoef_s, sizeof(SF_MIDL_FIRCoef_s));
			memcpy(DiamondVoice_DVConfig.sfStepLow_s.sfRxFilter, SF_LOW_FIRCoef_s, sizeof(SF_LOW_FIRCoef_s));


			// Reserved
			DiamondVoice_DVConfig.sf_reserv1 = 10;
			// Reserved - MBD
			DiamondVoice_DVConfig.sf_reserv2 = 12;
			DiamondVoice_DVConfig.sf_reserv3 = 200;
			DiamondVoice_DVConfig.sf_reserv4 = 4 * 50;

			SamsungDiamondVoiceEngineSFConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);


			/********************************************************************************************************/
			/*  VoiceBooster */
			/********************************************************************************************************/
			//	VB50 Main Function Parameter
			DiamondVoice_DVConfig.vbStepHigh_m = VB_HIGH_Param_m;
			DiamondVoice_DVConfig.vbStepMidh_m = VB_MIDH_Param_m;
			DiamondVoice_DVConfig.vbStepMidl_m = VB_MIDL_Param_m;
			DiamondVoice_DVConfig.vbStepLow_m = VB_LOW_Param_m;

			//	VB50 Dual SPK Function Parameter
			DiamondVoice_DVConfig.vbStepHigh_s = VB_HIGH_Param_s;
			DiamondVoice_DVConfig.vbStepMidh_s = VB_MIDH_Param_s;
			DiamondVoice_DVConfig.vbStepMidl_s = VB_MIDL_Param_s;
			DiamondVoice_DVConfig.vbStepLow_s = VB_LOW_Param_s;

			SamsungDiamondVoiceEngineVBConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);


			/********************************************************************************************************/
			/*  Acoustic Shock Free */
			/********************************************************************************************************/
			//	ASF Function Parameter
			DiamondVoice_DVConfig.asfFilterMode = ASF_FILTER_MODE2;
			DiamondVoice_DVConfig.asfLimiter		= ASF_PCMMAXLEVEL_M5DB;

			SamsungDiamondVoiceEngineASFConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);

			/********************************************************************************************************/
			/*  Dynamic Voice Enhancement */
			/********************************************************************************************************/
			//	DyVE Function Parameter
			DiamondVoice_DVConfig.dyveStepMaxGain		= step_maxgain;
			DiamondVoice_DVConfig.dyveMicSensitivity	= MIC_SENSITIVITY_6;   //¹ÝÀÀ ÀâÀ½ Å©±â
			DiamondVoice_DVConfig.dyvePreemphasis		= 6;
			DiamondVoice_DVConfig.dyveMicGain			= -2;// -2 (NB);//  -4 (WB)  // 3 (SWB);
			DiamondVoice_DVConfig.dyveRMSLimiter		= 3;
			DiamondVoice_DVConfig.dyveRxVADThd			= 0;
			memcpy(DiamondVoice_DVConfig.dyveRxFilter_max, DyVERXFIRCoef_Max, sizeof(DyVERXFIRCoef_Max));
			memcpy(DiamondVoice_DVConfig.dyveRxFilter_nom, DyVERXFIRCoef_Nom, sizeof(DyVERXFIRCoef_Nom));
			DiamondVoice_DVConfig.dyve_NumMIC			= 3;


			/* New VAD ¿ë ÆÄ¶ó¹ÌÅÍ */
			DiamondVoice_DVConfig.dyve_diff_thd = 10;// DYVE_DIFF_THD_10DB;
			DiamondVoice_DVConfig.dyve_hangover_thd = 50;// DYVE_HO_COUNT_THD_50;
			DiamondVoice_DVConfig.dyve_hangover_rms_thd = 100; // Fixed
			DiamondVoice_DVConfig.dyve_ns_in_rms_thd = -57;// -65;// -57;// 0xFFC7;			// °ªÀÌ ÀÛÀ»¼ö·Ï CR Voice °³¼± / ÀÛÀº ÀâÀ½¿¡ ¹Î°¨
			DiamondVoice_DVConfig.dyve_stat_rms_thd = -60;// DYVE_RMS_THD_M94DB; // DyVE_stat_rms_thd·Î º¯°æ: stationarity thd. ÀÌ °ªº¸´Ù ÀÛÀº nonstationary ½ÅÈ£¿¡ ´ëÇØ gain °­È­. (CR voice¿¡¼­ DyVE ÀÛµ¿ÇÏ´Â ¹üÀ§ ³»¿¡¼­ ÃÖ¼Ò°ª »ç¿ë)
			DiamondVoice_DVConfig.dyve_echo_thd = DYVE_RMS_THD_M80DB;  //Init
			DiamondVoice_DVConfig.dyve_noise_thd = -26;// DYVE_RMS_THD_M26DB;  //Init
			DiamondVoice_DVConfig.dyve_clean_cnt_thd = 10;// 10;// 0x96;// 150; // DYVE_HO_COUNT_THD_40;
			DiamondVoice_DVConfig.dyve_filter_trigger = DYVE_FILTER_TRIGGER_3DB;// DYVE_FILTER_TRIGGER_3DB;
			DiamondVoice_DVConfig.dyve_filter_trigger_cnt = 10;// 10;// 0xFA;// DyVE_FILTER_TRIGGER_CNT_250;

			/* A-DRC ¿ë ÆÄ¶ó¹ÌÅÍ */
			DiamondVoice_DVConfig.dyve_adrc_enable = DYVE_ADRC_TRIGGER_3DB;
			DiamondVoice_DVConfig.dyve_adrc_thd[0] = 0x0F;
			DiamondVoice_DVConfig.dyve_adrc_thd[1] = 0x0F;
			DiamondVoice_DVConfig.dyve_adrc_thd[2] = DYVE_ADRC_COMPRESSOR_THRESHOLD_M25DB;
			DiamondVoice_DVConfig.dyve_adrc_thd[3] = DYVE_ADRC_COMPRESSOR_THRESHOLD_M80DB;;
			DiamondVoice_DVConfig.dyve_adrc_slp_high = DYVE_ADRC_COMPRESSOR_SLOPE_2P5;
			DiamondVoice_DVConfig.dyve_adrc_slp_low = DYVE_ADRC_EXPANSION_SLOPE_1_1P0;
			DiamondVoice_DVConfig.dyve_adrc_gain = DYVE_ADRC_STATIC_GAIN_6dB;

			/* Reverved ÆÄ¶ó¹ÌÅÍ */
			DiamondVoice_DVConfig.dyve_nonstat_max = 0;	 // DyVE_nonstat_thd·Î º¯°æ (161228). Nonstationary gainÀÇ ÃÖ´ë°ª. Ä¿Áú¼ö·Ï CR voice ¼º´ÉÀÌ ³ô¾ÆÁöÁö¸¸ impulsive noise¿¡ gainÀÌ °úµµÇÏ°Ô ¿Ã¶ó°¥ ¼ö ÀÖÀ½.
			DiamondVoice_DVConfig.dyve_nonstat_offset = 0;	 // DyVE_stat_offset_thd·Î º¯°æ: StationaryÀÏ ¶§ dyve_ns_in_rms_thd Áõ°¡ ÃÖ´ë°ª.
			DiamondVoice_DVConfig.dyve_ho_gaindn_thd = 20;	 // DYVE_HO_COUNT_THD_50;	// DyVE_hangover_gain_dn_thd
			DiamondVoice_DVConfig.dyve_highnoise_thd = -45;	 // DyVE_loudrms_thd·Î º¯°æ (161124). °íµµ¼ÒÀ½ RMS threshold. Digital domain¿¡¼­ -30dB°¡ 80dBSPL°ú ºñ½ÁÇÑ ¼öÁØ.
			DiamondVoice_DVConfig.dyve_maxvol_indx = 7;	 //  Maximum volume index (EUR: 5, QDSP: 7)
			DiamondVoice_DVConfig.dyve_reserved_6 = 0;
			DiamondVoice_DVConfig.dyve_reserved_7 = 0;
			DiamondVoice_DVConfig.dyve_reserved_8 = 0;

			SamsungDiamondVoiceEngineDyVEConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);

			/********************************************************************************************************/
			/*  HOWL */
			/********************************************************************************************************/
			/* SVI Parameters -> Howing Canceller parameters */
			DiamondVoice_DVConfig.howl_param.howl_lowthd = 55;					//  HOWL_MINMAX_THRESHOLD_LowBand
			DiamondVoice_DVConfig.howl_param.howl_highthd = 45;					//  HOWL_MINMAX_THRESHOLD_HighBand
			DiamondVoice_DVConfig.howl_param.howl_bandthd1 = 30;				//	band1	62.5	Hz~	1437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd2 = 37;				//	band2	562.5	Hz~	1937.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd3 = 14;				// 	band3	1062.5	Hz~	2437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd4 = 2;					// 	band4	1562.5	Hz~	2937.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd5 = -3;				// 	band5	2062.5	Hz~	3437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd6 = 3;					//	band6	2562.5	Hz~	3937.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd7 = 20;				//	band7	3062.5	Hz~	4437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd8 = 20;				// 	band8	3562.5	Hz~	4937.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd9 = 5;					//	band9	4062.5	Hz~	5437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd10 = 5;				//	band10	4562.5	Hz~	5937.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd11 = 0;				//	band11	5062.5	Hz~	6437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd12 = 5;				//	band12	5562.5	Hz~	6937.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd13 = 35;				//	band13	6062.5	Hz~	7437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd14 = 25;				//	band14	6562.5	Hz~	7937.5	Hz

			DiamondVoice_DVConfig.howl_param.howl_weak_gain = 50;				// Gain_Band_low_Howl
			DiamondVoice_DVConfig.howl_param.howl_strong_gain = 5;				// Gain_Band_high_Howl
			DiamondVoice_DVConfig.howl_param.howl_global_gain = 23197;			// Gain_low_Howl
			DiamondVoice_DVConfig.howl_param.howl_frm_cnt = 35;					// Howling count

			SamsungDiamondVoiceEngineHOWLConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);


			/********************************************************************************************************/
			/*  Comfort Noise Generator */
			/********************************************************************************************************/
			//	CNG Function Parameter
			DiamondVoice_DVConfig.cngStepHigh_m.cngLevel = CNG_HIGH_Level_m;
			DiamondVoice_DVConfig.cngStepMidh_m.cngLevel = CNG_MIDH_Level_m;
			DiamondVoice_DVConfig.cngStepMidl_m.cngLevel = CNG_MIDL_Level_m;
			DiamondVoice_DVConfig.cngStepLow_m.cngLevel = CNG_LOW_Level_m;

			//	DualSPK CNG Function Parameter
			DiamondVoice_DVConfig.cngStepHigh_s.cngLevel = CNG_HIGH_Level_s;
			DiamondVoice_DVConfig.cngStepMidh_s.cngLevel = CNG_MIDH_Level_s;
			DiamondVoice_DVConfig.cngStepMidl_s.cngLevel = CNG_MIDL_Level_s;
			DiamondVoice_DVConfig.cngStepLow_s.cngLevel = CNG_LOW_Level_s;

			SamsungDiamondVoiceEngineCNGConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);


			/********************************************************************************************************/
			/*  Dynamic Hearing Aid */
			/********************************************************************************************************/
			//	DHA/EQ Function Parameter
			DiamondVoice_DVConfig.dhaMode = SAMSUNGDHAMODE_OFF;
			DiamondVoice_DVConfig.dhaChannel = 0;
			//DiamondVoice_DVConfig.dhaParam = (short *)dhaHearingLevel;
			memcpy(DiamondVoice_DVConfig.dhaParam, dhaHearingLevel, sizeof(dhaHearingLevel));

			SamsungDiamondVoiceEngineDHAConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);


			/********************************************************************************************************/
			/*  NarrowBand Quality */
			/********************************************************************************************************/
			// ADD NB Quality Function Parameter
			DiamondVoice_DVConfig.addMode.nbQualityMode = SAMSUNGSFADDMODE_NBEQOFF;
			memcpy(DiamondVoice_DVConfig.addnbQualityFilter, NBQualityCoef, sizeof(NBQualityCoef));
			SamsungDiamondVoiceEngineADDNBQualityConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);

			/********************************************************************************************************/
			/*  Dual Spk Shock Free */
			/********************************************************************************************************/
			// ADD  Dual Spk Shock Fnction Parameter
			DiamondVoice_DVConfig.addMode.DualSpkShockMode = SAMSUNGSFADDMODE_DUALSPKSHOCKOFF;
			SamsungDiamondVoiceEngineADDDualSpkShockConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);

			/********************************************************************************************************/
			/*  Mode Change Fade in/out */
			/********************************************************************************************************/
			DiamondVoice_DVConfig.FadeOutTime_m = 0;
			DiamondVoice_DVConfig.FadeInFrmNum_m = 0;

			DiamondVoice_DVConfig.FadeOutTime_s = 0;
			DiamondVoice_DVConfig.FadeInFrmNum_s = 0;

			SamsungDiamondVoiceEngineFadeConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);
		}

		//	Dynamic Params Setting
		{
			/*	Gain Function(SF/VB/CNG) Parameter	*/
			DiamondVoice_DVConfig.sfRxVolStepIndex = SF_VOLUMESTEP_7;
			SamsungDiamondVoiceEngineGAINConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);
		}
	}
	else    // WB
	{
		short sf_step_maxgain_m[11] = { -18,//sfStepGain_m_0
			-15,//sfStepGain_m_1
			-11,//sfStepGain_m_2
			-7,//sfStepGain_m_3
			-3,//sfStepGain_m_4
			1,//sfStepGain_m_5
			5,//sfStepGain_m_6
			8,//sfStepGain_m_7
			0,//sfStepGain_m_8
			0,//sfStepGain_m_9
			0,//sfStepGain_m_10
		};
		short SF_HIGH_FIRCoef_m[FIRFILTERTEMP] = { 49,//sfRxFilter_0
			-76,//sfRxFilter_1
			12,//sfRxFilter_2
			-176,//sfRxFilter_3
			-33,//sfRxFilter_4
			-154,//sfRxFilter_5
			25,//sfRxFilter_6
			-225,//sfRxFilter_7
			136,//sfRxFilter_8
			1,//sfRxFilter_9
			86,//sfRxFilter_10
			80,//sfRxFilter_11
			314,//sfRxFilter_12
			43,//sfRxFilter_13
			92,//sfRxFilter_14
			163,//sfRxFilter_15
			103,//sfRxFilter_16
			-493,//sfRxFilter_17
			180,//sfRxFilter_18
			-301,//sfRxFilter_19
			-529,//sfRxFilter_20
			59,//sfRxFilter_21
			-202,//sfRxFilter_22
			-657,//sfRxFilter_23
			249,//sfRxFilter_24
			102,//sfRxFilter_25
			571,//sfRxFilter_26
			915,//sfRxFilter_27
			1930,//sfRxFilter_28
			2161,//sfRxFilter_29
			-1814,//sfRxFilter_30
			10733,//sfRxFilter_31 
		};
		short SF_MIDH_FIRCoef_m[FIRFILTERTEMP] = { 0x0007, 0x0000, 0x001B, 0xFFF3, 0xFFEE, 0xFFE1, 0xFFD7, 0xFF9D, 0xFF91, 0xFF46, 0xFF50, 0xFEF1, 0xFEEA, 0xFEC7, 0xFEFF, 0xFEF4, 0xFF36, 0xFF49, 0xFFE4, 0x005B, 0x0048, 0x00C3, 0x015C, 0x0117, 0x00C2, 0x0012, 0x0038, 0x01C9, 0xFC2B, 0x042A, 0x0737, 0x29CE };
		short SF_MIDL_FIRCoef_m[FIRFILTERTEMP] = { 0x0007, 0x0000, 0x001B, 0xFFF3, 0xFFEE, 0xFFE1, 0xFFD7, 0xFF9D, 0xFF91, 0xFF46, 0xFF50, 0xFEF1, 0xFEEA, 0xFEC7, 0xFEFF, 0xFEF4, 0xFF36, 0xFF49, 0xFFE4, 0x005B, 0x0048, 0x00C3, 0x015C, 0x0117, 0x00C2, 0x0012, 0x0038, 0x01C9, 0xFC2B, 0x042A, 0x0737, 0x29CE };
		short SF_LOW_FIRCoef_m[FIRFILTERTEMP] = { 0x0007, 0x0000, 0x001B, 0xFFF3, 0xFFEE, 0xFFE1, 0xFFD7, 0xFF9D, 0xFF91, 0xFF46, 0xFF50, 0xFEF1, 0xFEEA, 0xFEC7, 0xFEFF, 0xFEF4, 0xFF36, 0xFF49, 0xFFE4, 0x005B, 0x0048, 0x00C3, 0x015C, 0x0117, 0x00C2, 0x0012, 0x0038, 0x01C9, 0xFC2B, 0x042A, 0x0737, 0x29CE };

		short sf_step_maxgain_s[11] = { -20, -16, -12, -8, -4, 0, 0, 0, 0, 0, 0 };
		short SF_HIGH_FIRCoef_s[FIRFILTERTEMP] = { -27, -35, -11, -48, -37, -41, 8, -16, -36, -83, -26, 4, 37, -1, -1, -77, -111, -50, 99, 12, -148, -155, 335, 1056, 1142, 345, -330, -266, 663, 1038, -1037, 11720 };
		short SF_MIDH_FIRCoef_s[FIRFILTERTEMP] = { -27, -35, -11, -48, -37, -41, 8, -16, -36, -83, -26, 4, 37, -1, -1, -77, -111, -50, 99, 12, -148, -155, 335, 1056, 1142, 345, -330, -266, 663, 1038, -1037, 11720 };
		short SF_MIDL_FIRCoef_s[FIRFILTERTEMP] = { -27, -35, -11, -48, -37, -41, 8, -16, -36, -83, -26, 4, 37, -1, -1, -77, -111, -50, 99, 12, -148, -155, 335, 1056, 1142, 345, -330, -266, 663, 1038, -1037, 11720 };
		short SF_LOW_FIRCoef_s[FIRFILTERTEMP] = { -27, -35, -11, -48, -37, -41, 8, -16, -36, -83, -26, 4, 37, -1, -1, -77, -111, -50, 99, 12, -148, -155, 335, 1056, 1142, 345, -330, -266, 663, 1038, -1037, 11720 };


		VBParam_type VB_HIGH_Param_m = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 2, 0, 0, 0 };        // WB (voice)
		VBParam_type VB_MIDH_Param_m = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 2, 0, 0, 0 };        // WB (voice)
		VBParam_type VB_MIDL_Param_m = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 2, 0, 0, 0 };        // WB (voice)
		VBParam_type VB_LOW_Param_m = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 2, 0, 0, 0 };        // WB (voice)

		VBParam_type VB_HIGH_Param_s = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 2, 0, 0, 0 };        // WB (voice)
		VBParam_type VB_MIDH_Param_s = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 2, 0, 0, 0 };        // WB (voice)
		VBParam_type VB_MIDL_Param_s = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 2, 0, 0, 0 };        // WB (voice)
		VBParam_type VB_LOW_Param_s = { 500, 3, 4, 5, { 1000, 2500, 4000, 6000, 8000 }, { 1, 1, 2, 3, -5 }, { 5, 5, 25, 10, 10 }, 2, 0, 0, 0 };        // WB (voice)

		short CNG_HIGH_Level_m = 35;
		short CNG_MIDH_Level_m = 35;
		short CNG_MIDL_Level_m = 35;
		short CNG_LOW_Level_m = 35;

		short CNG_HIGH_Level_s = 32;
		short CNG_MIDH_Level_s = 32;
		short CNG_MIDL_Level_s = 32;
		short CNG_LOW_Level_s = 32;
		
		/* FIR Filter for DyVE */
		short DyVERXFIRCoef_Max[7] = { -1297, -1688, -1892, -2187, -773, 3139, 24876 };
		//short DyVERXFIRCoef_Max[7] = { 0, 0, 0, 0, 0, 0, 0x4000 };
		short DyVERXFIRCoef_Nom[7] = { 0, 0, 0, 0, 0, 0, 0x4000 };

		DyVEStepGain_type step_maxgain = {
			8,
			8,
			7,
			7,
			6,
			6,
			5,
			5,
			0x0,
			0x0,
			0x0
		};

		//	DiamondVoice Mode
		DiamondVoice_DVConfig.dvMode = (SAMSUNGSF_ON | SAMSUNGVB_OFF | SAMSUNGASF_ON | SAMSUNGDYVERCV_ON | SAMSUNGDYVESPK_OFF | SAMSUNGCNG_OFF | SAMSUNGBIGDATARCV_OFF | SAMSUNGBIGDATASPK_OFF | SAMSUNGHOWL_OFF);
		DiamondVoice_DVConfig.dvDualMode = SAMSUNGDIAMONDVOICE_DUALSPK_DISABLE; // SAMSUNGDIAMONDVOICE_DUALSPK_ENABLE , SAMSUNGDIAMONDVOICE_DUALSPK_DISABLE
		SamsungDiamondVoiceEngineModeConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);

		//	Static Params Setting
		{

			/********************************************************************************************************/
			/*  SwingFree */
			/********************************************************************************************************/
			//	SF Function Common Parameter
			DiamondVoice_DVConfig.dvVolStep_Midh2High = 5;		// vol 6 ~ vol max		; high
			DiamondVoice_DVConfig.dvVolStep_Midl2Midh = 2;		// vol 4, vol5			; mid_high
			DiamondVoice_DVConfig.dvVolStep_Low2Midl = 1;		// vol 2, vol3			; mid_low

			DiamondVoice_DVConfig.sfWNLevel = 8;
			DiamondVoice_DVConfig.sfComThd = 19;
			DiamondVoice_DVConfig.sfComSlope = 85;
			DiamondVoice_DVConfig.sfExpThd = 75;
			DiamondVoice_DVConfig.sfExpSlope = 65;

			// Main
			DiamondVoice_DVConfig.sfHpfCutoff_m = 150;
			DiamondVoice_DVConfig.sfPeakLimiter_m = 100;
			DiamondVoice_DVConfig.sfPeakLimiterLPF_m = 7000;
			DiamondVoice_DVConfig.sfStepGain_m[0] = sf_step_maxgain_m[0];
			DiamondVoice_DVConfig.sfStepGain_m[1] = sf_step_maxgain_m[1];
			DiamondVoice_DVConfig.sfStepGain_m[2] = sf_step_maxgain_m[2];
			DiamondVoice_DVConfig.sfStepGain_m[3] = sf_step_maxgain_m[3];
			DiamondVoice_DVConfig.sfStepGain_m[4] = sf_step_maxgain_m[4];
			DiamondVoice_DVConfig.sfStepGain_m[5] = sf_step_maxgain_m[5];
			DiamondVoice_DVConfig.sfStepGain_m[6] = sf_step_maxgain_m[6];
			DiamondVoice_DVConfig.sfStepGain_m[7] = sf_step_maxgain_m[7];
			DiamondVoice_DVConfig.sfStepGain_m[8] = sf_step_maxgain_m[8];
			DiamondVoice_DVConfig.sfStepGain_m[9] = sf_step_maxgain_m[9];
			DiamondVoice_DVConfig.sfStepGain_m[10] = sf_step_maxgain_m[10];

			memcpy(DiamondVoice_DVConfig.sfStepHigh_m.sfRxFilter, SF_HIGH_FIRCoef_m, sizeof(SF_HIGH_FIRCoef_m));
			memcpy(DiamondVoice_DVConfig.sfStepMidh_m.sfRxFilter, SF_MIDH_FIRCoef_m, sizeof(SF_MIDH_FIRCoef_m));
			memcpy(DiamondVoice_DVConfig.sfStepMidl_m.sfRxFilter, SF_MIDL_FIRCoef_m, sizeof(SF_MIDL_FIRCoef_m));
			memcpy(DiamondVoice_DVConfig.sfStepLow_m.sfRxFilter, SF_LOW_FIRCoef_m, sizeof(SF_LOW_FIRCoef_m));


			// Sub
			DiamondVoice_DVConfig.sfHpfCutoff_s = 0;
			DiamondVoice_DVConfig.sfPeakLimiter_s = 10;
			DiamondVoice_DVConfig.sfPeakLimiterLPF_s = 7000;
			DiamondVoice_DVConfig.sfStepGain_s[0] = sf_step_maxgain_s[0];
			DiamondVoice_DVConfig.sfStepGain_s[1] = sf_step_maxgain_s[1];
			DiamondVoice_DVConfig.sfStepGain_s[2] = sf_step_maxgain_s[2];
			DiamondVoice_DVConfig.sfStepGain_s[3] = sf_step_maxgain_s[3];
			DiamondVoice_DVConfig.sfStepGain_s[4] = sf_step_maxgain_s[4];
			DiamondVoice_DVConfig.sfStepGain_s[5] = sf_step_maxgain_s[5];
			DiamondVoice_DVConfig.sfStepGain_s[6] = sf_step_maxgain_s[6];
			DiamondVoice_DVConfig.sfStepGain_s[7] = sf_step_maxgain_s[7];
			DiamondVoice_DVConfig.sfStepGain_s[8] = sf_step_maxgain_s[8];
			DiamondVoice_DVConfig.sfStepGain_s[9] = sf_step_maxgain_s[9];
			DiamondVoice_DVConfig.sfStepGain_s[10] = sf_step_maxgain_s[10];

			memcpy(DiamondVoice_DVConfig.sfStepHigh_s.sfRxFilter, SF_HIGH_FIRCoef_s, sizeof(SF_HIGH_FIRCoef_s));
			memcpy(DiamondVoice_DVConfig.sfStepMidh_s.sfRxFilter, SF_MIDH_FIRCoef_s, sizeof(SF_MIDH_FIRCoef_s));
			memcpy(DiamondVoice_DVConfig.sfStepMidl_s.sfRxFilter, SF_MIDL_FIRCoef_s, sizeof(SF_MIDL_FIRCoef_s));
			memcpy(DiamondVoice_DVConfig.sfStepLow_s.sfRxFilter, SF_LOW_FIRCoef_s, sizeof(SF_LOW_FIRCoef_s));


			// Reserved
			DiamondVoice_DVConfig.sf_reserv1 = 10;
			// Reserved - MBD
			DiamondVoice_DVConfig.sf_reserv2 = 12;
			DiamondVoice_DVConfig.sf_reserv3 = 200;
			DiamondVoice_DVConfig.sf_reserv4 = 4 * 50;

			SamsungDiamondVoiceEngineSFConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);


			/********************************************************************************************************/
			/*  VoiceBooster */
			/********************************************************************************************************/
			//	VB50 Main Function Parameter
			DiamondVoice_DVConfig.vbStepHigh_m = VB_HIGH_Param_m;
			DiamondVoice_DVConfig.vbStepMidh_m = VB_MIDH_Param_m;
			DiamondVoice_DVConfig.vbStepMidl_m = VB_MIDL_Param_m;
			DiamondVoice_DVConfig.vbStepLow_m = VB_LOW_Param_m;

			//	VB50 Dual SPK Function Parameter
			DiamondVoice_DVConfig.vbStepHigh_s = VB_HIGH_Param_s;
			DiamondVoice_DVConfig.vbStepMidh_s = VB_MIDH_Param_s;
			DiamondVoice_DVConfig.vbStepMidl_s = VB_MIDL_Param_s;
			DiamondVoice_DVConfig.vbStepLow_s = VB_LOW_Param_s;

			SamsungDiamondVoiceEngineVBConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);


			/********************************************************************************************************/
			/*  Acoustic Shock Free */
			/********************************************************************************************************/
			//	ASF Function Parameter
			DiamondVoice_DVConfig.asfFilterMode = ASF_FILTER_MODE2;
			DiamondVoice_DVConfig.asfLimiter = ASF_PCMMAXLEVEL_M6DB;

			SamsungDiamondVoiceEngineASFConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);

			/********************************************************************************************************/
			/*  Dynamic Voice Enhancement */
			/********************************************************************************************************/
			//	DyVE Function Parameter
			DiamondVoice_DVConfig.dyveStepMaxGain = step_maxgain;
			DiamondVoice_DVConfig.dyveMicSensitivity = MIC_SENSITIVITY_6;   //¹ÝÀÀ ÀâÀ½ Å©±â
			DiamondVoice_DVConfig.dyvePreemphasis = 9;
			DiamondVoice_DVConfig.dyveMicGain = 3;// -11;// -2 (NB);//  -11 (WB)  // 3 (SWB);
			DiamondVoice_DVConfig.dyveRMSLimiter = 3;
			DiamondVoice_DVConfig.dyveRxVADThd = 0;
			memcpy(DiamondVoice_DVConfig.dyveRxFilter_max, DyVERXFIRCoef_Max, sizeof(DyVERXFIRCoef_Max));
			memcpy(DiamondVoice_DVConfig.dyveRxFilter_nom, DyVERXFIRCoef_Nom, sizeof(DyVERXFIRCoef_Nom));
			DiamondVoice_DVConfig.dyve_NumMIC = 2;


			/* New VAD ¿ë ÆÄ¶ó¹ÌÅÍ */
			DiamondVoice_DVConfig.dyve_diff_thd = 10;// DYVE_DIFF_THD_10DB;
			DiamondVoice_DVConfig.dyve_hangover_thd = 50;// DYVE_HO_COUNT_THD_50;
			DiamondVoice_DVConfig.dyve_hangover_rms_thd = 100; // Fixed
			DiamondVoice_DVConfig.dyve_ns_in_rms_thd = -60;// 0xFFC7;			// °ªÀÌ ÀÛÀ»¼ö·Ï CR Voice °³¼± / ÀÛÀº ÀâÀ½¿¡ ¹Î°¨
			DiamondVoice_DVConfig.dyve_stat_rms_thd = -60;// DYVE_RMS_THD_M94DB; // DyVE_stat_rms_thd·Î º¯°æ: stationarity thd. ÀÌ °ªº¸´Ù ÀÛÀº nonstationary ½ÅÈ£¿¡ ´ëÇØ gain °­È­. (CR voice¿¡¼­ DyVE ÀÛµ¿ÇÏ´Â ¹üÀ§ ³»¿¡¼­ ÃÖ¼Ò°ª »ç¿ë)
			DiamondVoice_DVConfig.dyve_echo_thd = -80;  //Init
			DiamondVoice_DVConfig.dyve_noise_thd = -26;// DYVE_RMS_THD_M26DB;  //Init
			DiamondVoice_DVConfig.dyve_clean_cnt_thd = 10;// 0x96;// 150; // DYVE_HO_COUNT_THD_40;
			DiamondVoice_DVConfig.dyve_filter_trigger = 3;// DYVE_FILTER_TRIGGER_3DB;
			DiamondVoice_DVConfig.dyve_filter_trigger_cnt = 10;// 10;// 0xFA;// DyVE_FILTER_TRIGGER_CNT_250;

			/* A-DRC ¿ë ÆÄ¶ó¹ÌÅÍ */
			DiamondVoice_DVConfig.dyve_adrc_enable = DYVE_ADRC_TRIGGER_3DB;
			DiamondVoice_DVConfig.dyve_adrc_thd[0] = 10;
			DiamondVoice_DVConfig.dyve_adrc_thd[1] = 15;
			DiamondVoice_DVConfig.dyve_adrc_thd[2] = 25;
			DiamondVoice_DVConfig.dyve_adrc_thd[3] = 80;
			DiamondVoice_DVConfig.dyve_adrc_slp_high = 10;
			DiamondVoice_DVConfig.dyve_adrc_slp_low = 10;
			DiamondVoice_DVConfig.dyve_adrc_gain = DYVE_ADRC_STATIC_GAIN_9dB;

			/* Reverved ÆÄ¶ó¹ÌÅÍ */
			DiamondVoice_DVConfig.dyve_nonstat_max = 0;	 // DyVE_nonstat_thd·Î º¯°æ (161228). Nonstationary gainÀÇ ÃÖ´ë°ª. Ä¿Áú¼ö·Ï CR voice ¼º´ÉÀÌ ³ô¾ÆÁöÁö¸¸ impulsive noise¿¡ gainÀÌ °úµµÇÏ°Ô ¿Ã¶ó°¥ ¼ö ÀÖÀ½.
			DiamondVoice_DVConfig.dyve_nonstat_offset = 0;	 // DyVE_stat_offset_thd·Î º¯°æ: StationaryÀÏ ¶§ dyve_ns_in_rms_thd Áõ°¡ ÃÖ´ë°ª.
			DiamondVoice_DVConfig.dyve_ho_gaindn_thd = 20;	 // DYVE_HO_COUNT_THD_50;	// DyVE_hangover_gain_dn_thd
			DiamondVoice_DVConfig.dyve_highnoise_thd = -45;// -45;	 // DyVE_loudrms_thd·Î º¯°æ (161124). °íµµ¼ÒÀ½ RMS threshold. Digital domain¿¡¼­ -30dB°¡ 80dBSPL°ú ºñ½ÁÇÑ ¼öÁØ.
			DiamondVoice_DVConfig.dyve_maxvol_indx = 7;	 //  Maximum volume index (EUR: 5, QDSP: 7)
			DiamondVoice_DVConfig.dyve_reserved_6 = 0;
			DiamondVoice_DVConfig.dyve_reserved_7 = 0;
			DiamondVoice_DVConfig.dyve_reserved_8 = 0;

			SamsungDiamondVoiceEngineDyVEConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);

			/********************************************************************************************************/
			/*  HOWL */
			/********************************************************************************************************/
			/* SVI Parameters -> Howing Canceller parameters */
			DiamondVoice_DVConfig.howl_param.howl_lowthd = 70;					//  HOWL_MINMAX_THRESHOLD_LowBand
			DiamondVoice_DVConfig.howl_param.howl_highthd = 70;					//  HOWL_MINMAX_THRESHOLD_HighBand
			DiamondVoice_DVConfig.howl_param.howl_bandthd1 = 30;				//	band1	62.5	Hz~	1437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd2 = 37;				//	band2	562.5	Hz~	1937.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd3 = 14;				// 	band3	1062.5	Hz~	2437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd4 = 2;					// 	band4	1562.5	Hz~	2937.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd5 = -3;				// 	band5	2062.5	Hz~	3437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd6 = 3;					//	band6	2562.5	Hz~	3937.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd7 = 20;				//	band7	3062.5	Hz~	4437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd8 = 20;				// 	band8	3562.5	Hz~	4937.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd9 = 5;					//	band9	4062.5	Hz~	5437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd10 = 5;				//	band10	4562.5	Hz~	5937.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd11 = 0;				//	band11	5062.5	Hz~	6437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd12 = 5;				//	band12	5562.5	Hz~	6937.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd13 = 35;				//	band13	6062.5	Hz~	7437.5	Hz
			DiamondVoice_DVConfig.howl_param.howl_bandthd14 = 50;				//	band14	6562.5	Hz~	7937.5	Hz

			DiamondVoice_DVConfig.howl_param.howl_weak_gain = 50;				// Gain_Band_low_Howl
			DiamondVoice_DVConfig.howl_param.howl_strong_gain = 5;				// Gain_Band_high_Howl
			DiamondVoice_DVConfig.howl_param.howl_global_gain = 32767;// 200;			// Gain_low_Howl
			DiamondVoice_DVConfig.howl_param.howl_frm_cnt = 85;					// Howling count

			SamsungDiamondVoiceEngineHOWLConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);

			/********************************************************************************************************/
			/*  Comfort Noise Generator */
			/********************************************************************************************************/
			//	CNG Function Parameter
			DiamondVoice_DVConfig.cngStepHigh_m.cngLevel = CNG_HIGH_Level_m;
			DiamondVoice_DVConfig.cngStepMidh_m.cngLevel = CNG_MIDH_Level_m;
			DiamondVoice_DVConfig.cngStepMidl_m.cngLevel = CNG_MIDL_Level_m;
			DiamondVoice_DVConfig.cngStepLow_m.cngLevel = CNG_LOW_Level_m;

			//	DualSPK CNG Function Parameter
			DiamondVoice_DVConfig.cngStepHigh_s.cngLevel = CNG_HIGH_Level_s;
			DiamondVoice_DVConfig.cngStepMidh_s.cngLevel = CNG_MIDH_Level_s;
			DiamondVoice_DVConfig.cngStepMidl_s.cngLevel = CNG_MIDL_Level_s;
			DiamondVoice_DVConfig.cngStepLow_s.cngLevel = CNG_LOW_Level_s;

			SamsungDiamondVoiceEngineCNGConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);


			/********************************************************************************************************/
			/*  Dynamic Hearing Aid */
			/********************************************************************************************************/
			//	DHA/EQ Function Parameter
			DiamondVoice_DVConfig.dhaMode = SAMSUNGDHAMODE_OFF;
			DiamondVoice_DVConfig.dhaChannel = 0;
			//DiamondVoice_DVConfig.dhaParam = (short *)dhaHearingLevel;
			memcpy(DiamondVoice_DVConfig.dhaParam, dhaHearingLevel, sizeof(dhaHearingLevel));

			SamsungDiamondVoiceEngineDHAConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);


			/********************************************************************************************************/
			/*  NarrowBand Quality */
			/********************************************************************************************************/
			// ADD NB Quality Function Parameter
			DiamondVoice_DVConfig.addMode.nbQualityMode = SAMSUNGSFADDMODE_NBEQOFF;
			memcpy(DiamondVoice_DVConfig.addnbQualityFilter, NBQualityCoef, sizeof(NBQualityCoef));
			SamsungDiamondVoiceEngineADDNBQualityConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);

			/********************************************************************************************************/
			/*  Dual Spk Shock Free */
			/********************************************************************************************************/
			// ADD  Dual Spk Shock Fnction Parameter
			DiamondVoice_DVConfig.addMode.DualSpkShockMode = SAMSUNGSFADDMODE_DUALSPKSHOCKOFF;
			SamsungDiamondVoiceEngineADDDualSpkShockConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);

			/********************************************************************************************************/
			/*  Mode Change Fade in/out */
			/********************************************************************************************************/
			DiamondVoice_DVConfig.FadeOutTime_m = 2;
			DiamondVoice_DVConfig.FadeInFrmNum_m = 2;

			DiamondVoice_DVConfig.FadeOutTime_s = 0;
			DiamondVoice_DVConfig.FadeInFrmNum_s = 0;

			SamsungDiamondVoiceEngineFadeConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);
		}

		//	Dynamic Params Setting
		{
			/*	Gain Function(SF/VB/CNG) Parameter	*/
			DiamondVoice_DVConfig.sfRxVolStepIndex = SF_VOLUMESTEP_7;
			SamsungDiamondVoiceEngineGAINConfig(&SamsungDiamondVoiceEngine_var, &DiamondVoice_DVConfig);
		}
	}
}

#else

#include "samsungDiamondVoiceTx.h"

#define DIAMONDVOICE_FRAME_TX			SAMSUNGDIAMONDVOICEWIDEBAND_TX //	SAMSUNGDIAMONDVOICESUPERWIDEBAND_TX, SAMSUNGDIAMONDVOICEWIDEBAND_TX, SAMSUNGDIAMONDVOICENARROWBAND_TX

#define	FIRFILTERTEMP_TX					32

short DiamondVoice_Mode_v = 0;

short TXFIRCoef[FIRFILTERTEMP_TX] = { 0xFFF5, 0x0007, 0xFFFC, 0x0013, 0xFFFD, 0x0001, 0xFFE6, 0xFFD7, 0xFFD6, 0x000C, 0x0029, 0x0049, 0x000E, 0xFFF0, 0xFFC9, 0xFFCD, 0x001F, 0x006B, 0x0096, 0x0030, 0xFF51, 0xFF01, 0xFEEE, 0xFF75, 0x00B5, 0x011C, 0x0306, 0xFF81, 0xFF06, 0x0844, 0x2EAE };


#define NUM_PARAM 85
short LoadParm[NUM_PARAM] = { 0,0,0, };

SamsungDiamondVoiceTxParam DiamondVoice_DV_TX_Config = { 0, };
SamsungDiamondVoiceTxEngine_Handle_t SamsungDiamondVoiceEngine_vars_Tx;

//#define DEBUG_DUMP

#ifdef DEBUG_DUMP
FILE  *fp_spectro, *fp_fq_para, *fp_ch_minmax, *fp_ch_howl_flag, *fp_freq_howl_flag, *fp_freq_howl_gain, *fp_lsf_eng, *fp_lsf_band; // for howl debug
#endif

void usage(void) {
	printf("===========================================================================================\n");
	printf(" DiamondVoice Engine HELP	\n");
	printf("===========================================================================================\n");
	printf("\n");
	printf("Arguments : input.pcm output.pcm param.txt\n");
	printf(" Arg 1st  : input.pcm  : DiamondVoice input file \n");
	printf(" Arg 2nd  : output.pcm : DiamondVoice output file \n");
	printf(" Arg 3rd  : param.txt  : Tuning Parameter file \n");
	printf("===========================================================================================\n");
}

void ParseTuningFile(char *TuningFilePath)
{
	FILE *Tf;
	if ((Tf = fopen(TuningFilePath, "rb")) == NULL) {
		fprintf(stderr, "input Tuning file error..\n");
		exit(0);
	}

	int i;
	char dummy[NUM_PARAM];
	for (i = 0; i < NUM_PARAM; i++)
	{
		fscanf(Tf, "%s %d", &dummy, &LoadParm[i]);
	}

	int tmp_ind = 0;

	//Mode
	DiamondVoice_DV_TX_Config.mode = LoadParm[tmp_ind++];
	
	//HPF		.
	DiamondVoice_DV_TX_Config.hpf_cutoff = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.hpf_gain = LoadParm[tmp_ind++];

	// WISE VOICE PRAM
	DiamondVoice_DV_TX_Config.wisevoice_device_mode = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_att_time = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_rel_time = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_thd[0] = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_thd[1] = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_thd[2] = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_thd[3] = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_slp_high = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_slp_low =  LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_gain = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_InGain = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_OutGain = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_ngmode = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_ngpara[0] = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_ngpara[1] = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_ComThd = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_ComSlope = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_ExpThd = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.wisevoice_ExpSlope = LoadParm[tmp_ind++];
	

	// Tx Filter & Tx AGC & Tx Limiter & Tx Gain
	for (i = 0; i < 32; i++)
	{
		DiamondVoice_DV_TX_Config.firFilter[i] = LoadParm[tmp_ind++];
	}
	

	DiamondVoice_DV_TX_Config.agc_comThd = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.agc_comSlope = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.agc_expThd = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.agc_expSlope = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.gain = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.limit_thd = LoadParm[tmp_ind++];

	//CNG
	DiamondVoice_DV_TX_Config.cng_level = LoadParm[tmp_ind++];

	// HOWL
	DiamondVoice_DV_TX_Config.howl_param.howl_lowthd   = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_highthd  = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd1 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd2 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd3 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd4 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd5 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd6 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd7 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd8 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd9 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd10 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd11 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd12 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd13 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_bandthd14 = LoadParm[tmp_ind++];

	DiamondVoice_DV_TX_Config.howl_param.howl_weak_gain   = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_strong_gain = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_global_gain = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.howl_frm_cnt = LoadParm[tmp_ind++];

	DiamondVoice_DV_TX_Config.howl_param.reserved1 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.reserved2 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.reserved3 = LoadParm[tmp_ind++];
	DiamondVoice_DV_TX_Config.howl_param.reserved4 = LoadParm[tmp_ind++];
}

int main(int argc, char *argv[])
{
	printf("===========================================================================================\n");
	printf(" DiamondVoice Engine Simulation	\n");
	printf("===========================================================================================\n");

	if (argc != 4) { //Normal case argc is 4

		printf("argc: %d\n\n\n", argc);
		usage();

		return 0;
	}

	//argv[0]  : "D:\\VisualstudioWorkspace\\Predict_3QUEST\\DiamondVoice_Ref\\Debug\\DiamondVoice_Ref.exe"
	//argv[1]  : "input.pcm"
	//argv[2]  : "output.pcm"
	//argv[3]  : "param.txt"

#ifdef DEBUG_DUMP
	// for howl debug
	fp_spectro = fopen("howl_spectro.txt", "w");
	fp_fq_para = fopen("howl_para.txt", "w");
	fp_ch_minmax = fopen("howl_band_minmax.txt", "w");
	fp_ch_howl_flag = fopen("howl_band_flag.txt", "w");
	fp_freq_howl_flag = fopen("howl_freq_flag.txt", "w");
	fp_freq_howl_gain = fopen("howl_freq_gain.txt", "w");
	fp_lsf_eng = fopen("howl_lsf_eng.txt", "w");
	fp_lsf_band = fopen("howl_lsf_band.txt", "w");
#endif

	FILE *ifp, *ofp;

	short Speech_buf_TX[640], Output_buf_TX[640];
	long FrmCnt;
	if ((ifp = fopen(argv[1], "rb")) == (FILE *)NULL)
		exit(fprintf(stderr, "input file error..\n"));

	if ((ofp = fopen(argv[2], "wb")) == (FILE *)NULL)
		exit(fprintf(stderr, "output file error..\n"));


	ParseTuningFile(argv[3]);


	printf(" [1] Input pcm path : %s \n", argv[1]);
	printf(" [2] Output pcm path : %s \n", argv[2]);
	printf(" [3] Tuning file path : %s \n", argv[3]);
	
	

	//	Initialization for NarrowBand or Wideband
	SamsungDiamondVoiceTxEngineInit(&SamsungDiamondVoiceEngine_vars_Tx, DIAMONDVOICE_FRAME_TX);//wb fix

	//	I/O Config
	SamsungDiamondVoiceTxEngineInOutConfig(&SamsungDiamondVoiceEngine_vars_Tx, Speech_buf_TX, Output_buf_TX);

	//	DiamondVoice Mode
	SamsungDiamondVoiceTxEngineModeConfig(&SamsungDiamondVoiceEngine_vars_Tx, &DiamondVoice_DV_TX_Config);
	
	/*	DiamondVoice Device Setting	*/
	{
		//HPF		.
		SamsungDiamondVoiceTxEngineHPFConfig(&SamsungDiamondVoiceEngine_vars_Tx, &DiamondVoice_DV_TX_Config);

		// WISE VOICE PRAM
		SamsungDiamondVoiceTxEngineWiseVoiceConfig(&SamsungDiamondVoiceEngine_vars_Tx, &DiamondVoice_DV_TX_Config);
		
		// Tx Filter & Tx AGC & Tx Limiter & Tx Gain
		SamsungDiamondVoiceTxEngineConfig(&SamsungDiamondVoiceEngine_vars_Tx, &DiamondVoice_DV_TX_Config);

		// HOWL
		SamsungDiamondVoiceTxEngineHOWLTxConfig(&SamsungDiamondVoiceEngine_vars_Tx, &DiamondVoice_DV_TX_Config);

		//CNG
		SamsungDiamondVoiceTxEngineCNGConfig(&SamsungDiamondVoiceEngine_vars_Tx, &DiamondVoice_DV_TX_Config);
	}

	//get total frame size
	FILE *fp = fopen(argv[1], "rb");
	fseek(fp, 0, SEEK_END);
	int TotalFrameSize = ftell(fp);
	TotalFrameSize = (TotalFrameSize / DIAMONDVOICE_FRAME_TX)>>1;
	fclose(fp);


	FrmCnt = 0;

	printf("\n == Start Simulation ==\n\n");

	while (fread(Speech_buf_TX, sizeof(short), DIAMONDVOICE_FRAME_TX, ifp) == (unsigned)DIAMONDVOICE_FRAME_TX) {

		SamsungDiamondVoiceTxEngineExe(&SamsungDiamondVoiceEngine_vars_Tx, &DiamondVoice_DV_TX_Config, Output_buf_TX, Speech_buf_TX);

		fwrite(Output_buf_TX, sizeof(short), DIAMONDVOICE_FRAME_TX, ofp);

		FrmCnt++;

		//if ((FrmCnt % 100) == 0)	
		printf("\rFrmCnt: %d / %d", FrmCnt, TotalFrameSize);
	}

	printf("\n\n == Finished Simulation == \n\n");
	//printf("%d\n%d\n",sum_eng,cnt);

	fclose(ifp);
	fclose(ofp);

#ifdef DEBUG_DUMP
	// for howl debug file close
	fclose(fp_spectro);
	fclose(fp_fq_para);
	fclose(fp_ch_minmax);
	fclose(fp_ch_howl_flag);
	fclose(fp_freq_howl_flag);
	fclose(fp_freq_howl_gain);
	fclose(fp_lsf_eng);
	fclose(fp_lsf_band);
#endif

	return 0;
}
#endif
