
#include "Define_config.h"
//#include "SamsungSolomonVoiceW_Int.h"
//#include "SamsungSolomonVoiceW_Table.h"
//#include "SamsungSolomonVoiceW_basic_op.h"

#if(FLAG_SELECT_C_DSP == 1)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#endif




#define Q_check 18

void SolomonVoiceWPreNSInit(PRENSStatus* PRENS_buf, SamsungSolomonVoiceWTxPRENSParam* PreNS_param, COMMONBUF* common_buf, CHANNEL channel);
void SolomonVoiceWNSInit(NSStatus* NS_buf, SamsungSolomonVoiceWTxNSParam* NS_param, COMMONBUF* common_buf, CHANNEL channel);
void SolomonVoiceW_RES_ParamConfig(SamsungSolomonVoiceWTxRESParam* RES_param, RESStatus *RES_buf, SamsungSolomonVoiceWTxRESParam* param, CHANNEL channel);
void SolomonVoiceWRESInit(RESStatus *RES_buf, SamsungSolomonVoiceWTxRESParam* RES_param, COMMONBUF* common_buf, CHANNEL channel);
#if 0//#ifdef __EXE_ANC__
void SolomonVoiceWANCInit(ANCStatus* ANC_buf, SamsungSolomonVoiceWTxANCParam* ANC_param, COMMONBUF* common_buf, CHANNEL channel);
#endif
void fn_fDRC(AECStatus* AEC_buf, RESStatus* RES_buf, SamsungSolomonVoiceWTxNSParam* NS_param, short* data_buffer, short FFT_HALFLEN, short BLK_NORM, CHANNEL channel);
void fx_SolomonVoice_Npsd_ini_calculation(int *outSNR, int *outSNRtmp, short *PH1, int *EE, short Nband, short betaA, short betaB);
void fx_SolomonVoice_WienerQ31_to_GainQ15(short *G, int *Wiener, short powerIndex, short Nband);
int fx_SolomonVoice_invSNR_calculation(int *SNR, short OneOverNband, short Nband);
void fx_SolomonVoice_FNLMS_filter_update(short *W, short *Wvar, int *DD, int *RR, short NHalfFFT);
void fx_SolomonVoice_EchoPSD_estimation(int *EchoPSD, int *EchoPower, int b_new_dc, int b_old_dc, int b_new_ic, int b_old_ic, short blk_norm_rx, short minPSD, short Q, short Nband);
void fx_SolomonVoice_noisefloor_smoothing(short *Nfloor, int*NfloorTMP, short Nband);
void fx_SolomonVoice_global_SNR_averaging(int *SNRglobal, int SNRmtx[][4], short Nband);
void fx_SolomonVoice_aprioriSNR_recursiveAVG(int *SNRavg, int *SNRtmp, short Nband4k, short Nband8k);
void fx_SolomonVoice_tx_Silence_mode_detection(FRAMEStatus* FRAME_buf, AECStatus* AEC_buf, RESStatus* RES_buf, NSStatus* NS_buf, SamsungSolomonVoiceWTxNSParam* NS_param);
int fx_SolomonVoice_iniSNR_smoothing(int *SNRsmoothout, int *SNRin, short OneOverNband, short forget, short Nband);
void fx_SolomonVoice_noisefloor_cal(int *Nfloor, int *SNR, short y1, short y2, short OneOverX1X2Q8, int Lx1, short BandStart, short BandEnd);
void fx_SolomonVoice_Npsd_2nd_estimation(int *Npsd, int *EE, short *PH1, short MinNpsd, short NORM, short Q, short Nband, short BetaMin);
int fx_SolomonVoice_recursiveAVG_ls(int OldVal, int NewVal, short beOld, short beNew, short blk_norm, short Q);
short fx_SolomonVoice_EchoPSD_gain_cal(short g, short g_res, short flag_rx, short flag_st, short xecc, short xecc_thd, short g_highxecc, short g_lowxecc);
void fx_SolomonVoice_aprioriSNR_freqSmoothing(int *SNRsmooth, int *SNRin, short Nband);
void fx_SolomonVoice_SNR_to_PH1_lookuptable(short *PH1, int *SNR, short FixXi[][3], short FixXiindex, short SPPtable_flag, short increase_flag, short SNRcompensation, short Nband);
void fx_32bit_Band_Forced_DownScaling(int *BandNoisePSD, short bit_shift, short Nband);
void fx_16bit_Band_Forced_DownScaling(short *BandNoisePSD, short bit_shift, short Nband);
void fx_SolomonVoice_FNLMS_error_cal(int *EE, int *DD, int *DD2, int *RR, int *RRstep, short *W, short *W2, short NHalfFFT);
void fx_SolomonVoice_2nd_PH1_estimation(short *PH1, int *EE, int *Npsd, short Xi, short SPPtable_flag, short NORM, short Nband);
void fx_SolomonVoice_recursive_avg_SS_highcomplexity(short *avg, short *in, short forgetNew, short forgetOld, short Nand);
void fx_SolomonVoice_prevent_stagnation_PH1(short *ph1, short *ph1_avg, short Nband);
#ifndef KHW_OPTI_20191216
void fx_SolomonVoice_prevent_stagnation_PH1_1mic(short *ph1, short *ph1_avg, short Nband);
#endif
void fx_SolomonVoice_DD_SNRprio_estimation(int *SNRprio, int *SNRprioCopy, int *SNRpost, int *SNRpostPrev, short *G, short b_old, short b_new, int SNRmin, int SNRmax, short Nband);
void fx_SolomonVoice_Npsd_2nd_estimation_1mic(int *Npsd, int *EE, short *PH1, short MinNpsd, short NORM, short Q, short Nband);
void fx_SolomonVoice_Npsd_Silence_estimation(int *NpsdSilence, int *EE, short FlagSilence, int b_old, int b_new, short blk_norm, short Q, short Nband);
void fx_SolomonVoice_FFTbin_gain_applying(short *OutBin, short *GainBin, short NHalfFFT);
int fx_SolomonVoice_recursiveAVG_ll(int OldVal, int NewVal, int beOld, int beNew, short BLK_NORM, short Q);
void fx_SolomonVoice_WienerQ31_to_GainQ15_Gmin(short *G, int *Wiener, short powerIndex, short Nband, short Gmin);
void fx_SolomonVoice_initial_SNR_estimation(int *SNRout, int *EE, int *NN, int*DD, short DDgain, short Qsnr, short Nband);
int fx_SolomonVoice_Wiener_gainvector_Q31(int *Gwiener, int *SNRprio, short Nband, short OneOverNband);
void fx_SolomonVoice_postSNR_estimation(int* outSNR, int *EEq30, int *Npsd, short Norm, short gainNpsd, short Nband);
void fx_SolomonVoice_forgetfactor_cal_Cepstral_smoothing(short *Beta_ceps_smoothing, short *Beta_ceps, short Flag_loud, short forget);
void fx_SolomonVoice_EchoPower_estimation(int *EchoPSD, short *EchoBandGain, short EchoGain, short Nband);
void fx_SolomonVoice_postSNR_cal_with_limitation_Q15(int *SNRpost, int *EE, int *NN, int SNRmin, int SNRmax, short Nband);
int fx_SolomonVoice_FNLMS_coef_cal(int ErrbyIn, int PwrIn, short PwrInMin, short step_fnlms);
void fx_SolomonVoice_Gain_band_to_bin(short *Gbin, short *Gband, short CHindex[][2], short MinGband, short Nband);
//void fn_FrmVAD(DVTX_ECNS_Cfg_t* DVTX_ECNS_vars);
//int fn_Adaptive_NC(DVTX_ECNS_Cfg_t* DVTX_ECNS_vars, short flag_inner, short flag_outer);
//int FN_f0_based_pre_Noise_suppression(DVTX_ECNS_Cfg_t* DVTX_ECNS_vars, short F0flag);
void fx_SolomonVoice_FNLMS_filter(short* data_buffer, RESStatus* RES_buf, AECStatus* AEC_buf, NSStatus* NS_buf, short FrmDT, short DIVID_BY_SHIFT_NUM_BIN, short FFT_HALFLEN, short FFT_LEN, short Flag_Tx_Clipping, CHANNEL channel, short NBBTmode);
void fx_SolomonVoice_RES(COMMONBUF* common_buf, AECStatus* AEC_buf, RESStatus* RES_buf, NSStatus* NS_buf, SamsungSolomonVoiceWTxAECParam* AEC_param, SamsungSolomonVoiceWTxFRAMEParam* Frame_param, SamsungSolomonVoiceWTxRESParam* RES_param, SamsungSolomonVoiceWTxNSParam* NS_param,
	short *data_buffer, short DIVID_BY_MULT_NUM_CH, short BLK_NORM, short BLK_NORM_rx, short CHAN_HIGH, short NUM_CHAN, short FFT_HALFLEN, CHANNEL channel);
