diff --git a/src/libespeak-ng/mbrowrap.c b/src/libespeak-ng/mbrowrap.c index fe12d5b7..84a11312 100644 --- a/src/libespeak-ng/mbrowrap.c +++ b/src/libespeak-ng/mbrowrap.c @@ -520,7 +520,7 @@ static ssize_t receive_from_mbrola(void *buffer, size_t bufsize) * API functions. */ -int init_MBR(const char *voice_path) +int init_mbrola(char *voice_path) { int error, result; unsigned char wavhdr[45]; @@ -563,7 +563,7 @@ int init_MBR(const char *voice_path) return 0; } -void close_MBR(void) +void close_mbrola(void) { stop_mbrola(); free_pending_data(); @@ -572,15 +572,15 @@ void close_MBR(void) mbr_volume = 1.0; } -int reset_MBR() +void reset_mbrola(void) { int result, success = 1; char dummybuf[4096]; if (mbr_state == MBR_IDLE) - return 1; + return; if (!mbr_pid) - return 0; + return; if (kill(mbr_pid, SIGUSR1) == -1) success = 0; free_pending_data(); @@ -594,10 +594,9 @@ int reset_MBR() success = 0; if (!mbrola_has_errors() && success) mbr_state = MBR_IDLE; - return success; } -int read_MBR(void *buffer, int nb_samples) +int read_mbrola(short *buffer, int nb_samples) { int result = receive_from_mbrola(buffer, nb_samples * 2); if (result > 0) @@ -605,23 +604,23 @@ int read_MBR(void *buffer, int nb_samples) return result; } -int write_MBR(const char *data) +int write_mbrola(char *data) { mbr_state = MBR_NEWDATA; return send_to_mbrola(data); } -int flush_MBR(void) +int flush_mbrola(void) { return send_to_mbrola("\n#\n") == 3; } -int getFreq_MBR(void) +int getFreq_mbrola(void) { return mbr_samplerate; } -void setVolumeRatio_MBR(float value) +void setVolumeRatio_mbrola(float value) { if (value == mbr_volume) return; @@ -636,7 +635,7 @@ void setVolumeRatio_MBR(float value) init_MBR(mbr_voice_path); } -int lastErrorStr_MBR(char *buffer, int bufsize) +int lastErrorStr_mbrola(char *buffer, int bufsize) { int result; if (mbr_pid) @@ -645,9 +644,28 @@ int lastErrorStr_MBR(char *buffer, int bufsize) return result >= bufsize ? (bufsize - 1) : result; } -void resetError_MBR(void) +void setNoError_mbrola(int no_error) { - mbr_errorbuf[0] = 0; + (void)no_error; // unused } -#endif \ No newline at end of file +BOOL load_MBR(void) +{ + init_MBR = init_mbrola; + close_MBR = close_mbrola; + reset_MBR = reset_mbrola; + read_MBR = read_mbrola; + write_MBR = write_mbrola; + flush_MBR = flush_mbrola; + getFreq_MBR = getFreq_mbrola; + setVolumeRatio_MBR = setVolumeRatio_mbrola; + lastErrorStr_MBR = lastErrorStr_mbrola; + setNoError_MBR = setNoError_mbrola; + return 1; +} + +void unload_MBR(void) +{ +} + +#endif diff --git a/src/libespeak-ng/mbrowrap.h b/src/libespeak-ng/mbrowrap.h index d492f5a6..f612a01b 100644 --- a/src/libespeak-ng/mbrowrap.h +++ b/src/libespeak-ng/mbrowrap.h @@ -34,23 +34,13 @@ typedef int (WINAPI *PROCIC)(char *); typedef int (WINAPI *PROCISI)(short *, int); typedef char * (WINAPI *PROCVCI)(char *, int); -PROCIC init_MBR; -PROCIC write_MBR; -PROCIV flush_MBR; -PROCISI read_MBR; -PROCVV close_MBR; -PROCVV reset_MBR; -PROCIV lastError_MBR; -PROCVCI lastErrorStr_MBR; -PROCVI setNoError_MBR; -PROCIV getFreq_MBR; -PROCVF setVolumeRatio_MBR; - -BOOL load_MBR(); -void unload_MBR(); - #else +#define WINAPI +typedef int BOOL; + +#endif + /* * Initialize mbrola. The 'voice_path' argument must contain the * path and file name to the mbrola voice database to be used. Returned @@ -59,22 +49,20 @@ void unload_MBR(); * error reason. If this is successful, then close_MBR() must be called * before init_MBR() can be called again. */ -int init_MBR(const char *voice_path); +int (WINAPI *init_MBR)(char *voice_path); /* * Stop mbrola and release any resources. It is necessary to call * this after a successful call to init_MBR() before init_MBR() can be * called again. */ -void close_MBR(void); +void (WINAPI *close_MBR)(void); /* * Stop any ongoing processing and flush all buffers. After this call - * any synthesis request will start afresh. A non-zero value is returned - * on success, or 0 on failure. If not successful, lastErrorStr_MBR() will - * provide the error reason. + * any synthesis request will start afresh. */ -int reset_MBR(); +void (WINAPI *reset_MBR)(void); /* * Return at most 'nb_samples' audio samples into 'buffer'. The returned @@ -82,14 +70,14 @@ int reset_MBR(); * If not successful, lastErrorStr_MBR() will provide the error reason. * Samples are always 16-bit little endian. */ -int read_MBR(void *buffer, int nb_samples); +int (WINAPI *read_MBR)(short *buffer, int nb_samples); /* * Write a NULL terminated string of phoneme in the input buffer. * Return the number of chars actually written, or -1 on error. * If not successful, lastErrorStr_MBR() will provide the error reason. */ -int write_MBR(const char *data); +int (WINAPI *write_MBR)(char *data); /* * Send a flush command to the mbrola input stream. @@ -97,17 +85,17 @@ int write_MBR(const char *data); * or 0 on failure. If not successful, lastErrorStr_MBR() will provide * the error reason. */ -int flush_MBR(void); +int (WINAPI *flush_MBR)(void); /* * Return the audio sample frequency of the used voice database. */ -int getFreq_MBR(void); +int (WINAPI *getFreq_MBR)(void); /* * Overall volume. */ -void setVolumeRatio_MBR(float value); +void (WINAPI *setVolumeRatio_MBR)(float value); /* * Copy into 'buffer' at most 'bufsize' bytes from the latest error @@ -117,22 +105,15 @@ void setVolumeRatio_MBR(float value); * calls to lastErrorStr_MBR() will return the same message unless it * is explicitly cleared with resetError_MBR(). */ -int lastErrorStr_MBR(char *buffer, int bufsize); +int (WINAPI *lastErrorStr_MBR)(char *buffer, int bufsize); /* - * Clear any pending error message. + * Tolerance to missing diphones. */ -void resetError_MBR(void); +void (WINAPI *setNoError_MBR)(int no_error); -/* - * Tolerance to missing diphones (always active so this is ignored) - */ -static inline void setNoError_MBR(int no_error) -{ - (void)no_error; // unused -} - -#endif +BOOL load_MBR(void); +void unload_MBR(void); #ifdef __cplusplus } diff --git a/src/libespeak-ng/synth_mbrola.c b/src/libespeak-ng/synth_mbrola.c index 5a687727..d26145ad 100644 --- a/src/libespeak-ng/synth_mbrola.c +++ b/src/libespeak-ng/synth_mbrola.c @@ -73,6 +73,9 @@ espeak_ng_STATUS LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, return ENS_OK; } + if (!load_MBR()) + return ENS_MBROLA_NOT_FOUND; + sprintf(path, "%s/mbrola/%s", path_home, mbrola_voice); #ifdef PLATFORM_POSIX // if not found, then also look in @@ -89,12 +92,6 @@ espeak_ng_STATUS LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, } close_MBR(); #endif -#ifdef PLATFORM_WINDOWS - if (load_MBR() == FALSE) { // load mbrola.dll - fprintf(stderr, "Can't load mbrola.dll\n"); - return ENS_MBROLA_NOT_FOUND; - } -#endif if (init_MBR(path) != 0) // initialise the required mbrola voice return ENS_MBROLA_VOICE_NOT_FOUND;