/* Copyright (c) 2000-2003                             */
/*   Yamashita Lab., Ritsumeikan University            */
/*   Takao Kobayashi, Takashi Masuko, Masatsune Tamura */
/*   Tokyo Institute of Technology                     */
/*   Keiichi Tokuda, Takayoshi Yoshimura, Heiga Zen    */
/*   Nagoya Institute of Technology                    */
/*   All rights reserved                               */

#ifndef _SYNTHESIS_H_
#define _SYNTHESIS_H_

typedef enum {NON,SILB,SILE,PAU} SILENCE;
typedef enum {NO,YES} BOOLEAN_WIN;

/* 音素 */

typedef struct _phoneme {
	char *phoneme;
	double time;
	double ctime;	/* 直前までの累積時間。時間長修正の後で設定 */
	struct _phoneme *next;
	struct _phoneme *prev;
	struct _mora *parent;
	int sid;	/* speaker ID */
	double alpha;	/* warping parameter */
} PHONEME;

#ifndef WIN32
PHONEME *phhead;
PHONEME *phtail;
#endif
#ifdef WIN32
extern PHONEME *phhead;
extern PHONEME *phtail;
#endif

/* モーラ */

typedef struct _mora {
	char *yomi;     /* カナ表記 */
	int position;
	int acdist;
	BOOLEAN_WIN chouonka;
	BOOLEAN_WIN devoiced;
	SILENCE silence;
	PHONEME *phead;
	PHONEME *ptail;
	struct _mora *next;
	struct _mora *prev;
	struct _morph *parent;
} MORA;

#ifndef WIN32
MORA *mrhead;
MORA *mrtail;
#endif
#ifdef WIN32
extern MORA *mrhead;
extern MORA *mrtail;
#endif

typedef struct _accent{
	char prepos; /* 先行品詞情報: V, A, N, *(all), -(None) */
	int form;   /* アクセント結合様式 */
	int ctype;  /* 結合アクセント価 */
	int ctype2;  /* 結合アクセント価 (付属語で、先行語が有核、無核によって
	                結合アクセント値が変わる場合 (F6とF9) がある。) */
} ACCENT;

#define MAX_ACCENT      4

/* 形態素 */
typedef struct _morph {
	char *kanji;    /* 漢字表記 */
	char *pron;     /* カナ表記：茶筌の「読み」出力 */
	int nmora;
	int nbyte;		/* 漢字表記での文字数 */
	int hinshiID;
	int katsuyogataID;
	int katsuyokeiID;
	int accentType;
	ACCENT accent[MAX_ACCENT];
	int n_accent;
	struct _morph *submorph;
	SILENCE silence;
	MORA *mrhead;
	MORA *mrtail;
	struct _morph *next;
	struct _morph *prev;
	struct _aphrase *parent;
} MORPH;

#ifndef WIN32
MORPH *mphead;
MORPH *mptail;
#endif
#ifdef WIN32
extern MORPH *mphead;
extern MORPH *mptail;
#endif

/* アクセント句 */
typedef struct _aphrase {
	int nmora;
	int accentType;
	int position;		/* 呼気段落中でのアクセント句の位置 */
	SILENCE silence;
	BOOLEAN_WIN interrogative;
	MORPH *mphead;
	MORPH *mptail;
	struct _aphrase *next;
	struct _aphrase *prev;
	struct _breath *parent;
} APHRASE;

#ifndef WIN32
APHRASE *ahead;
APHRASE *atail;
#endif
#ifdef WIN32
extern APHRASE *ahead;
extern APHRASE *atail;
#endif

/* 呼気段落 */
typedef struct _breath {
	int nmora;
	int position;   /* 文中での呼気段落の位置。ポーズも一つの呼気段落に
	                   なるが数にはいれず、その position は -1 */
	SILENCE silence;
	APHRASE *ahead;
	APHRASE *atail;
	struct _breath *next;
	struct _breath *prev;
	struct _sentence *parent;
} BREATH;

#ifndef WIN32
BREATH *bhead;
BREATH *btail;
#endif
#ifdef WIN32
extern BREATH *bhead;
extern BREATH *btail;
#endif

/* 文章 */
typedef struct _sentence {
	int nmora;
	int nbreath;	/* ポーズ以外の呼気段落の数 */
	BREATH *bhead;
	BREATH *btail;
	struct _sentence *prev;
	struct _sentence *next;
} SENTENCE;

#ifndef WIN32
SENTENCE *shead;
SENTENCE *stail;
SENTENCE *sentence;
#endif
#ifdef WIN32
extern SENTENCE *shead;
extern SENTENCE *stail;
extern SENTENCE *sentence;
#endif

typedef struct _wave
{
  short *data;
  int rate;
} WAVE;

#ifndef WIN32
WAVE wave;
#endif
#ifdef WIN32
extern WAVE wave;
#endif

typedef struct _param
{
  double *data;
  int rate;
} PARAM;

#ifndef WIN32
PARAM power;
PARAM f0;
PARAM alpha;
#endif
#ifdef WIN32
extern PARAM power;
extern PARAM f0;
extern PARAM alpha;
#endif

#define MAX_UTTER 9192
extern char chasen_input[MAX_UTTER];

#endif //_SYNTHESIS_H_