void fx_SolomonVoice_NS(DVTX_ECNS_Cfg_t* DVTX_ECNS_vars, FRAMEStatus* FRAME_buf, AECStatus* AEC_buf, RESStatus* RES_buf, NSStatus* NS_buf, MixingStatus* Mix_buf,
	SamsungSolomonVoiceWTxFRAMEParam* Frame_param, SamsungSolomonVoiceWTxNSParam* NS_param,
	short *data_buffer, short DIVID_BY_MULT_NUM_CH, short BLK_NORM, short CHAN_HIGH, short NUM_CHAN, short FFT_HALFLEN, CHANNEL channel, short NBBTmode, VADACCStatus *VADACC_buf, short BLK_NORM_Acc);
int FN_SOLOMONVOICEW_TX_RES_NS_NBBT(DVTX_ECNS_Cfg_t* DVTX_ECNS_vars, CHANNEL channel);
int FN_SOLOMONVOICEW_TX_RES_NS(DVTX_ECNS_Cfg_t* DVTX_ECNS_vars, CHANNEL channel);
void SolomonVoiceW_ANC_ParamConfig(SamsungSolomonVoiceWTxANCParam* ANC_param, SamsungSolomonVoiceWTxANCParam* param);
void SolomonVoiceW_PreNS_ParamConfig(SamsungSolomonVoiceWTxPRENSParam* PreNS_param, SamsungSolomonVoiceWTxPRENSParam* param);
void SolomonVoiceW_NS_ParamConfig(SamsungSolomonVoiceWTxNSParam* NS_param, SamsungSolomonVoiceWTxNSParam* param);
