Browse Source

Convert src/compiledata.cpp to src/libespeak-ng/compiledata.c.

master
Reece H. Dunn 9 years ago
parent
commit
8218109400
3 changed files with 47 additions and 74 deletions
  1. 1
    1
      Makefile.am
  2. 2
    2
      src/espeakedit.cpp
  3. 44
    71
      src/libespeak-ng/compiledata.c

+ 1
- 1
Makefile.am View File



common_FLAGS = -Isrc/include/espeak-ng common_FLAGS = -Isrc/include/espeak-ng
common_SOURCE = \ common_SOURCE = \
src/libespeak-ng/compiledata.c \
src/libespeak-ng/compiledict.c \ src/libespeak-ng/compiledict.c \
src/libespeak-ng/compilembrola.c \ src/libespeak-ng/compilembrola.c \
src/libespeak-ng/dictionary.c \ src/libespeak-ng/dictionary.c \
src/libespeak-ng/debug.c src/libespeak-ng/debug.c


espeakedit_SOURCE = \ espeakedit_SOURCE = \
src/compiledata.cpp \
src/espeakedit.cpp src/espeakedit.cpp


if OPT_KLATT if OPT_KLATT

+ 2
- 2
src/espeakedit.cpp View File

"<a href=\"http://espeak.sourceforge.net/\">http://espeak.sourceforge.net</a><br>" "<a href=\"http://espeak.sourceforge.net/\">http://espeak.sourceforge.net</a><br>"
"Licensed under <a href=\"http://espeak.sourceforge.net/license.html\">GNU General Public License version 3</a></font>"; "Licensed under <a href=\"http://espeak.sourceforge.net/license.html\">GNU General Public License version 3</a></font>";


extern void CompilePhonemeData(long rate, FILE *log);
extern espeak_ng_STATUS CompileIntonation(FILE *log);
extern "C" void CompilePhonemeData(long rate, FILE *log);
extern "C" espeak_ng_STATUS CompileIntonation(FILE *log);


int progress_max; int progress_max;
int gui_flag = 0; int gui_flag = 0;

src/compiledata.cpp → src/libespeak-ng/compiledata.c View File

NAMETAB *manifest = NULL; NAMETAB *manifest = NULL;
int n_manifest; int n_manifest;


extern char path_source[sizeof(path_home)+20];

extern int progress_max;
extern int gui_flag;
extern char voice_name2[40];

extern "C" int utf8_in(int *c, const char *buf);
extern "C" int utf8_out(unsigned int c, char *buf);
extern int utf8_in(int *c, const char *buf);
extern int utf8_out(unsigned int c, char *buf);
extern void DrawEnvelopes(); extern void DrawEnvelopes();


typedef struct { typedef struct {
const char *name; const char *name;
char buf[120]; char buf[120];


static const char *INV = "Invalid";

static const char *instn_category_string[16] = { static const char *instn_category_string[16] = {
"", "", "IF", "IF OR", "", "", "IF", "IF OR",
"", "", "", "", "", "", "", "",
}; };


static const char *instn_jumps[] = { static const char *instn_jumps[] = {
"JMP", INV, INV, INV,
"JMP false", "SwitchNextVowelType", "SwitchPrevVowelType", INV};
"JMP", "Invalid", "Invalid", "Invalid",
"JMP false", "SwitchNextVowelType", "SwitchPrevVowelType", "Invalid"};


static char instn1_paramtype[] = { static char instn1_paramtype[] = {
0, 3, 3, 3, 3, 3, 3, 1, 0, 3, 3, 3, 3, 3, 3, 1,
static FILE *f_phindex; static FILE *f_phindex;
static FILE *f_phtab; static FILE *f_phtab;
static FILE *f_phcontents; static FILE *f_phcontents;
static FILE *f_errors = stderr;
static FILE *f_errors = NULL;
static FILE *f_prog_log = NULL; static FILE *f_prog_log = NULL;
static FILE *f_report; static FILE *f_report;


return(0); return(0);
} }


snprintf(filename, sizeof(filename), "%s/%s", path_source, path);
snprintf(filename, sizeof(filename), "%s/../phsource/%s", path_home, path);
LoadSpectSeq(spectseq, filename); LoadSpectSeq(spectseq, filename);


if(spectseq->frames == NULL) if(spectseq->frames == NULL)
total += spectseq->frames[frame-1]->length; total += spectseq->frames[frame-1]->length;
} }
} }
seq_out.length_total = int(total);
seq_out.length_total = (int)total;


