diff --git a/src/include/espeak-ng/espeak_ng.h b/src/include/espeak-ng/espeak_ng.h index 40a4af74..6f0e2b46 100644 --- a/src/include/espeak-ng/espeak_ng.h +++ b/src/include/espeak-ng/espeak_ng.h @@ -48,6 +48,8 @@ typedef enum { ENS_MBROLA_VOICE_NOT_FOUND = 0x100008FF, ENS_EVENT_BUFFER_FULL = 0x100009FF, ENS_NOT_SUPPORTED = 0x10000AFF, + ENS_UNSUPPORTED_SPECT_FORMAT = 0x10000BFF, + ENS_NO_SPECT_FRAMES = 0x10000CFF, } espeak_ng_STATUS; typedef enum { diff --git a/src/libespeak-ng/compiledata.c b/src/libespeak-ng/compiledata.c index a6a4352c..62bdb5b2 100644 --- a/src/libespeak-ng/compiledata.c +++ b/src/libespeak-ng/compiledata.c @@ -1093,10 +1093,8 @@ int LoadSpect(const char *path, int control) } snprintf(filename, sizeof(filename), "%s/../phsource/%s", path_home, path); - LoadSpectSeq(spectseq, filename); - - if (spectseq->frames == NULL) { - error("Bad vowel file, no frames: '%s'", path); + if (LoadSpectSeq(spectseq, filename) != ENS_OK) { + error("Bad vowel file: '%s'", path); SpectSeqDestroy(spectseq); return 0; } diff --git a/src/libespeak-ng/spect.c b/src/libespeak-ng/spect.c index c7d7fead..17005717 100644 --- a/src/libespeak-ng/spect.c +++ b/src/libespeak-ng/spect.c @@ -19,6 +19,7 @@ #include "config.h" +#include #include #if HAVE_STDINT_H #include @@ -272,7 +273,7 @@ static float GetFrameLength(SpectSeq *spect, int frame) return (spect->frames[ix]->time - spect->frames[frame]->time) * 1000.0 + adjust; } -int LoadSpectSeq(SpectSeq *spect, const char *filename) +espeak_ng_STATUS LoadSpectSeq(SpectSeq *spect, const char *filename) { short n, temp; int ix; @@ -283,7 +284,7 @@ int LoadSpectSeq(SpectSeq *spect, const char *filename) FILE *stream = fopen(filename, "rb"); if (stream == NULL) { fprintf(stderr, "Failed to open: '%s'", filename); - return 0; + return errno; } fread(&id1, sizeof(uint32_t), 1, stream); @@ -298,7 +299,7 @@ int LoadSpectSeq(SpectSeq *spect, const char *filename) else { fprintf(stderr, "Unsupported spectral file format.\n"); fclose(stream); - return 1; + return ENS_UNSUPPORTED_SPECT_FORMAT; } fread(&name_len, sizeof(uint32_t), 1, stream); @@ -315,7 +316,7 @@ int LoadSpectSeq(SpectSeq *spect, const char *filename) if (n == 0) { fclose(stream); - return 0; + return ENS_NO_SPECT_FRAMES; } if (spect->frames != NULL) { @@ -371,5 +372,5 @@ int LoadSpectSeq(SpectSeq *spect, const char *filename) spect->frames[ix]->length_adjust = spect->frames[ix]->length - GetFrameLength(spect, ix); } fclose(stream); - return 0; + return ENS_OK; } diff --git a/src/libespeak-ng/spect.h b/src/libespeak-ng/spect.h index 3d8800d5..d0be68d3 100644 --- a/src/libespeak-ng/spect.h +++ b/src/libespeak-ng/spect.h @@ -1,7 +1,7 @@ /* * Copyright (C) 2005 to 2007 by Jonathan Duddington * email: jonsd@users.sourceforge.net - * Copyright (C) 2013-2015 Reece H. Dunn + * Copyright (C) 2013-2016 Reece H. Dunn * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -126,7 +126,7 @@ typedef struct { SpectSeq *SpectSeqCreate(); void SpectSeqDestroy(SpectSeq *spect); -int LoadSpectSeq(SpectSeq *spect, const char *filename); +espeak_ng_STATUS LoadSpectSeq(SpectSeq *spect, const char *filename); #ifdef __cplusplus }