Browse Source

Move more code into espeak_ng_InitializeOutput.

master
Reece H. Dunn 9 years ago
parent
commit
9fe525fb13
2 changed files with 25 additions and 25 deletions
  1. 3
    2
      src/include/espeak-ng/espeak_ng.h
  2. 22
    23
      src/libespeak-ng/speak_lib.c

+ 3
- 2
src/include/espeak-ng/espeak_ng.h View File

ESPEAK_NG_API espeak_ng_STATUS ESPEAK_NG_API espeak_ng_STATUS
espeak_ng_Initialize(void); 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_API espeak_ng_STATUS
espeak_ng_CompileDictionary(const char *dsource, espeak_ng_CompileDictionary(const char *dsource,

+ 22
- 23
src/libespeak-ng/speak_lib.c View File

#endif #endif


#pragma GCC visibility push(default) #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_mode = output_mode;
my_audio = NULL; my_audio = NULL;
option_waveout = 0; option_waveout = 0;
WavegenInitSound(); 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) int GetFileLength(const char *filename)
switch (output_type) switch (output_type)
{ {
case AUDIO_OUTPUT_PLAYBACK: case AUDIO_OUTPUT_PLAYBACK:
espeak_ng_InitializeOutput(ENOUTPUT_MODE_SPEAK_AUDIO);
espeak_ng_InitializeOutput(ENOUTPUT_MODE_SPEAK_AUDIO, buf_length);
break; break;
case AUDIO_OUTPUT_RETRIEVAL: case AUDIO_OUTPUT_RETRIEVAL:
espeak_ng_InitializeOutput(0);
espeak_ng_InitializeOutput(0, buf_length);
break; break;
case AUDIO_OUTPUT_SYNCHRONOUS: case AUDIO_OUTPUT_SYNCHRONOUS:
espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS);
espeak_ng_InitializeOutput(ENOUTPUT_MODE_SYNCHRONOUS, buf_length);
break; break;
case AUDIO_OUTPUT_SYNCH_PLAYBACK: 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; 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_phonemes = 0;
option_phoneme_events = (options & (espeakINITIALIZE_PHONEME_EVENTS | espeakINITIALIZE_PHONEME_IPA)); option_phoneme_events = (options & (espeakINITIALIZE_PHONEME_EVENTS | espeakINITIALIZE_PHONEME_IPA));



Loading…
Cancel
Save