#include <clip.h>

#ifdef  WIN32
STREAMCALLBACK* g_callback;
void stream_play(int BLKS, STREAMCALLBACK* callback, int param, int fram4) { g_callback = callback; }
void stream_stop() { }
#endif//WIN32

int main(int argc, char* argv[]) {
	static uint32_t DataBuf[999999];
	int16_t wbuff[320];
	FILE* fp;

	if(!argv[1]) { argv[1] = "bgm_001.wav"; }
//	if(!argv[1]) { argv[1] = "bgm_002.wav"; }
//	if(!argv[1]) { argv[1] = "bgm_003.wav"; }
//	if(!argv[1]) { argv[1] = "bgm_004.wav"; }
//	if(!argv[1]) { argv[1] = "bgm_005.wav"; }
//	if(!argv[1]) { argv[1] = "bgm_006.wav"; }
//	if(!argv[1]) { argv[1] = "se_001.wav"; }
//	if(!argv[1]) { argv[1] = "se_002.wav"; }
//	if(!argv[1]) { argv[1] = "se_004.wav"; }

	fp = fopen(argv[1], "rb");
	if(!fp) { DIE(); }
	fread(DataBuf, 1, sizeof DataBuf, fp);
	fclose(fp);

	fp = fopen("out.s16", "wb");
	if(!fp) { DIE(); }

	TrueSpeech_Init(1);
	TrueSpeech_PlayCh(0, DataBuf, 1);
//	TrueSpeech_SetChAtt(0, 6);
	while(TrueSpeech_GetChStat(0)) {
		(*g_callback)(wbuff, 0);
		fwrite(wbuff, 1, sizeof wbuff, fp);
	}

	fclose(fp);

	printf("再生するには、soxを使ってください。\n");
	printf("全体再生する方法: sox -r 16k out.s16 -d\n");
	printf("部分再生する方法: sox -r 16k out.s16 -d trim 40 10\n");

	return 0;
}
