/* HTS_Stream_load_pdf_and_tree: load PDFs and trees */ static void HTS_Stream_load_pdf_and_tree(HTS_Stream * stream, FILE ** pdf_fp, FILE ** tree_fp, HTS_Boolean msd_flag, int interpolation_size) { int i; /* initialize */ stream->msd_flag = msd_flag; stream->interpolation_size = interpolation_size; stream->model = (HTS_Model *) HTS_calloc(interpolation_size, sizeof(HTS_Model)); /* load */ for (i = 0; i < stream->interpolation_size; i++) { if (!pdf_fp[i]) HTS_error(1, "HTS_Stream_load_pdf_and_tree: File for duration PDFs is not specified.\n"); if (!tree_fp[i]) HTS_error(1, "HTS_Stream_load_pdf_and_tree: File for duration trees is not specified.\n"); HTS_Model_initialize(&stream->model[i]); HTS_Model_load_tree(&stream->model[i], tree_fp[i]); HTS_Model_load_pdf(&stream->model[i], pdf_fp[i], stream->model[i].ntree, stream->msd_flag); } /* check */ for (i = 1; i < stream->interpolation_size; i++) if (stream->model[0].vector_length != stream->model[i].vector_length) HTS_error(1, "HTS_Stream_load_pdf_and_tree: Vector sizes of state output vectors are different in between given modelsets.\n"); /* set */ stream->vector_length = stream->model[0].vector_length; }
/* HTS_Audio_open: open audio device */ static void HTS_Audio_open(HTS_Audio * audio, int sampling_rate, int max_buff_size) { if (audio->sampling_rate == sampling_rate && audio->max_buff_size == max_buff_size) return; HTS_Audio_close(audio); audio->sampling_rate = sampling_rate; audio->max_buff_size = max_buff_size; if (audio->max_buff_size <= 0) return; audio->err = Pa_Initialize(); if (audio->err != paNoError) HTS_error(0, "hts_engine: Failed to initialize your output audio device to play waveform.\n"); audio->parameters.device = Pa_GetDefaultOutputDevice(); audio->parameters.channelCount = 1; audio->parameters.sampleFormat = paInt16; audio->parameters.suggestedLatency = Pa_GetDeviceInfo(audio->parameters.device)->defaultLowOutputLatency; audio->parameters.hostApiSpecificStreamInfo = NULL; audio->err = Pa_OpenStream(&audio->stream, NULL, &audio->parameters, sampling_rate, max_buff_size, paClipOff, NULL, NULL); if (audio->err != paNoError) HTS_error(0, "hts_engine: Failed to open your output audio device to play waveform.\n"); audio->err = Pa_StartStream(audio->stream); if (audio->err != paNoError) HTS_error(0, "hts_engine: Failed to start your output audio device to play waveform.\n"); audio->buff = (short *) HTS_calloc(max_buff_size, sizeof(short)); audio->buff_size = 0; }
/* HTS_ModelSet_load_parameter: load model */ void HTS_ModelSet_load_parameter(HTS_ModelSet * ms, FILE ** pdf_fp, FILE ** tree_fp, FILE ** win_fp, int stream_index, HTS_Boolean msd_flag, int window_size, int interpolation_size) { int i; /* check */ if (pdf_fp == NULL) HTS_error(1, "HTS_ModelSet_load_parameter: File for pdfs is not specified.\n"); if (tree_fp == NULL) HTS_error(1, "HTS_ModelSet_load_parameter: File for wins is not specified.\n"); if (win_fp == NULL) HTS_error(1, "HTS_ModelSet_load_parameter: File for wins is not specified.\n"); /* initialize */ if (!ms->stream) { ms->stream = (HTS_Stream *) HTS_calloc(ms->nstream, sizeof(HTS_Stream)); for (i = 0; i < ms->nstream; i++) HTS_Stream_initialize(&ms->stream[i]); } /* load */ HTS_Stream_load_pdf_and_tree(&ms->stream[stream_index], pdf_fp, tree_fp, msd_flag, interpolation_size); HTS_Stream_load_dynamic_window(&ms->stream[stream_index], win_fp, window_size); }
/* HTS_Audio_close: close audio device */ static void HTS_Audio_close(HTS_Audio * audio) { MMRESULT error; if (audio->max_buff_size <= 0) return; /* stop audio */ error = waveOutReset(audio->hwaveout); if (error != MMSYSERR_NOERROR) HTS_error(0, "hts_engine: Cannot stop and reset your output audio device.\n"); /* unprepare */ error = waveOutUnprepareHeader(audio->hwaveout, &(audio->buff_1), sizeof(WAVEHDR)); if (error != MMSYSERR_NOERROR) HTS_error(0, "hts_engine: Cannot cleanup the audio datablocks to play waveform.\n"); error = waveOutUnprepareHeader(audio->hwaveout, &(audio->buff_2), sizeof(WAVEHDR)); if (error != MMSYSERR_NOERROR) HTS_error(0, "hts_engine: Cannot cleanup the audio datablocks to play waveform.\n"); /* close */ error = waveOutClose(audio->hwaveout); if (error != MMSYSERR_NOERROR) HTS_error(0, "hts_engine: Failed to close your output audio device.\n"); HTS_free(audio->buff_1.lpData); HTS_free(audio->buff_2.lpData); HTS_free(audio->buff); }
/* HTS_ModelSet_load_duration: load duration model and number of state */ HTS_Boolean HTS_ModelSet_load_duration(HTS_ModelSet * ms, HTS_File ** pdf_fp, HTS_File ** tree_fp, int interpolation_size) { /* check */ if (ms == NULL) { return FALSE; } if (interpolation_size <= 0) { HTS_ModelSet_clear(ms); return FALSE; } if (pdf_fp == NULL) { HTS_error(1, "HTS_ModelSet_load_duration: File for duration PDFs is not specified.\n"); HTS_ModelSet_clear(ms); return FALSE; } if (tree_fp == NULL) { HTS_error(1, "HTS_ModelSet_load_duration: File for duration trees is not specified.\n"); HTS_ModelSet_clear(ms); return FALSE; } if (HTS_Stream_load_pdf_and_tree(&ms->duration, pdf_fp, tree_fp, interpolation_size) == FALSE) { HTS_ModelSet_clear(ms); return FALSE; } ms->nstate = ms->duration.vector_length; return TRUE; }
/* HTS_Audio_close: close audio device */ void HTS_Audio_close(HTS_Audio * as) { MMRESULT error; if (as->buff_size != 0) HTS_Audio_write_buffer(as); while (as->now_buff_1 == TRUE) Sleep(AUDIO_WAIT_BUFF_MS); while (as->now_buff_2 == TRUE) Sleep(AUDIO_WAIT_BUFF_MS); /* stop audio */ error = waveOutReset(as->hwaveout); if (error != MMSYSERR_NOERROR) HTS_error(0, "hts_engine: Cannot stop and reset your output audio device.\n"); /* unprepare */ error = waveOutUnprepareHeader(as->hwaveout, &(as->buff_1), sizeof(WAVEHDR)); if (error != MMSYSERR_NOERROR) HTS_error(0, "hts_engine: Cannot cleanup the audio datablocks to play waveform.\n"); error = waveOutUnprepareHeader(as->hwaveout, &(as->buff_2), sizeof(WAVEHDR)); if (error != MMSYSERR_NOERROR) HTS_error(0, "hts_engine: Cannot cleanup the audio datablocks to play waveform.\n"); /* close */ error = waveOutClose(as->hwaveout); if (error != MMSYSERR_NOERROR) HTS_error(0, "hts_engine: Failed to close your output audio device.\n"); HTS_free(as->buff_1.lpData); HTS_free(as->buff_2.lpData); HTS_free(as->buff); }
/* HTS_Audio_open: open audio device */ static void HTS_Audio_open(HTS_Audio * audio, int sampling_rate, int max_buff_size) { MMRESULT error; if (audio->sampling_rate == sampling_rate && audio->max_buff_size == max_buff_size) return; HTS_Audio_close(audio); audio->sampling_rate = sampling_rate; audio->max_buff_size = max_buff_size; if (audio->max_buff_size <= 0) return; /* queue */ audio->which_buff = 1; audio->now_buff_1 = FALSE; audio->now_buff_2 = FALSE; audio->buff = (short *) HTS_calloc(max_buff_size, sizeof(short)); /* format */ audio->waveformatex.wFormatTag = WAVE_FORMAT_PCM; audio->waveformatex.nChannels = AUDIO_CHANNEL; audio->waveformatex.nSamplesPerSec = sampling_rate; audio->waveformatex.wBitsPerSample = sizeof(short) * 8; audio->waveformatex.nBlockAlign = AUDIO_CHANNEL * audio->waveformatex.wBitsPerSample / 8; audio->waveformatex.nAvgBytesPerSec = sampling_rate * audio->waveformatex.nBlockAlign; /* open */ error = waveOutOpen(&audio->hwaveout, WAVE_MAPPER, &audio->waveformatex, (DWORD) HTS_Audio_callback_function, (DWORD) audio, CALLBACK_FUNCTION); if (error != MMSYSERR_NOERROR) HTS_error(0, "hts_engine: Failed to open your output audio device to play waveform.\n"); /* prepare */ audio->buff_1.lpData = (LPSTR) HTS_calloc(max_buff_size, sizeof(short)); audio->buff_1.dwBufferLength = max_buff_size * sizeof(short); audio->buff_1.dwFlags = WHDR_BEGINLOOP | WHDR_ENDLOOP; audio->buff_1.dwLoops = 1; audio->buff_1.lpNext = 0; audio->buff_1.reserved = 0; error = waveOutPrepareHeader(audio->hwaveout, &(audio->buff_1), sizeof(WAVEHDR)); if (error != MMSYSERR_NOERROR) HTS_error(0, "hts_engine: Cannot initialize audio datablocks to play waveform.\n"); audio->buff_2.lpData = (LPSTR) HTS_calloc(max_buff_size, sizeof(short)); audio->buff_2.dwBufferLength = max_buff_size * sizeof(short); audio->buff_2.dwFlags = WHDR_BEGINLOOP | WHDR_ENDLOOP; audio->buff_2.dwLoops = 1; audio->buff_2.lpNext = 0; audio->buff_2.reserved = 0; error = waveOutPrepareHeader(audio->hwaveout, &(audio->buff_2), sizeof(WAVEHDR)); if (error != MMSYSERR_NOERROR) HTS_error(0, "hts_engine: Cannot initialize audio datablocks to play waveform.\n"); }
/* HTS_Model_load_tree: load trees */ static void HTS_Model_load_tree(HTS_Model * model, FILE * fp) { char buff[HTS_MAXBUFLEN]; HTS_Question *question, *last_question; HTS_Tree *tree, *last_tree; int state; /* check */ if (fp == NULL) HTS_error(1, "HTS_Model_load_tree: File for trees is not specified.\n"); model->ntree = 0; last_question = NULL; last_tree = NULL; while (!feof(fp)) { HTS_get_pattern_token(fp, buff); /* parse questions */ if (strcmp(buff, "QS") == 0) { question = (HTS_Question *) HTS_calloc(1, sizeof(HTS_Question)); HTS_Question_load(question, fp); if (model->question) last_question->next = question; else model->question = question; question->next = NULL; last_question = question; } /* parse trees */ state = HTS_get_state_num(buff); if (state != 0) { tree = (HTS_Tree *) HTS_calloc(1, sizeof(HTS_Tree)); tree->next = NULL; tree->root = NULL; tree->head = NULL; tree->state = state; HTS_Tree_parse_pattern(tree, buff); HTS_Tree_load(tree, fp, model->question); if (model->tree) last_tree->next = tree; else model->tree = tree; tree->next = NULL; last_tree = tree; model->ntree++; } } /* No Tree information in tree file */ if (model->tree == NULL) HTS_error(1, "HTS_Model_load_tree: No trees are loaded.\n"); }
/* HTS_ModelSet_load_duration: load duration model and number of state */ void HTS_ModelSet_load_duration(HTS_ModelSet * ms, FILE ** pdf_fp, FILE ** tree_fp, int interpolation_size) { /* check */ if (pdf_fp == NULL) HTS_error(1, "HTS_ModelSet_load_duration: File for duration PDFs is not specified.\n"); if (tree_fp == NULL) HTS_error(1, "HTS_ModelSet_load_duration: File for duration trees is not specified.\n"); HTS_Stream_load_pdf_and_tree(&ms->duration, pdf_fp, tree_fp, FALSE, interpolation_size); ms->nstate = ms->duration.vector_length; }
/* HTS_Stream_load_pdf: load pdf */ static HTS_Boolean HTS_Stream_load_pdf(HTS_Stream * stream, HTS_File ** fp, int ntree, int interpolation_size) { int i; HTS_Boolean result = TRUE; /* initialize */ stream->interpolation_size = interpolation_size; stream->model = (HTS_Model *) HTS_calloc(interpolation_size, sizeof(HTS_Model)); /* load pdfs */ for (i = 0; i < stream->interpolation_size; i++) { HTS_Model_initialize(&stream->model[i]); if (HTS_Model_load_pdf(&stream->model[i], fp[i], ntree, &stream->msd_flag) == FALSE) result = FALSE; } if (result == FALSE) { HTS_Stream_clear(stream); return FALSE; } /* check */ for (i = 1; i < stream->interpolation_size; i++) { if (stream->model[0].vector_length != stream->model[1].vector_length) { HTS_error(1, "HTS_Stream_load_pdf: # of states are different in between given modelsets.\n"); HTS_Stream_clear(stream); return FALSE; } } /* set */ stream->vector_length = stream->model[0].vector_length; return TRUE; }
/* HTS_ModelSet_get_gv_switch_index: get index of GV switch tree and PDF */ void HTS_ModelSet_get_gv_switch_index(HTS_ModelSet * ms, char *string, int *tree_index, int *pdf_index) { HTS_Tree *tree; HTS_Pattern *pattern; HTS_Boolean find; find = FALSE; (*tree_index) = 2; (*pdf_index) = 1; for (tree = ms->gv_switch.tree; tree; tree = tree->next) { pattern = tree->head; if (!pattern) find = TRUE; for (; pattern; pattern = pattern->next) if (HTS_pattern_match(string, pattern->string)) { find = TRUE; break; } if (find) break; (*tree_index)++; } if (tree == NULL) { HTS_error(1, "HTS_ModelSet_get_gv_switch_index: Cannot find model %s.\n", string); return; } (*pdf_index) = HTS_Tree_search_node(tree, string); }
/* HTS_Audio_write_buffer: send buffer to audio device */ static void HTS_Audio_write_buffer(HTS_Audio * audio) { MMRESULT error; if (audio->which_buff == 1) { while (audio->now_buff_1 == TRUE) Sleep(AUDIO_WAIT_BUFF_MS); audio->now_buff_1 = TRUE; audio->which_buff = 2; memcpy(audio->buff_1.lpData, audio->buff, audio->buff_size * sizeof(short)); audio->buff_1.dwBufferLength = audio->buff_size * sizeof(short); error = waveOutWrite(audio->hwaveout, &(audio->buff_1), sizeof(WAVEHDR)); } else { while (audio->now_buff_2 == TRUE) Sleep(AUDIO_WAIT_BUFF_MS); audio->now_buff_2 = TRUE; audio->which_buff = 1; memcpy(audio->buff_2.lpData, audio->buff, audio->buff_size * sizeof(short)); audio->buff_2.dwBufferLength = audio->buff_size * sizeof(short); error = waveOutWrite(audio->hwaveout, &(audio->buff_2), sizeof(WAVEHDR)); } if (error != MMSYSERR_NOERROR) HTS_error(0, "hts_engine: Cannot send datablocks to your output audio device to play waveform.\n"); }
/* HTS_fread: wrapper for fread */ static size_t HTS_fread(void *buf, size_t size, size_t n, HTS_File * fp) { if (fp == NULL || size == 0 || n == 0) { return 0; } if (fp->type == HTS_FILE) { return fread(buf, size, n, (FILE *) fp->pointer); } else if (fp->type == HTS_DATA) { HTS_Data *d = (HTS_Data *) fp->pointer; size_t i, length = size * n; unsigned char *c = (unsigned char *) buf; for (i = 0; i < length; i++) { if (d->index < d->size) c[i] = d->data[d->index++]; else break; } if (i == 0) return 0; else return i / size; } HTS_error(0, "HTS_fread: Unknown file type.\n"); return 0; }
/* HTS_ModelSet_get_parameter_index: get index of parameter tree and PDF */ void HTS_ModelSet_get_parameter_index(HTS_ModelSet * ms, char *string, int *tree_index, int *pdf_index, int stream_index, int state_index, int interpolation_index) { HTS_Tree *tree; HTS_Pattern *pattern; HTS_Boolean find; find = FALSE; (*tree_index) = 2; (*pdf_index) = 1; for (tree = ms->stream[stream_index].model[interpolation_index].tree; tree; tree = tree->next) { if (tree->state == state_index) { pattern = tree->head; if (!pattern) find = TRUE; for (; pattern; pattern = pattern->next) if (HTS_pattern_match(string, pattern->string)) { find = TRUE; break; } if (find) break; } (*tree_index)++; } if (tree == NULL) HTS_error(1, "HTS_ModelSet_get_parameter_index: Cannot find model %s.\n", string); (*pdf_index) = HTS_Tree_search_node(tree, string); }
/* HTS_ModelSet_load_parameter: load model */ HTS_Boolean HTS_ModelSet_load_parameter(HTS_ModelSet * ms, HTS_File ** pdf_fp, HTS_File ** tree_fp, HTS_File ** win_fp, int stream_index, int window_size, int interpolation_size) { int i; /* check */ if (ms == NULL) { return FALSE; } if (stream_index < 0 || stream_index >= ms->nstream || window_size <= 0 || interpolation_size <= 0) { HTS_ModelSet_clear(ms); return FALSE; } if (pdf_fp == NULL) { HTS_error(1, "HTS_ModelSet_load_parameter: File for pdfs is not specified.\n"); HTS_ModelSet_clear(ms); return FALSE; } if (tree_fp == NULL) { HTS_error(1, "HTS_ModelSet_load_parameter: File for wins is not specified.\n"); HTS_ModelSet_clear(ms); return FALSE; } if (win_fp == NULL) { HTS_error(1, "HTS_ModelSet_load_parameter: File for wins is not specified.\n"); HTS_ModelSet_clear(ms); return FALSE; } /* initialize */ if (!ms->stream) { ms->stream = (HTS_Stream *) HTS_calloc(ms->nstream, sizeof(HTS_Stream)); for (i = 0; i < ms->nstream; i++) HTS_Stream_initialize(&ms->stream[i]); } /* load */ if (HTS_Stream_load_pdf_and_tree(&ms->stream[stream_index], pdf_fp, tree_fp, interpolation_size) == FALSE) { HTS_ModelSet_clear(ms); return FALSE; } if (HTS_Stream_load_dynamic_window(&ms->stream[stream_index], win_fp, window_size) == FALSE) { HTS_ModelSet_clear(ms); return FALSE; } return TRUE; }
/* HTS_Node_find: find node for given number */ static HTS_Node *HTS_Node_find(HTS_Node * node, const int num) { for (; node; node = node->next) if (node->index == num) return node; HTS_error(1, "HTS_Node_find: Cannot find node %d.\n", num); return NULL; /* make compiler happy */ }
/* HTS_get_fp: wrapper for fopen */ FILE *HTS_get_fp(const char *name, const char *opt) { FILE *fp = fopen(name, opt); if (fp == NULL) HTS_error(2, "HTS_get_fp: Cannot open %s.\n", name); return (fp); }
/* HTS_Audio_flush: flush remain data */ void HTS_Audio_flush(HTS_Audio * audio) { if (audio->buff_size > 0) { audio->err = Pa_WriteStream(audio->stream, audio->buff, audio->buff_size); if (audio->err != paNoError && audio->err != paOutputUnderflowed) HTS_error(0, "hts_engine: Cannot send datablocks to your output audio device to play waveform.\n"); audio->buff_size = 0; } }
/* HTS_Stream_load_pdf_and_tree: load PDFs and trees */ static HTS_Boolean HTS_Stream_load_pdf_and_tree(HTS_Stream * stream, HTS_File ** pdf_fp, HTS_File ** tree_fp, int interpolation_size) { int i; HTS_Boolean result = TRUE; /* initialize */ stream->interpolation_size = interpolation_size; stream->model = (HTS_Model *) HTS_calloc(interpolation_size, sizeof(HTS_Model)); /* load */ for (i = 0; i < stream->interpolation_size; i++) { if (!pdf_fp[i]) { HTS_error(1, "HTS_Stream_load_pdf_and_tree: File for duration PDFs is not specified.\n"); HTS_Stream_clear(stream); return FALSE; } if (!tree_fp[i]) { HTS_error(1, "HTS_Stream_load_pdf_and_tree: File for duration trees is not specified.\n"); HTS_Stream_clear(stream); return FALSE; } HTS_Model_initialize(&stream->model[i]); result = HTS_Model_load_tree(&stream->model[i], tree_fp[i]); if (result == FALSE) { HTS_Stream_clear(stream); return FALSE; } result = HTS_Model_load_pdf(&stream->model[i], pdf_fp[i], stream->model[i].ntree, &stream->msd_flag); if (result == FALSE) { HTS_Stream_clear(stream); return FALSE; } } /* check */ for (i = 1; i < stream->interpolation_size; i++) if (stream->model[0].vector_length != stream->model[i].vector_length) { HTS_error(1, "HTS_Stream_load_pdf_and_tree: Vector sizes of state output vectors are different in between given modelsets.\n"); HTS_Stream_clear(stream); return FALSE; } /* set */ stream->vector_length = stream->model[0].vector_length; return TRUE; }
/* HTS_Audio_write: send data to audio device */ void HTS_Audio_write(HTS_Audio * audio, short data) { audio->buff[audio->buff_size++] = data; if (audio->buff_size >= audio->max_buff_size) { audio->err = Pa_WriteStream(audio->stream, audio->buff, audio->max_buff_size); if (audio->err != paNoError && audio->err != paOutputUnderflowed) HTS_error(0, "hts_engine: Cannot send datablocks to your output audio device to play waveform.\n"); audio->buff_size = 0; } }
/* HTS_Question_find_question: find question from question list */ static HTS_Question *HTS_Question_find_question(HTS_Question * question, const char *buff) { for (; question; question = question->next) if (strcmp(buff, question->string) == 0) return question; HTS_error(1, "HTS_Question_find_question: Cannot find question %s.\n", buff); return NULL; /* make compiler happy */ }
/* HTS_fopen: wrapper for fopen */ HTS_File *HTS_fopen(const char *name, const char *opt) { HTS_File *fp = utf8_fopen(name, opt); if (fp == NULL) { HTS_error(1, "HTS_fopen: Cannot open %s.\n", name); return NULL; } return fp; }
/* HTS_feof: wrapper for feof */ int HTS_feof(HTS_File *fp) { if (fp == NULL) { return 1; } else if (fp->type == HTS_FILE) { return feof((FILE *) fp->pointer); } else if (fp->type == HTS_DATA) { HTS_Data *d = (HTS_Data *) fp->pointer; return d->size <= d->index ? 1 : 0; } HTS_error(0, "HTS_feof: Unknown file type.\n"); return 1; }
/* HTS_calloc: wrapper for calloc */ char *HTS_calloc(const size_t num, const size_t size) { #ifdef FESTIVAL char *mem = (char *) safe_wcalloc(num * size); #else char *mem = (char *) calloc(num, size); #endif /* FESTIVAL */ if (mem == NULL) HTS_error(1, "HTS_calloc: Cannot allocate memory.\n"); return mem; }
/* HTS_fgetc: wrapper for fgetc */ int HTS_fgetc(HTS_File *fp) { if (fp == NULL) { return EOF; } else if (fp->type == HTS_FILE) { return fgetc((FILE *) fp->pointer); } else if (fp->type == HTS_DATA) { HTS_Data *d = (HTS_Data *) fp->pointer; if (d->size <= d->index) return EOF; return (int) d->data[d->index++]; } HTS_error(0, "HTS_fgetc: Unknown file type.\n"); return EOF; }
/* HTS_fopen_from_fn: wrapper for fopen */ HTS_File *HTS_fopen_from_fn(const char *name, const char *opt) { HTS_File *fp = (HTS_File *) HTS_calloc(1, sizeof(HTS_File)); fp->type = HTS_FILE; fp->pointer = (void *) fopen(name, opt); if (fp->pointer == NULL) { HTS_error(0, "HTS_fopen: Cannot open %s.\n", name); HTS_free(fp); return NULL; } return fp; }
/* HTS_Audio_close: close audio device */ static void HTS_Audio_close(HTS_Audio * audio) { if (audio->max_buff_size <= 0) return; if (audio->buff_size > 0) { audio->err = Pa_WriteStream(audio->stream, audio->buff, audio->buff_size); if (audio->err != paNoError && audio->err != paOutputUnderflowed) HTS_error(0, "hts_engine: Cannot send datablocks to your output audio device to play waveform.\n"); audio->buff_size = 0; } HTS_free(audio->buff); audio->err = Pa_StopStream(audio->stream); if (audio->err != paNoError) HTS_error(0, "hts_engine: Cannot stop your output audio device.\n"); audio->err = Pa_CloseStream(audio->stream); if (audio->err != paNoError) HTS_error(0, "hts_engine: Failed to close your output audio device.\n"); Pa_Terminate(); }
/* HTS_calloc: wrapper for calloc */ void *HTS_calloc(const size_t num, const size_t size) { size_t n = num * size; #ifdef FESTIVAL void *mem = (void *) safe_wcalloc(n); #else void *mem = (void *) malloc(n); #endif /* FESTIVAL */ memset(mem, 0, n); if (mem == NULL) HTS_error(1, "HTS_calloc: Cannot allocate memory.\n"); return mem; }
/* HTS_ftell: rapper for ftell */ size_t HTS_ftell(HTS_File * fp) { if (fp == NULL) { return 0; } else if (fp->type == HTS_FILE) { fpos_t pos; fgetpos((FILE *) fp->pointer, &pos); #if defined(_WIN32) || defined(__CYGWIN__) || defined(__APPLE__) || defined(__ANDROID__) return (size_t) pos; #else return (size_t) pos.__pos; #endif /* _WIN32 || __CYGWIN__ || __APPLE__ || __ANDROID__ */ } HTS_error(0, "HTS_ftell: Unknown file type.\n"); return 0; }
/* HTS_Label_load_from_strings: load label from strings */ void HTS_Label_load_from_strings(HTS_Label * label, size_t sampling_rate, size_t fperiod, char **lines, size_t num_lines) { char buff[HTS_MAXBUFLEN]; HTS_LabelString *lstring = NULL; size_t i; size_t data_index; double start, end; const double rate = (double) sampling_rate / ((double) fperiod * 1e+7); if (label->head || label->size != 0) { HTS_error(1, "HTS_Label_load_from_fp: label list is not initialized.\n"); return; } /* copy label */ for (i = 0; i < num_lines; i++) { if (!isgraph((int) lines[i][0])) break; label->size++; if (lstring) { lstring->next = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString)); lstring = lstring->next; } else { /* first time */ lstring = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString)); label->head = lstring; } data_index = 0; if (isdigit_string(lines[i])) { /* has frame infomation */ HTS_get_token_from_string(lines[i], &data_index, buff); start = atof(buff); HTS_get_token_from_string(lines[i], &data_index, buff); end = atof(buff); HTS_get_token_from_string(lines[i], &data_index, buff); lstring->name = HTS_strdup(buff); lstring->start = rate * start; lstring->end = rate * end; } else { lstring->start = -1.0; lstring->end = -1.0; lstring->name = HTS_strdup(lines[i]); } lstring->next = NULL; } HTS_Label_check_time(label); }