#include <stdio.h>
#include <io.h>
#include <direct.h>

#include "Define_config.h"
#include "SamsungSolomonVoiceW.h"

#if(FLAG_SELECT_C_DSP == 1)
#include <stdlib.h>
#endif

#define DIAMONDVOICE_FRAME_TX			320 //	SAMSUNGDIAMONDVOICEWIDEBAND_TX, SAMSUNGDIAMONDVOICENARROWBAND_TX

int FrmCnt_main;

#if(FLAG_SELECT_C_DSP == 1)
FILE *fp_debug_ns_para, *fp_debug_ns_vec1, *fp_debug_ns_vec2, *fp_debug_aecoutpwr, *fp_debug_ns_vec3, *fp_debug_ns_vec4, *fp_debug_ns_vec5, *fp_debug_res_regression;
FILE *fp_debug_Pwr_RX_AECIN_dB_C, *fp_debug_ADF_C;
FILE *fp_debug_AEC_in_inner, *fp_debug_AEC_in_outer1, *fp_debug_AEC_in_outer2, *fp_debug_AEC_out_inner, *fp_debug_AEC_out_outer1, *fp_debug_AEC_out_outer2;
FILE /**fp_debug_FNLMSin_acc, */*fp_debug_FNLMSin_inner, *fp_debug_FNLMSin_outer, /**fp_debug_FNLMSout_acc, */*fp_debug_FNLMSout_inner, *fp_debug_FNLMSout_outr;
FILE /**fp_debug_RESout_acc, */*fp_debug_RESout_inner, *fp_debug_RESout_outer;
FILE *fp_debug_NSout_acc, *fp_debug_NSout_inner, *fp_debug_NSout_outer;

FILE *fp_debug_BFfbf_outer, *fp_debug_BFbm_outer, *fp_debug_BFgsc_outer;

FILE *fp_debug_acc_E_low, *fp_debug_acc_E_hig, *fp_debug_acc_E_rat, *fp_debug_acc__zcr, *fp_debug_acc_ticflag, *fp_debug_acc_txt;
FILE *fp_debug_NS;
FILE *fp_debug_dump;
FILE *fp_WnlmsFilterCoeff;
FILE *fp_npvss_nlms;
FILE *fp_Wfnlms_new;
FILE *fp_inoutVAD;
FILE *fp_f0contour;
FILE *fp_dbg_Mixing;
FILE *fp_dbg_Unfit;
FILE *fp_dbg_Unfitpcm;
FILE *fp_dbg_Wind;
FILE *fp_dbg_Wind_Imsc;
FILE *fp_fft_out_inner;
FILE *fp_fft_out_outer;
FILE *fp_dbg_NoiseState;
FILE *fp_dbg_AMSState;
FILE *fp_dbg_ACCState;
FILE *fp_dbg_MixingState;
FILE *fp_dbg_Mixingdbg0;
FILE *fp_dbg_Mixingdbg1;
FILE *fp_dbg_Mixingdbg2;
FILE *fp_dbg_Mixingdbg3;
FILE *fp_dbg_MBDRC;
FILE *fp_deg_2micBF[N_fp_2micBF_debuffiles];
FILE *fp_dbg_Tic_txt, *fp_dbg_Tic_pcm;

// solomonvoice_sub_module_point_tmp
FILE *fp_fx_SolomonVoice_ringbacktone_detection;

FILE *fp_f0_based_preNS_para;
FILE *fp_inner8kout;
#endif

// 1mic ECNS-------------------------------
SamsungSolomonVoiceParam DiamondVoice_DV_TX_Config = { 0, };
SamsungSolomonVoiceEngine_Handle_t SamsungDiamondVoiceEngine_vars_Tx = { 0, }; 

