/*
   HARK Library
   Copyright (C) 2021 Honda Research Institute Japan Inc.
 */

#if !defined(_HARKLIB_NODE_SYNTHESIZE_H_INCLUDED_)
#define _HARKLIB_NODE_SYNTHESIZE_H_INCLUDED_ 1

#include "hark-lib/hark-lib.h"
#include "hark-lib/node.h"

#include "hark-lib/matrix.h"

#include "hark-lib/extlib/fft.hpp"

namespace hark
{
namespace node
{
    class Synthesize: public NodeDef
    {
    public:
        Synthesize();
        virtual void reset();
        virtual bool operator () (size_t count, InputDataBundle &input, OutputDataBundle &output);

    private:
        virtual void initialize(InputDataBundle &input);
        void SynthesizeFrameMatrix(int count, InputDataBundle &input);
        void SynthesizeFrameMap(int count, InputDataBundle &input);
        
    private:
        int _length;
        int _advance;
        int _overlap_frame;
        int _sampling_rate;
        int _window_type;
        int _min_freq;
        int _max_freq;

        int _min_freq_ind;
        int _max_freq_ind;

        rfft<float> _rfft1;
        std::deque<std::map<int, data> > _wave_buffer_map;
        std::deque<Matrix<float> > _wave_buffer_matrix;
        size_t _wave_buffer_offset;
        std::vector<float> _window;
        std::vector<float> _wave;
        std::map<int, std::vector<float> > _last_frame;
        Matrix<float> _last_frame_matrix;
        bool _enable_synthesis;
        bool _enable_sw_save;
        float _wn_factor;
        float _output_gain;
    };
}
}

#endif /* #if !defined(_HARKLIB_NODE_SYNTHESIZE_H_INCLUDED_) */

/* end of file */