if((control & 1) && (marker1_set == 0)) if((control & 1) && (marker1_set == 0))
{ {
else else
fr_out = (frame_t *)&seq_out.frame[n_frames]; fr_out = (frame_t *)&seq_out.frame[n_frames];


x = int(fr->length + 0.5); // round to nearest mS
x = (int)(fr->length + 0.5); // round to nearest mS
if(x > 255) x = 255; if(x > 255) x = 255;
fr_out->length = x; fr_out->length = x;


fr_out->frflags = fr->markers | klatt_flag; fr_out->frflags = fr->markers | klatt_flag;


rms = int(GetFrameRms(fr, spectseq->amplitude));
rms = (int)GetFrameRms(fr, spectseq->amplitude);
if(rms > 255) rms = 255; if(rms > 255) rms = 255;
fr_out->rms = rms; fr_out->rms = rms;


pkheight = spectseq->amplitude * fr->amp_adjust * fr->peaks[peak].pkheight; pkheight = spectseq->amplitude * fr->amp_adjust * fr->peaks[peak].pkheight;
pkheight = pkheight/640000; pkheight = pkheight/640000;
if(pkheight > 255) pkheight = 255; if(pkheight > 255) pkheight = 255;
fr_out->fheight[peak] = int(pkheight);
fr_out->fheight[peak] = (int)pkheight;


if(peak < 6) if(peak < 6)
{ {
if((sr1 != samplerate_native) || (sr2 != sr1*2)) if((sr1 != samplerate_native) || (sr2 != sr1*2))
{ {
int fd_temp; int fd_temp;
char command[sizeof(path_source)+200];
char command[sizeof(path_home)+250];


failed = 0; failed = 0;


fname2 = msg; fname2 = msg;
} }


sprintf(command,"sox \"%s%s.wav\" -r %d -c1 -t wav %s\n",path_source,fname2,samplerate_native, fname_temp);
sprintf(command,"sox \"%s/../phsource/%s.wav\" -r %d -c1 -t wav %s\n",path_home,fname2,samplerate_native, fname_temp);
if(system(command) != 0) if(system(command) != 0)
{ {
failed = 1; failed = 1;
} }
else else
{ {
x = (float(sample) / scale_factor) + 0.5;
sample2= int(x);
x = ((float)sample / scale_factor) + 0.5;
sample2= (int)x;
if(sample2 > 127) if(sample2 > 127)
sample2 = 127; sample2 = 127;
if(sample2 < -128) if(sample2 < -128)


if(env_lin[ix2] > 0) if(env_lin[ix2] > 0)
{ {
yy = env_y[ix2] + (env_y[ix2+1] - env_y[ix2]) * (float(x) - env_x[ix2]) / (env_x[ix2+1] - env_x[ix2]);
y = int(yy * 2.55);
yy = env_y[ix2] + (env_y[ix2+1] - env_y[ix2]) * ((float)x - env_x[ix2]) / (env_x[ix2+1] - env_x[ix2]);
y = (int)(yy * 2.55);
} }
else else
if(n_points > 3) if(n_points > 3)
int addr = 0; int addr = 0;
int type_code=' '; int type_code=' ';
REF_HASH_TAB *p, *p2; REF_HASH_TAB *p, *p2;
char buf[sizeof(path_source)+120];
char buf[sizeof(path_home)+150];


if(strcmp(path,"NULL")==0) if(strcmp(path,"NULL")==0)
return(0); return(0);


if(addr == 0) if(addr == 0)
{ {
sprintf(buf,"%s%s",path_source,path);
sprintf(buf,"%s/../phsource/%s",path_home,path);


if((f = fopen(buf,"rb")) == NULL) if((f = fopen(buf,"rb")) == NULL)
{ {
sprintf(buf,"%s%s.wav",path_source,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);
if(phoneme_tab2[ix].type == phINVALID) if(phoneme_tab2[ix].type == phINVALID)
{ {
fprintf(f_errors,"%3d: Phoneme [%s] not declared, referenced at line %d\n",linenum, fprintf(f_errors,"%3d: Phoneme [%s] not declared, referenced at line %d\n",linenum,
WordToString(phoneme_tab2[ix].mnemonic),int(phoneme_tab2[ix].program));
WordToString(phoneme_tab2[ix].mnemonic),(int)(phoneme_tab2[ix].program));
error_count++; error_count++;
phoneme_tab2[ix].type = 0; // prevent the error message repeating phoneme_tab2[ix].type = 0; // prevent the error message repeating
} }
char line_buf[80]; char line_buf[80];
char names[6][80]; char names[6][80];
char phcode[7]; char phcode[7];
char save_voice_name[80];


NextItem(tSTRING); NextItem(tSTRING);
strcpy(foreign_table_name, item_string); strcpy(foreign_table_name, item_string);
strcpy(save_voice_name,voice_name2);


if((foreign_table = SelectPhonemeTableName(foreign_table_name)) < 0) if((foreign_table = SelectPhonemeTableName(foreign_table_name)) < 0)
{ {
n_bytes = n_bytes / 4; n_bytes = n_bytes / 4;
p_start[2] = n_bytes >> 8; // index of next table p_start[2] = n_bytes >> 8; // index of next table
p_start[3] = n_bytes; p_start[3] = n_bytes;

if(gui_flag != 0)
{
LoadVoice(voice_name2,0); // reset the original phoneme table
LoadVoiceVariant(save_voice_name,0);
}
} // end of CompileEquivalents } // end of CompileEquivalents




{//============================== {//==============================
int item; int item;
FILE *f; FILE *f;
char buf[sizeof(path_source)+120];
char buf[sizeof(path_home)+120];


linenum = 1; linenum = 1;




case kINCLUDE: case kINCLUDE:
NextItem(tSTRING); NextItem(tSTRING);
sprintf(buf,"%s%s",path_source,item_string);
sprintf(buf,"%s/../phsource/%s",path_home,item_string);


if((stack_ix < N_STACK) && (f = fopen_log(f_errors,buf,"rb")) != NULL) if((stack_ix < N_STACK) && (f = fopen_log(f_errors,buf,"rb")) != NULL)
{ {


static void CompilePhonemeData2(const char *source, FILE *log) static void CompilePhonemeData2(const char *source, FILE *log)
{//================================================ {//================================================
char fname[sizeof(path_source)+40];
char fname[sizeof(path_home)+40];
sprintf(fname,"%s/../phsource",path_home);


#ifdef MAKE_ENVELOPES #ifdef MAKE_ENVELOPES
make_envs(); make_envs();
#endif #endif


fprintf(log,"Compiling phoneme data: %s\n",path_source);
fprintf(log,"Compiling phoneme data: %s\n",fname);
n_envelopes = 0; n_envelopes = 0;
error_count = 0; error_count = 0;
resample_count = 0; resample_count = 0;


f_errors = log; f_errors = log;


if(!access(path_source, 755))
if(!access(fname, 755))
{ {
fprintf(log,"Can't find phoneme source directory: %s\n",path_source);
fprintf(log,"Can't find phoneme source directory: %s\n",fname);
return; return;
} }


strncpy0(current_fname,source,sizeof(current_fname)); strncpy0(current_fname,source,sizeof(current_fname));


sprintf(fname,"%s/%s",path_source,"phonemes");
sprintf(fname,"%s/../phsource/phonemes",path_home);
f_in = fopen_log(f_errors,fname,"rb"); f_in = fopen_log(f_errors,fname,"rb");
if(f_in == NULL) if(f_in == NULL)
{ {
return; return;
} }


progress_max = 0;
while(fgets(fname,sizeof(fname),f_in) != NULL)
{
// count the number of phoneme tables declared in the master phonemes file
if(memcmp(fname,"phonemetable",12)==0)
progress_max++;
}
rewind(f_in);

sprintf(fname,"%s%s",path_source,"error_log");
sprintf(fname,"%s/../phsource/%s",path_home,"error_log");
if((f_errors = fopen_log(f_errors,fname,"w")) == NULL) if((f_errors = fopen_log(f_errors,fname,"w")) == NULL)
f_errors = stderr; f_errors = stderr;


sprintf(fname,"%s%s",path_source,"compile_report");
sprintf(fname,"%s/../phsource/%s",path_home,"compile_report");
f_report = fopen_log(f_errors, fname,"w"); f_report = fopen_log(f_errors, fname,"w");




"# ------- ---------\n"); "# ------- ---------\n");




fprintf(f_errors, "Source data path = '%s'\n", path_source);
fprintf(f_errors, "Master phonemes file = '%s/phonemes'\n", path_source);
fprintf(f_errors, "Source data path = '%s/../phsource'\n", path_home);
fprintf(f_errors, "Master phonemes file = '%s/../phsource/phonemes'\n", path_home);
fprintf(f_errors, "Output to '%s/'\n\n", path_home); fprintf(f_errors, "Output to '%s/'\n\n", path_home);


sprintf(fname,"%s/%s",path_home,"phondata"); sprintf(fname,"%s/%s",path_home,"phondata");
return; return;
} }


sprintf(fname,"%scompile_prog_log",path_source);
sprintf(fname,"%s/../phsource/compile_prog_log",path_home);
f_prog_log = fopen_log(f_errors,fname,"wb"); f_prog_log = fopen_log(f_errors,fname,"wb");


fprintf(log,"Compiling phoneme data: %s\n",path_source);
fprintf(log,"Compiling phoneme data: %s/../phsource\n",path_home);


// write a word so that further data doesn't start at displ=0 // write a word so that further data doesn't start at displ=0
Write4Bytes(f_phdata,version_phdata); Write4Bytes(f_phdata,version_phdata);


LoadPhData(NULL); LoadPhData(NULL);


if(gui_flag != 0)
LoadVoice(voice_name2,0);

CompileReport(); CompileReport();
#ifdef MAKE_ENVELOPES #ifdef MAKE_ENVELOPES
DrawEnvelopes(); DrawEnvelopes();
// env_rise2, env_rise2, // env_rise2, env_rise2,
// env_risefallrise, env_risefallrise // env_risefallrise, env_risefallrise


int LookupEnvelope(const char *name)
int LookupEnvelopeName(const char *name)
{//================================= {//=================================
return(LookupMnem(envelope_names, name)); return(LookupMnem(envelope_names, name));
} }


char name[12]; char name[12];
char tune_names[N_TUNE_NAMES][12]; char tune_names[N_TUNE_NAMES][12];
char buf[sizeof(path_source)+120];
char buf[sizeof(path_home)+150];


error_count = 0; error_count = 0;
f_errors = log; f_errors = log;


sprintf(buf,"%sintonation.txt",path_source);
sprintf(buf,"%s/../phsource/intonation.txt",path_home);
if((f_in = fopen(buf, "r")) == NULL) if((f_in = fopen(buf, "r")) == NULL)
{ {
sprintf(buf,"%sintonation",path_source);
sprintf(buf,"%s/../phsource/intonation",path_home);
if((f_in = fopen_log(f_errors, buf, "r")) == NULL) if((f_in = fopen_log(f_errors, buf, "r")) == NULL)
{ {
fprintf(log,"Can't read file: %s\n",buf); fprintf(log,"Can't read file: %s\n",buf);
while(isspace(*p)) p++; while(isspace(*p)) p++;


ix = 0; ix = 0;
while((ix < int(sizeof(name) - 1)) && !isspace(*p))
while((ix < (int)(sizeof(name) - 1)) && !isspace(*p))
{ {
name[ix++] = *p++; name[ix++] = *p++;
} }


case kTUNE_HEADENV: case kTUNE_HEADENV:
NextItem(tSTRING); NextItem(tSTRING);
if((ix = LookupEnvelope(item_string)) < 0)
if((ix = LookupEnvelopeName(item_string)) < 0)
error("Bad envelope name: '%s'",item_string); error("Bad envelope name: '%s'",item_string);
else else
new_tune.stressed_env = ix; new_tune.stressed_env = ix;


case kTUNE_HEADEXTEND: case kTUNE_HEADEXTEND:
// up to 8 numbers // up to 8 numbers
for(ix=0; ix < int(sizeof(new_tune.head_extend)); ix++)
for(ix=0; ix < (int)(sizeof(new_tune.head_extend)); ix++)
{ {
if(!isdigit(c = CheckNextChar()) && (c != '-')) if(!isdigit(c = CheckNextChar()) && (c != '-'))
break; break;


case kTUNE_NUCLEUS0: case kTUNE_NUCLEUS0:
NextItem(tSTRING); NextItem(tSTRING);
if((ix = LookupEnvelope(item_string)) < 0)
if((ix = LookupEnvelopeName(item_string)) < 0)
{ {
error("Bad envelope name: '%s'",item_string); error("Bad envelope name: '%s'",item_string);
break; break;


case kTUNE_NUCLEUS1: case kTUNE_NUCLEUS1:
NextItem(tSTRING); NextItem(tSTRING);
if((ix = LookupEnvelope(item_string)) < 0)
if((ix = LookupEnvelopeName(item_string)) < 0)
{ {
error("Bad envelope name: '%s'",item_string); error("Bad envelope name: '%s'",item_string);
break; break;


case kTUNE_SPLIT: case kTUNE_SPLIT:
NextItem(tSTRING); NextItem(tSTRING);
if((ix = LookupEnvelope(item_string)) < 0)
if((ix = LookupEnvelopeName(item_string)) < 0)
{ {
error("Bad envelope name: '%s'",item_string); error("Bad envelope name: '%s'",item_string);
break; break;

Loading…
Cancel
Save