/************************************
        SV_NS.h
/************************************/

#include "SV_common_include.h"

typedef struct{
	int FirstFrame;

	int NpsdBias;
	int frmVAD;
	int noiseLevel;
	int flag_Tx_silence;

	int band_low;

	INT64 Npsdgsc[HFFTLEN];
	INT64 NpsdBM[HFFTLEN];
	double G_H1_res[NUM_CHAN];
	int REchoPSDch[NUM_CHAN];

} SV_NS_T;

// Processing
static void fn_Get_xiopt_fromTable(int *xiopt, int idxFixXi, int invSNR, int n);
static int fn_2nd_Npsd_estimation(int *Npsd, int Q_Npsd, int *EE, int Q_EE, int *ph1_GbyL, int *snr, int frmVAD, int noiseLevel);
static int fn_1st_Npsd_estimation(int *Npsd, int Q_Npsd, int *spp_smooth, int *EE, int Q_EE, int *Npsd_BM, int Q_Npsd_BM, int *snr, int frmVAD, int noiseLevel, int band_low);
static int fn_NoiseSpectrumEstimation(int *Npsd, int Q_Npsd, int *EE, int Q_EE, int *NN, int Q_NN, int *ph1_GbyL, int *REchoPSDch, SV_NS_T* stNS);
static void fn_SPP(int *spp, int *EE, int Q_EE, int *Npsd, int Q_Npsd, int NpsdBias, int alpha_time, int alpha_freq, int n);
static int fn_Npsd_gain(int gain_Npsd, int FLAG_tx_noisefree);
static void fn_decisiondirected_prioriSNR(int *prioSNR, int *EE, int Q_EE, int *Npsd, int Q_Npsd, int gain_Npsd, int *Gmmse);
static void fn_prioriSNR_smoothing(int *prioSNR_sm, int *prioSNR_double, int n);
static void fn_noise_floor(int *band_noise_floor, int *snr, int frmVAD, int flag_Tx_silence, int n);
static void fn_NS_gain_smoothing(int *G_final, int *Gmmse, int *ph1_GbyL, int *spp, int *band_noise_floor, int n);
static void fn_NSoutBin(ComplexInt *Xtx, int *G_NS_final, int *G_H1_res);

extern void SV_NS_Exe(ComplexInt* inout_sp,int nsp,SV_NS_T* p_struct);
//inout_sp - input and output spectrum
//p_struct - pointer to the module internal structure

// Setting parameters
extern void SV_NS_SetPar(INT64* Npsdgsc, double* G_H1_res, double* G_REchoPSDch, SV_NS_T* p_struct);

// flagTxsilence - ???
// noiselevel - ???
// p_struct - pointer to the module structure (to be initialized)

// Init
extern void SV_NS_Init(int Fs, SV_NS_T* p_struct);
// Fs - {8000, 16000}
// p_struct - pointer to the module structure (to be initialized)
