#pragma once

#include <queue>
namespace speaker{
namespace openJtalk{
	
	///
	///OpenJtalkをラップしたクラス
	///ディレクトリの扱いの簡易化とオブジェクトをデストラクタで自動破棄されるようにしたもの
	///
	class COpenJtalkCore:public ISpeaker{

	private:
		typedef std::deque<CString> SynthesisQueue;
		OpenJTalk openJtalk_internal;		//内部オブジェクト
		bool manageFlag;					//管理フラグ
		CComAutoCriticalSection synthesisQueueCS;
		SynthesisQueue synthesisQueue;
		HANDLE synthesisEventObject;
		HANDLE endEventObject;
	protected:
		///
		///コンストラクタ
		///
		COpenJtalkCore();

		///
		///デストラクタ
		///
		virtual ~COpenJtalkCore();

	

	protected:
		///
		///初期化関数
		///
		void Initialize( HTS_Boolean use_lpf, int sampling_rate,
                          int fperiod, double alpha, int stage, double beta, int audio_buff_size,
                          double uv_threshold, HTS_Boolean use_log_gain, double gv_weight_mgc,
                          double gv_weight_lf0, double gv_weight_lpf);


		///
		///音声ファイル読み込み
		///
		void Load( const TChar_P in_voiceDataDir,const TChar_P in_dictinalyDataDir, Char_P fn_ms_dur, Char_P fn_ts_dur,
                    Char_P fn_ms_mgc, Char_P fn_ts_mgc, Char_P *fn_ws_mgc, int num_ws_mgc,
                    Char_P fn_ms_lf0, Char_P fn_ts_lf0, Char_P *fn_ws_lf0, int num_ws_lf0,
                    Char_P fn_ms_lpf, Char_P fn_ts_lpf, Char_P *fn_ws_lpf, int num_ws_lpf,
                    Char_P fn_ms_gvm, Char_P fn_ts_gvm, Char_P fn_ms_gvl, Char_P fn_ts_gvl,
                    Char_P fn_ms_gvf, Char_P fn_ts_gvf, Char_P fn_gv_switch);
		
	public:

		///
		///音声合成
		///
		void Synthesis( const TChar_P txt, FILE * wavfp, FILE * logfp);


		///
		///音声合成インターフェース実装
		///
		void Synthesis(const TChar_P txt);


		///
		///非同期読み上げインターフェース実装
		///
		void SynthesisAsync(const TChar_P txt);

		///
		///オブジェクトのクリア
		///
		void Clear();


	private:
		///
		///非同期読み上げ用のスレッド関数
		///
		static void  SynthesisThreadFunction(void *userData);
	};
	

}
}