
#ifndef ___ESTIMATIONTF_HPP___
#define ___ESTIMATIONTF_HPP___

#include "hark-lib/matrix.h"
#include "hark-lib/tf.h"

//using namespace std;
//using namespace HARK;

namespace hark
{
class EstimationTransferFunction
{
public:
    EstimationTransferFunction(int sampling_rate, int fft_length, bool is_debug,  
                               string dir_export, bool is_export, int history_frames, int history_period);
    virtual ~EstimationTransferFunction();

    bool getBasefromFile(const string &file_name, int &num_frq, int &num_mic, int &num_src);
    bool getBaseinDirectory(const string &dir_name, int &num_frq, int &num_mic, int &num_src);

    void initHistoryData();

    bool exportIntermData(const string &dir_name, int i_row);
    bool exportHistoryData(const string &dir_name, int i_row);
    bool exportTransferFunction(const string &name, bool isDir);

    void copyKeepTF();

    void estimateTransferFunction(int count, BF::Matrix &x, std::vector<BF::SourceLocation> sources);

    void copyInitTFdatabase();	// (add 2020.10)
    void resetTFdatabase();		// (add 2020.10)

    void outputTF(const bool &isSendAll,
                  RCPtr<TransferFunction> &tfData, 
                  vector<BF::SourceLocation> location); // (add 2020.10)

private:
    void initIntermData();

    BF::Matrix _RelaTF(BF::Matrix X);
    void _getIntermediate(int tfId, float &id, float &x, float &y, float &z, float &frames, 
                          Matrix<std::complex<float> > &myu,
                          Matrix<std::complex<float> > &sig);
    void _setIntermediate(int tfId, float frames,
                          Matrix<std::complex<float> > myu,
                          Matrix<std::complex<float> > sig);

    int SamplingRate;
    bool IsDebug;
    std::string DirExport;
    bool IsExport;
    int HistoryFrames;
    int HistoryPeriod;
    int numFFT;
    int numFreq;
    int numMic;
    int numSrc;

    BF::TransformFunctionDatabase TransFuncDatabase;
    BF::FMatrix IntermData;
    BF::FMatrix HistoryData;

    int idxHist;

    vector<BF::Matrix> keepTFdata;

    BF::TransformFunctionDatabase *initTransFuncDatabase = NULL; // (add 2020.10)
};
}

#endif //___ESTIMATIONTF_HPP___
