From 619fc6424d093b9a684eda77a9916361af15b563 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 3 Jan 2016 14:53:11 +0000 Subject: [PATCH] Make LoadDataFile return an espeak_ng_STATUS code. --- src/include/espeak-ng/espeak_ng.h | 2 +- src/libespeak-ng/compiledata.c | 43 +++++++++++++++++-------------- src/libespeak-ng/spect.c | 2 +- src/libespeak-ng/speech.c | 4 +-- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/include/espeak-ng/espeak_ng.h b/src/include/espeak-ng/espeak_ng.h index 6a95f176..a4e22f50 100644 --- a/src/include/espeak-ng/espeak_ng.h +++ b/src/include/espeak-ng/espeak_ng.h @@ -48,7 +48,7 @@ typedef enum { ENS_MBROLA_VOICE_NOT_FOUND = 0x100008FF, ENS_EVENT_BUFFER_FULL = 0x100009FF, ENS_NOT_SUPPORTED = 0x10000AFF, - ENS_UNSUPPORTED_SPECT_FORMAT = 0x10000BFF, + ENS_UNSUPPORTED_PHON_FORMAT = 0x10000BFF, ENS_NO_SPECT_FRAMES = 0x10000CFF, } espeak_ng_STATUS; diff --git a/src/libespeak-ng/compiledata.c b/src/libespeak-ng/compiledata.c index 8126a631..4bd10d97 100644 --- a/src/libespeak-ng/compiledata.c +++ b/src/libespeak-ng/compiledata.c @@ -1483,7 +1483,7 @@ static int LoadEnvelope2(FILE *f, const char *fname) return displ; } -static int LoadDataFile(const char *path, int control) +static espeak_ng_STATUS LoadDataFile(const char *path, int control, int *addr) { // load spectrum sequence or sample data from a file. // return index into spect or sample data area. bit 23=1 if a sample @@ -1491,15 +1491,16 @@ static int LoadDataFile(const char *path, int control) FILE *f; int id; int hash; - int addr = 0; int type_code = ' '; REF_HASH_TAB *p, *p2; char buf[sizeof(path_home)+150]; if (strcmp(path, "NULL") == 0) - return 0; - if (strcmp(path, "DFT") == 0) - return 1; + return ENS_OK; + if (strcmp(path, "DFT") == 0) { + *addr = 1; + return ENS_OK; + } count_references++; @@ -1508,7 +1509,7 @@ static int LoadDataFile(const char *path, int control) while (p != NULL) { if (strcmp(path, p->string) == 0) { duplicate_references++; - addr = p->value; // already loaded this data + *addr = p->value; // already loaded this data break; } p = (REF_HASH_TAB *)p->link; @@ -1521,7 +1522,7 @@ static int LoadDataFile(const char *path, int control) sprintf(buf, "%s/../phsource/%s.wav", path_home, path); if ((f = fopen(buf, "rb")) == NULL) { error("Can't read file: %s", path); - return 0; + return errno; } } @@ -1529,32 +1530,34 @@ static int LoadDataFile(const char *path, int control) rewind(f); if (id == 0x43455053) { - addr = LoadSpect(path, control); + *addr = LoadSpect(path, control); type_code = 'S'; } else if (id == 0x46464952) { - addr = LoadWavefile(f, path); + *addr = LoadWavefile(f, path); type_code = 'W'; } else if (id == 0x43544950) { - addr = LoadEnvelope(f, path); + *addr = LoadEnvelope(f, path); type_code = 'E'; } else if (id == 0x45564E45) { - addr = LoadEnvelope2(f, path); + *addr = LoadEnvelope2(f, path); type_code = 'E'; } else { error("File not SPEC or RIFF: %s", path); - addr = -1; + *addr = -1; + fclose(f); + return ENS_UNSUPPORTED_PHON_FORMAT; } fclose(f); - if (addr > 0) - fprintf(f_phcontents, "%c 0x%.5x %s\n", type_code, addr & 0x7fffff, path); + if (*addr > 0) + fprintf(f_phcontents, "%c 0x%.5x %s\n", type_code, *addr & 0x7fffff, path); } // add this item to the hash table - if (addr > 0) { + if (*addr > 0) { p = ref_hash_tab[hash]; p2 = (REF_HASH_TAB *)malloc(sizeof(REF_HASH_TAB)+strlen(path)+1); - p2->value = addr; + p2->value = *addr; p2->ph_mnemonic = phoneme_out->mnemonic; // phoneme which uses this file p2->ph_table = n_phoneme_tabs-1; strcpy(p2->string, path); @@ -1562,7 +1565,7 @@ static int LoadDataFile(const char *path, int control) ref_hash_tab[hash] = p2; } - return addr; + return ENS_OK; } static void CompileToneSpec(void) @@ -1577,12 +1580,12 @@ static void CompileToneSpec(void) if (item_terminator == ',') { NextItemBrackets(tSTRING, 3); - pitch_env = LoadDataFile(item_string, 0); + LoadDataFile(item_string, 0, &pitch_env); } if (item_terminator == ',') { NextItemBrackets(tSTRING, 1); - amp_env = LoadDataFile(item_string, 0); + LoadDataFile(item_string, 0, &_env); } if (pitch1 < pitch2) { @@ -1633,7 +1636,7 @@ static void CompileSound(int keyword, int isvowel) } } } - addr = LoadDataFile(path, isvowel); + LoadDataFile(path, isvowel, &addr); addr = addr / 4; // addr is words not bytes *prog_out++ = sound_instns[keyword-kFMT] + ((value & 0xff) << 4) + ((addr >> 16) & 0xf); diff --git a/src/libespeak-ng/spect.c b/src/libespeak-ng/spect.c index 17005717..c478984a 100644 --- a/src/libespeak-ng/spect.c +++ b/src/libespeak-ng/spect.c @@ -299,7 +299,7 @@ espeak_ng_STATUS LoadSpectSeq(SpectSeq *spect, const char *filename) else { fprintf(stderr, "Unsupported spectral file format.\n"); fclose(stream); - return ENS_UNSUPPORTED_SPECT_FORMAT; + return ENS_UNSUPPORTED_PHON_FORMAT; } fread(&name_len, sizeof(uint32_t), 1, stream); diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index bbfe1428..8bcc51e6 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -404,8 +404,8 @@ ESPEAK_NG_API void espeak_ng_GetStatusCodeMessage(espeak_ng_STATUS status, char case ENS_NOT_SUPPORTED: strncpy0(buffer, "The requested functionality has not been built into espeak-ng.", length); break; - case ENS_UNSUPPORTED_SPECT_FORMAT: - strncpy0(buffer, "The spectral file is not in a supported format.", length); + case ENS_UNSUPPORTED_PHON_FORMAT: + strncpy0(buffer, "The phoneme file is not in a supported format.", length); break; case ENS_NO_SPECT_FRAMES: strncpy0(buffer, "The spectral file does not contain any frame data.", length);