From 9fe525fb13667df4368eaf8f566669e636a480b3 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Fri, 1 Jan 2016 16:40:16 +0000 Subject: [PATCH] Move more code into espeak_ng_InitializeOutput. --- src/include/espeak-ng/espeak_ng.h | 5 ++-- src/libespeak-ng/speak_lib.c | 45 +++++++++++++++---------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/include/espeak-ng/espeak_ng.h b/src/include/espeak-ng/espeak_ng.h index 810ce3c2..2ba9564e 100644 --- a/src/include/espeak-ng/espeak_ng.h +++ b/src/include/espeak-ng/espeak_ng.h @@ -55,8 +55,9 @@ espeak_ng_InitializePath(const char *path); ESPEAK_NG_API espeak_ng_STATUS espeak_ng_Initialize(void); -ESPEAK_NG_API void -espeak_ng_InitializeOutput(espeak_ng_OUTPUT_MODE output_mode); +ESPEAK_NG_API espeak_ng_STATUS +espeak_ng_InitializeOutput(espeak_ng_OUTPUT_MODE output_mode, + int buffer_length); ESPEAK_NG_API espeak_ng_STATUS espeak_ng_CompileDictionary(const char *dsource, diff --git a/src/libespeak-ng/speak_lib.c b/src/libespeak-ng/speak_lib.c index 72d98b89..87140016 100644 --- a/src/libespeak-ng/speak_lib.c +++ b/src/libespeak-ng/speak_lib.c @@ -203,7 +203,7 @@ int sync_espeak_terminated_msg(uint32_t unique_identifier, void *user_data) #endif #pragma GCC visibility push(default) -ESPEAK_NG_API void espeak_ng_InitializeOutput(espeak_ng_OUTPUT_MODE output_mode) +ESPEAK_NG_API espeak_ng_STATUS espeak_ng_InitializeOutput(espeak_ng_OUTPUT_MODE output_mode, int buffer_length) { my_mode = output_mode; my_audio = NULL; @@ -214,6 +214,23 @@ ESPEAK_NG_API void espeak_ng_InitializeOutput(espeak_ng_OUTPUT_MODE output_mode) option_waveout = 0; WavegenInitSound(); } + + // buflength is in mS, allocate 2 bytes per sample + if ((buffer_length == 0) || (output_mode & ENOUTPUT_MODE_SPEAK_AUDIO)) + buffer_length = 200; + + outbuf_size = (buffer_length * samplerate)/500; + outbuf = (unsigned char *)realloc(outbuf, outbuf_size); + if ((out_start = outbuf) == NULL) + return ENE_OUT_OF_MEMORY; + + // allocate space for event list. Allow 200 events per second. + // Add a constant to allow for very small buf_length + n_event_list = (buffer_length*200)/1000 + 20; + if ((event_list = (espeak_EVENT *)realloc(event_list, sizeof(espeak_EVENT) * n_event_list)) == NULL) + return ENE_OUT_OF_MEMORY; + + return ENS_OK; } int GetFileLength(const char *filename) @@ -618,37 +635,19 @@ ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output_type, int buf_length switch (output_type) { case AUDIO_OUTPUT_PLAYBACK: - espeak_ng_InitializeOutput(ENOUTPUT_MODE_SPEAK_AUDIO); + espeak_ng_InitializeOutput(ENOUTPUT_MODE_SPEAK_AUDIO, buf_length); break; case AUDIO_OUTPUT_RETRIEVAL: - espeak_ng_InitializeOutput(0); + espeak_ng_InitializeOutput(0, buf_length); break; case AUDIO_OUTPUT_SYNCHRONOUS: - espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS); + espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS, buf_length); break; case AUDIO_OUTPUT_SYNCH_PLAYBACK: - espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS | ENOUTPUT_MODE_SPEAK_AUDIO); + espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS | ENOUTPUT_MODE_SPEAK_AUDIO, buf_length); break; } - if (f_logespeak) - fprintf(f_logespeak, "INIT mode %d options 0x%x\n", output_type, options); - - // buflength is in mS, allocate 2 bytes per sample - if ((buf_length == 0) || (output_type == AUDIO_OUTPUT_PLAYBACK) || (output_type == AUDIO_OUTPUT_SYNCH_PLAYBACK)) - buf_length = 200; - - outbuf_size = (buf_length * samplerate)/500; - outbuf = (unsigned char *)realloc(outbuf, outbuf_size); - if ((out_start = outbuf) == NULL) - return EE_INTERNAL_ERROR; - - // allocate space for event list. Allow 200 events per second. - // Add a constant to allow for very small buf_length - n_event_list = (buf_length*200)/1000 + 20; - if ((event_list = (espeak_EVENT *)realloc(event_list, sizeof(espeak_EVENT) * n_event_list)) == NULL) - return EE_INTERNAL_ERROR; - option_phonemes = 0; option_phoneme_events = (options & (espeakINITIALIZE_PHONEME_EVENTS | espeakINITIALIZE_PHONEME_IPA));