Browse Source

Make LoadDataFile return an espeak_ng_STATUS code.

master
Reece H. Dunn 9 years ago
parent
commit
619fc6424d

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

ENS_MBROLA_VOICE_NOT_FOUND = 0x100008FF, ENS_MBROLA_VOICE_NOT_FOUND = 0x100008FF,
ENS_EVENT_BUFFER_FULL = 0x100009FF, ENS_EVENT_BUFFER_FULL = 0x100009FF,
ENS_NOT_SUPPORTED = 0x10000AFF, ENS_NOT_SUPPORTED = 0x10000AFF,
ENS_UNSUPPORTED_SPECT_FORMAT = 0x10000BFF,
ENS_UNSUPPORTED_PHON_FORMAT = 0x10000BFF,
ENS_NO_SPECT_FRAMES = 0x10000CFF, ENS_NO_SPECT_FRAMES = 0x10000CFF,
} espeak_ng_STATUS; } espeak_ng_STATUS;



+ 23
- 20
src/libespeak-ng/compiledata.c View File

return displ; 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. // load spectrum sequence or sample data from a file.
// return index into spect or sample data area. bit 23=1 if a sample // return index into spect or sample data area. bit 23=1 if a sample
FILE *f; FILE *f;
int id; int id;
int hash; int hash;
int addr = 0;
int type_code = ' '; int type_code = ' ';
REF_HASH_TAB *p, *p2; REF_HASH_TAB *p, *p2;
char buf[sizeof(path_home)+150]; char buf[sizeof(path_home)+150];


if (strcmp(path, "NULL") == 0) 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++; count_references++;


while (p != NULL) { while (p != NULL) {
if (strcmp(path, p->string) == 0) { if (strcmp(path, p->string) == 0) {
duplicate_references++; duplicate_references++;
addr = p->value; // already loaded this data
*addr = p->value; // already loaded this data
break; break;
} }
p = (REF_HASH_TAB *)p->link; p = (REF_HASH_TAB *)p->link;
sprintf(buf, "%s/../phsource/%s.wav", path_home, path); sprintf(buf, "%s/../phsource/%s.wav", path_home, path);
if ((f = fopen(buf, "rb")) == NULL) { if ((f = fopen(buf, "rb")) == NULL) {
error("Can't read file: %s", path); error("Can't read file: %s", path);
return 0;
return errno;
} }
} }


rewind(f); rewind(f);


if (id == 0x43455053) { if (id == 0x43455053) {
addr = LoadSpect(path, control);
*addr = LoadSpect(path, control);
type_code = 'S'; type_code = 'S';
} else if (id == 0x46464952) { } else if (id == 0x46464952) {
addr = LoadWavefile(f, path);
*addr = LoadWavefile(f, path);
type_code = 'W'; type_code = 'W';
} else if (id == 0x43544950) { } else if (id == 0x43544950) {
addr = LoadEnvelope(f, path);
*addr = LoadEnvelope(f, path);
type_code = 'E'; type_code = 'E';
} else if (id == 0x45564E45) { } else if (id == 0x45564E45) {
addr = LoadEnvelope2(f, path);
*addr = LoadEnvelope2(f, path);
type_code = 'E'; type_code = 'E';
} else { } else {
error("File not SPEC or RIFF: %s", path); error("File not SPEC or RIFF: %s", path);
addr = -1;
*addr = -1;
fclose(f);
return ENS_UNSUPPORTED_PHON_FORMAT;
} }
fclose(f); 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 // add this item to the hash table
if (addr > 0) {
if (*addr > 0) {
p = ref_hash_tab[hash]; p = ref_hash_tab[hash];
p2 = (REF_HASH_TAB *)malloc(sizeof(REF_HASH_TAB)+strlen(path)+1); 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_mnemonic = phoneme_out->mnemonic; // phoneme which uses this file
p2->ph_table = n_phoneme_tabs-1; p2->ph_table = n_phoneme_tabs-1;
strcpy(p2->string, path); strcpy(p2->string, path);
ref_hash_tab[hash] = p2; ref_hash_tab[hash] = p2;
} }


return addr;
return ENS_OK;
} }


static void CompileToneSpec(void) static void CompileToneSpec(void)


if (item_terminator == ',') { if (item_terminator == ',') {
NextItemBrackets(tSTRING, 3); NextItemBrackets(tSTRING, 3);
pitch_env = LoadDataFile(item_string, 0);
LoadDataFile(item_string, 0, &pitch_env);
} }


if (item_terminator == ',') { if (item_terminator == ',') {
NextItemBrackets(tSTRING, 1); NextItemBrackets(tSTRING, 1);
amp_env = LoadDataFile(item_string, 0);
LoadDataFile(item_string, 0, &amp_env);
} }


if (pitch1 < pitch2) { if (pitch1 < pitch2) {
} }
} }
} }
addr = LoadDataFile(path, isvowel);
LoadDataFile(path, isvowel, &addr);
addr = addr / 4; // addr is words not bytes addr = addr / 4; // addr is words not bytes


*prog_out++ = sound_instns[keyword-kFMT] + ((value & 0xff) << 4) + ((addr >> 16) & 0xf); *prog_out++ = sound_instns[keyword-kFMT] + ((value & 0xff) << 4) + ((addr >> 16) & 0xf);

+ 1
- 1
src/libespeak-ng/spect.c View File

else { else {
fprintf(stderr, "Unsupported spectral file format.\n"); fprintf(stderr, "Unsupported spectral file format.\n");
fclose(stream); fclose(stream);
return ENS_UNSUPPORTED_SPECT_FORMAT;
return ENS_UNSUPPORTED_PHON_FORMAT;
} }


fread(&name_len, sizeof(uint32_t), 1, stream); fread(&name_len, sizeof(uint32_t), 1, stream);

+ 2
- 2
src/libespeak-ng/speech.c View File

case ENS_NOT_SUPPORTED: case ENS_NOT_SUPPORTED:
strncpy0(buffer, "The requested functionality has not been built into espeak-ng.", length); strncpy0(buffer, "The requested functionality has not been built into espeak-ng.", length);
break; 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; break;
case ENS_NO_SPECT_FRAMES: case ENS_NO_SPECT_FRAMES:
strncpy0(buffer, "The spectral file does not contain any frame data.", length); strncpy0(buffer, "The spectral file does not contain any frame data.", length);

Loading…
Cancel
Save