Browse Source

Make the MBROLA API consistent between the Windows and POSIX versions.

master
Reece H. Dunn 9 years ago
parent
commit
b9fcb84bad
3 changed files with 55 additions and 59 deletions
  1. 33
    15
      src/libespeak-ng/mbrowrap.c
  2. 19
    38
      src/libespeak-ng/mbrowrap.h
  3. 3
    6
      src/libespeak-ng/synth_mbrola.c

+ 33
- 15
src/libespeak-ng/mbrowrap.c View File

* API functions. * API functions.
*/ */


int init_MBR(const char *voice_path)
int init_mbrola(char *voice_path)
{ {
int error, result; int error, result;
unsigned char wavhdr[45]; unsigned char wavhdr[45];
return 0; return 0;
} }


void close_MBR(void)
void close_mbrola(void)
{ {
stop_mbrola(); stop_mbrola();
free_pending_data(); free_pending_data();
mbr_volume = 1.0; mbr_volume = 1.0;
} }


int reset_MBR()
void reset_mbrola(void)
{ {
int result, success = 1; int result, success = 1;
char dummybuf[4096]; char dummybuf[4096];


if (mbr_state == MBR_IDLE) if (mbr_state == MBR_IDLE)
return 1;
return;
if (!mbr_pid) if (!mbr_pid)
return 0;
return;
if (kill(mbr_pid, SIGUSR1) == -1) if (kill(mbr_pid, SIGUSR1) == -1)
success = 0; success = 0;
free_pending_data(); free_pending_data();
success = 0; success = 0;
if (!mbrola_has_errors() && success) if (!mbrola_has_errors() && success)
mbr_state = MBR_IDLE; 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); int result = receive_from_mbrola(buffer, nb_samples * 2);
if (result > 0) if (result > 0)
return result; return result;
} }


int write_MBR(const char *data)
int write_mbrola(char *data)
{ {
mbr_state = MBR_NEWDATA; mbr_state = MBR_NEWDATA;
return send_to_mbrola(data); return send_to_mbrola(data);
} }


int flush_MBR(void)
int flush_mbrola(void)
{ {
return send_to_mbrola("\n#\n") == 3; return send_to_mbrola("\n#\n") == 3;
} }


int getFreq_MBR(void)
int getFreq_mbrola(void)
{ {
return mbr_samplerate; return mbr_samplerate;
} }


void setVolumeRatio_MBR(float value)
void setVolumeRatio_mbrola(float value)
{ {
if (value == mbr_volume) if (value == mbr_volume)
return; return;
init_MBR(mbr_voice_path); init_MBR(mbr_voice_path);
} }


int lastErrorStr_MBR(char *buffer, int bufsize)
int lastErrorStr_mbrola(char *buffer, int bufsize)
{ {
int result; int result;
if (mbr_pid) if (mbr_pid)
return result >= bufsize ? (bufsize - 1) : result; return result >= bufsize ? (bufsize - 1) : result;
} }


void resetError_MBR(void)
void setNoError_mbrola(int no_error)
{
(void)no_error; // unused
}

BOOL load_MBR(void)
{ {
mbr_errorbuf[0] = 0;
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;
} }


#endif
void unload_MBR(void)
{
}

#endif

+ 19
- 38
src/libespeak-ng/mbrowrap.h View File

typedef int (WINAPI *PROCISI)(short *, int); typedef int (WINAPI *PROCISI)(short *, int);
typedef char * (WINAPI *PROCVCI)(char *, 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 #else


#define WINAPI
typedef int BOOL;

#endif

/* /*
* Initialize mbrola. The 'voice_path' argument must contain the * Initialize mbrola. The 'voice_path' argument must contain the
* path and file name to the mbrola voice database to be used. Returned * path and file name to the mbrola voice database to be used. Returned
* error reason. If this is successful, then close_MBR() must be called * error reason. If this is successful, then close_MBR() must be called
* before init_MBR() can be called again. * 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 * Stop mbrola and release any resources. It is necessary to call
* this after a successful call to init_MBR() before init_MBR() can be * this after a successful call to init_MBR() before init_MBR() can be
* called again. * called again.
*/ */
void close_MBR(void);
void (WINAPI *close_MBR)(void);


/* /*
* Stop any ongoing processing and flush all buffers. After this call * 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 * Return at most 'nb_samples' audio samples into 'buffer'. The returned
* If not successful, lastErrorStr_MBR() will provide the error reason. * If not successful, lastErrorStr_MBR() will provide the error reason.
* Samples are always 16-bit little endian. * 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. * Write a NULL terminated string of phoneme in the input buffer.
* Return the number of chars actually written, or -1 on error. * Return the number of chars actually written, or -1 on error.
* If not successful, lastErrorStr_MBR() will provide the error reason. * 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. * Send a flush command to the mbrola input stream.
* or 0 on failure. If not successful, lastErrorStr_MBR() will provide * or 0 on failure. If not successful, lastErrorStr_MBR() will provide
* the error reason. * the error reason.
*/ */
int flush_MBR(void);
int (WINAPI *flush_MBR)(void);


/* /*
* Return the audio sample frequency of the used voice database. * Return the audio sample frequency of the used voice database.
*/ */
int getFreq_MBR(void);
int (WINAPI *getFreq_MBR)(void);


/* /*
* Overall volume. * Overall volume.
*/ */
void setVolumeRatio_MBR(float value);
void (WINAPI *setVolumeRatio_MBR)(float value);


/* /*
* Copy into 'buffer' at most 'bufsize' bytes from the latest error * Copy into 'buffer' at most 'bufsize' bytes from the latest error
* calls to lastErrorStr_MBR() will return the same message unless it * calls to lastErrorStr_MBR() will return the same message unless it
* is explicitly cleared with resetError_MBR(). * is explicitly cleared with resetError_MBR().
*/ */
int lastErrorStr_MBR(char *buffer, int bufsize);

/*
* Clear any pending error message.
*/
void resetError_MBR(void);
int (WINAPI *lastErrorStr_MBR)(char *buffer, int bufsize);


/* /*
* Tolerance to missing diphones (always active so this is ignored)
* Tolerance to missing diphones.
*/ */
static inline void setNoError_MBR(int no_error)
{
(void)no_error; // unused
}
void (WINAPI *setNoError_MBR)(int no_error);


#endif
BOOL load_MBR(void);
void unload_MBR(void);


#ifdef __cplusplus #ifdef __cplusplus
} }

+ 3
- 6
src/libespeak-ng/synth_mbrola.c View File

return ENS_OK; return ENS_OK;
} }


if (!load_MBR())
return ENS_MBROLA_NOT_FOUND;

sprintf(path, "%s/mbrola/%s", path_home, mbrola_voice); sprintf(path, "%s/mbrola/%s", path_home, mbrola_voice);
#ifdef PLATFORM_POSIX #ifdef PLATFORM_POSIX
// if not found, then also look in // if not found, then also look in
} }
close_MBR(); close_MBR();
#endif #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 if (init_MBR(path) != 0) // initialise the required mbrola voice
return ENS_MBROLA_VOICE_NOT_FOUND; return ENS_MBROLA_VOICE_NOT_FOUND;

Loading…
Cancel
Save