All sound file information goes to soundicon_tab. The contents of the files are not loaded to memory before they are needed for synthesis. This removes N_SOUNDICON_SLOTS that divided soundicon_tab into two parts for unknown reasons. TODO: LoadConfig() is currently undocumented. The logic should be moved to LoadVoice() and documented.master
#include "speech.h" // for path_home, GetFileLength, PATHSEP | #include "speech.h" // for path_home, GetFileLength, PATHSEP | ||||
#include "synthesize.h" // for samplerate | #include "synthesize.h" // for samplerate | ||||
int n_soundicon_tab = N_SOUNDICON_SLOTS; | |||||
int n_soundicon_tab = 0; | |||||
SOUND_ICON soundicon_tab[N_SOUNDICON_TAB]; | SOUND_ICON soundicon_tab[N_SOUNDICON_TAB]; | ||||
int LookupSoundicon(int c) | int LookupSoundicon(int c) | ||||
{ | { | ||||
// Find the sound icon number for a punctuation character | |||||
// Find the sound icon number for a punctuation character and load the audio file if it's not yet loaded | |||||
int ix; | int ix; | ||||
for (ix = N_SOUNDICON_SLOTS; ix < n_soundicon_tab; ix++) { | |||||
for (ix = 0; ix < n_soundicon_tab; ix++) { | |||||
if (soundicon_tab[ix].name == c) { | if (soundicon_tab[ix].name == c) { | ||||
if (soundicon_tab[ix].length == 0) { | |||||
if (LoadSoundFile(NULL, ix, NULL) != ENS_OK) | |||||
if (soundicon_tab[ix].length == 0) { // not yet loaded, load now | |||||
if (LoadSoundFile(NULL, ix, NULL) != ENS_OK) { | |||||
return -1; // sound file is not available | return -1; // sound file is not available | ||||
} | |||||
} | } | ||||
return ix; | return ix; | ||||
} | } | ||||
int LoadSoundFile2(const char *fname) | int LoadSoundFile2(const char *fname) | ||||
{ | { | ||||
// Load a sound file into one of the reserved slots in the sound icon table | |||||
// (if it'snot already loaded) | |||||
// Load a sound file into the sound icon table and memory | |||||
// (if it's not already loaded) | |||||
// returns -1 on error or the index of loaded file on success | |||||
int ix; | int ix; | ||||
static int slot = -1; | |||||
for (ix = 0; ix < n_soundicon_tab; ix++) { | for (ix = 0; ix < n_soundicon_tab; ix++) { | ||||
if (((soundicon_tab[ix].filename != NULL) && strcmp(fname, soundicon_tab[ix].filename) == 0)) | |||||
return ix; // already loaded | |||||
if (((soundicon_tab[ix].filename != NULL) && strcmp(fname, soundicon_tab[ix].filename) == 0)) { | |||||
// the file information is found. If length = 0 it needs to be loaded to memory | |||||
if (soundicon_tab[ix].length == 0) { | |||||
if (LoadSoundFile(NULL, ix, NULL) != ENS_OK) | |||||
return -1; // sound file is not available | |||||
} | |||||
return ix; // sound file already loaded to memory | |||||
} | |||||
} | } | ||||
// load the file into the next slot | |||||
slot++; | |||||
if (slot >= N_SOUNDICON_SLOTS) | |||||
slot = 0; | |||||
if (LoadSoundFile(fname, slot, NULL) != ENS_OK) | |||||
// load the file into the current slot and increase index | |||||
if (LoadSoundFile(fname, n_soundicon_tab, NULL) != ENS_OK) | |||||
return -1; | return -1; | ||||
soundicon_tab[slot].filename = (char *)realloc(soundicon_tab[ix].filename, strlen(fname)+1); | |||||
strcpy(soundicon_tab[slot].filename, fname); | |||||
return slot; | |||||
soundicon_tab[n_soundicon_tab].filename = (char *)realloc(soundicon_tab[n_soundicon_tab].filename, strlen(fname)+1); | |||||
strcpy(soundicon_tab[n_soundicon_tab].filename, fname); | |||||
n_soundicon_tab++; | |||||
return n_soundicon_tab - 1; | |||||
} | } |
int LoadSoundFile2(const char *fname); | int LoadSoundFile2(const char *fname); | ||||
typedef struct { | typedef struct { | ||||
int name; | |||||
int name; // used for detecting punctuation | |||||
int length; | int length; | ||||
char *data; | char *data; | ||||
char *filename; | char *filename; | ||||
} SOUND_ICON; | } SOUND_ICON; | ||||
#define N_SOUNDICON_TAB 80 // total entries in soundicon_tab | |||||
#define N_SOUNDICON_SLOTS 4 // number of slots reserved for dynamic loading of audio files | |||||
#define N_SOUNDICON_TAB 80 // total entries for dynamic loading of audio files | |||||
extern int n_soundicon_tab; | extern int n_soundicon_tab; | ||||
extern SOUND_ICON soundicon_tab[N_SOUNDICON_TAB]; | extern SOUND_ICON soundicon_tab[N_SOUNDICON_TAB]; |
#include "phoneme.h" // for PHONEME_TAB, PHONEME_TAB_LIST | #include "phoneme.h" // for PHONEME_TAB, PHONEME_TAB_LIST | ||||
#include "speech.h" // for path_home, GetFileLength, PATHSEP | #include "speech.h" // for path_home, GetFileLength, PATHSEP | ||||
#include "mbrola.h" // for mbrola_name | #include "mbrola.h" // for mbrola_name | ||||
#include "soundicon.h" // for N_SOUNDICON_SLOTS, soundicon_tab | |||||
#include "soundicon.h" // for soundicon_tab | |||||
#include "synthesize.h" // for PHONEME_LIST, frameref_t, PHONE... | #include "synthesize.h" // for PHONEME_LIST, frameref_t, PHONE... | ||||
#include "translate.h" // for Translator, LANGUAGE_OPTIONS | #include "translate.h" // for Translator, LANGUAGE_OPTIONS | ||||
#include "voice.h" // for ReadTonePoints, tone_points, voice | #include "voice.h" // for ReadTonePoints, tone_points, voice | ||||
char c1; | char c1; | ||||
char string[200]; | char string[200]; | ||||
for (ix = 0; ix < N_SOUNDICON_SLOTS; ix++) { | |||||
soundicon_tab[ix].filename = NULL; | |||||
soundicon_tab[ix].data = NULL; | |||||
} | |||||
sprintf(buf, "%s%c%s", path_home, PATHSEP, "config"); | sprintf(buf, "%s%c%s", path_home, PATHSEP, "config"); | ||||
if ((f = fopen(buf, "r")) == NULL) | if ((f = fopen(buf, "r")) == NULL) | ||||
return; | return; | ||||
else if (memcmp(buf, "soundicon", 9) == 0) { | else if (memcmp(buf, "soundicon", 9) == 0) { | ||||
ix = sscanf(&buf[10], "_%c %s", &c1, string); | ix = sscanf(&buf[10], "_%c %s", &c1, string); | ||||
if (ix == 2) { | if (ix == 2) { | ||||
// add sound file information to soundicon array | |||||
// the file will be loaded to memory by LoadSoundFile2() | |||||
soundicon_tab[n_soundicon_tab].name = c1; | soundicon_tab[n_soundicon_tab].name = c1; | ||||
soundicon_tab[n_soundicon_tab].filename = strdup(string); | soundicon_tab[n_soundicon_tab].filename = strdup(string); | ||||
soundicon_tab[n_soundicon_tab++].length = 0; | soundicon_tab[n_soundicon_tab++].length = 0; |