The compile_phoneme_data operation now produces an image file phsource/envelopes.png which shows the shape of the envelopes. git-svn-id: https://espeak.svn.sourceforge.net/svnroot/espeak/trunk@78 d46cf337-b52f-0410-862d-fd96e6ae7743master
# ADD BSC32 /nologo | # ADD BSC32 /nologo | ||||
LINK32=link.exe | LINK32=link.exe | ||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept | ||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept | |||||
# ADD LINK32 kernel32.lib winmm.lib user32.lib gdi32.lib winspool.lib comdlg32.lib PAStaticWMME.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept | |||||
!ENDIF | !ENDIF | ||||
extern void Write4Bytes(FILE *f, int value); | extern void Write4Bytes(FILE *f, int value); | ||||
extern void MakeVowelLists(void); | extern void MakeVowelLists(void); | ||||
extern void FindPhonemesUsed(void); | extern void FindPhonemesUsed(void); | ||||
extern void DrawEnvelopes(); | |||||
extern int CompileDictionary(const char *dsource, const char *dict_name, FILE *log, char *fname); | extern int CompileDictionary(const char *dsource, const char *dict_name, FILE *log, char *fname); | ||||
extern char voice_name[]; | extern char voice_name[]; | ||||
} REF_HASH_TAB; | } REF_HASH_TAB; | ||||
#define N_ENVELOPES 30 | |||||
#define ENV_LEN 128 | |||||
int n_envelopes = 0; | |||||
char envelope_paths[N_ENVELOPES][80]; | |||||
unsigned char envelope_dat[N_ENVELOPES][ENV_LEN]; | |||||
class Compile | class Compile | ||||
{//========== | {//========== | ||||
public: | public: | ||||
int LoadSpect(const char *path, int control); | int LoadSpect(const char *path, int control); | ||||
int LoadWavefile(FILE *f, const char *fname); | int LoadWavefile(FILE *f, const char *fname); | ||||
int LoadEnvelope(FILE *f, const char *fname); | int LoadEnvelope(FILE *f, const char *fname); | ||||
int LoadEnvelope2(FILE *f, const char *fname); | |||||
int LoadDataFile(const char *path, int control); | int LoadDataFile(const char *path, int control); | ||||
int AddSpect(int phcode, int *list, int control); | int AddSpect(int phcode, int *list, int control); | ||||
void AddSpectList(int *list, int control); | void AddSpectList(int *list, int control); | ||||
fread(buf,1,128,f); | fread(buf,1,128,f); | ||||
fwrite(buf,1,128,f_phdata); | fwrite(buf,1,128,f_phdata); | ||||
if(n_envelopes < N_ENVELOPES) | |||||
{ | |||||
strncpy0(envelope_paths[n_envelopes],fname,sizeof(envelope_paths[0])); | |||||
memcpy(envelope_dat[n_envelopes],buf,sizeof(envelope_dat[0])); | |||||
n_envelopes++; | |||||
} | |||||
return(displ); | return(displ); | ||||
} | } | ||||
type_code = 'E'; | type_code = 'E'; | ||||
} | } | ||||
else | else | ||||
if(id == 0x45564E45) | |||||
{ | |||||
ix = LoadEnvelope2(f,path); | |||||
type_code = 'E'; | |||||
} | |||||
else | |||||
{ | { | ||||
Error("File not SPEC or RIFF",path); | Error("File not SPEC or RIFF",path); | ||||
ix = -1; | ix = -1; | ||||
if(ix > 0) | if(ix > 0) | ||||
{ | { | ||||
// fprintf(f_phcontents,"%c %-15s %4d 0x%.5x %s\n",type_code,current_fname,linenum,ix & 0x7fffff,path); | |||||
fprintf(f_phcontents,"%c 0x%.5x %s\n",type_code,ix & 0x7fffff,path); | fprintf(f_phcontents,"%c 0x%.5x %s\n",type_code,ix & 0x7fffff,path); | ||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
int Compile::LoadEnvelope2(FILE *f, const char *fname) | |||||
{//=================================================== | |||||
int ix; | |||||
int n; | |||||
int x, y; | |||||
int displ; | |||||
int n_points; | |||||
char line_buf[128]; | |||||
float env_x[20]; | |||||
float env_y[20]; | |||||
int env_lin[20]; | |||||
unsigned char env[ENV_LEN]; | |||||
n_points = 0; | |||||
fgets(line_buf,sizeof(line_buf),f); // skip first line | |||||
while(!feof(f)) | |||||
{ | |||||
if(fgets(line_buf,sizeof(line_buf),f) == NULL) | |||||
break; | |||||
env_lin[n_points] = 0; | |||||
n = sscanf(line_buf,"%f %f %d",&env_x[n_points],&env_y[n_points],&env_lin[n_points]); | |||||
if(n >= 2) | |||||
{ | |||||
env_x[n_points] *= 1.28; // convert range 0-100 to 0-128 | |||||
n_points++; | |||||
} | |||||
} | |||||
env_x[n_points] = env_x[n_points-1]; | |||||
env_y[n_points] = env_y[n_points-1]; | |||||
ix = -1; | |||||
for(x=0; x<ENV_LEN; x++) | |||||
{ | |||||
if(x > env_x[ix+4]) | |||||
ix++; | |||||
if(n_points > 3) | |||||
y = (int)(polint(&env_x[ix],&env_y[ix],4,x) * 2.55); // convert to range 0-255 | |||||
else | |||||
y = (int)(polint(&env_x[ix],&env_y[ix],3,x) * 2.55); | |||||
if(y < 0) y = 0; | |||||
if(y > 255) y = 255; | |||||
env[x] = y; | |||||
} | |||||
if(n_envelopes < N_ENVELOPES) | |||||
{ | |||||
strncpy0(envelope_paths[n_envelopes],fname,sizeof(envelope_paths[0])); | |||||
memcpy(envelope_dat[n_envelopes],env,ENV_LEN); | |||||
n_envelopes++; | |||||
} | |||||
displ = ftell(f_phdata); | |||||
fwrite(env,1,128,f_phdata); | |||||
return(displ); | |||||
} | |||||
static int ref_sorter(char **a, char **b) | static int ref_sorter(char **a, char **b) | ||||
{//====================================== | {//====================================== | ||||
make_envs(); | make_envs(); | ||||
#endif | #endif | ||||
n_envelopes = 0; | |||||
error_count = 0; | error_count = 0; | ||||
memset(markers_used,0,sizeof(markers_used)); | memset(markers_used,0,sizeof(markers_used)); | ||||
LoadPhData(); | LoadPhData(); | ||||
LoadVoice(voice_name,0); | LoadVoice(voice_name,0); | ||||
Report(); | Report(); | ||||
DrawEnvelopes(); | |||||
report_dict = CompileAllDictionaries(); | report_dict = CompileAllDictionaries(); | ||||
#include "translate.h" | #include "translate.h" | ||||
#include "wave.h" | #include "wave.h" | ||||
const char *version_string = "1.28.05 17.Aug.07"; | |||||
const char *version_string = "1.28.07 21.Aug.07"; | |||||
const int version_phdata = 0x012801; | const int version_phdata = 0x012801; | ||||
int option_device_number = -1; | int option_device_number = -1; |
LoadVoice(voice_name,0); // reset the original phoneme table | LoadVoice(voice_name,0); // reset the original phoneme table | ||||
delete progress; | delete progress; | ||||
} | } | ||||
extern int n_envelopes; | |||||
extern char envelope_paths[][80]; | |||||
extern unsigned char envelope_dat[][128]; | |||||
#define HT_ENV 140 | |||||
#define WD_ENV 128*2 | |||||
void DrawEnvelopes() | |||||
{//================ | |||||
int ix_env; | |||||
int y_base; | |||||
int x; | |||||
unsigned char *env; | |||||
char name[80]; | |||||
wxBitmap bitmap(WD_ENV,HT_ENV*n_envelopes); | |||||
// Create a memory DC | |||||
wxMemoryDC dc; | |||||
dc.SelectObject(bitmap); | |||||
dc.SetBrush(*wxWHITE_BRUSH); | |||||
dc.SetFont(*wxSWISS_FONT); | |||||
dc.Clear(); | |||||
for(ix_env=0; ix_env<n_envelopes; ix_env++) | |||||
{ | |||||
y_base = HT_ENV * ix_env; | |||||
dc.SetPen(*wxLIGHT_GREY_PEN); | |||||
dc.DrawLine(0,y_base+0,256,y_base+0); | |||||
dc.DrawLine(0,y_base+64,256,y_base+64); | |||||
dc.DrawLine(0,y_base+128,256,y_base+128); | |||||
dc.DrawLine(128,y_base+0,128,y_base+128); | |||||
dc.SetPen(*wxBLACK_PEN); | |||||
strncpy0(name,envelope_paths[ix_env],sizeof(name)); | |||||
dc.DrawText(wxString(name,wxConvLocal),1,y_base); | |||||
env = envelope_dat[ix_env]; | |||||
y_base = y_base+128; | |||||
for(x=0; x<127; x++) | |||||
{ | |||||
dc.DrawLine(x*2, y_base-env[x]/2, (x+1)*2, y_base-env[x+1]/2); | |||||
} | |||||
} | |||||
bitmap.SaveFile(path_phsource+_T("/envelopes.png"),wxBITMAP_TYPE_PNG); | |||||
} | |||||
#else | #else | ||||
// notdef USE_PORTAUDIO | // notdef USE_PORTAUDIO | ||||
void wave_flush(void* theHandler) {} | |||||
void wave_init() {} | void wave_init() {} | ||||
void* wave_open(char* the_api) {return (void *)1;} | void* wave_open(char* the_api) {return (void *)1;} | ||||
size_t wave_write(void* theHandler, char* theMono16BitsWaveBuffer, size_t theSize) {return theSize;} | size_t wave_write(void* theHandler, char* theMono16BitsWaveBuffer, size_t theSize) {return theSize;} | ||||
void wave_terminate() {} | void wave_terminate() {} | ||||
uint32_t wave_get_read_position(void* theHandler) {return 0;} | uint32_t wave_get_read_position(void* theHandler) {return 0;} | ||||
uint32_t wave_get_write_position(void* theHandler) {return 0;} | uint32_t wave_get_write_position(void* theHandler) {return 0;} | ||||
int wave_get_remaining_time(uint32_t sample, uint32_t* time) {return 0;} | |||||
void wave_flush(void* theHandler) {} | void wave_flush(void* theHandler) {} | ||||
typedef int (t_wave_callback)(void); | typedef int (t_wave_callback)(void); | ||||
void wave_set_callback_is_output_enabled(t_wave_callback* cb) {} | void wave_set_callback_is_output_enabled(t_wave_callback* cb) {} | ||||
extern void* wave_test_get_write_buffer() {return 0;} | |||||
extern void* wave_test_get_write_buffer() {return NULL;} | |||||
int wave_get_remaining_time(uint32_t sample, uint32_t* time) | |||||
{ | |||||
if (!time) return(-1); | |||||
*time = (uint32_t)0; | |||||
return 0; | |||||
} | |||||
#endif // of USE_PORTAUDIO | #endif // of USE_PORTAUDIO | ||||