mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-20 19:21:57 +00:00
Make LoadDataFile return an espeak_ng_STATUS code.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user