From 56ddf6c3397610901fe0a32b4deed5c8928479c4 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 13 Dec 2015 12:53:21 +0000 Subject: [PATCH] espeakedit: remove wxWidgets from compiledata.cpp --- src/compiledata.cpp | 92 +++++++++------------------------------------ src/espeakedit.cpp | 5 +-- src/spect.cpp | 17 ++++++++- src/spect.h | 4 +- 4 files changed, 37 insertions(+), 81 deletions(-) diff --git a/src/compiledata.cpp b/src/compiledata.cpp index fdc5ca69..ba200bb4 100644 --- a/src/compiledata.cpp +++ b/src/compiledata.cpp @@ -24,13 +24,6 @@ #include #include -#include "wx/wx.h" -#include "wx/wfstream.h" -#include "wx/dir.h" -#include "wx/filename.h" -#include -#include "wx/progdlg.h" - #include "speak_lib.h" #include "espeak_ng.h" @@ -40,15 +33,11 @@ #include "voice.h" #include "spect.h" +#include #ifdef PLATFORM_POSIX #include #endif -// wxWidgets 3 name changes -#if wxCHECK_VERSION(3, 0, 0) -#define wxOPEN wxFD_OPEN -#endif - typedef struct { unsigned int value; char *name; @@ -1529,7 +1518,7 @@ int LoadSpect(const char *path, int control) int klatt_flag=0; SpectFrame *fr; frame_t *fr_out; - wxString path_sep = _T("/"); + char filename[sizeof(path_home)+20]; SPECT_SEQ seq_out; SPECT_SEQK seqk_out; @@ -1542,16 +1531,8 @@ int LoadSpect(const char *path, int control) return(0); } - wxString filename = wxString(path_source,wxConvLocal) + path_sep + wxString(path,wxConvLocal); - wxFileInputStream stream(filename); - - if(stream.Ok() == FALSE) - { - error("Failed to open: '%s'",path); - SpectSeqDestroy(spectseq); - return(0); - } - LoadSpectSeq(spectseq, stream); + snprintf(filename, sizeof(filename), "%s/%s", path_source, path); + LoadSpectSeq(spectseq, filename); if(spectseq->frames == NULL) { @@ -3427,27 +3408,25 @@ static void CompilePhonemeFiles() -static void CompilePhonemeData2(const char *source) +static void CompilePhonemeData2(const char *source, FILE *log) {//================================================ char fname[sizeof(path_source)+40]; - wxString report; - wxString report_dict; #ifdef MAKE_ENVELOPES make_envs(); #endif - wxLogStatus(_T("Compiling phoneme data: ")+wxString(path_source,wxConvLocal)); + fprintf(log,"Compiling phoneme data: %s\n",path_source); n_envelopes = 0; error_count = 0; resample_count = 0; memset(markers_used,0,sizeof(markers_used)); - f_errors = stderr; + f_errors = log; - if(!wxDirExists(path_source)) + if(!access(path_source, 755)) { - fprintf(stderr,"Can't find phoneme source directory: %s\n",path_source); + fprintf(log,"Can't find phoneme source directory: %s\n",path_source); return; } @@ -3457,7 +3436,7 @@ make_envs(); f_in = fopen_log(f_errors,fname,"rb"); if(f_in == NULL) { - wxLogError(_T("Can't read master phonemes file:\n") + wxString(fname,wxConvLocal)); + fprintf(log,"Can't read master phonemes file: %s\n",fname); return; } @@ -3519,7 +3498,7 @@ make_envs(); sprintf(fname,"%scompile_prog_log",path_source); f_prog_log = fopen_log(f_errors,fname,"wb"); - fprintf(stderr,"Compiling phoneme data: %s\n",path_source); + fprintf(log,"Compiling phoneme data: %s\n",path_source); // write a word so that further data doesn't start at displ=0 Write4Bytes(f_phdata,version_phdata); @@ -3558,30 +3537,16 @@ fprintf(f_errors,"\nRefs %d, Reused %d\n",count_references,duplicate_references if(resample_count > 0) { fprintf(f_errors, "\n%d WAV files resampled to %d Hz\n", resample_count, samplerate_native); - report.Printf(_T("Compiled phonemes: %d errors, %d files resampled to %d Hz. "),error_count, resample_count, samplerate_native); + fprintf(log,"Compiled phonemes: %d errors, %d files resampled to %d Hz.\n",error_count, resample_count, samplerate_native); } else { - report.Printf(_T("Compiled phonemes: %d errors."),error_count); + fprintf(log,"Compiled phonemes: %d errors.\n",error_count); } if(f_errors != stderr) fclose(f_errors); - if(error_count > 0) - { - report += _T(" See file: '")+wxString(path_source,wxConvLocal)+_T("phsource/error_log'."); - wxLogError(report); - } - wxLogStatus(report + report_dict); - - if(gui_flag == 0) - { - strncpy0(fname,(report+report_dict).mb_str(wxConvLocal),sizeof(fname)); - fprintf(stderr,"%s\n",fname); - - } - ReadPhondataManifest(); } // end of CompilePhonemeData @@ -3646,7 +3611,6 @@ espeak_ng_STATUS CompileIntonation(FILE *log) int found; int tune_number = 0; FILE *f_out; - wxString report; TUNE *tune_data; TUNE new_tune; @@ -3664,7 +3628,7 @@ espeak_ng_STATUS CompileIntonation(FILE *log) sprintf(buf,"%sintonation",path_source); if((f_in = fopen_log(f_errors, buf, "r")) == NULL) { - wxLogError(_T("Can't read file: ") + wxString(buf,wxConvLocal)); + fprintf(log,"Can't read file: %s\n",buf); fclose(f_errors); return ENE_READ_ERROR; } @@ -3924,8 +3888,7 @@ espeak_ng_STATUS CompileIntonation(FILE *log) fclose(f_in); fclose(f_out); - report.Printf(_T("Compiled %d intonation tunes: %d errors."),n_tune_names, error_count); - wxLogStatus(report); + fprintf(log,"Compiled %d intonation tunes: %d errors.\n",n_tune_names, error_count); LoadPhData(NULL); @@ -3934,28 +3897,9 @@ espeak_ng_STATUS CompileIntonation(FILE *log) -void CompilePhonemeData() +void CompilePhonemeData(long rate, FILE *log) { - WavegenInit(22050, 0); + WavegenInit(rate, 0); WavegenSetVoice(voice); - CompilePhonemeData2("phonemes"); + CompilePhonemeData2("phonemes", log); } - - -void CompileSampleRate() -{ - long value; -#ifndef PLATFORM_POSIX - wxLogError(_T("Change Sample Rate needs the 'sox' program. It probably doesn't work on Windows")); -#endif - - value = wxGetNumberFromUser(_T("Compile phoneme data with a specified sample rate"), _T("Sample rate"), _T("Resample (needs 'sox' program)"), 22050, 5000, 48000); - - if(value > 1000) - { - WavegenInit(value, 0); - WavegenSetVoice(voice); - CompilePhonemeData2("phonemes"); - } -} - diff --git a/src/espeakedit.cpp b/src/espeakedit.cpp index eebd9cb2..18264c70 100644 --- a/src/espeakedit.cpp +++ b/src/espeakedit.cpp @@ -41,8 +41,7 @@ static const char *about_string = "espeakedit %s
Author: "http://espeak.sourceforge.net
" "Licensed under GNU General Public License version 3
"; -extern void CompilePhonemeData(void); -extern void CompileSampleRate(void); +extern void CompilePhonemeData(long rate, FILE *log); extern espeak_ng_STATUS CompileIntonation(FILE *log); int progress_max; @@ -122,7 +121,7 @@ else fprintf(stderr, "Failed to load default voice\n"); exit(1); } - CompilePhonemeData(); + CompilePhonemeData(22050, stderr); CompileIntonation(stderr); } exit(0); diff --git a/src/spect.cpp b/src/spect.cpp index 365ed1dc..078bd821 100644 --- a/src/spect.cpp +++ b/src/spect.cpp @@ -27,6 +27,7 @@ #include "synthesize.h" #include "voice.h" #include "spect.h" +#include "wx/wfstream.h" #include "wx/txtstrm.h" #include "wx/datstrm.h" @@ -252,6 +253,7 @@ SpectSeq *SpectSeqCreate() spect->numframes = 0; spect->frames = NULL; + spect->name = NULL; pk_select = 1; spect->grid = 1; @@ -279,6 +281,7 @@ void SpectSeqDestroy(SpectSeq *spect) } delete spect->frames; } + free(spect->name); delete spect; } @@ -300,7 +303,7 @@ static float GetFrameLength(SpectSeq &spect, int frame) -int LoadSpectSeq(SpectSeq *spect, wxInputStream & stream) +int LoadSpectSeq(SpectSeq *spect, const char *filename) {//======================================= int n; int ix; @@ -308,6 +311,13 @@ int LoadSpectSeq(SpectSeq *spect, wxInputStream & stream) int set_max_y=0; float time_offset; + wxFileInputStream stream(filename); + if(stream.Ok() == FALSE) + { + fprintf(stderr, "Failed to open: '%s'", filename); + return(0); + } + wxDataInputStream s(stream); id1 = s.Read32(); @@ -333,12 +343,15 @@ int LoadSpectSeq(SpectSeq *spect, wxInputStream & stream) return(1); } - spect->name = s.ReadString(); + wxString name = s.ReadString(); n = s.Read16(); spect->amplitude = s.Read16(); spect->max_y = s.Read16(); s.Read16(); + free(spect->name); + spect->name = strdup(name.mb_str(wxConvLocal)); + if(n==0) return(0); if(spect->frames != NULL) diff --git a/src/spect.h b/src/spect.h index b3df8b0b..5a956dbd 100644 --- a/src/spect.h +++ b/src/spect.h @@ -114,7 +114,7 @@ struct SpectSeq int numframes; int amplitude; int spare; - wxString name; + char *name; SpectFrame **frames; PitchEnvelope pitchenv; @@ -130,4 +130,4 @@ struct SpectSeq SpectSeq *SpectSeqCreate(); void SpectSeqDestroy(SpectSeq *spect); -int LoadSpectSeq(SpectSeq *spect, wxInputStream& stream); +int LoadSpectSeq(SpectSeq *spect, const char *filename);