short Speech_buf_Tx_Inner[SAMSUNGDIAMONDVOICEWIDEBAND_TX];//   = (short *)malloc(sizeof(short)* SAMSUNGDIAMONDVOICEWIDEBAND_TX);
short Speech_buf_Tx_Outer_1[SAMSUNGDIAMONDVOICEWIDEBAND_TX];// = (short *)malloc(sizeof(short)* SAMSUNGDIAMONDVOICEWIDEBAND_TX);		
short Speech_buf_Tx_Outer_2[SAMSUNGDIAMONDVOICEWIDEBAND_TX];// = (short *)malloc(sizeof(short)* SAMSUNGDIAMONDVOICEWIDEBAND_TX);		
short Speech_buf_RX_Inner[SAMSUNGDIAMONDVOICEWIDEBAND_TX];//   = (short *)malloc(sizeof(short)* SAMSUNGDIAMONDVOICEWIDEBAND_TX);
short Speech_buf_RX_Outer[SAMSUNGDIAMONDVOICEWIDEBAND_TX];//   = (short *)malloc(sizeof(short)* SAMSUNGDIAMONDVOICEWIDEBAND_TX);
short Output_buf_TX[SAMSUNGDIAMONDVOICEWIDEBAND_TX];//   = (short *)malloc(sizeof(short)* SAMSUNGDIAMONDVOICEWIDEBAND_TX);

short Speech_buf_Tx_Acc[SAMSUNGDIAMONDVOICEWIDEBAND_TX];// = (short *)malloc(sizeof(short)* SAMSUNGDIAMONDVOICEWIDEBAND_TX);		

#if(FLAG_SELECT_C_DSP == 1)
/* dbg output */
short Output_buf_Inner_NB[SAMSUNGDIAMONDVOICEWIDEBAND_TX>>1];// = (short *)malloc(sizeof(short)* SAMSUNGDIAMONDVOICEWIDEBAND_TX);
short Output_buf_Outer[SAMSUNGDIAMONDVOICEWIDEBAND_TX];// = (short *)malloc(sizeof(short)* SAMSUNGDIAMONDVOICEWIDEBAND_TX);
short Output_buf_Inner_WB[SAMSUNGDIAMONDVOICEWIDEBAND_TX];// = (short *)malloc(sizeof(short)* SAMSUNGDIAMONDVOICEWIDEBAND_TX);
#endif

