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
| @@ -73,7 +73,7 @@ BSC32=bscmake.exe | |||
| # ADD BSC32 /nologo | |||
| 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 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 | |||
| @@ -75,6 +75,7 @@ | |||
| extern void Write4Bytes(FILE *f, int value); | |||
| extern void MakeVowelLists(void); | |||
| extern void FindPhonemesUsed(void); | |||
| extern void DrawEnvelopes(); | |||
| extern int CompileDictionary(const char *dsource, const char *dict_name, FILE *log, char *fname); | |||
| extern char voice_name[]; | |||
| @@ -91,6 +92,14 @@ typedef struct { | |||
| } 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 | |||
| {//========== | |||
| public: | |||
| @@ -119,6 +128,7 @@ private: | |||
| int LoadSpect(const char *path, int control); | |||
| int LoadWavefile(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 AddSpect(int phcode, int *list, int control); | |||
| void AddSpectList(int *list, int control); | |||
| @@ -879,6 +889,13 @@ int Compile::LoadEnvelope(FILE *f, const char *fname) | |||
| fread(buf,1,128,f); | |||
| 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); | |||
| } | |||
| @@ -971,6 +988,12 @@ int Compile::LoadDataFile(const char *path, int control) | |||
| type_code = 'E'; | |||
| } | |||
| else | |||
| if(id == 0x45564E45) | |||
| { | |||
| ix = LoadEnvelope2(f,path); | |||
| type_code = 'E'; | |||
| } | |||
| else | |||
| { | |||
| Error("File not SPEC or RIFF",path); | |||
| ix = -1; | |||
| @@ -979,7 +1002,6 @@ int Compile::LoadDataFile(const char *path, int control) | |||
| 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); | |||
| } | |||
| @@ -1808,6 +1830,67 @@ void make_envs() | |||
| } | |||
| #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) | |||
| {//====================================== | |||
| @@ -2081,6 +2164,7 @@ void Compile::CPhonemeTab(const char *source) | |||
| make_envs(); | |||
| #endif | |||
| n_envelopes = 0; | |||
| error_count = 0; | |||
| memset(markers_used,0,sizeof(markers_used)); | |||
| @@ -2192,7 +2276,7 @@ fprintf(f_errors,"Refs %d, Reused %d\n",count_references,duplicate_references); | |||
| LoadPhData(); | |||
| LoadVoice(voice_name,0); | |||
| Report(); | |||
| DrawEnvelopes(); | |||
| report_dict = CompileAllDictionaries(); | |||
| @@ -35,7 +35,7 @@ | |||
| #include "translate.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; | |||
| int option_device_number = -1; | |||
| @@ -506,3 +506,55 @@ void MakeVowelLists(void) | |||
| LoadVoice(voice_name,0); // reset the original phoneme table | |||
| 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); | |||
| } | |||
| @@ -1020,6 +1020,7 @@ void *wave_test_get_write_buffer() | |||
| #else | |||
| // notdef USE_PORTAUDIO | |||
| void wave_flush(void* theHandler) {} | |||
| void wave_init() {} | |||
| void* wave_open(char* the_api) {return (void *)1;} | |||
| size_t wave_write(void* theHandler, char* theMono16BitsWaveBuffer, size_t theSize) {return theSize;} | |||
| @@ -1028,11 +1029,17 @@ int wave_is_busy(void* theHandler) {return 0;} | |||
| void wave_terminate() {} | |||
| uint32_t wave_get_read_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) {} | |||
| typedef int (t_wave_callback)(void); | |||
| 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 | |||