int main(int argc, char *argv[])
{
	// 1mic ECNS-------------------------------
	short i;
	short ams_flag = 0;

	FILE *ifp1, *ifp2, *ifp3, *ifp4, *ifp5, *ofp1;
#if(FLAG_SELECT_C_DSP == 1)
	char path_name[200] = "";

	sprintf(path_name, "%s%s", argv[8], "\\out");
	if (_access(path_name, 0) == -1)
		_mkdir(path_name);
	path_name[0] = "\n";

	sprintf(path_name, "%s%s", argv[8], "\\debug");
	if (_access(path_name, 0) == -1)
		_mkdir(path_name);
	path_name[0] = "\n";
	
	// solomonvoice_sub_module_point_tmp
	sprintf(path_name, "%s%s", argv[8], "\\debug\\fp_fx_SolomonVoice_ringbacktone_detection.txt");	
	fp_fx_SolomonVoice_ringbacktone_detection = fopen(path_name, "w");  path_name[0] = "\n";

	
	// 1mic ECNS-------------------------------
	sprintf(path_name, "%s%s", argv[8], "\\debug\\Wfnlms_new.txt");	 
	fp_Wfnlms_new = fopen(path_name, "w");  path_name[0] = "\n";

	sprintf(path_name, "%s%s", argv[8], "\\debug\\debug_ns_para.txt");	
	fp_debug_ns_para = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\debug_ns_vec1.txt");	
	fp_debug_ns_vec1 = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\debug_ns_vec2.txt");	
	fp_debug_ns_vec2 = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\debug_ns_aecoutpwr.txt");	
	fp_debug_aecoutpwr = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\debug_ns_vec3.txt");	
	fp_debug_ns_vec3 = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\debug_ns_vec4.txt");	
	fp_debug_ns_vec4 = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\debug_ns_vec5.txt");	
	fp_debug_ns_vec5 = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\WnlmsFilterCoeff.txt");	
	fp_WnlmsFilterCoeff = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\npvss_nlms.txt");	
	fp_npvss_nlms = fopen(path_name, "w");  path_name[0] = "\n";

	sprintf(path_name, "%s%s", argv[8], "\\debug\\debug_res_regression.txt");	
	fp_debug_res_regression = fopen(path_name, "w");  path_name[0] = "\n";

	sprintf(path_name, "%s%s", argv[8], "\\debug\\Pwr_RX_AECIN_dB_C.txt");	
	fp_debug_Pwr_RX_AECIN_dB_C = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\ADF_C.txt");	
	fp_debug_ADF_C = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\NS.txt");	
	fp_debug_NS = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\dump.txt");	
	fp_debug_dump = fopen(path_name, "w");  path_name[0] = "\n";

	sprintf(path_name, "%s%s", argv[8], "\\debug\\f0contour.txt");	
	fp_f0contour = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\inoutVAD.txt");	
	fp_inoutVAD = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\fp_f0_based_preNS_para.txt");	
	fp_f0_based_preNS_para = fopen(path_name, "w");  path_name[0] = "\n";

	sprintf(path_name, "%s%s", argv[8], "\\debug\\_0_AECin_inner.pcm");
	fp_debug_AEC_in_inner = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_0_AECin_outer1.pcm");
	fp_debug_AEC_in_outer1 = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_0_AECin_outer2.pcm");
	fp_debug_AEC_in_outer2 = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_1_AECout_inner.pcm");
	fp_debug_AEC_out_inner = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_1_AECout_outer1.pcm");
	fp_debug_AEC_out_outer1 = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_1_AECout_outer2.pcm");
	fp_debug_AEC_out_outer2 = fopen(path_name, "wb");  path_name[0] = "\n";

	//sprintf(path_name, "%s%s", argv[8], "\\debug\\_2_FNLMSin_acc.pcm");
	//fp_debug_FNLMSin_acc = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_2_FNLMSin_inner.pcm");
	fp_debug_FNLMSin_inner = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_2_FNLMSin_outer.pcm");
	fp_debug_FNLMSin_outer = fopen(path_name, "wb");  path_name[0] = "\n";
	//sprintf(path_name, "%s%s", argv[8], "\\debug\\_3_FNLMSout_acc.pcm");
	//fp_debug_FNLMSout_acc = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_3_FNLMSout_inner.pcm");
	fp_debug_FNLMSout_inner = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_3_FNLMSout_outer.pcm");
	fp_debug_FNLMSout_outr = fopen(path_name, "wb");  path_name[0] = "\n";

	sprintf(path_name, "%s%s", argv[8], "\\debug\\_4_RESout_inner.pcm");
	fp_debug_RESout_inner = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_4_RESout_outer.pcm");
	fp_debug_RESout_outer = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_5_NSout_acc.pcm");
	fp_debug_NSout_acc = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_5_NSout_inner.pcm");
	fp_debug_NSout_inner = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_5_NSout_outer.pcm");
	fp_debug_NSout_outer = fopen(path_name, "wb");  path_name[0] = "\n";

	sprintf(path_name, "%s%s", argv[8], "\\debug\\_6_BFout_fbf_0424_3.pcm");
	fp_debug_BFfbf_outer = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_6_BFout_bm_0424_3.pcm");
	fp_debug_BFbm_outer = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_6_BFout_gsc_0424_3.pcm");
	fp_debug_BFgsc_outer = fopen(path_name, "wb");  path_name[0] = "\n";
	
	sprintf(path_name, "%s%s", argv[8], "\\debug\\__acc_dbg.txt");
	fp_debug_acc_txt = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\__acc_dbg_Elow.pcm");
	fp_debug_acc_E_low = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\__acc_dbg_Ehigh.pcm");
	fp_debug_acc_E_hig = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\__acc_dbg_Eratio.pcm");
	fp_debug_acc_E_rat = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\__acc_dbg_zcr.pcm");
	fp_debug_acc__zcr = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\__acc_dbg_ticflag.pcm");
	fp_debug_acc_ticflag = fopen(path_name, "wb");  path_name[0] = "\n";
	
	// inner write
	sprintf(path_name, "%s%s", argv[8], "\\debug\\outinner.pcm");	
	fp_inner8kout = fopen(path_name, "wb");  path_name[0] = "\n";

	//Mixing
	sprintf(path_name, "%s%s%s%s%s", argv[8], "\\debug\\_NoiseState", "_", argv[7], ".pcm");
	fp_dbg_NoiseState = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s%s%s%s", argv[8], "\\debug\\_AMSState", "_", argv[7], ".pcm");
	fp_dbg_AMSState = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s%s%s%s", argv[8], "\\debug\\_MixingState", "_", argv[7], ".pcm");
	fp_dbg_MixingState = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s%s%s%s", argv[8], "\\debug\\_ACCState", "_", argv[7], ".pcm");
	fp_dbg_ACCState = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_Mixing_veryLowLevel.pcm");
	fp_dbg_Mixingdbg0 = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_Mixing_LowLevel.pcm");
	fp_dbg_Mixingdbg1 = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_Mixing_highLevel.pcm");
	fp_dbg_Mixingdbg2 = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_Mixing_windLevel.pcm");
	fp_dbg_Mixingdbg3 = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_pf_fft_1.bin");
	fp_fft_out_inner = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_pf_fft_2.bin");
	fp_fft_out_outer = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s%s%s%s", argv[8], "\\debug\\_A_dbg_Mixing", "_", argv[7], ".txt");
	fp_dbg_Mixing = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s%s%s%s", argv[8], "\\debug\\_A_dbg_Unfit", "_", argv[7], ".txt");
	fp_dbg_Unfit = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s%s%s%s", argv[8], "\\debug\\_UnfitState", "_", argv[7], ".pcm");
	fp_dbg_Unfitpcm = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s%s%s%s", argv[8], "\\debug\\_A_dbg_Wind", "_", argv[7], ".txt");
	fp_dbg_Wind = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s%s%s%s", argv[8], "\\debug\\_A_dbg_Wind_Imsc", "_", argv[7], ".pcm");
	fp_dbg_Wind_Imsc = fopen(path_name, "wb");  path_name[0] = "\n";
	sprintf(path_name, "%s%s%s%s%s", argv[8], "\\debug\\_A_dbg_MBDRC", "_", argv[7], ".txt");
	fp_dbg_MBDRC = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s%s%s%s", argv[8], "\\debug\\_A_dbg_Tic", "_", argv[7], ".txt");
	fp_dbg_Tic_txt = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s%s%s%s", argv[8], "\\debug\\_A_dbg_Tic", "_", argv[7], ".pcm");
	fp_dbg_Tic_pcm = fopen(path_name, "wb");  path_name[0] = "\n";

	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF00.txt");
	fp_deg_2micBF[0] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF01.txt");
	fp_deg_2micBF[1] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF02.txt");
	fp_deg_2micBF[2] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF03.txt");
	fp_deg_2micBF[3] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF04.txt");
	fp_deg_2micBF[4] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF05.txt");
	fp_deg_2micBF[5] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF06.txt");
	fp_deg_2micBF[6] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF07.txt");
	fp_deg_2micBF[7] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF08.txt");
	fp_deg_2micBF[8] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF09.txt");
	fp_deg_2micBF[9] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF10.txt");
	fp_deg_2micBF[10] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF11.txt");
	fp_deg_2micBF[11] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF12.txt");
	fp_deg_2micBF[12] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF13.txt");
	fp_deg_2micBF[13] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF14.txt");
	fp_deg_2micBF[14] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF15.txt");
	fp_deg_2micBF[15] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF16.txt");
	fp_deg_2micBF[16] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF17.txt");
	fp_deg_2micBF[17] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF18.txt");
	fp_deg_2micBF[18] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF19.txt");
	fp_deg_2micBF[19] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF20.txt");
	fp_deg_2micBF[20] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF21.txt");
	fp_deg_2micBF[21] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF20.txt");
	fp_deg_2micBF[22] = fopen(path_name, "w");  path_name[0] = "\n";
	sprintf(path_name, "%s%s", argv[8], "\\debug\\_A_dbg_BF21.txt");
	fp_deg_2micBF[23] = fopen(path_name, "w");  path_name[0] = "\n";

	sprintf(path_name, "%s%s%s%s", argv[8], "\\", argv[1], ".pcm");	
	if ((ifp1 = fopen(path_name, "rb")) == (FILE *)NULL)
		exit(fprintf(stderr, "Inear input file error..\n"));

	sprintf(path_name, "%s%s%s%s", argv[8], "\\", argv[2], ".pcm");
	if ((ifp2 = fopen(path_name, "rb")) == (FILE *)NULL)
		exit(fprintf(stderr, "Outer main input file error..\n"));

	sprintf(path_name, "%s%s%s%s", argv[8], "\\", argv[3], ".pcm");
	if ((ifp3 = fopen(path_name, "rb")) == (FILE *)NULL)
		exit(fprintf(stderr, "Outer sub input file error..\n"));

	sprintf(path_name, "%s%s%s%s", argv[8], "\\", argv[4], ".pcm");
	if ((ifp4 = fopen(path_name, "rb")) == (FILE *)NULL)
		exit(fprintf(stderr, "RX input file error..\n"));

	sprintf(path_name, "%s%s%s%s", argv[8], "\\", argv[5], ".pcm");
	if ((ifp5 = fopen(path_name, "rb")) == (FILE *)NULL)
		exit(fprintf(stderr, "ACC input file error..\n"));

	sprintf(path_name, "%s%s%s%s%s%s", argv[8], "\\out\\", argv[6], "_", argv[7], ".pcm");
	if ((ofp1 = fopen(path_name, "wb")) == (FILE *)NULL)
		exit(fprintf(stderr, "output file error..\n"));

#endif
	
	SamsungSolomonVoiceWEngineInit(&SamsungDiamondVoiceEngine_vars_Tx);

	SamsungSolomonVoiceWParamSetting(&DiamondVoice_DV_TX_Config, DIAMONDVOICE_FRAME_TX);

	SamsungSolomonVoiceWEngineConfig(&SamsungDiamondVoiceEngine_vars_Tx, &DiamondVoice_DV_TX_Config);

	FrmCnt_main = 0;
	while ((fread(Speech_buf_Tx_Inner, sizeof(short), DIAMONDVOICE_FRAME_TX, ifp1) == (unsigned)DIAMONDVOICE_FRAME_TX)
		&& (fread(Speech_buf_Tx_Outer_1, sizeof(short), DIAMONDVOICE_FRAME_TX, ifp2) == (unsigned)DIAMONDVOICE_FRAME_TX)
		&& (fread(Speech_buf_Tx_Outer_2, sizeof(short), DIAMONDVOICE_FRAME_TX, ifp3) == (unsigned)DIAMONDVOICE_FRAME_TX)
		&& (fread(Speech_buf_RX_Inner, sizeof(short), DIAMONDVOICE_FRAME_TX, ifp4) == (unsigned)DIAMONDVOICE_FRAME_TX)
		&& (fread(Speech_buf_Tx_Acc, sizeof(short), DIAMONDVOICE_FRAME_TX, ifp5) == (unsigned)DIAMONDVOICE_FRAME_TX))
	{
#if(FLAG_SELECT_C_DSP == 1)
		FrmCnt_main++;
		if (FrmCnt_main == 1611)
			FrmCnt_main = FrmCnt_main;
#endif

		for (i = 0; i < SAMSUNGDIAMONDVOICEWIDEBAND_TX; i++)
			Speech_buf_RX_Outer[i] = Speech_buf_RX_Inner[i];

#if(FLAG_SELECT_C_DSP == 1)
		SamsungSolomonVoiceWEngineExe(&SamsungDiamondVoiceEngine_vars_Tx, &DiamondVoice_DV_TX_Config, 
			Speech_buf_Tx_Inner, Speech_buf_Tx_Outer_1, Speech_buf_Tx_Outer_2, Speech_buf_RX_Inner, Speech_buf_RX_Outer, Speech_buf_Tx_Acc, Output_buf_TX,
			Output_buf_Inner_NB, Output_buf_Inner_WB, Output_buf_Outer);

		ams_flag = SamsungSolomonVoiceWGetAMSStatus(&SamsungDiamondVoiceEngine_vars_Tx);
#else
		SamsungSolomonVoiceWEngineExe(&SamsungDiamondVoiceEngine_vars_Tx, &DiamondVoice_DV_TX_Config,
			Speech_buf_Tx_Inner, Speech_buf_Tx_Outer_1, Speech_buf_Tx_Outer_2, Speech_buf_RX_Inner, Speech_buf_RX_Outer, Speech_buf_Tx_Acc, Output_buf_TX);
#endif
		
		fwrite(Output_buf_TX, sizeof(short), DIAMONDVOICE_FRAME_TX, ofp1);

		printf("\r%ld, AMS : %d", FrmCnt_main, ams_flag);

	}
	printf("\n\n\n");

	fclose(ifp1);
	fclose(ifp2);
	fclose(ifp3);
	fclose(ifp4);
	fclose(ifp5);

	fclose(ofp1);

#if(FLAG_SELECT_C_DSP == 1)
	fclose(fp_Wfnlms_new);
	fclose(fp_debug_ns_para);
	fclose(fp_debug_ns_vec1);
	fclose(fp_debug_ns_vec2);
	fclose(fp_debug_aecoutpwr);
	fclose(fp_debug_ns_vec3);
	fclose(fp_debug_ns_vec4);
	fclose(fp_debug_ns_vec5);
	fclose(fp_WnlmsFilterCoeff);
	fclose(fp_npvss_nlms);

	fclose(fp_debug_res_regression);

	fclose(fp_debug_Pwr_RX_AECIN_dB_C);
	fclose(fp_debug_ADF_C);
	fclose(fp_debug_AEC_in_inner);
	fclose(fp_debug_AEC_in_outer1);
	fclose(fp_debug_AEC_in_outer2);
	fclose(fp_debug_AEC_out_inner);
	fclose(fp_debug_AEC_out_outer1);
	fclose(fp_debug_AEC_out_outer2);
	//fclose(fp_debug_FNLMSin_acc);
	fclose(fp_debug_FNLMSin_inner);
	fclose(fp_debug_FNLMSin_outer);
	//fclose(fp_debug_FNLMSout_acc);
	fclose(fp_debug_FNLMSout_inner);
	fclose(fp_debug_FNLMSout_outr);
	fclose(fp_debug_RESout_inner);
	fclose(fp_debug_RESout_outer);
	fclose(fp_debug_NSout_acc);
	fclose(fp_debug_NSout_inner);
	fclose(fp_debug_NSout_outer);

	fclose(fp_debug_BFfbf_outer);
	fclose(fp_debug_BFbm_outer);
	fclose(fp_debug_BFgsc_outer);

	fclose(fp_debug_acc_txt);
	fclose(fp_debug_acc_E_low);
	fclose(fp_debug_acc_E_hig);
	fclose(fp_debug_acc_E_rat);
	fclose(fp_debug_acc_ticflag);
	fclose(fp_debug_acc__zcr);
	fclose(fp_debug_NS);
	fclose(fp_debug_dump);

	fclose(fp_f0contour);
	fclose(fp_inoutVAD);

	fclose(fp_f0_based_preNS_para);

	 //solomonvoice_sub_module_point_tmp
	fclose(fp_fx_SolomonVoice_ringbacktone_detection);

	fclose(fp_dbg_Wind);
	fclose(fp_dbg_Wind_Imsc);
	fclose(fp_dbg_Mixing);
	fclose(fp_dbg_Unfit);
	fclose(fp_dbg_Unfitpcm);
	fclose(fp_dbg_NoiseState);
	fclose(fp_dbg_AMSState);
	fclose(fp_dbg_ACCState);
	fclose(fp_dbg_MixingState);
	fclose(fp_dbg_Mixingdbg0);
	fclose(fp_dbg_Mixingdbg1);
	fclose(fp_dbg_Mixingdbg2);
	fclose(fp_dbg_Mixingdbg3);
	fclose(fp_dbg_MBDRC);
	fclose(fp_dbg_Tic_txt);
	fclose(fp_dbg_Tic_pcm);
	fclose(fp_fft_out_inner);
	fclose(fp_fft_out_outer);

	fclose(fp_inner8kout);

	for (i = 0; i < N_fp_2micBF_debuffiles; i++)
	{
		fclose(fp_deg_2micBF[i]);
	}

#endif

	return 0;
}

