From 0ad59a7f55f0a8a797d60b8892f0d2f0f1a40dc0 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Tue, 22 Dec 2015 10:08:51 +0000 Subject: [PATCH 1/4] Support converting the markdown-based documentation to HTML. --- .gitignore | 3 ++- Makefile.am | 13 ++++++++--- README.md | 35 ++++++++++++++++++++++------ _layouts/webpage.html | 54 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 _layouts/webpage.html diff --git a/.gitignore b/.gitignore index 757d4cb5..2591834b 100644 --- a/.gitignore +++ b/.gitignore @@ -41,8 +41,9 @@ libespeak-ng.a libespeak-ng.la libespeak-ng.so* -# programs +# build output +*.html *.exe src/espeak-ng diff --git a/Makefile.am b/Makefile.am index 3b9b621b..cb9a87d5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,15 +50,22 @@ distclean-local: rm -rf espeak-data/phondata-manifest rm -f espeak-data/*_dict +##### documentation: + +%.html: %.md _layouts/webpage.html + cat $< | sed -e 's/\.md)/.html)/g' | kramdown --template _layouts/webpage.html > $@ + +docs: README.html + +docs/speak_lib.h: src/include/espeak-ng/speak_lib.h + cp $< $@ + ##### build targets: libespeak_ng_includedir = $(includedir)/espeak-ng libespeak_ng_include_HEADERS = \ src/include/espeak-ng/speak_lib.h -docs/speak_lib.h: src/include/espeak-ng/speak_lib.h - cp $< $@ - lib_LTLIBRARIES += src/libespeak-ng.la src_libespeak_ng_la_LDFLAGS = -version-info $(SHARED_VERSION) -lpthread -lm diff --git a/README.md b/README.md index 12529f35..287c7f64 100644 --- a/README.md +++ b/README.md @@ -39,22 +39,39 @@ Optionally, you need: 2. the portaudio development library to enable portaudio output; 3. the sonic development library to enable sonic audio speed up support. +To build the documentation, you need: + +1. the `kramdown` markdown processor. + ### Debian +Core dependencies: + | Dependency | Install | |---------------|------------------------------------------------------------------| | autotools | `sudo apt-get install make autoconf automake libtool pkg-config` | | c11 compiler | `sudo apt-get install gcc` | -| pulseaudio | `sudo apt-get install libpulse-dev` | -| portaudio | `sudo apt-get install libportaudio-dev` | -| sonic | `sudo apt-get install libsonic-dev` | + +Optional dependencies: + +| Dependency | Install | +|------------|-----------------------------------------| +| pulseaudio | `sudo apt-get install libpulse-dev` | +| portaudio | `sudo apt-get install libportaudio-dev` | +| sonic | `sudo apt-get install libsonic-dev` | + +Documentation dependencies: + +| Dependency | Install | +|---------------|--------------------------------------| +| kramdown | `sudo apt-get install ruby-kramdown` | Cross-compiling for windows: -| Dependency | Install | -|-------------------------|--------------------------------------------------------| -| 32-bit Windows compiler | `sudo apt-get install mingw-w64-i686-dev` | -| 64-bit Windows compiler | `sudo apt-get install mingw-w64-x86-64-dev` | +| Dependency | Install | +|-------------------------|---------------------------------------------| +| 32-bit Windows compiler | `sudo apt-get install mingw-w64-i686-dev` | +| 64-bit Windows compiler | `sudo apt-get install mingw-w64-x86-64-dev` | ## Building @@ -65,6 +82,10 @@ be built via the standard autotools commands: $ ./configure --prefix=/usr $ make +The documentation can be built by running: + + make doc + ### Audio Output Configuration The following `configure` options control which audio interfaces to use: diff --git a/_layouts/webpage.html b/_layouts/webpage.html new file mode 100644 index 00000000..bf4677b0 --- /dev/null +++ b/_layouts/webpage.html @@ -0,0 +1,54 @@ + + + + + + + + + +<%= @body %> + + From a60f7ae56c8e0a338e6723cf77fc33a89413125f Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Tue, 22 Dec 2015 10:10:44 +0000 Subject: [PATCH 2/4] Don't use '$ ' at the start of build commands in the documentation. --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 287c7f64..70a2767a 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,9 @@ Cross-compiling for windows: The `espeak-ng` and `speak-ng` programs, along with the espeak-ng voices, can be built via the standard autotools commands: - $ ./autogen.sh - $ ./configure --prefix=/usr - $ make + ./autogen.sh + ./configure --prefix=/usr + make The documentation can be built by running: @@ -155,7 +155,7 @@ __NOTE:__ This currently fails to build `espeak-ng.exe`, but does build Before installing, you can test the built espeak-ng using the following command: - $ ESPEAK_DATA_PATH=`pwd` LD_LIBRARY_PATH=src:${LD_LIBRARY_PATH} src/espeak-ng ... + ESPEAK_DATA_PATH=`pwd` LD_LIBRARY_PATH=src:${LD_LIBRARY_PATH} src/espeak-ng ... The `ESPEAK_DATA_PATH` variable needs to be set to use the espeak-ng data from the source tree. Otherwise, espeak-ng will look in `$(HOME)` or @@ -170,7 +170,7 @@ version). You can install eSpeak NG by running the following command: - $ sudo make LIBDIR=/usr/lib/x86_64-linux-gnu install + sudo make LIBDIR=/usr/lib/x86_64-linux-gnu install The `LIBDIR` path may be different to the one on your system (the above is for 64-bit Debian/Ubuntu releases that use the multi-arch package @@ -179,19 +179,19 @@ structure -- that is, Debian Wheezy or later). You can find out where espeak-ng is installed to on your system if you already have an espeak-ng install by running: - $ find /usr/lib | grep libespeak-ng + find /usr/lib | grep libespeak-ng ## Building Voices If you are modifying a language's phoneme, voice or dictionary files, you can just build that voice by running: - $ make + make For example, if you add entries in the `dictsource/en_extra` file, you can run: - $ make en + make en to build an English voice file with those changes in without rebuilding all the voices. This will make it easier to spot errors. @@ -227,7 +227,7 @@ These early releases have been checked into the historical branch, with the 1.24.02 release as the last entry. This makes it possible to use the replace functionality of git to see the earlier history: - $ git replace 8d59235f 63c1c019 + git replace 8d59235f 63c1c019 __NOTE:__ The source releases contain the `big_endian`, `espeak-edit`, `praat-mod`, `riskos`, `windows_dll` and `windows_sapi` folders. These From 12e0bb122b05d18402d8ff9773585b7bea8378b9 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Tue, 22 Dec 2015 15:06:50 +0000 Subject: [PATCH 3/4] Reformat the code using the uncrustify program. --- src/espeak-ng.c | 437 +++--- src/libespeak-ng/compiledata.c | 2192 +++++++++++++---------------- src/libespeak-ng/compiledict.c | 1228 +++++++--------- src/libespeak-ng/compilembrola.c | 48 +- src/libespeak-ng/debug.c | 32 +- src/libespeak-ng/debug.h | 10 +- src/libespeak-ng/dictionary.c | 2096 +++++++++++---------------- src/libespeak-ng/espeak_command.c | 358 ++--- src/libespeak-ng/espeak_command.h | 82 +- src/libespeak-ng/event.c | 336 ++--- src/libespeak-ng/event.h | 6 +- src/libespeak-ng/fifo.c | 239 ++-- src/libespeak-ng/fifo.h | 8 +- src/libespeak-ng/intonation.c | 614 ++++---- src/libespeak-ng/klatt.c | 441 +++--- src/libespeak-ng/klatt.h | 11 +- src/libespeak-ng/mbrowrap.c | 4 +- src/libespeak-ng/numbers.c | 1646 +++++++++------------- src/libespeak-ng/phoneme.h | 6 +- src/libespeak-ng/phonemelist.c | 347 ++--- src/libespeak-ng/readclause.c | 2030 +++++++++++--------------- src/libespeak-ng/setlengths.c | 449 +++--- src/libespeak-ng/speak_lib.c | 527 +++---- src/libespeak-ng/spect.c | 241 ++-- src/libespeak-ng/spect.h | 6 +- src/libespeak-ng/speech.h | 2 +- src/libespeak-ng/synth_mbrola.c | 352 ++--- src/libespeak-ng/synthdata.c | 673 ++++----- src/libespeak-ng/synthesize.c | 1024 ++++++-------- src/libespeak-ng/synthesize.h | 6 +- src/libespeak-ng/tr_languages.c | 978 ++++++------- src/libespeak-ng/translate.c | 1996 ++++++++++---------------- src/libespeak-ng/translate.h | 15 +- src/libespeak-ng/voices.c | 1086 ++++++-------- src/libespeak-ng/wave.c | 559 ++++---- src/libespeak-ng/wave.h | 18 +- src/libespeak-ng/wave_pulse.c | 143 +- src/libespeak-ng/wave_sada.c | 84 +- src/libespeak-ng/wavegen.c | 803 +++++------ src/speak-ng.c | 466 +++--- 40 files changed, 8895 insertions(+), 12704 deletions(-) diff --git a/src/espeak-ng.c b/src/espeak-ng.c index 218afd07..c54c5d5b 100644 --- a/src/espeak-ng.c +++ b/src/espeak-ng.c @@ -31,7 +31,7 @@ #include "speak_lib.h" #include "espeak_ng.h" -extern void strncpy0(char *to,const char *from, int size); +extern void strncpy0(char *to, const char *from, int size); extern int utf8_in(int *c, const char *buf); extern int GetFileLength(const char *filename); @@ -132,59 +132,50 @@ void DisplayVoices(FILE *f_out, char *language) const espeak_VOICE **voices; espeak_VOICE voice_select; - static char genders[4] = {'-','M','F','-'}; + static char genders[4] = { '-', 'M', 'F', '-' }; - if((language != NULL) && (language[0] != 0)) - { + if ((language != NULL) && (language[0] != 0)) { // display only voices for the specified language, in order of priority voice_select.languages = language; voice_select.age = 0; voice_select.gender = 0; voice_select.name = NULL; voices = espeak_ListVoices(&voice_select); - } - else - { + } else { voices = espeak_ListVoices(NULL); } - fprintf(f_out,"Pty Language Age/Gender VoiceName File Other Languages\n"); + fprintf(f_out, "Pty Language Age/Gender VoiceName File Other Languages\n"); - for(ix=0; (v = voices[ix]) != NULL; ix++) - { + for (ix = 0; (v = voices[ix]) != NULL; ix++) { count = 0; p = v->languages; - while(*p != 0) - { + while (*p != 0) { len = strlen(p+1); lang_name = p+1; - if(v->age == 0) - strcpy(age_buf," "); + if (v->age == 0) + strcpy(age_buf, " "); else - sprintf(age_buf,"%3d",v->age); + sprintf(age_buf, "%3d", v->age); - if(count==0) - { - for(j=0; j < sizeof(buf); j++) - { + if (count == 0) { + for (j = 0; j < sizeof(buf); j++) { // replace spaces in the name - if((c = v->name[j]) == ' ') + if ((c = v->name[j]) == ' ') c = '_'; - if((buf[j] = c) == 0) + if ((buf[j] = c) == 0) break; } - fprintf(f_out,"%2d %-12s%s%c %-20s %-13s ", - p[0],lang_name,age_buf,genders[v->gender],buf,v->identifier); - } - else - { - fprintf(f_out,"(%s %d)",lang_name,p[0]); + fprintf(f_out, "%2d %-12s%s%c %-20s %-13s ", + p[0], lang_name, age_buf, genders[v->gender], buf, v->identifier); + } else { + fprintf(f_out, "(%s %d)", lang_name, p[0]); } count++; p += len+2; } - fputc('\n',f_out); + fputc('\n', f_out); } } @@ -196,9 +187,8 @@ static void Write4Bytes(FILE *f, int value) // Write 4 bytes to a file, least significant first int ix; - for(ix=0; ix<4; ix++) - { - fputc(value & 0xff,f); + for (ix = 0; ix < 4; ix++) { + fputc(value & 0xff, f); value = value >> 8; } } @@ -208,37 +198,35 @@ static void Write4Bytes(FILE *f, int value) int OpenWavFile(char *path, int rate) { static unsigned char wave_hdr[44] = { - 'R','I','F','F',0x24,0xf0,0xff,0x7f,'W','A','V','E','f','m','t',' ', - 0x10,0,0,0,1,0,1,0, 9,0x3d,0,0,0x12,0x7a,0,0, - 2,0,0x10,0,'d','a','t','a', 0x00,0xf0,0xff,0x7f + 'R', 'I', 'F', 'F', 0x24, 0xf0, 0xff, 0x7f, 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ', + 0x10, 0, 0, 0, 1, 0, 1, 0, 9, 0x3d, 0, 0, 0x12, 0x7a, 0, 0, + 2, 0, 0x10, 0, 'd', 'a', 't', 'a', 0x00, 0xf0, 0xff, 0x7f }; - if(path == NULL) - return(2); + if (path == NULL) + return (2); - while(isspace(*path)) path++; + while (isspace(*path)) path++; f_wavfile = NULL; - if(path[0] != 0) - { - if(strcmp(path,"stdout")==0) + if (path[0] != 0) { + if (strcmp(path, "stdout") == 0) f_wavfile = stdout; else - f_wavfile = fopen(path,"wb"); + f_wavfile = fopen(path, "wb"); } - if(f_wavfile == NULL) - { - fprintf(stderr,"Can't write to: '%s'\n",path); - return(1); + if (f_wavfile == NULL) { + fprintf(stderr, "Can't write to: '%s'\n", path); + return (1); } - fwrite(wave_hdr,1,24,f_wavfile); - Write4Bytes(f_wavfile,rate); - Write4Bytes(f_wavfile,rate * 2); - fwrite(&wave_hdr[32],1,12,f_wavfile); - return(0); + fwrite(wave_hdr, 1, 24, f_wavfile); + Write4Bytes(f_wavfile, rate); + Write4Bytes(f_wavfile, rate * 2); + fwrite(&wave_hdr[32], 1, 12, f_wavfile); + return (0); } @@ -247,17 +235,17 @@ static void CloseWavFile() { unsigned int pos; - if((f_wavfile==NULL) || (f_wavfile == stdout)) + if ((f_wavfile == NULL) || (f_wavfile == stdout)) return; fflush(f_wavfile); pos = ftell(f_wavfile); - fseek(f_wavfile,4,SEEK_SET); - Write4Bytes(f_wavfile,pos - 8); + fseek(f_wavfile, 4, SEEK_SET); + Write4Bytes(f_wavfile, pos - 8); - fseek(f_wavfile,40,SEEK_SET); - Write4Bytes(f_wavfile,pos - 44); + fseek(f_wavfile, 40, SEEK_SET); + Write4Bytes(f_wavfile, pos - 44); fclose(f_wavfile); f_wavfile = NULL; @@ -269,27 +257,20 @@ static int SynthCallback(short *wav, int numsamples, espeak_EVENT *events) { char fname[210]; - if(quiet) return(0); // -q quiet mode + if (quiet) return (0); // -q quiet mode - if(wav == NULL) - { + if (wav == NULL) { CloseWavFile(); - return(0); + return (0); } - while(events->type != 0) - { - if(events->type == espeakEVENT_SAMPLERATE) - { + while (events->type != 0) { + if (events->type == espeakEVENT_SAMPLERATE) { samplerate = events->id.number; samples_split = samples_split_seconds * samplerate; - } - else - if(events->type == espeakEVENT_SENTENCE) - { + } else if (events->type == espeakEVENT_SENTENCE) { // start a new WAV file when the limit is reached, at this sentence boundary - if((samples_split > 0) && (samples_total > samples_split)) - { + if ((samples_split > 0) && (samples_total > samples_split)) { CloseWavFile(); samples_total = 0; wavefile_count++; @@ -298,27 +279,22 @@ static int SynthCallback(short *wav, int numsamples, espeak_EVENT *events) events++; } - if(f_wavfile == NULL) - { - if(samples_split > 0) - { - sprintf(fname,"%s_%.2d%s",wavefile,wavefile_count+1,filetype); - if(OpenWavFile(fname, samplerate) != 0) - return(1); - } - else - { - if(OpenWavFile(wavefile, samplerate) != 0) - return(1); + if (f_wavfile == NULL) { + if (samples_split > 0) { + sprintf(fname, "%s_%.2d%s", wavefile, wavefile_count+1, filetype); + if (OpenWavFile(fname, samplerate) != 0) + return (1); + } else { + if (OpenWavFile(wavefile, samplerate) != 0) + return (1); } } - if(numsamples > 0) - { + if (numsamples > 0) { samples_total += numsamples; - fwrite(wav,numsamples*2,1,f_wavfile); + fwrite(wav, numsamples*2, 1, f_wavfile); } - return(0); + return (0); } @@ -343,42 +319,41 @@ struct option { int optind; static int optional_argument; static const char *arg_opts = "abfgklpsvw"; // which options have arguments -static char *opt_string=""; +static char *opt_string = ""; #define no_argument 0 #define required_argument 1 #define optional_argument 2 #endif -int main (int argc, char **argv) +int main(int argc, char **argv) { - static struct option long_options[] = - { - {"help", no_argument, 0, 'h'}, - {"stdin", no_argument, 0, 0x100}, - {"compile-debug", optional_argument, 0, 0x101}, - {"compile", optional_argument, 0, 0x102}, - {"punct", optional_argument, 0, 0x103}, - {"voices", optional_argument, 0, 0x104}, - {"stdout", no_argument, 0, 0x105}, - {"split", optional_argument, 0, 0x106}, - {"path", required_argument, 0, 0x107}, - {"phonout", required_argument, 0, 0x108}, - {"pho", no_argument, 0, 0x109}, - {"ipa", optional_argument, 0, 0x10a}, - {"version", no_argument, 0, 0x10b}, - {"sep", optional_argument, 0, 0x10c}, - {"tie", optional_argument, 0, 0x10d}, - {"compile-mbrola", optional_argument, 0, 0x10e}, - {"compile-intonations", no_argument, 0, 0x10f}, - {"compile-phonemes", no_argument, 0, 0x110}, - {0, 0, 0, 0} + static struct option long_options[] = { + { "help", no_argument, 0, 'h' }, + { "stdin", no_argument, 0, 0x100 }, + { "compile-debug", optional_argument, 0, 0x101 }, + { "compile", optional_argument, 0, 0x102 }, + { "punct", optional_argument, 0, 0x103 }, + { "voices", optional_argument, 0, 0x104 }, + { "stdout", no_argument, 0, 0x105 }, + { "split", optional_argument, 0, 0x106 }, + { "path", required_argument, 0, 0x107 }, + { "phonout", required_argument, 0, 0x108 }, + { "pho", no_argument, 0, 0x109 }, + { "ipa", optional_argument, 0, 0x10a }, + { "version", no_argument, 0, 0x10b }, + { "sep", optional_argument, 0, 0x10c }, + { "tie", optional_argument, 0, 0x10d }, + { "compile-mbrola", optional_argument, 0, 0x10e }, + { "compile-intonations", no_argument, 0, 0x10f }, + { "compile-phonemes", no_argument, 0, 0x110 }, + { 0, 0, 0, 0 } }; - static const char* err_load = "Failed to read "; + static const char *err_load = "Failed to read "; - FILE *f_text=NULL; - char *p_text=NULL; + FILE *f_text = NULL; + char *p_text = NULL; FILE *f_phonemes_out = stdout; char *data_path = NULL; // use default path for espeak-data @@ -417,15 +392,13 @@ int main (int argc, char **argv) #ifdef NEED_GETOPT optind = 1; opt_string = ""; - while(optind < argc) - { + while (optind < argc) { int len; char *p; - if((c = *opt_string) == 0) - { + if ((c = *opt_string) == 0) { opt_string = argv[optind]; - if(opt_string[0] != '-') + if (opt_string[0] != '-') break; optind++; @@ -435,45 +408,36 @@ int main (int argc, char **argv) opt_string++; p = optarg2 = opt_string; - if(c == '-') - { - if(p[0] == 0) + if (c == '-') { + if (p[0] == 0) break; // -- means don't interpret further - as commands - opt_string=""; - for(ix=0;; ix++) - { - if(long_options[ix].name == 0) + opt_string = ""; + for (ix = 0;; ix++) { + if (long_options[ix].name == 0) break; len = strlen(long_options[ix].name); - if(memcmp(long_options[ix].name,p,len)==0) - { + if (memcmp(long_options[ix].name, p, len) == 0) { c = long_options[ix].val; optarg2 = NULL; - if((long_options[ix].has_arg != 0) && (p[len]=='=')) - { + if ((long_options[ix].has_arg != 0) && (p[len] == '=')) { optarg2 = &p[len+1]; } break; } } - } - else - if(strchr(arg_opts,c) != NULL) - { - opt_string=""; - if(optarg2[0]==0) - { + } else if (strchr(arg_opts, c) != NULL) { + opt_string = ""; + if (optarg2[0] == 0) { // the option's value is in the next argument optarg2 = argv[optind++]; } } #else - while(true) - { - c = getopt_long (argc, argv, "a:b:f:g:hk:l:mp:qs:v:w:xXz", - long_options, &option_index); + while (true) { + c = getopt_long(argc, argv, "a:b:f:g:hk:l:mp:qs:v:w:xXz", + long_options, &option_index); /* Detect the end of the options. */ if (c == -1) @@ -485,7 +449,7 @@ int main (int argc, char **argv) { case 'b': // input character encoding, 8bit, 16bit, UTF8 - if((sscanf(optarg2,"%d",&value) == 1) && (value <= 4)) + if ((sscanf(optarg2, "%d", &value) == 1) && (value <= 4)) synth_flags |= value; else synth_flags |= espeakCHARS_8BIT; @@ -523,7 +487,7 @@ int main (int argc, char **argv) break; case 'f': - strncpy0(filename,optarg2,sizeof(filename)); + strncpy0(filename, optarg2, sizeof(filename)); break; case 'l': @@ -543,12 +507,12 @@ int main (int argc, char **argv) break; case 'v': - strncpy0(voicename,optarg2,sizeof(voicename)); + strncpy0(voicename, optarg2, sizeof(voicename)); break; case 'w': option_waveout = 1; - strncpy0(wavefile,optarg2,sizeof(filename)); + strncpy0(wavefile, optarg2, sizeof(filename)); break; case 'z': // remove pause from the end of a sentence @@ -561,34 +525,33 @@ int main (int argc, char **argv) case 0x105: // --stdout option_waveout = 1; - strcpy(wavefile,"stdout"); + strcpy(wavefile, "stdout"); break; case 0x101: // --compile-debug case 0x102: // --compile - strncpy0(voicename,optarg2,sizeof(voicename)); + strncpy0(voicename, optarg2, sizeof(voicename)); flag_compile = c; quiet = 1; break; case 0x103: // --punct option_punctuation = 1; - if(optarg2 != NULL) - { + if (optarg2 != NULL) { ix = 0; - while((ix < N_PUNCTLIST) && ((option_punctlist[ix] = optarg2[ix]) != 0)) ix++; + while ((ix < N_PUNCTLIST) && ((option_punctlist[ix] = optarg2[ix]) != 0)) ix++; option_punctlist[N_PUNCTLIST-1] = 0; option_punctuation = 2; } break; case 0x104: // --voices - espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,0,data_path,0); - DisplayVoices(stdout,optarg2); + espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, data_path, 0); + DisplayVoices(stdout, optarg2); exit(0); case 0x106: // -- split - if(optarg2 == NULL) + if (optarg2 == NULL) samples_split_seconds = 30 * 60; // default 30 minutes else samples_split_seconds = atoi(optarg2) * 60; @@ -599,9 +562,8 @@ int main (int argc, char **argv) break; case 0x108: // --phonout - if((f_phonemes_out = fopen(optarg2,"w")) == NULL) - { - fprintf(stderr,"Can't write to: %s\n",optarg2); + if ((f_phonemes_out = fopen(optarg2, "w")) == NULL) { + fprintf(stderr, "Can't write to: %s\n", optarg2); } break; @@ -611,10 +573,9 @@ int main (int argc, char **argv) case 0x10a: // --ipa phoneme_options |= espeakPHONEMES_IPA; - if(optarg2 != NULL) - { + if (optarg2 != NULL) { // deprecated and obsolete - switch(atoi(optarg2)) + switch (atoi(optarg2)) { case 1: phonemes_separator = '_'; @@ -638,36 +599,36 @@ int main (int argc, char **argv) case 0x10c: // --sep phoneme_options |= espeakPHONEMES_SHOW; - if(optarg2 == 0) + if (optarg2 == 0) phonemes_separator = ' '; else utf8_in(&phonemes_separator, optarg2); - if(phonemes_separator == 'z') + if (phonemes_separator == 'z') phonemes_separator = 0x200c; // ZWNJ break; case 0x10d: // --tie phoneme_options |= (espeakPHONEMES_SHOW | espeakPHONEMES_TIE); - if(optarg2 == 0) + if (optarg2 == 0) phonemes_separator = 0x0361; // default: combining-double-inverted-breve else utf8_in(&phonemes_separator, optarg2); - if(phonemes_separator == 'z') + if (phonemes_separator == 'z') phonemes_separator = 0x200d; // ZWJ break; case 0x10e: // --compile-mbrola - samplerate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK,0,data_path,0); + samplerate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, data_path, 0); espeak_ng_CompileMbrolaVoice(optarg2, stdout); exit(0); case 0x10f: // --compile-intonations - samplerate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK,0,data_path,espeakINITIALIZE_PATH_ONLY); + samplerate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, data_path, espeakINITIALIZE_PATH_ONLY); espeak_ng_CompileIntonation(stdout); exit(0); case 0x110: // --compile-phonemes - samplerate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK,0,data_path,espeakINITIALIZE_PATH_ONLY); + samplerate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, data_path, espeakINITIALIZE_PATH_ONLY); espeak_ng_CompilePhonemeData(22050, stdout); exit(0); @@ -677,167 +638,135 @@ int main (int argc, char **argv) } - if(option_waveout || quiet) - { + if (option_waveout || quiet) { // writing to a file (or no output), we can use synchronous mode - samplerate = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,0,data_path,0); + samplerate = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, data_path, 0); samples_split = samplerate * samples_split_seconds; espeak_SetSynthCallback(SynthCallback); - if(samples_split) - { + if (samples_split) { char *extn; - extn = strrchr(wavefile,'.'); - if((extn != NULL) && ((wavefile + strlen(wavefile) - extn) <= 4)) - { - strcpy(filetype,extn); + extn = strrchr(wavefile, '.'); + if ((extn != NULL) && ((wavefile + strlen(wavefile) - extn) <= 4)) { + strcpy(filetype, extn); *extn = 0; } } - } - else - { + } else { // play the sound output - samplerate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK,0,data_path,0); + samplerate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, data_path, 0); } - if(voicename[0] == 0) - strcpy(voicename,"default"); + if (voicename[0] == 0) + strcpy(voicename, "default"); - if(espeak_SetVoiceByName(voicename) != EE_OK) - { - memset(&voice_select,0,sizeof(voice_select)); + if (espeak_SetVoiceByName(voicename) != EE_OK) { + memset(&voice_select, 0, sizeof(voice_select)); voice_select.languages = voicename; - if(espeak_SetVoiceByProperties(&voice_select) != EE_OK) - { - fprintf(stderr,"%svoice '%s'\n",err_load,voicename); + if (espeak_SetVoiceByProperties(&voice_select) != EE_OK) { + fprintf(stderr, "%svoice '%s'\n", err_load, voicename); exit(2); } } - if(flag_compile) - { + if (flag_compile) { // This must be done after the voice is set espeak_CompileDictionary("", stderr, flag_compile & 0x1); exit(0); } // set any non-default values of parameters. This must be done after espeak_Initialize() - if(speed > 0) - espeak_SetParameter(espeakRATE,speed,0); - if(volume >= 0) - espeak_SetParameter(espeakVOLUME,volume,0); - if(pitch >= 0) - espeak_SetParameter(espeakPITCH,pitch,0); - if(option_capitals >= 0) - espeak_SetParameter(espeakCAPITALS,option_capitals,0); - if(option_punctuation >= 0) - espeak_SetParameter(espeakPUNCTUATION,option_punctuation,0); - if(wordgap >= 0) - espeak_SetParameter(espeakWORDGAP,wordgap,0); - if(option_linelength > 0) - espeak_SetParameter(espeakLINELENGTH,option_linelength,0); - if(option_punctuation == 2) + if (speed > 0) + espeak_SetParameter(espeakRATE, speed, 0); + if (volume >= 0) + espeak_SetParameter(espeakVOLUME, volume, 0); + if (pitch >= 0) + espeak_SetParameter(espeakPITCH, pitch, 0); + if (option_capitals >= 0) + espeak_SetParameter(espeakCAPITALS, option_capitals, 0); + if (option_punctuation >= 0) + espeak_SetParameter(espeakPUNCTUATION, option_punctuation, 0); + if (wordgap >= 0) + espeak_SetParameter(espeakWORDGAP, wordgap, 0); + if (option_linelength > 0) + espeak_SetParameter(espeakLINELENGTH, option_linelength, 0); + if (option_punctuation == 2) espeak_SetPunctuationList(option_punctlist); espeak_SetPhonemeTrace(phoneme_options | (phonemes_separator << 8), f_phonemes_out); - if(filename[0]==0) - { - if((optind < argc) && (flag_stdin == 0)) - { + if (filename[0] == 0) { + if ((optind < argc) && (flag_stdin == 0)) { // there's a non-option parameter, and no -f or --stdin // use it as text p_text = argv[optind]; - } - else - { + } else { f_text = stdin; - if(flag_stdin == 0) - { + if (flag_stdin == 0) { flag_stdin = 2; } } - } - else - { + } else { filesize = GetFileLength(filename); - f_text = fopen(filename,"r"); + f_text = fopen(filename, "r"); } - if((f_text == NULL) && (p_text == NULL)) - { - fprintf(stderr,"%sfile '%s'\n",err_load,filename); + if ((f_text == NULL) && (p_text == NULL)) { + fprintf(stderr, "%sfile '%s'\n", err_load, filename); exit(1); } - if(p_text != NULL) - { + if (p_text != NULL) { int size; size = strlen(p_text); - espeak_Synth(p_text,size+1,0,POS_CHARACTER,0,synth_flags,NULL,NULL); - } - else - if(flag_stdin) - { + espeak_Synth(p_text, size+1, 0, POS_CHARACTER, 0, synth_flags, NULL, NULL); + } else if (flag_stdin) { int max = 1000; p_text = (char *)malloc(max); - if(flag_stdin == 2) - { + if (flag_stdin == 2) { // line by line input on stdin - while(fgets(p_text,max,stdin) != NULL) - { + while (fgets(p_text, max, stdin) != NULL) { p_text[max-1] = 0; - espeak_Synth(p_text,max,0,POS_CHARACTER,0,synth_flags,NULL,NULL); + espeak_Synth(p_text, max, 0, POS_CHARACTER, 0, synth_flags, NULL, NULL); } - } - else - { + } else { // bulk input on stdin ix = 0; - while(!feof(stdin)) - { + while (!feof(stdin)) { p_text[ix++] = fgetc(stdin); - if(ix >= (max-1)) - { + if (ix >= (max-1)) { max += 1000; - p_text = (char *)realloc(p_text,max); + p_text = (char *)realloc(p_text, max); } } - if(ix > 0) - { + if (ix > 0) { p_text[ix-1] = 0; - espeak_Synth(p_text,ix+1,0,POS_CHARACTER,0,synth_flags,NULL,NULL); + espeak_Synth(p_text, ix+1, 0, POS_CHARACTER, 0, synth_flags, NULL, NULL); } } - } - else - if(f_text != NULL) - { - if((p_text = (char *)malloc(filesize+1)) == NULL) - { - fprintf(stderr,"Failed to allocate memory %d bytes",filesize); + } else if (f_text != NULL) { + if ((p_text = (char *)malloc(filesize+1)) == NULL) { + fprintf(stderr, "Failed to allocate memory %d bytes", filesize); exit(3); } - fread(p_text,1,filesize,f_text); - p_text[filesize]=0; - espeak_Synth(p_text,filesize+1,0,POS_CHARACTER,0,synth_flags,NULL,NULL); + fread(p_text, 1, filesize, f_text); + p_text[filesize] = 0; + espeak_Synth(p_text, filesize+1, 0, POS_CHARACTER, 0, synth_flags, NULL, NULL); fclose(f_text); } - if(espeak_Synchronize() != EE_OK) - { + if (espeak_Synchronize() != EE_OK) { fprintf(stderr, "espeak_Synchronize() failed, maybe error when opening output device\n"); exit(4); } - if(f_phonemes_out != stdout) + if (f_phonemes_out != stdout) fclose(f_phonemes_out); // needed for WinCE - return(0); + return (0); } diff --git a/src/libespeak-ng/compiledata.c b/src/libespeak-ng/compiledata.c index 945086bb..acc95d38 100644 --- a/src/libespeak-ng/compiledata.c +++ b/src/libespeak-ng/compiledata.c @@ -79,70 +79,70 @@ enum { }; static keywtab_t k_conditions[] = { - {"AND", 0, k_AND}, - {"OR", 0, k_OR}, - {"THEN", 0, k_THEN}, - {"NOT", 0, k_NOT}, - {"prevPh", tWHICH_PHONEME, 0}, - {"prevPhW", tWHICH_PHONEME, 5}, - {"thisPh", tWHICH_PHONEME, 1}, - {"nextPh", tWHICH_PHONEME, 2}, - {"next2Ph", tWHICH_PHONEME, 3}, - {"nextPhW", tWHICH_PHONEME, 4}, - {"next2PhW", tWHICH_PHONEME, 6}, - {"nextVowel",tWHICH_PHONEME, 7}, - {"prevVowel",tWHICH_PHONEME, 8}, - {"next3PhW", tWHICH_PHONEME, 9}, - {"prev2PhW", tWHICH_PHONEME, 10}, + { "AND", 0, k_AND }, + { "OR", 0, k_OR }, + { "THEN", 0, k_THEN }, + { "NOT", 0, k_NOT }, + { "prevPh", tWHICH_PHONEME, 0 }, + { "prevPhW", tWHICH_PHONEME, 5 }, + { "thisPh", tWHICH_PHONEME, 1 }, + { "nextPh", tWHICH_PHONEME, 2 }, + { "next2Ph", tWHICH_PHONEME, 3 }, + { "nextPhW", tWHICH_PHONEME, 4 }, + { "next2PhW", tWHICH_PHONEME, 6 }, + { "nextVowel", tWHICH_PHONEME, 7 }, + { "prevVowel", tWHICH_PHONEME, 8 }, + { "next3PhW", tWHICH_PHONEME, 9 }, + { "prev2PhW", tWHICH_PHONEME, 10 }, - {"PreVoicing", tTEST, 0xf01}, - {"KlattSynth", tTEST, 0xf02}, - {"MbrolaSynth", tTEST, 0xf03}, - {NULL, 0, 0} + { "PreVoicing", tTEST, 0xf01 }, + { "KlattSynth", tTEST, 0xf02 }, + { "MbrolaSynth", tTEST, 0xf03 }, + { NULL, 0, 0 } }; static keywtab_t k_properties[] = { - {"isPause", 0, phPAUSE}, - {"isVowel", 0, phVOWEL}, - {"isNasal", 0, phNASAL}, - {"isLiquid", 0, phLIQUID}, - {"isUStop", 0, phSTOP}, - {"isVStop", 0, phVSTOP}, - {"isVFricative", 0, phVFRICATIVE}, + { "isPause", 0, phPAUSE }, + { "isVowel", 0, phVOWEL }, + { "isNasal", 0, phNASAL }, + { "isLiquid", 0, phLIQUID }, + { "isUStop", 0, phSTOP }, + { "isVStop", 0, phVSTOP }, + { "isVFricative", 0, phVFRICATIVE }, - {"isPalatal", 0, i_isPalatal}, - {"isLong", 0, i_isLong}, - {"isRhotic", 0, i_isRhotic}, - {"isSibilant", 0, i_isSibilant}, - {"isFlag1", 0, i_isFlag1}, - {"isFlag2", 0, i_isFlag2}, - {"isFlag3", 0, i_isFlag3}, + { "isPalatal", 0, i_isPalatal }, + { "isLong", 0, i_isLong }, + { "isRhotic", 0, i_isRhotic }, + { "isSibilant", 0, i_isSibilant }, + { "isFlag1", 0, i_isFlag1 }, + { "isFlag2", 0, i_isFlag2 }, + { "isFlag3", 0, i_isFlag3 }, - {"isVel", 0, i_isVel}, + { "isVel", 0, i_isVel }, - {"isDiminished", 0, i_isDiminished}, - {"isUnstressed", 0, i_isUnstressed}, - {"isNotStressed",0, i_isNotStressed}, - {"isStressed", 0, i_isStressed}, - {"isMaxStress", 0, i_isMaxStress}, + { "isDiminished", 0, i_isDiminished }, + { "isUnstressed", 0, i_isUnstressed }, + { "isNotStressed", 0, i_isNotStressed }, + { "isStressed", 0, i_isStressed }, + { "isMaxStress", 0, i_isMaxStress }, - {"isBreak", 0, i_isBreak}, - {"isPause2", 0, i_isBreak}, // synonym for isBreak - {"isWordStart", 0, i_isWordStart}, - {"notWordStart", 0, i_notWordStart}, - {"isWordEnd", 0, i_isWordEnd}, - {"isAfterStress",0, i_isAfterStress}, - {"isNotVowel", 0, i_isNotVowel}, - {"isFinalVowel", 0, i_isFinalVowel}, - {"isVoiced", 0, i_isVoiced}, // voiced consonant, or vowel - {"isFirstVowel", 0, i_isFirstVowel}, - {"isSecondVowel", 0, i_isSecondVowel}, - {"isSeqFlag1", 0, i_isSeqFlag1}, - {"isTranslationGiven", 0, i_IsTranslationGiven}, // phoneme translation given in **_list or as [[...]] + { "isBreak", 0, i_isBreak }, + { "isPause2", 0, i_isBreak }, // synonym for isBreak + { "isWordStart", 0, i_isWordStart }, + { "notWordStart", 0, i_notWordStart }, + { "isWordEnd", 0, i_isWordEnd }, + { "isAfterStress", 0, i_isAfterStress }, + { "isNotVowel", 0, i_isNotVowel }, + { "isFinalVowel", 0, i_isFinalVowel }, + { "isVoiced", 0, i_isVoiced }, // voiced consonant, or vowel + { "isFirstVowel", 0, i_isFirstVowel }, + { "isSecondVowel", 0, i_isSecondVowel }, + { "isSeqFlag1", 0, i_isSeqFlag1 }, + { "isTranslationGiven", 0, i_IsTranslationGiven }, // phoneme translation given in **_list or as [[...]] - {NULL, 0, 0} + { NULL, 0, 0 } }; enum { @@ -201,162 +201,162 @@ enum { kTUNE_SPLIT, }; -static unsigned const char utf8_bom[] = {0xef,0xbb,0xbf,0}; +static unsigned const char utf8_bom[] = { 0xef, 0xbb, 0xbf, 0 }; static keywtab_t k_intonation[] = { - {"tune", 0, kTUNE}, - {"endtune", 0, kENDTUNE}, - {"prehead", 0, kTUNE_PREHEAD}, - {"onset", 0, kTUNE_ONSET}, - {"head", 0, kTUNE_HEAD}, - {"headenv", 0, kTUNE_HEADENV}, - {"headextend", 0, kTUNE_HEADEXTEND}, - {"headlast", 0, kTUNE_HEADLAST}, - {"nucleus0", 0, kTUNE_NUCLEUS0}, - {"nucleus", 0, kTUNE_NUCLEUS1}, - {"split", 0, kTUNE_SPLIT}, - {NULL, 0, -1} + { "tune", 0, kTUNE }, + { "endtune", 0, kENDTUNE }, + { "prehead", 0, kTUNE_PREHEAD }, + { "onset", 0, kTUNE_ONSET }, + { "head", 0, kTUNE_HEAD }, + { "headenv", 0, kTUNE_HEADENV }, + { "headextend", 0, kTUNE_HEADEXTEND }, + { "headlast", 0, kTUNE_HEADLAST }, + { "nucleus0", 0, kTUNE_NUCLEUS0 }, + { "nucleus", 0, kTUNE_NUCLEUS1 }, + { "split", 0, kTUNE_SPLIT }, + { NULL, 0, -1 } }; static keywtab_t keywords[] = { - {"vowel", tPHONEME_TYPE, phVOWEL}, - {"liquid", tPHONEME_TYPE, phLIQUID}, - {"pause", tPHONEME_TYPE, phPAUSE}, - {"stress", tPHONEME_TYPE, phSTRESS}, - {"virtual", tPHONEME_TYPE, phVIRTUAL}, + { "vowel", tPHONEME_TYPE, phVOWEL }, + { "liquid", tPHONEME_TYPE, phLIQUID }, + { "pause", tPHONEME_TYPE, phPAUSE }, + { "stress", tPHONEME_TYPE, phSTRESS }, + { "virtual", tPHONEME_TYPE, phVIRTUAL }, - {"fricative", tPHONEME_TYPE, phFRICATIVE}, - {"vstop", tPHONEME_TYPE, phVSTOP}, - {"vfricative",tPHONEME_TYPE, phVFRICATIVE}, - {"delete_phoneme", tPHONEME_TYPE, phDELETED}, + { "fricative", tPHONEME_TYPE, phFRICATIVE }, + { "vstop", tPHONEME_TYPE, phVSTOP }, + { "vfricative", tPHONEME_TYPE, phVFRICATIVE }, + { "delete_phoneme", tPHONEME_TYPE, phDELETED }, // type of consonant - {"stop", tPHONEME_TYPE, phSTOP}, - {"frc", tPHONEME_TYPE, phFRICATIVE}, - {"nasal", tPHONEME_TYPE, phNASAL}, - {"flp", tPHONEME_TYPE, phVSTOP}, - {"afr", tPHONEME_TYPE, phSTOP}, // treat as stop - {"apr", tPHONEME_TYPE, phFRICATIVE}, // [h] voiceless approximant + { "stop", tPHONEME_TYPE, phSTOP }, + { "frc", tPHONEME_TYPE, phFRICATIVE }, + { "nasal", tPHONEME_TYPE, phNASAL }, + { "flp", tPHONEME_TYPE, phVSTOP }, + { "afr", tPHONEME_TYPE, phSTOP }, // treat as stop + { "apr", tPHONEME_TYPE, phFRICATIVE }, // [h] voiceless approximant // keywords - {"phonemenumber",tSTATEMENT, kPHONEMENUMBER}, - {"phonemetable",tSTATEMENT, kPHONEMETABLE}, - {"include", tSTATEMENT, kINCLUDE}, - {(const char *)utf8_bom, tSTATEMENT, kUTF8_BOM}, + { "phonemenumber", tSTATEMENT, kPHONEMENUMBER }, + { "phonemetable", tSTATEMENT, kPHONEMETABLE }, + { "include", tSTATEMENT, kINCLUDE }, + { (const char *)utf8_bom, tSTATEMENT, kUTF8_BOM }, - {"phoneme", tSTATEMENT, kPHONEMESTART}, - {"procedure", tSTATEMENT, kPROCEDURE}, - {"endphoneme", tSTATEMENT, kENDPHONEME}, - {"endprocedure", tSTATEMENT, kENDPROCEDURE}, - {"equivalents", tSTATEMENT, kEQUIVALENTS}, - {"import_phoneme", tSTATEMENT, kIMPORT_PH}, - {"stress_type",tSTATEMENT, kSTRESSTYPE}, - {"starttype", tSTATEMENT, kSTARTTYPE}, - {"endtype", tSTATEMENT, kENDTYPE}, - {"voicingswitch", tSTATEMENT, kVOICINGSWITCH}, + { "phoneme", tSTATEMENT, kPHONEMESTART }, + { "procedure", tSTATEMENT, kPROCEDURE }, + { "endphoneme", tSTATEMENT, kENDPHONEME }, + { "endprocedure", tSTATEMENT, kENDPROCEDURE }, + { "equivalents", tSTATEMENT, kEQUIVALENTS }, + { "import_phoneme", tSTATEMENT, kIMPORT_PH }, + { "stress_type", tSTATEMENT, kSTRESSTYPE }, + { "starttype", tSTATEMENT, kSTARTTYPE }, + { "endtype", tSTATEMENT, kENDTYPE }, + { "voicingswitch", tSTATEMENT, kVOICINGSWITCH }, - {"IF", tSTATEMENT, kIF}, - {"ELSE", tSTATEMENT, kELSE}, - {"ELIF", tSTATEMENT, kELIF}, - {"ELSEIF", tSTATEMENT, kELIF}, // same as ELIF - {"ENDIF", tSTATEMENT, kENDIF}, - {"CALL", tSTATEMENT, kCALLPH}, - {"RETURN", tSTATEMENT, kRETURN}, + { "IF", tSTATEMENT, kIF }, + { "ELSE", tSTATEMENT, kELSE }, + { "ELIF", tSTATEMENT, kELIF }, + { "ELSEIF", tSTATEMENT, kELIF }, // same as ELIF + { "ENDIF", tSTATEMENT, kENDIF }, + { "CALL", tSTATEMENT, kCALLPH }, + { "RETURN", tSTATEMENT, kRETURN }, - {"PrevVowelEndings", tSTATEMENT, kSWITCH_PREVVOWEL}, - {"NextVowelStarts", tSTATEMENT, kSWITCH_NEXTVOWEL}, - {"EndSwitch", tSTATEMENT, kENDSWITCH}, + { "PrevVowelEndings", tSTATEMENT, kSWITCH_PREVVOWEL }, + { "NextVowelStarts", tSTATEMENT, kSWITCH_NEXTVOWEL }, + { "EndSwitch", tSTATEMENT, kENDSWITCH }, - {"Tone", tSTATEMENT, kTONESPEC}, - {"FMT", tSTATEMENT, kFMT}, - {"WAV", tSTATEMENT, kWAV}, - {"VowelStart", tSTATEMENT, kVOWELSTART}, - {"VowelEnding",tSTATEMENT, kVOWELENDING}, - {"addWav", tSTATEMENT, kANDWAV}, + { "Tone", tSTATEMENT, kTONESPEC }, + { "FMT", tSTATEMENT, kFMT }, + { "WAV", tSTATEMENT, kWAV }, + { "VowelStart", tSTATEMENT, kVOWELSTART }, + { "VowelEnding", tSTATEMENT, kVOWELENDING }, + { "addWav", tSTATEMENT, kANDWAV }, - {"Vowelin", tSTATEMENT, kVOWELIN}, - {"Vowelout", tSTATEMENT, kVOWELOUT}, - {"Continue", tSTATEMENT, kCONTINUE}, + { "Vowelin", tSTATEMENT, kVOWELIN }, + { "Vowelout", tSTATEMENT, kVOWELOUT }, + { "Continue", tSTATEMENT, kCONTINUE }, - {"ChangePhoneme", tINSTRN1, i_CHANGE_PHONEME}, - {"ChangeNextPhoneme", tINSTRN1, i_REPLACE_NEXT_PHONEME}, - {"InsertPhoneme", tINSTRN1, i_INSERT_PHONEME}, - {"AppendPhoneme", tINSTRN1, i_APPEND_PHONEME}, - {"IfNextVowelAppend", tINSTRN1, i_APPEND_IFNEXTVOWEL}, - {"ChangeIfDiminished", tINSTRN1, i_CHANGE_IF + 0}, - {"ChangeIfUnstressed", tINSTRN1, i_CHANGE_IF + 1}, - {"ChangeIfNotStressed", tINSTRN1, i_CHANGE_IF + 2}, - {"ChangeIfStressed", tINSTRN1, i_CHANGE_IF + 3}, + { "ChangePhoneme", tINSTRN1, i_CHANGE_PHONEME }, + { "ChangeNextPhoneme", tINSTRN1, i_REPLACE_NEXT_PHONEME }, + { "InsertPhoneme", tINSTRN1, i_INSERT_PHONEME }, + { "AppendPhoneme", tINSTRN1, i_APPEND_PHONEME }, + { "IfNextVowelAppend", tINSTRN1, i_APPEND_IFNEXTVOWEL }, + { "ChangeIfDiminished", tINSTRN1, i_CHANGE_IF + 0 }, + { "ChangeIfUnstressed", tINSTRN1, i_CHANGE_IF + 1 }, + { "ChangeIfNotStressed", tINSTRN1, i_CHANGE_IF + 2 }, + { "ChangeIfStressed", tINSTRN1, i_CHANGE_IF + 3 }, - {"PauseBefore",tINSTRN1, i_PAUSE_BEFORE}, - {"PauseAfter", tINSTRN1, i_PAUSE_AFTER}, - {"Length", tINSTRN1, i_SET_LENGTH}, - {"length", tINSTRN1, i_SET_LENGTH}, - {"LongLength", tINSTRN1, i_LONG_LENGTH}, - {"LengthAdd", tINSTRN1, i_ADD_LENGTH}, - {"Lengthmod", tINSTRN1, i_LENGTH_MOD}, - {"lengthmod", tINSTRN1, i_LENGTH_MOD}, - {"ipa", tINSTRN1, i_IPA_NAME}, + { "PauseBefore", tINSTRN1, i_PAUSE_BEFORE }, + { "PauseAfter", tINSTRN1, i_PAUSE_AFTER }, + { "Length", tINSTRN1, i_SET_LENGTH }, + { "length", tINSTRN1, i_SET_LENGTH }, + { "LongLength", tINSTRN1, i_LONG_LENGTH }, + { "LengthAdd", tINSTRN1, i_ADD_LENGTH }, + { "Lengthmod", tINSTRN1, i_LENGTH_MOD }, + { "lengthmod", tINSTRN1, i_LENGTH_MOD }, + { "ipa", tINSTRN1, i_IPA_NAME }, // flags - {"wavef", tPHONEME_FLAG, phWAVE}, - {"unstressed", tPHONEME_FLAG, phUNSTRESSED}, - {"fortis", tPHONEME_FLAG, phFORTIS}, - {"sibilant", tPHONEME_FLAG, phSIBILANT}, - {"nolink", tPHONEME_FLAG, phNOLINK}, - {"trill", tPHONEME_FLAG, phTRILL}, - {"vowel2", tPHONEME_FLAG, phVOWEL2}, - {"palatal", tPHONEME_FLAG, phPALATAL}, - {"long", tPHONEME_FLAG, phLONG}, - {"dontlist", tPHONEME_FLAG, phDONTLIST}, - {"brkafter", tPHONEME_FLAG, phBRKAFTER}, - {"rhotic", tPHONEME_FLAG, phRHOTIC}, - {"nonsyllabic",tPHONEME_FLAG, phNONSYLLABIC}, - {"lengthenstop",tPHONEME_FLAG, phLENGTHENSTOP}, - {"nopause", tPHONEME_FLAG, phNOPAUSE}, - {"prevoice", tPHONEME_FLAG, phPREVOICE}, + { "wavef", tPHONEME_FLAG, phWAVE }, + { "unstressed", tPHONEME_FLAG, phUNSTRESSED }, + { "fortis", tPHONEME_FLAG, phFORTIS }, + { "sibilant", tPHONEME_FLAG, phSIBILANT }, + { "nolink", tPHONEME_FLAG, phNOLINK }, + { "trill", tPHONEME_FLAG, phTRILL }, + { "vowel2", tPHONEME_FLAG, phVOWEL2 }, + { "palatal", tPHONEME_FLAG, phPALATAL }, + { "long", tPHONEME_FLAG, phLONG }, + { "dontlist", tPHONEME_FLAG, phDONTLIST }, + { "brkafter", tPHONEME_FLAG, phBRKAFTER }, + { "rhotic", tPHONEME_FLAG, phRHOTIC }, + { "nonsyllabic", tPHONEME_FLAG, phNONSYLLABIC }, + { "lengthenstop", tPHONEME_FLAG, phLENGTHENSTOP }, + { "nopause", tPHONEME_FLAG, phNOPAUSE }, + { "prevoice", tPHONEME_FLAG, phPREVOICE }, - {"flag1", tPHONEME_FLAG, phFLAG1}, - {"flag2", tPHONEME_FLAG, phFLAG2}, - {"flag3", tPHONEME_FLAG, phFLAG3}, + { "flag1", tPHONEME_FLAG, phFLAG1 }, + { "flag2", tPHONEME_FLAG, phFLAG2 }, + { "flag3", tPHONEME_FLAG, phFLAG3 }, // voiced / unvoiced - {"vcd", tPHONEME_FLAG, phVOICED}, - {"vls", tPHONEME_FLAG, phFORTIS}, + { "vcd", tPHONEME_FLAG, phVOICED }, + { "vls", tPHONEME_FLAG, phFORTIS }, // place of articulation, set bits 16-19 of phflags - {"blb", tPLACE, 1}, - {"lbd", tPLACE, 2}, - {"dnt", tPLACE, 3}, - {"alv", tPLACE, 4}, - {"rfx", tPLACE, 5}, - {"pla", tPLACE, 6}, - {"pal", tPLACE, 7}, - {"vel", tPLACE, 8}, - {"lbv", tPLACE, 9}, - {"uvl", tPLACE, 10}, - {"phr", tPLACE, 11}, - {"glt", tPLACE, 12}, + { "blb", tPLACE, 1 }, + { "lbd", tPLACE, 2 }, + { "dnt", tPLACE, 3 }, + { "alv", tPLACE, 4 }, + { "rfx", tPLACE, 5 }, + { "pla", tPLACE, 6 }, + { "pal", tPLACE, 7 }, + { "vel", tPLACE, 8 }, + { "lbv", tPLACE, 9 }, + { "uvl", tPLACE, 10 }, + { "phr", tPLACE, 11 }, + { "glt", tPLACE, 12 }, // vowel transition attributes - {"len=", tTRANSITION, 1}, - {"rms=", tTRANSITION, 2}, - {"f1=", tTRANSITION, 3}, - {"f2=", tTRANSITION, 4}, - {"f3=", tTRANSITION, 5}, - {"brk", tTRANSITION, 6}, - {"rate", tTRANSITION, 7}, - {"glstop", tTRANSITION, 8}, - {"lenadd", tTRANSITION, 9}, - {"f4", tTRANSITION, 10}, - {"gpaus", tTRANSITION, 11}, - {"colr=", tTRANSITION, 12}, - {"amp=", tTRANSITION, 13}, // set rms of 1st frame as fraction of rms of 2nd frame (1/30ths) + { "len=", tTRANSITION, 1 }, + { "rms=", tTRANSITION, 2 }, + { "f1=", tTRANSITION, 3 }, + { "f2=", tTRANSITION, 4 }, + { "f3=", tTRANSITION, 5 }, + { "brk", tTRANSITION, 6 }, + { "rate", tTRANSITION, 7 }, + { "glstop", tTRANSITION, 8 }, + { "lenadd", tTRANSITION, 9 }, + { "f4", tTRANSITION, 10 }, + { "gpaus", tTRANSITION, 11 }, + { "colr=", tTRANSITION, 12 }, + { "amp=", tTRANSITION, 13 }, // set rms of 1st frame as fraction of rms of 2nd frame (1/30ths) - {NULL, 0, -1} + { NULL, 0, -1 } }; @@ -391,44 +391,39 @@ static void ReadPhondataManifest() { // Read the phondata-manifest file FILE *f; - int n_lines=0; + int n_lines = 0; int ix; char *p; unsigned int value; char buf[sizeof(path_home)+40]; char name[120]; - sprintf(buf,"%s%c%s",path_home,PATHSEP,"phondata-manifest"); - if((f = fopen(buf, "r")) == NULL) + sprintf(buf, "%s%c%s", path_home, PATHSEP, "phondata-manifest"); + if ((f = fopen(buf, "r")) == NULL) return; - while(fgets(buf, sizeof(buf), f) != NULL) + while (fgets(buf, sizeof(buf), f) != NULL) n_lines++; rewind(f); - if(manifest != NULL) - { - for(ix=0; ix < n_manifest; ix++) + if (manifest != NULL) { + for (ix = 0; ix < n_manifest; ix++) free(manifest[ix].name); } - if((manifest = (NAMETAB *)realloc(manifest, n_lines * sizeof(NAMETAB))) == NULL) - { + if ((manifest = (NAMETAB *)realloc(manifest, n_lines * sizeof(NAMETAB))) == NULL) { fclose(f); return; } n_manifest = 0; - while(fgets(buf, sizeof(buf), f) != NULL) - { - if(!isalpha(buf[0])) + while (fgets(buf, sizeof(buf), f) != NULL) { + if (!isalpha(buf[0])) continue; - if(sscanf(&buf[2], "%x %s", &value, name) == 2) - { - if((p = (char *)malloc(strlen(name)+1)) != NULL) - { + if (sscanf(&buf[2], "%x %s", &value, name) == 2) { + if ((p = (char *)malloc(strlen(name)+1)) != NULL) { strcpy(p, name); manifest[n_manifest].value = value; manifest[n_manifest].name = p; @@ -441,16 +436,14 @@ static void ReadPhondataManifest() static const char *KeyToMnem(keywtab_t *ktab, int type, int value) { - while(ktab->mnem != NULL) - { - if(ktab->data == value) - { - if((type == -1) || (type == ktab->type)) - return(ktab->mnem); + while (ktab->mnem != NULL) { + if (ktab->data == value) { + if ((type == -1) || (type == ktab->type)) + return (ktab->mnem); } ktab++; } - return(NULL); + return (NULL); } static void DecompilePhoneme(FILE *f_out, PHONEME_TAB *ph, int compile_phoneme) @@ -499,156 +492,134 @@ static void DecompilePhoneme(FILE *f_out, PHONEME_TAB *ph, int compile_phoneme) return; - if(compile_phoneme) - { - fprintf(f_out,"\nPhoneme %s (%d)\n",WordToString(ph->mnemonic),ph->code); - } - else - { - fprintf(f_out,"\nProcedure %s\n",proc_names[n_procs]); + if (compile_phoneme) { + fprintf(f_out, "\nPhoneme %s (%d)\n", WordToString(ph->mnemonic), ph->code); + } else { + fprintf(f_out, "\nProcedure %s\n", proc_names[n_procs]); } pc = prog_buf; - while(pc < prog_out) - { + while (pc < prog_out) { instn = *pc++; instn_category = (instn >> 12) & 0xf; data1 = instn & 0xff; type2 = (instn >> 8) & 0xf; - fprintf(f_out, " %.3x: %.4x %s",(unsigned int)(pc-prog_buf),instn,instn_category_string[instn_category]); + fprintf(f_out, " %.3x: %.4x %s", (unsigned int)(pc-prog_buf), instn, instn_category_string[instn_category]); - switch(instn_category) + switch (instn_category) { case 0: case 1: type2 = instn >> 8; - if(instn < 0x100) - { - if(data1 > 2) + if (instn < 0x100) { + if (data1 > 2) data1 = 0; - fprintf(f_out,"%s",instn0_string[data1]); - } - else - if(type2 == i_IPA_NAME) - { - for(ix = 0; ix < data1; ix += 2) - { + fprintf(f_out, "%s", instn0_string[data1]); + } else if (type2 == i_IPA_NAME) { + for (ix = 0; ix < data1; ix += 2) { instn = *pc++; buf[ix] = instn >> 8; buf[ix+1] = instn & 0xff; } buf[ix] = 0; - fprintf(f_out,"ipa %s",buf); - } - else - { - fprintf(f_out,"%s(",KeyToMnem(keywords, tINSTRN1, type2)); - switch(instn1_paramtype[type2]) + fprintf(f_out, "ipa %s", buf); + } else { + fprintf(f_out, "%s(", KeyToMnem(keywords, tINSTRN1, type2)); + switch (instn1_paramtype[type2]) { case 0: - fprintf(f_out,"%.4x",instn); + fprintf(f_out, "%.4x", instn); break; case 1: - fprintf(f_out,"%d",data1); + fprintf(f_out, "%d", data1); break; case 3: - fprintf(f_out,"%s",WordToString(phoneme_tab2[data1].mnemonic)); + fprintf(f_out, "%s", WordToString(phoneme_tab2[data1].mnemonic)); break; } - fprintf(f_out,")"); + fprintf(f_out, ")"); } break; case 2: case 3: - if(type2 < 12) - { - fprintf(f_out," %s(",nextPh_string[type2 % 6]); - if(type2 >= 6) - { - switch(data1 >> 5) + if (type2 < 12) { + fprintf(f_out, " %s(", nextPh_string[type2 % 6]); + if (type2 >= 6) { + switch (data1 >> 5) { case 0: name = KeyToMnem(keywords, tPHONEME_TYPE, (data1 & 0x1f)); - if(name != NULL) - fprintf(f_out,"is%s",name); + if (name != NULL) + fprintf(f_out, "is%s", name); else - fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f)); + fprintf(f_out, "%d %d", (data1 >> 5), (data1 & 0x1f)); break; case 1: - fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f)); + fprintf(f_out, "%d %d", (data1 >> 5), (data1 & 0x1f)); break; case 2: - fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f)); + fprintf(f_out, "%d %d", (data1 >> 5), (data1 & 0x1f)); break; case 4: name = KeyToMnem(k_properties, -1, 0x80+(data1 & 0x1f)); - if(name != NULL) - fprintf(f_out,"%s",name); + if (name != NULL) + fprintf(f_out, "%s", name); else - fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f)); + fprintf(f_out, "%d %d", (data1 >> 5), (data1 & 0x1f)); break; default: - fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f)); + fprintf(f_out, "%d %d", (data1 >> 5), (data1 & 0x1f)); break; } + } else { + fprintf(f_out, "%s", WordToString(phoneme_tab2[data1].mnemonic)); } - else - { - fprintf(f_out,"%s",WordToString(phoneme_tab2[data1].mnemonic)); - } - } - else - if(type2 == 8) - { + } else if (type2 == 8) { // list of numbers - fprintf(f_out," StressLevel("); + fprintf(f_out, " StressLevel("); any = 0; - for(ix=0; ix<8; ix++) - { - if(data1 & (1 << ix)) - { - if(any) - fputc(',',f_out); + for (ix = 0; ix < 8; ix++) { + if (data1 & (1 << ix)) { + if (any) + fputc(',', f_out); any = 1; - fprintf(f_out,"%d",ix); + fprintf(f_out, "%d", ix); } } - } - else - { + } else { name = KeyToMnem(k_conditions, tTEST, instn & 0xfff); - fprintf(f_out,"%s(",name); + fprintf(f_out, "%s(", name); } - fprintf(f_out,")"); + fprintf(f_out, ")"); break; case 6: - fprintf(f_out,"%s",instn_jumps[(instn >> 9) & 7]); - fprintf(f_out," %d",instn & 0x1ff); + fprintf(f_out, "%s", instn_jumps[(instn >> 9) & 7]); + fprintf(f_out, " %d", instn & 0x1ff); break; case 9: address = ((data1 & 0xf) << 4) + *pc++; - fprintf(f_out,"CALL %.5x",address); + fprintf(f_out, "CALL %.5x", address); break; case 10: - fprintf(f_out,"%s",instn10_string[type2]); - switch(type2) + fprintf(f_out, "%s", instn10_string[type2]); + switch (type2) { case 1: case 2: address = (data1 << 16) + pc[0]; address2 = (pc[1] << 16) + pc[2]; pc += 3; - fprintf(f_out, " %.6x %.8x",address,address2); + fprintf(f_out, " %.6x %.8x", address, address2); break; case 3: address = ((instn & 0xf) << 16) + *pc++; address2 = ((instn & 0xf0) << 12) + *pc++; - fprintf(f_out, " %.5x %.5x",address,address2); + fprintf(f_out, " %.5x %.5x", address, address2); break; } break; @@ -659,10 +630,10 @@ static void DecompilePhoneme(FILE *f_out, PHONEME_TAB *ph, int compile_phoneme) case 14: case 15: address = ((instn & 0xf) << 16) + *pc++; - fprintf(f_out, " %d %.5x",(instn >> 4) & 0xff,address*4); + fprintf(f_out, " %d %.5x", (instn >> 4) & 0xff, address*4); break; } - fprintf(f_out,"\n"); + fprintf(f_out, "\n"); } } @@ -766,15 +737,15 @@ static int ref_sorter(char **a, char **b) REF_HASH_TAB *p1 = (REF_HASH_TAB *)(*a); REF_HASH_TAB *p2 = (REF_HASH_TAB *)(*b); - ix = strcoll(p1->string,p2->string); - if(ix != 0) + ix = strcoll(p1->string, p2->string); + if (ix != 0) return ix; ix = p1->ph_table - p2->ph_table; - if(ix != 0) + if (ix != 0) return ix; - return(p1->ph_mnemonic - p2->ph_mnemonic); + return (p1->ph_mnemonic - p2->ph_mnemonic); } @@ -791,77 +762,65 @@ static void CompileReport(void) int procedure_num; int prev_mnemonic; - if(f_report == NULL) + if (f_report == NULL) return; // make a list of all the references and sort it list = (REF_HASH_TAB **)malloc((count_references)* sizeof(REF_HASH_TAB *)); - if(list == NULL) + if (list == NULL) return; - fprintf(f_report,"\n%d phoneme tables\n",n_phoneme_tabs); - fprintf(f_report," new total\n"); - for(ix=0; ixlink); } } n = ix; - qsort((void *)list,n,sizeof(REF_HASH_TAB *),(int (*)(const void *,const void *))ref_sorter); + qsort((void *)list, n, sizeof(REF_HASH_TAB *), (int (*)(const void *, const void *))ref_sorter); data_path = ""; prev_mnemonic = 0; prev_table = 0; - for(ix=0; ixstring, data_path) != 0) - { + if (strcmp(list[ix]->string, data_path) != 0) { data_path = list[ix]->string; j = strlen(data_path); - fprintf(f_report,"%s",data_path); - } - else - { - if((list[ix]->ph_table == prev_table) && (list[ix]->ph_mnemonic == prev_mnemonic)) + fprintf(f_report, "%s", data_path); + } else { + if ((list[ix]->ph_table == prev_table) && (list[ix]->ph_mnemonic == prev_mnemonic)) continue; // same phoneme, don't list twice } - while(j < 14) - { - fputc(' ',f_report); // pad filename with spaces + while (j < 14) { + fputc(' ', f_report); // pad filename with spaces j++; } prev_mnemonic = list[ix]->ph_mnemonic; - if((prev_mnemonic >> 24) == 'P') - { + if ((prev_mnemonic >> 24) == 'P') { // a procedure, not a phoneme procedure_num = atoi(WordToString(prev_mnemonic)); - fprintf(f_report," %s %s", phoneme_tab_list2[prev_table = list[ix]->ph_table].name, proc_names[procedure_num]); + fprintf(f_report, " %s %s", phoneme_tab_list2[prev_table = list[ix]->ph_table].name, proc_names[procedure_num]); + } else { + fprintf(f_report, " [%s] %s", WordToString(prev_mnemonic), phoneme_tab_list2[prev_table = list[ix]->ph_table].name); } - else - { - fprintf(f_report," [%s] %s",WordToString(prev_mnemonic), phoneme_tab_list2[prev_table = list[ix]->ph_table].name); - } - fputc('\n',f_report); + fputc('\n', f_report); } - for(ix=0; ixmnem != NULL) - { + while (p->mnem != NULL) { word = StringToWord(p->mnem); phoneme_tab2[p->value].mnemonic = word; phoneme_tab2[p->value].code = p->value; - if(n_phcodes <= p->value) + if (n_phcodes <= p->value) n_phcodes = p->value+1; p++; } @@ -991,41 +947,37 @@ static int LookupPhoneme(const char *string, int control) int use; unsigned int word; - if(strcmp(string,"NULL")==0) - return(1); + if (strcmp(string, "NULL") == 0) + return (1); ix = strlen(string); - if((ix==0) || (ix> 4)) - { - error("Bad phoneme name '%s'",string); + if ((ix == 0) || (ix > 4)) { + error("Bad phoneme name '%s'", string); } word = StringToWord(string); // don't use phoneme number 0, reserved for string terminator start = 1; - if(control==2) + if (control == 2) start = 8; // don't look for control and stress phonemes (allows these characters to be // used for other purposes) use = 0; - for(ix=start; ix= N_PHONEME_TAB-1) - return(-1); // phoneme table is full + if (use == 0) { + if (control == 0) + return (-1); + if (n_phcodes >= N_PHONEME_TAB-1) + return (-1); // phoneme table is full use = n_phcodes++; } @@ -1033,7 +985,7 @@ static int LookupPhoneme(const char *string, int control) phoneme_tab2[use].mnemonic = word; phoneme_tab2[use].type = phINVALID; phoneme_tab2[use].program = linenum; // for error report if the phoneme remains undeclared - return(use); + return (use); } @@ -1042,15 +994,15 @@ static unsigned int get_char() { unsigned int c; c = fgetc(f_in); - if(c == '\n') + if (c == '\n') linenum++; - return(c); + return (c); } static void unget_char(unsigned int c) { - ungetc(c,f_in); - if(c == '\n') + ungetc(c, f_in); + if (c == '\n') linenum--; } @@ -1058,16 +1010,16 @@ static void unget_char(unsigned int c) int CheckNextChar() { int c; - while(((c = get_char()) == ' ') || (c == '\t')); + while (((c = get_char()) == ' ') || (c == '\t')) ; unget_char(c); - return(c); + return (c); } static int NextItem(int type) { int acc; - unsigned char c=0; + unsigned char c = 0; unsigned char c2; int ix; int sign; @@ -1079,118 +1031,100 @@ static int NextItem(int type) f_in_displ = ftell(f_in); f_in_linenum = linenum; - while(!feof(f_in)) - { + while (!feof(f_in)) { c = get_char(); - if(c=='/') - { - if((c2 = get_char())=='/') - { + if (c == '/') { + if ((c2 = get_char()) == '/') { // comment, ignore to end of line - while(!feof(f_in) && ((c = get_char()) != '\n')); - } - else - { + while (!feof(f_in) && ((c = get_char()) != '\n')) ; + } else { unget_char(c2); } } - if(!isspace(c)) - { + if (!isspace(c)) { break; } } - if(feof(f_in)) - return(-2); + if (feof(f_in)) + return (-2); - if(c == '(') - { - if(type == tOPENBRACKET) - return(1); - return(-1); + if (c == '(') { + if (type == tOPENBRACKET) + return (1); + return (-1); } ix = 0; - while(!feof(f_in) && !isspace(c) && (c != '(') && (c != ')') && (c != ',')) - { - if(c == '\\') + while (!feof(f_in) && !isspace(c) && (c != '(') && (c != ')') && (c != ',')) { + if (c == '\\') c = get_char(); item_string[ix++] = c; c = get_char(); - if(feof(f_in)) + if (feof(f_in)) break; - if(item_string[ix-1] == '=') + if (item_string[ix-1] == '=') break; } item_string[ix] = 0; - while(isspace(c)) - { + while (isspace(c)) { c = get_char(); } item_terminator = ' '; - if((c == ')') || (c == '(') || (c == ',')) + if ((c == ')') || (c == '(') || (c == ',')) item_terminator = c; - if((c == ')') || (c == ',')) + if ((c == ')') || (c == ',')) c = ' '; - if(!feof(f_in)) + if (!feof(f_in)) unget_char(c); - if(type == tSTRING) - { - return(0); + if (type == tSTRING) { + return (0); } - if((type == tNUMBER) || (type == tSIGNEDNUMBER)) - { + if ((type == tNUMBER) || (type == tSIGNEDNUMBER)) { acc = 0; sign = 1; p = item_string; - if((*p == '-') && (type == tSIGNEDNUMBER)) - { + if ((*p == '-') && (type == tSIGNEDNUMBER)) { sign = -1; p++; } - if(!isdigit(*p)) - { - if((type == tNUMBER) && (*p == '-')) - error("Expected an unsigned number",NULL); + if (!isdigit(*p)) { + if ((type == tNUMBER) && (*p == '-')) + error("Expected an unsigned number", NULL); else - error("Expected a number",NULL); + error("Expected a number", NULL); } - while(isdigit(*p)) - { + while (isdigit(*p)) { acc *= 10; acc += (*p - '0'); p++; } - return(acc * sign); + return (acc * sign); } - if((type >= tKEYWORD) && (type <= tINTONATION)) - { + if ((type >= tKEYWORD) && (type <= tINTONATION)) { pk = keyword_tabs[type-tKEYWORD]; - while(pk->mnem != NULL) - { - if(strcmp(item_string,pk->mnem)==0) - { + while (pk->mnem != NULL) { + if (strcmp(item_string, pk->mnem) == 0) { item_type = pk->type; - return(pk->data); + return (pk->data); } pk++; } item_type = -1; - return(-1); // keyword not found + return (-1); // keyword not found } - if(type == tPHONEMEMNEM) - { - return(LookupPhoneme(item_string,2)); + if (type == tPHONEMEMNEM) { + return (LookupPhoneme(item_string, 2)); } - return(-1); + return (-1); } @@ -1202,13 +1136,12 @@ static int NextItemMax(int max) char msg[80]; value = NextItem(tNUMBER); - if(value > max) - { + if (value > max) { sprintf(msg, "Value %d is greater than maximum %d", value, max); error(msg, NULL); value = max; } - return(value); + return (value); } @@ -1221,30 +1154,27 @@ static int NextItemBrackets(int type, int control) int value; - if((control & 1) == 0) - { - if(!NextItem(tOPENBRACKET)) - { + if ((control & 1) == 0) { + if (!NextItem(tOPENBRACKET)) { error("Expected '('", NULL); } } value = NextItem(type); - if((control & 2) && (item_terminator == ',')) - return(value); + if ((control & 2) && (item_terminator == ',')) + return (value); - if(item_terminator != ')') - { + if (item_terminator != ')') { error("Expected ')'", NULL); } - return(value); + return (value); } static void UngetItem() { - fseek(f_in,f_in_displ,SEEK_SET); + fseek(f_in, f_in_displ, SEEK_SET); linenum = f_in_linenum; } @@ -1253,17 +1183,17 @@ static void UngetItem() static int Range(int value, int divide, int min, int max) { - if(value < 0) + if (value < 0) value -= divide/2; else value += divide/2; value = value / divide; - if(value > max) + if (value > max) value = max; - if(value < min) + if (value < min) value = min; - return(value - min); + return (value - min); } @@ -1271,50 +1201,43 @@ int CompileVowelTransition(int which) { // Compile a vowel transition int key; - int len=0; - int rms=0; - int f1=0; - int f2=0; - int f2_min=0; - int f2_max=0; - int f3_adj=0; - int f3_amp=0; - int flags=0; - int vcolour=0; + int len = 0; + int rms = 0; + int f1 = 0; + int f2 = 0; + int f2_min = 0; + int f2_max = 0; + int f3_adj = 0; + int f3_amp = 0; + int flags = 0; + int vcolour = 0; int x; int instn = i_VOWELIN; int word1; int word2; - if(which==1) - { + if (which == 1) { len = 50 / 2; // defaults for transition into vowel rms = 25 / 2; - if(phoneme_out->type == phSTOP) - { + if (phoneme_out->type == phSTOP) { len = 42 / 2; // defaults for transition into vowel rms = 30 / 2; } - } - else - if(which==2) - { + } else if (which == 2) { instn = i_VOWELOUT; len = 36 / 2; // defaults for transition out of vowel rms = 16 / 2; } - for(;; ) - { + for (;;) { key = NextItem(tKEYWORD); - if(item_type != tTRANSITION) - { + if (item_type != tTRANSITION) { UngetItem(); break; } - switch(key & 0xf) + switch (key & 0xf) { case 1: len = Range(NextItem(tNUMBER), 2, 0, 63) & 0x3f; @@ -1331,8 +1254,7 @@ int CompileVowelTransition(int which) f2 = Range(NextItem(tNUMBER), 50, 0, 63) & 0x3f; f2_min = Range(NextItem(tSIGNEDNUMBER), 50, -15, 15) & 0x1f; f2_max = Range(NextItem(tSIGNEDNUMBER), 50, -15, 15) & 0x1f; - if(f2_min > f2_max) - { + if (f2_min > f2_max) { x = f2_min; f2_min = f2_max; f2_max = x; @@ -1378,7 +1300,7 @@ int CompileVowelTransition(int which) prog_out[3] = word2; prog_out += 4; - return(0); + return (0); } @@ -1395,9 +1317,9 @@ int LoadSpect(const char *path, int control) int rms; float total; float pkheight; - int marker1_set=0; - int frame_vowelbreak=0; - int klatt_flag=0; + int marker1_set = 0; + int frame_vowelbreak = 0; + int klatt_flag = 0; SpectFrame *fr; frame_t *fr_out; char filename[sizeof(path_home)+20]; @@ -1407,153 +1329,133 @@ int LoadSpect(const char *path, int control) // create SpectSeq and import data spectseq = SpectSeqCreate(); - if(spectseq == NULL) - { + if (spectseq == NULL) { Error("Failed to create SpectSeq"); - return(0); + return (0); } snprintf(filename, sizeof(filename), "%s/../phsource/%s", path_home, path); LoadSpectSeq(spectseq, filename); - if(spectseq->frames == NULL) - { - error("Bad vowel file, no frames: '%s'",path); + if (spectseq->frames == NULL) { + error("Bad vowel file, no frames: '%s'", path); SpectSeqDestroy(spectseq); - return(0); + return (0); } // do we need additional klatt data ? - for(frame=0; frame < spectseq->numframes; frame++) - { - for(ix=5; ixframes[frame]->klatt_param[ix] != 0) + for (frame = 0; frame < spectseq->numframes; frame++) { + for (ix = 5; ix < N_KLATTP2; ix++) { + if (spectseq->frames[frame]->klatt_param[ix] != 0) klatt_flag = FRFLAG_KLATT; } } displ = ftell(f_phdata); - seq_out.n_frames=0; - seq_out.sqflags=0; - seq_out.length_total=0; + seq_out.n_frames = 0; + seq_out.sqflags = 0; + seq_out.length_total = 0; total = 0; - for(frame=0; frame < spectseq->numframes; frame++) - { - if(spectseq->frames[frame]->keyframe) - { - if(seq_out.n_frames == 1) - { + for (frame = 0; frame < spectseq->numframes; frame++) { + if (spectseq->frames[frame]->keyframe) { + if (seq_out.n_frames == 1) { frame_vowelbreak = frame; } - if(spectseq->frames[frame]->markers & 0x2) - { + if (spectseq->frames[frame]->markers & 0x2) { // marker 1 is set marker1_set = 1; } seq_out.n_frames++; - if(frame > 0) + if (frame > 0) total += spectseq->frames[frame-1]->length; } } seq_out.length_total = (int)total; - if((control & 1) && (marker1_set == 0)) - { + if ((control & 1) && (marker1_set == 0)) { // This is a vowel, but no Vowel Break marker is set // set a marker flag for the second frame of a vowel spectseq->frames[frame_vowelbreak]->markers |= FRFLAG_VOWEL_CENTRE; } n_frames = 0; - for(frame=0; frame < spectseq->numframes; frame++) - { + for (frame = 0; frame < spectseq->numframes; frame++) { fr = spectseq->frames[frame]; - if(fr->keyframe) - { - if(klatt_flag) + if (fr->keyframe) { + if (klatt_flag) fr_out = &seqk_out.frame[n_frames]; else fr_out = (frame_t *)&seq_out.frame[n_frames]; 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->frflags = fr->markers | klatt_flag; rms = (int)GetFrameRms(fr, spectseq->amplitude); - if(rms > 255) rms = 255; + if (rms > 255) rms = 255; fr_out->rms = rms; - if(n_frames == (seq_out.n_frames-1)) + if (n_frames == (seq_out.n_frames-1)) fr_out->length = 0; // give last frame zero length // write: peak data count_frames++; - for(peak=0; peak < 8; peak++) - { - if(peak < 7) + for (peak = 0; peak < 8; peak++) { + if (peak < 7) fr_out->ffreq[peak] = fr->peaks[peak].pkfreq; pkheight = spectseq->amplitude * fr->amp_adjust * fr->peaks[peak].pkheight; pkheight = pkheight/640000; - if(pkheight > 255) pkheight = 255; + if (pkheight > 255) pkheight = 255; fr_out->fheight[peak] = (int)pkheight; - if(peak < 6) - { + if (peak < 6) { x = fr->peaks[peak].pkwidth/4; - if(x > 255) x = 255; + if (x > 255) x = 255; fr_out->fwidth[peak] = x; - if(peak < 3) - { + if (peak < 3) { x2 = fr->peaks[peak].pkright/4; - if(x2 > 255) x2 = 255; + if (x2 > 255) x2 = 255; fr_out->fright[peak] = x2; } } - if(peak < 4) - { + if (peak < 4) { x = fr->peaks[peak].klt_bw / 2; - if(x > 255) x = 255; + if (x > 255) x = 255; fr_out->bw[peak] = x; } } - for(ix=0; ix<5; ix++) - { + for (ix = 0; ix < 5; ix++) { fr_out->klattp[ix] = fr->klatt_param[ix]; fr_out->klattp[KLATT_FNZ] = fr->klatt_param[KLATT_FNZ] / 2; } - if(klatt_flag) - { + if (klatt_flag) { // additional klatt parameters - for(ix=0; ix<5; ix++) - { + for (ix = 0; ix < 5; ix++) { fr_out->klattp2[ix] = fr->klatt_param[ix+5]; } - for(peak=0; peak<7; peak++) - { + for (peak = 0; peak < 7; peak++) { fr_out->klatt_ap[ix] = fr->peaks[peak].klt_ap; x = fr->peaks[peak].klt_bp / 2; - if(x > 255) x = 255; + if (x > 255) x = 255; fr_out->klatt_bp[ix] = x; } } - if(fr_out->bw[1] == 0) - { + if (fr_out->bw[1] == 0) { fr_out->bw[0] = 89 / 2; fr_out->bw[1] = 90 / 2; fr_out->bw[2] = 140 / 2; @@ -1564,25 +1466,22 @@ int LoadSpect(const char *path, int control) } } - if(klatt_flag) - { + if (klatt_flag) { seqk_out.n_frames = seq_out.n_frames; seqk_out.sqflags = seq_out.sqflags; seqk_out.length_total = seq_out.length_total; ix = (char *)(&seqk_out.frame[seqk_out.n_frames]) - (char *)(&seqk_out); ix = (ix+3) & 0xfffc; // round up to multiple of 4 bytes - fwrite(&seqk_out,ix,1,f_phdata); - } - else - { + fwrite(&seqk_out, ix, 1, f_phdata); + } else { ix = (char *)(&seq_out.frame[seq_out.n_frames]) - (char *)(&seq_out); ix = (ix+3) & 0xfffc; // round up to multiple of 4 bytes - fwrite(&seq_out,ix,1,f_phdata); + fwrite(&seq_out, ix, 1, f_phdata); } SpectSeqDestroy(spectseq); - return(displ); + return (displ); } @@ -1605,76 +1504,67 @@ static int LoadWavefile(FILE *f, const char *fname) const char *fname2; char fname_temp[100]; char msg[120]; - int scale_factor=0; + int scale_factor = 0; - fseek(f,24,SEEK_SET); + fseek(f, 24, SEEK_SET); sr1 = Read4Bytes(f); sr2 = Read4Bytes(f); - fseek(f,40,SEEK_SET); + fseek(f, 40, SEEK_SET); - if((sr1 != samplerate_native) || (sr2 != sr1*2)) - { + if ((sr1 != samplerate_native) || (sr2 != sr1*2)) { int fd_temp; char command[sizeof(path_home)+250]; failed = 0; #ifdef PLATFORM_POSIX - strcpy(fname_temp,"/tmp/espeakXXXXXX"); - if((fd_temp = mkstemp(fname_temp)) >= 0) - { + strcpy(fname_temp, "/tmp/espeakXXXXXX"); + if ((fd_temp = mkstemp(fname_temp)) >= 0) { close(fd_temp); } #else - strcpy(fname_temp,tmpnam(NULL)); + strcpy(fname_temp, tmpnam(NULL)); #endif fname2 = fname; len = strlen(fname); - if(strcmp(&fname[len-4], ".wav") == 0) - { + if (strcmp(&fname[len-4], ".wav") == 0) { strcpy(msg, fname); msg[len-4] = 0; fname2 = msg; } - 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) - { + 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) { failed = 1; } - if(failed || (GetFileLength(fname_temp) <= 0)) - { - if(resample_fails < 2) + if (failed || (GetFileLength(fname_temp) <= 0)) { + if (resample_fails < 2) error("Resample command failed: %s", command); resample_fails++; - if(sr1 != samplerate_native) - { + if (sr1 != samplerate_native) { sprintf(msg, "Can't resample (%d to %d): %s", sr1, samplerate_native, fname); error("%s", msg); - } - else - { + } else { error("WAV file is not mono: %s", fname); } remove(fname_temp); - return(0); + return (0); } - f = fopen(fname_temp,"rb"); - if(f == NULL) - { - error("Can't read temp file: %s",fname_temp); - return(0); + f = fopen(fname_temp, "rb"); + if (f == NULL) { + error("Can't read temp file: %s", fname_temp); + return (0); } - if(f_report != NULL) + if (f_report != NULL) fprintf(f_report, "resampled %s\n", fname); resample_count++; resample_wav = 1; - fseek(f,40,SEEK_SET); // skip past the WAV header, up to before "data length" + fseek(f, 40, SEEK_SET); // skip past the WAV header, up to before "data length" } displ = ftell(f_phdata); @@ -1682,21 +1572,19 @@ static int LoadWavefile(FILE *f, const char *fname) // data contains: 4 bytes of length (n_samples * 2), followed by 2-byte samples (lsb byte first) length = Read4Bytes(f); - while(!feof(f)) - { + while (!feof(f)) { c1 = fgetc(f); c3 = fgetc(f); - if(feof(f)) break; + if (feof(f)) break; c2 = c3 << 24; c2 = c2 >> 16; // sign extend sample = (c1 & 0xff) + c2; - if(sample > max) + if (sample > max) max = sample; - else - if(sample < -max) + else if (sample < -max) max = -sample; } @@ -1704,16 +1592,14 @@ static int LoadWavefile(FILE *f, const char *fname) scale_factor = (max / 127) + 1; #define MIN_FACTOR -1 // was 6, disable use of 16 bit samples - if(scale_factor > MIN_FACTOR) - { + if (scale_factor > MIN_FACTOR) { length = length/2 + (scale_factor << 16); } - Write4Bytes(f_phdata,length); - fseek(f,44,SEEK_SET); + Write4Bytes(f_phdata, length); + fseek(f, 44, SEEK_SET); - while(!feof(f)) - { + while (!feof(f)) { c1 = fgetc(f); c3 = fgetc(f); c2 = c3 << 24; @@ -1721,39 +1607,34 @@ static int LoadWavefile(FILE *f, const char *fname) sample = (c1 & 0xff) + c2; - if(feof(f)) break; + if (feof(f)) break; - if(scale_factor <= MIN_FACTOR) - { - fputc(sample & 0xff,f_phdata); - fputc(sample >> 8,f_phdata); - } - else - { + if (scale_factor <= MIN_FACTOR) { + fputc(sample & 0xff, f_phdata); + fputc(sample >> 8, f_phdata); + } else { x = ((float)sample / scale_factor) + 0.5; - sample2= (int)x; - if(sample2 > 127) + sample2 = (int)x; + if (sample2 > 127) sample2 = 127; - if(sample2 < -128) + if (sample2 < -128) sample2 = -128; - fputc(sample2,f_phdata); + fputc(sample2, f_phdata); } } length = ftell(f_phdata); - while((length & 3) != 0) - { + while ((length & 3) != 0) { // pad to a multiple of 4 bytes - fputc(0,f_phdata); + fputc(0, f_phdata); length++; } - if(resample_wav != 0) - { + if (resample_wav != 0) { fclose(f); remove(fname_temp); } - return(displ | 0x800000); // set bit 23 to indicate a wave file rather than a spectrum + return (displ | 0x800000); // set bit 23 to indicate a wave file rather than a spectrum } @@ -1765,21 +1646,19 @@ static int LoadEnvelope(FILE *f, const char *fname) displ = ftell(f_phdata); - fseek(f,12,SEEK_SET); - if(fread(buf,128,1,f) == 0) - { - error("Failed to read envelope: %s",fname); + fseek(f, 12, SEEK_SET); + if (fread(buf, 128, 1, f) == 0) { + error("Failed to read envelope: %s", fname); } - fwrite(buf,128,1,f_phdata); + fwrite(buf, 128, 1, 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])); + 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); } @@ -1788,18 +1667,17 @@ static int LoadEnvelope(FILE *f, const char *fname) static int Hash8(const char *string) { int c; - int chars=0; - int hash=0; + int chars = 0; + int hash = 0; - while((c = *string++) != 0) - { + while ((c = *string++) != 0) { c = tolower(c) - 'a'; hash = hash * 8 + c; hash = (hash & 0x1ff) ^ (hash >> 8); /* exclusive or */ chars++; } - return((hash+chars) & 0xff); + return ((hash+chars) & 0xff); } @@ -1819,16 +1697,14 @@ static int LoadEnvelope2(FILE *f, const char *fname) 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) + 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) - { + 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] *= (float)1.28; // convert range 0-100 to 0-128 n_points++; } @@ -1838,40 +1714,35 @@ static int LoadEnvelope2(FILE *f, const char *fname) ix = -1; ix2 = 0; - for(x=0; x env_x[ix+4]) + for (x = 0; x < ENV_LEN; x++) { + if (x > env_x[ix+4]) ix++; - if(x >= env_x[ix2+1]) + if (x >= env_x[ix2+1]) ix2++; - 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); - } + } else if (n_points > 3) + y = (int)(polint(&env_x[ix], &env_y[ix], 4, x) * 2.55); // convert to range 0-255 else - 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; + 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); + 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); + fwrite(env, 1, 128, f_phdata); - return(displ); + return (displ); } static int LoadDataFile(const char *path, int control) @@ -1883,23 +1754,21 @@ static int LoadDataFile(const char *path, int control) int id; int hash; int addr = 0; - int type_code=' '; + int type_code = ' '; REF_HASH_TAB *p, *p2; char buf[sizeof(path_home)+150]; - if(strcmp(path,"NULL")==0) - return(0); - if(strcmp(path,"DFT")==0) - return(1); + if (strcmp(path, "NULL") == 0) + return (0); + if (strcmp(path, "DFT") == 0) + return (1); count_references++; hash = Hash8(path); p = ref_hash_tab[hash]; - while(p != NULL) - { - if(strcmp(path,p->string)==0) - { + while (p != NULL) { + if (strcmp(path, p->string) == 0) { duplicate_references++; addr = p->value; // already loaded this data break; @@ -1907,121 +1776,97 @@ static int LoadDataFile(const char *path, int control) p = (REF_HASH_TAB *)p->link; } - if(addr == 0) - { - sprintf(buf,"%s/../phsource/%s",path_home,path); + if (addr == 0) { + sprintf(buf, "%s/../phsource/%s", path_home, path); - if((f = fopen(buf,"rb")) == NULL) - { - sprintf(buf,"%s/../phsource/%s.wav",path_home,path); - if((f = fopen(buf,"rb")) == NULL) - { - error("Can't read file: %s",path); - return(0); + if ((f = fopen(buf, "rb")) == NULL) { + sprintf(buf, "%s/../phsource/%s.wav", path_home, path); + if ((f = fopen(buf, "rb")) == NULL) { + error("Can't read file: %s", path); + return (0); } } id = Read4Bytes(f); rewind(f); - if(id == 0x43455053) - { + if (id == 0x43455053) { addr = LoadSpect(path, control); type_code = 'S'; - } - else - if(id == 0x46464952) - { - addr = LoadWavefile(f,path); + } else if (id == 0x46464952) { + addr = LoadWavefile(f, path); type_code = 'W'; - } - else - if(id == 0x43544950) - { - addr = LoadEnvelope(f,path); + } else if (id == 0x43544950) { + addr = LoadEnvelope(f, path); type_code = 'E'; - } - else - if(id == 0x45564E45) - { - addr = LoadEnvelope2(f,path); + } else if (id == 0x45564E45) { + addr = LoadEnvelope2(f, path); type_code = 'E'; - } - else - { - error("File not SPEC or RIFF: %s",path); + } else { + error("File not SPEC or RIFF: %s", path); addr = -1; } fclose(f); - if(addr > 0) - { - fprintf(f_phcontents,"%c 0x%.5x %s\n",type_code,addr & 0x7fffff,path); + if (addr > 0) { + fprintf(f_phcontents, "%c 0x%.5x %s\n", type_code, addr & 0x7fffff, path); } } // add this item to the hash table - if(addr > 0) - { + if (addr > 0) { p = ref_hash_tab[hash]; p2 = (REF_HASH_TAB *)malloc(sizeof(REF_HASH_TAB)+strlen(path)+1); p2->value = addr; p2->ph_mnemonic = phoneme_out->mnemonic; // phoneme which uses this file p2->ph_table = n_phoneme_tabs-1; - strcpy(p2->string,path); + strcpy(p2->string, path); p2->link = (char *)p; ref_hash_tab[hash] = p2; } - return(addr); + return (addr); } static int CompileToneSpec(void) { - int pitch1=0; - int pitch2=0; + int pitch1 = 0; + int pitch2 = 0; int pitch_env = 0; int amp_env = 0; - pitch1 = NextItemBrackets(tNUMBER,2); - pitch2 = NextItemBrackets(tNUMBER,3); + pitch1 = NextItemBrackets(tNUMBER, 2); + pitch2 = NextItemBrackets(tNUMBER, 3); - if(item_terminator == ',') - { - NextItemBrackets(tSTRING,3); + if (item_terminator == ',') { + NextItemBrackets(tSTRING, 3); pitch_env = LoadDataFile(item_string, 0); } - if(item_terminator == ',') - { - NextItemBrackets(tSTRING,1); + if (item_terminator == ',') { + NextItemBrackets(tSTRING, 1); amp_env = LoadDataFile(item_string, 0); } - if(pitch1 < pitch2) - { + if (pitch1 < pitch2) { phoneme_out->start_type = pitch1; phoneme_out->end_type = pitch2; - } - else - { + } else { phoneme_out->start_type = pitch2; phoneme_out->end_type = pitch1; } - if(pitch_env != 0) - { + if (pitch_env != 0) { *prog_out++ = i_PITCHENV + ((pitch_env >> 16) & 0xf); *prog_out++ = pitch_env; } - if(amp_env != 0) - { + if (amp_env != 0) { *prog_out++ = i_AMPENV + ((amp_env >> 16) & 0xf); *prog_out++ = amp_env; } - return(0); + return (0); } @@ -2031,33 +1876,26 @@ int CompileSound(int keyword, int isvowel) int addr; int value = 0; char path[N_ITEM_STRING]; - static int sound_instns[] = {i_FMT, i_WAV, i_VWLSTART, i_VWLENDING, i_WAVADD}; + static int sound_instns[] = { i_FMT, i_WAV, i_VWLSTART, i_VWLENDING, i_WAVADD }; - NextItemBrackets(tSTRING,2); + NextItemBrackets(tSTRING, 2); strcpy(path, item_string); - if(item_terminator == ',') - { - if((keyword == kVOWELSTART) || (keyword == kVOWELENDING)) - { - value = NextItemBrackets(tSIGNEDNUMBER,1); - if(value > 127) - { + if (item_terminator == ',') { + if ((keyword == kVOWELSTART) || (keyword == kVOWELENDING)) { + value = NextItemBrackets(tSIGNEDNUMBER, 1); + if (value > 127) { value = 127; - error("Parameter > 127",NULL); + error("Parameter > 127", NULL); } - if(value < -128) - { + if (value < -128) { value = -128; - error("Parameter < -128",NULL); + error("Parameter < -128", NULL); } - } - else - { - value = NextItemBrackets(tNUMBER,1); - if(value > 255) - { + } else { + value = NextItemBrackets(tNUMBER, 1); + if (value > 255) { value = 255; - error("Parameter > 255",NULL); + error("Parameter > 255", NULL); } } } @@ -2066,7 +1904,7 @@ int CompileSound(int keyword, int isvowel) *prog_out++ = sound_instns[keyword-kFMT] + ((value & 0xff) << 4) + ((addr >> 16) & 0xf); *prog_out++ = addr & 0xffff; - return(0); + return (0); } @@ -2098,111 +1936,93 @@ int CompileIf(int elif) then_count = 2; after_if = 1; - while(!finish) - { + while (!finish) { not_flag = 0; word2 = 0; - if(prog_out >= prog_out_max) - { + if (prog_out >= prog_out_max) { error("Phoneme program too large", NULL); - return(0); + return (0); } - if((key = NextItem(tCONDITION)) < 0) - error("Expected a condition, not '%s'",item_string); + if ((key = NextItem(tCONDITION)) < 0) + error("Expected a condition, not '%s'", item_string); - if((item_type == 0) && (key == k_NOT)) - { + if ((item_type == 0) && (key == k_NOT)) { not_flag = 1; - if((key = NextItem(tCONDITION)) < 0) - error("Expected a condition, not '%s'",item_string); + if ((key = NextItem(tCONDITION)) < 0) + error("Expected a condition, not '%s'", item_string); } - if(item_type == tWHICH_PHONEME) - { + if (item_type == tWHICH_PHONEME) { // prevPh(), thisPh(), nextPh(), next2Ph() etc - if(key >= 6) - { + if (key >= 6) { // put the 'which' code in the next instruction word2 = key; key = 6; } key = key << 8; - data = NextItemBrackets(tPROPERTIES,0); - if(data >= 0) - { + data = NextItemBrackets(tPROPERTIES, 0); + if (data >= 0) { word = key + data + 0x700; - } - else - { - data = LookupPhoneme(item_string,2); + } else { + data = LookupPhoneme(item_string, 2); word = key + data; } - } - else - if(item_type == tTEST) - { - if(key == kTHISSTRESS) - { + } else if (item_type == tTEST) { + if (key == kTHISSTRESS) { bitmap = 0; brackets = 2; do { - data = NextItemBrackets(tNUMBER,brackets); - if(data > 7) - error("Expected list of stress levels",NULL); + data = NextItemBrackets(tNUMBER, brackets); + if (data > 7) + error("Expected list of stress levels", NULL); bitmap |= (1 << data); brackets = 3; - } while(item_terminator == ','); + } while (item_terminator == ','); word = i_StressLevel | bitmap; - } - else - { + } else { word = key; } - } - else - { - error("Unexpected keyword '%s'",item_string); + } else { + error("Unexpected keyword '%s'", item_string); - if((strcmp(item_string, "phoneme") == 0) || (strcmp(item_string, "endphoneme") == 0)) - return(-1); + if ((strcmp(item_string, "phoneme") == 0) || (strcmp(item_string, "endphoneme") == 0)) + return (-1); } // output the word prog_last_if = prog_out; *prog_out++ = word | i_CONDITION; - if(word2 != 0) + if (word2 != 0) *prog_out++ = word2; - if(not_flag) + if (not_flag) *prog_out++ = i_NOT; // expect AND, OR, THEN - switch(NextItem(tCONDITION)) + switch (NextItem(tCONDITION)) { case k_AND: break; case k_OR: - if(prog_last_if != NULL) + if (prog_last_if != NULL) *prog_last_if |= i_OR; break; case k_THEN: finish = 1; break; default: - error("Expected AND, OR, THEN",NULL); + error("Expected AND, OR, THEN", NULL); break; } } - if(finish != 1) - { + if (finish != 1) { } - if(elif == 0) - { + if (elif == 0) { if_level++; if_stack[if_level].p_else = NULL; } @@ -2211,7 +2031,7 @@ int CompileIf(int elif) if_stack[if_level].p_then = prog_out; *prog_out++ = i_JUMP_FALSE; - return(0); + return (0); } @@ -2221,26 +2041,20 @@ void FillThen(int add) int offset; p = if_stack[if_level].p_then; - if(p != NULL) - { + if (p != NULL) { offset = prog_out - p + add; - if((then_count == 1) && (if_level == 1)) - { + if ((then_count == 1) && (if_level == 1)) { // The THEN part only contains one statement, we can remove the THEN jump // and the interpreter will implicitly skip the statement. - while(p < prog_out) - { + while (p < prog_out) { p[0] = p[1]; p++; } prog_out--; - } - else - { - if(offset > MAX_JUMP) - { - error("IF block is too long",NULL); + } else { + if (offset > MAX_JUMP) { + error("IF block is too long", NULL); } *p = i_JUMP_FALSE + offset; } @@ -2256,48 +2070,41 @@ int CompileElse(void) USHORT *ref; USHORT *p; - if(if_level < 1) - { - error("ELSE not expected",NULL); - return(0); + if (if_level < 1) { + error("ELSE not expected", NULL); + return (0); } - if(if_stack[if_level].returned == 0) - { + if (if_stack[if_level].returned == 0) { FillThen(1); - } - else - { + } else { FillThen(0); } - if(if_stack[if_level].returned == 0) - { + if (if_stack[if_level].returned == 0) { ref = prog_out; *prog_out++ = 0; - if((p = if_stack[if_level].p_else) != NULL) - { + if ((p = if_stack[if_level].p_else) != NULL) { *ref = ref - p; // backwards offset to the previous else } if_stack[if_level].p_else = ref; } - return(0); + return (0); } int CompileElif(void) { - if(if_level < 1) - { - error("ELIF not expected",NULL); - return(0); + if (if_level < 1) { + error("ELIF not expected", NULL); + return (0); } CompileElse(); CompileIf(1); - return(0); + return (0); } @@ -2307,24 +2114,20 @@ int CompileEndif(void) int chain; int offset; - if(if_level < 1) - { - error("ENDIF not expected",NULL); - return(0); + if (if_level < 1) { + error("ENDIF not expected", NULL); + return (0); } FillThen(0); - if((p = if_stack[if_level].p_else) != NULL) - { - do - { + if ((p = if_stack[if_level].p_else) != NULL) { + do { chain = *p; // a chain of previous else links offset = prog_out - p; - if(offset > MAX_JUMP) - { - error("IF block is too long",NULL); + if (offset > MAX_JUMP) { + error("IF block is too long", NULL); } *p = i_JUMP + offset; @@ -2333,7 +2136,7 @@ int CompileEndif(void) } if_level--; - return(0); + return (0); } @@ -2343,17 +2146,16 @@ static int CompileSwitch(int type) // 1: SwitchPrevVowelType // 2: SwitchNextVowelType - if(type == 0) - { + if (type == 0) { // check the instructions in the Switch - return(0); + return (0); } - if(type == 1) + if (type == 1) *prog_out++ = i_SWITCH_PREVVOWEL+6; - if(type == 2) + if (type == 2) *prog_out++ = i_SWITCH_NEXTVOWEL+6; - return(0); + return (0); } @@ -2362,15 +2164,13 @@ static PHONEME_TAB_LIST *FindPhonemeTable(const char *string) { int ix; - for(ix=0; ixphoneme_tab_ptr[ix].mnemonic) - { - return(&phtab->phoneme_tab_ptr[ix]); + for (ix = 1; ix < 256; ix++) { + if (mnem == phtab->phoneme_tab_ptr[ix].mnemonic) { + return (&phtab->phoneme_tab_ptr[ix]); } } - error("Phoneme reference not found: '%s'",string); - return(NULL); + error("Phoneme reference not found: '%s'", string); + return (NULL); } @@ -2424,16 +2219,15 @@ static void ImportPhoneme(void) NextItem(tSTRING); - if((ph = FindPhoneme(item_string)) == NULL) + if ((ph = FindPhoneme(item_string)) == NULL) return; ph_mnem = phoneme_out->mnemonic; ph_code = phoneme_out->code; - memcpy(phoneme_out,ph,sizeof(PHONEME_TAB)); + memcpy(phoneme_out, ph, sizeof(PHONEME_TAB)); phoneme_out->mnemonic = ph_mnem; phoneme_out->code = ph_code; - if(phoneme_out->type != phVOWEL) - { + if (phoneme_out->type != phVOWEL) { phoneme_out->end_type = 0; // voicingswitch, this must be set later to refer to a local phoneme } @@ -2449,23 +2243,19 @@ static void CallPhoneme(void) NextItem(tSTRING); // first look for a procedure name - for(ix=0; ixprogram; - if(phoneme_out->type == phINVALID) - { + if (phoneme_out->type == phINVALID) { // Phoneme type has not been set. Copy it from the called phoneme phoneme_out->type = ph->type; phoneme_flags = ph->phflags & ~phARTICULATION; @@ -2484,7 +2274,7 @@ static void CallPhoneme(void) static void DecThenCount() { - if(then_count >0) + if (then_count > 0) then_count--; } @@ -2492,7 +2282,7 @@ static void InstnPlusPhoneme(int instn) { int phcode; - phcode = NextItemBrackets(tPHONEMEMNEM,0); + phcode = NextItemBrackets(tPHONEMEMNEM, 0); *prog_out++ = instn + phcode; } @@ -2524,23 +2314,19 @@ int CompilePhoneme(int compile_phoneme) place_articulation = 0; NextItem(tSTRING); - if(compile_phoneme) - { - phcode = LookupPhoneme(item_string,1); // declare phoneme if not already there - if(phcode == -1) return(0); + if (compile_phoneme) { + phcode = LookupPhoneme(item_string, 1); // declare phoneme if not already there + if (phcode == -1) return (0); phoneme_out = &phoneme_tab2[phcode]; - } - else - { + } else { // declare a procedure - if(n_procs >= N_PROCS) - { - error("Too many procedures",NULL); - return(0); + if (n_procs >= N_PROCS) { + error("Too many procedures", NULL); + return (0); } strcpy(proc_names[n_procs], item_string); phoneme_out = &phoneme_out2; - sprintf(number_buf,"%.3dP", n_procs); + sprintf(number_buf, "%.3dP", n_procs); phoneme_out->mnemonic = StringToWord(number_buf); } @@ -2552,30 +2338,27 @@ int CompilePhoneme(int compile_phoneme) phoneme_out->end_type = 0; phoneme_out->length_mod = 0; - while(!endphoneme && !feof(f_in)) - { - if((keyword = NextItem(tKEYWORD)) < 0) - { - if(keyword == -2) - { - error("Missing 'endphoneme' before end-of-file",NULL); // end of file + while (!endphoneme && !feof(f_in)) { + if ((keyword = NextItem(tKEYWORD)) < 0) { + if (keyword == -2) { + error("Missing 'endphoneme' before end-of-file", NULL); // end of file break; } - error("Bad keyword in phoneme definition '%s'",item_string); + error("Bad keyword in phoneme definition '%s'", item_string); continue; } - switch(item_type) + switch (item_type) { case tPHONEME_TYPE: - if(phoneme_out->type != phINVALID) - error("More than one phoneme type: %s",item_string); + if (phoneme_out->type != phINVALID) + error("More than one phoneme type: %s", item_string); phoneme_out->type = keyword; break; case tPLACE: - if(place_articulation > 0) - error("Place of articulation has already been given: %s",item_string); + if (place_articulation > 0) + error("Place of articulation has already been given: %s", item_string); place_articulation = keyword; break; @@ -2585,7 +2368,7 @@ int CompilePhoneme(int compile_phoneme) case tINSTRN1: // instruction group 0, with 8 bit operands which set data in PHONEME_DATA - switch(keyword) + switch (keyword) { case i_CHANGE_PHONEME: case i_APPEND_PHONEME: @@ -2615,17 +2398,13 @@ int CompilePhoneme(int compile_phoneme) case i_SET_LENGTH: value = NextItemMax(511); - if(phoneme_out->type == phVOWEL) - { + if (phoneme_out->type == phVOWEL) { value = (value * vowel_length_factor)/100; } - if(after_if == 0) - { + if (after_if == 0) { phoneme_out->std_length = value/2; - } - else - { + } else { *prog_out++ = (i_SET_LENGTH << 8) + value/2; DecThenCount(); } @@ -2645,46 +2424,38 @@ int CompilePhoneme(int compile_phoneme) case i_IPA_NAME: NextItem(tSTRING); - if(strcmp(item_string,"NULL")==0) - strcpy(item_string," "); + if (strcmp(item_string, "NULL") == 0) + strcpy(item_string, " "); // copy the string, recognize characters in the form U+9999 flags = 0; count = 0; ix = 1; - for(p=item_string; *p != 0; ) - { + for (p = item_string; *p != 0;) { p += utf8_in(&c, p); - if((c == '|') && (count > 0)) - { + if ((c == '|') && (count > 0)) { // '|' means don't allow a tie or joiner before this letter flags |= (1 << (count -1)); - } - else - if((c=='U') && (p[0]=='+')) - { + } else if ((c == 'U') && (p[0] == '+')) { int j; // U+9999 p++; - memcpy(number_buf,p,4); // U+ should be followed by 4 hex digits + memcpy(number_buf, p, 4); // U+ should be followed by 4 hex digits number_buf[4] = 0; c = '#'; - sscanf(number_buf,"%x",&c); + sscanf(number_buf, "%x", &c); // move past the 4 hexdecimal digits - for(j=0; j<4; j++) - { - if(!isalnum(*p)) + for (j = 0; j < 4; j++) { + if (!isalnum(*p)) break; p++; } ix += utf8_out(c, &ipa_buf[ix]); count++; - } - else - { + } else { ix += utf8_out(c, &ipa_buf[ix]); count++; } @@ -2693,13 +2464,12 @@ int CompilePhoneme(int compile_phoneme) ipa_buf[ix] = 0; start = 1; - if(flags != 0) + if (flags != 0) start = 0; // only include the flags byte if bits are set value = strlen(&ipa_buf[start]); // number of UTF-8 bytes *prog_out++ = (i_IPA_NAME << 8) + value; - for(ix=0; ix < value; ix += 2) - { + for (ix = 0; ix < value; ix += 2) { *prog_out++ = (ipa_buf[ix+start] << 8) + (ipa_buf[ix+start+1] & 0xff); } DecThenCount(); @@ -2708,7 +2478,7 @@ int CompilePhoneme(int compile_phoneme) break; case tSTATEMENT: - switch(keyword) + switch (keyword) { case kIMPORT_PH: ImportPhoneme(); @@ -2717,41 +2487,36 @@ int CompilePhoneme(int compile_phoneme) case kSTARTTYPE: phcode = NextItem(tPHONEMEMNEM); - if(phcode == -1) - phcode = LookupPhoneme(item_string,1); + if (phcode == -1) + phcode = LookupPhoneme(item_string, 1); phoneme_out->start_type = phcode; break; case kENDTYPE: phcode = NextItem(tPHONEMEMNEM); - if(phcode == -1) - phcode = LookupPhoneme(item_string,1); - if(phoneme_out->type == phVOWEL) - { + if (phcode == -1) + phcode = LookupPhoneme(item_string, 1); + if (phoneme_out->type == phVOWEL) { phoneme_out->end_type = phcode; - } - else - { - if(phcode != phoneme_out->start_type) - { - error("endtype must equal starttype for consonants",NULL); + } else { + if (phcode != phoneme_out->start_type) { + error("endtype must equal starttype for consonants", NULL); } } break; case kVOICINGSWITCH: phcode = NextItem(tPHONEMEMNEM); - if(phcode == -1) - phcode = LookupPhoneme(item_string,1); + if (phcode == -1) + phcode = LookupPhoneme(item_string, 1); phoneme_out->end_type = phcode; // use end_type field for consonants as voicing_switch break; case kSTRESSTYPE: value = NextItem(tNUMBER); phoneme_out->std_length = value; - if(prog_out > prog_buf) - { - error("stress phonemes can't contain program instructions",NULL); + if (prog_out > prog_buf) { + error("stress phonemes can't contain program instructions", NULL); prog_out = prog_buf; } break; @@ -2791,10 +2556,10 @@ int CompilePhoneme(int compile_phoneme) case kFMT: if_stack[if_level].returned = 1; DecThenCount(); - if(phoneme_out->type == phVOWEL) - endphoneme = CompileSound(keyword,1); + if (phoneme_out->type == phVOWEL) + endphoneme = CompileSound(keyword, 1); else - endphoneme = CompileSound(keyword,0); + endphoneme = CompileSound(keyword, 0); break; case kWAV: @@ -2803,7 +2568,7 @@ int CompilePhoneme(int compile_phoneme) case kVOWELENDING: case kANDWAV: DecThenCount(); - endphoneme = CompileSound(keyword,0); + endphoneme = CompileSound(keyword, 0); break; case kVOWELIN: @@ -2834,16 +2599,14 @@ int CompilePhoneme(int compile_phoneme) case kINCLUDE: case kPHONEMENUMBER: case kPHONEMETABLE: - error("Missing 'endphoneme' before '%s'",item_string); // drop through to endphoneme + error("Missing 'endphoneme' before '%s'", item_string); // drop through to endphoneme case kENDPHONEME: case kENDPROCEDURE: endphoneme = 1; - if(if_level > 0) - { - error("Missing ENDIF",NULL); + if (if_level > 0) { + error("Missing ENDIF", NULL); } - if((prog_out > prog_buf) && (if_stack[0].returned == 0)) - { + if ((prog_out > prog_buf) && (if_stack[0].returned == 0)) { *prog_out++ = i_RETURN; } break; @@ -2853,67 +2616,57 @@ int CompilePhoneme(int compile_phoneme) } } - if(endphoneme != 1) - { - error("'endphoneme' not expected here",NULL); + if (endphoneme != 1) { + error("'endphoneme' not expected here", NULL); } - if(compile_phoneme) - { - if(phoneme_out->type == phINVALID) - { - error("Phoneme type is missing",NULL); + if (compile_phoneme) { + if (phoneme_out->type == phINVALID) { + error("Phoneme type is missing", NULL); phoneme_out->type = 0; } phoneme_out->phflags = place_articulation << 16; phoneme_out->phflags |= phoneme_flags; - if(phoneme_out->phflags & phVOICED) - { - if(phoneme_out->type == phSTOP) + if (phoneme_out->phflags & phVOICED) { + if (phoneme_out->type == phSTOP) phoneme_out->type = phVSTOP; - else - if(phoneme_out->type == phFRICATIVE) + else if (phoneme_out->type == phFRICATIVE) phoneme_out->type = phVFRICATIVE; } - if(phoneme_out->std_length == 0) - { - if(phoneme_out->type == phVOWEL) + if (phoneme_out->std_length == 0) { + if (phoneme_out->type == phVOWEL) phoneme_out->std_length = 180/2; // default length for vowel } - phoneme_out->phflags |= phLOCAL; //declared in this phoneme table + phoneme_out->phflags |= phLOCAL; // declared in this phoneme table - if(phoneme_out->type == phDELETED) - { + if (phoneme_out->type == phDELETED) { phoneme_out->mnemonic = 0x01; // will not be recognised } } DecompilePhoneme(f_errors, phoneme_out, compile_phoneme); - if(prog_out > prog_buf) - { + if (prog_out > prog_buf) { // write out the program for this phoneme fflush(f_phindex); phoneme_out->program = ftell(f_phindex) / sizeof(USHORT); - if(f_prog_log != NULL) - { + if (f_prog_log != NULL) { phoneme_prog_log.addr = phoneme_out->program; phoneme_prog_log.length = prog_out - prog_buf; fwrite(&phoneme_prog_log, 1, sizeof(phoneme_prog_log), f_prog_log); } - if(compile_phoneme == 0) - { + if (compile_phoneme == 0) { proc_addr[n_procs++] = ftell(f_phindex) / sizeof(USHORT); } fwrite(prog_buf, sizeof(USHORT), prog_out - prog_buf, f_phindex); } - return(0); + return (0); } @@ -2930,48 +2683,44 @@ static void WritePhonemeTables() PHONEME_TAB *p; value = n_phoneme_tabs; - fputc(value,f_phtab); - fputc(0,f_phtab); - fputc(0,f_phtab); - fputc(0,f_phtab); + fputc(value, f_phtab); + fputc(0, f_phtab); + fputc(0, f_phtab); + fputc(0, f_phtab); - for(ix=0; ix 0) - { + if ((length = p_equivalence - equivalence_buf) > 0) { // terminate the list of phoneme equivalence tables pw = (int *)p_equivalence; pw[0] = 0; // write the equivalence data into phondata, and remember it's address ix = ftell(f_phdata); - fprintf(f_phcontents,"Q 0x%.5x %s\n", ix, phoneme_tab_list2[n_phoneme_tabs-1].name); + fprintf(f_phcontents, "Q 0x%.5x %s\n", ix, phoneme_tab_list2[n_phoneme_tabs-1].name); phoneme_tab_list2[n_phoneme_tabs-1].equivalence_tables = ix; fwrite(equivalence_buf, length+4, 1, f_phdata); } @@ -3023,17 +2769,15 @@ static void StartPhonemeTable(const char *name) int j; PHONEME_TAB *p; - fprintf(f_errors,"______________________________\nPhoneme Table: '%s'\n",name); + fprintf(f_errors, "______________________________\nPhoneme Table: '%s'\n", name); - if(n_phoneme_tabs >= N_PHONEME_TABS-1) - { + if (n_phoneme_tabs >= N_PHONEME_TABS-1) { Error("Too many phonemetables"); return; } - p = (PHONEME_TAB *)calloc(sizeof(PHONEME_TAB),N_PHONEME_TAB); + p = (PHONEME_TAB *)calloc(sizeof(PHONEME_TAB), N_PHONEME_TAB); - if(p == NULL) - { + if (p == NULL) { Error("Out of memory"); return; } @@ -3045,32 +2789,26 @@ static void StartPhonemeTable(const char *name) phoneme_tab_list2[n_phoneme_tabs].includes = 0; p_equivalence = equivalence_buf; - if(n_phoneme_tabs > 0) - { + if (n_phoneme_tabs > 0) { NextItem(tSTRING); // name of base phoneme table - for(ix=0; ix &equivalence_buf[sizeof(equivalence_buf) - 16]) - { - error("'equivalents' tables are too large",NULL); + if (p_equivalence > &equivalence_buf[sizeof(equivalence_buf) - 16]) { + error("'equivalents' tables are too large", NULL); break; } - if(foreign_error == 0) - { + if (foreign_error == 0) { phcode[0] = foreign_phoneme = LookupPhonemeString(names[0]); - if(foreign_phoneme == 0) - { - sprintf(line_buf,"%s/%s", foreign_table_name, names[0]); + if (foreign_phoneme == 0) { + sprintf(line_buf, "%s/%s", foreign_table_name, names[0]); error("Unknown phoneme '%s'", line_buf); } } - for(ix=1; ix 2) || (phcode[0] != phcode[1])) - { + if ((n_names > 2) || (phcode[0] != phcode[1])) { // write: foreign phoneme number, then a string of local phoneme numbers memcpy(p_equivalence, phcode, n_names); p_equivalence += n_names; @@ -3197,46 +2926,41 @@ static void CompilePhonemeFiles() count_frames = 0; n_procs = 0; - for(;; ) - { - if(feof(f_in)) - { + for (;;) { + if (feof(f_in)) { // end of file, go back to previous from, from which this was included - if(stack_ix == 0) + if (stack_ix == 0) break; // end of top level, finished fclose(f_in); f_in = stack[--stack_ix].file; - strcpy(current_fname,stack[stack_ix].fname); + strcpy(current_fname, stack[stack_ix].fname); linenum = stack[stack_ix].linenum; - fprintf(f_errors,"\n\n"); + fprintf(f_errors, "\n\n"); } item = NextItem(tKEYWORD); - switch(item) + switch (item) { case kUTF8_BOM: break; // ignore bytes 0xef 0xbb 0xbf case kINCLUDE: NextItem(tSTRING); - sprintf(buf,"%s/../phsource/%s",path_home,item_string); + sprintf(buf, "%s/../phsource/%s", path_home, item_string); - if((stack_ix < N_STACK) && (f = fopen_log(f_errors,buf,"rb")) != NULL) - { - fprintf(f_errors,"include %s\n",item_string); + if ((stack_ix < N_STACK) && (f = fopen_log(f_errors, buf, "rb")) != NULL) { + fprintf(f_errors, "include %s\n", item_string); stack[stack_ix].linenum = linenum; - strcpy(stack[stack_ix].fname,current_fname); + strcpy(stack[stack_ix].fname, current_fname); stack[stack_ix++].file = f_in; f_in = f; - strncpy0(current_fname,item_string,sizeof(current_fname)); + strncpy0(current_fname, item_string, sizeof(current_fname)); linenum = 1; - } - else - { + } else { error("Missing file: %s", item_string); } break; @@ -3248,8 +2972,7 @@ static void CompilePhonemeFiles() break; case kPHONEMESTART: - if(n_phoneme_tabs == 0) - { + if (n_phoneme_tabs == 0) { Error("phonemetable is missing"); return; } @@ -3265,7 +2988,7 @@ static void CompilePhonemeFiles() break; default: - if(!feof(f_in)) + if (!feof(f_in)) Error("Keyword 'phoneme' expected"); break; } @@ -3278,93 +3001,90 @@ static void CompilePhonemeFiles() static espeak_ng_STATUS CompilePhonemeData2(const char *source, FILE *log) { char fname[sizeof(path_home)+40]; - sprintf(fname,"%s/../phsource",path_home); + sprintf(fname, "%s/../phsource", path_home); #ifdef MAKE_ENVELOPES make_envs(); #endif - fprintf(log,"Compiling phoneme data: %s\n",fname); + fprintf(log, "Compiling phoneme data: %s\n", fname); n_envelopes = 0; error_count = 0; resample_count = 0; - memset(markers_used,0,sizeof(markers_used)); + memset(markers_used, 0, sizeof(markers_used)); f_errors = log; - if(!access(fname, 755)) - { - fprintf(log,"Can't find phoneme source directory: %s\n",fname); + if (!access(fname, 755)) { + fprintf(log, "Can't find phoneme source directory: %s\n", fname); return ENE_READ_ERROR; } - strncpy0(current_fname,source,sizeof(current_fname)); + strncpy0(current_fname, source, sizeof(current_fname)); - sprintf(fname,"%s/../phsource/phonemes",path_home); - f_in = fopen_log(f_errors,fname,"rb"); - if(f_in == NULL) - { - fprintf(log,"Can't read master phonemes file: %s\n",fname); + sprintf(fname, "%s/../phsource/phonemes", path_home); + f_in = fopen_log(f_errors, fname, "rb"); + if (f_in == NULL) { + fprintf(log, "Can't read master phonemes file: %s\n", fname); return ENE_READ_ERROR; } - sprintf(fname,"%s/../phsource/%s",path_home,"error_log"); - if((f_errors = fopen_log(f_errors,fname,"w")) == NULL) + sprintf(fname, "%s/../phsource/%s", path_home, "error_log"); + if ((f_errors = fopen_log(f_errors, fname, "w")) == NULL) f_errors = stderr; - sprintf(fname,"%s/../phsource/%s",path_home,"compile_report"); - f_report = fopen_log(f_errors, fname,"w"); + sprintf(fname, "%s/../phsource/%s", path_home, "compile_report"); + f_report = fopen_log(f_errors, fname, "w"); - sprintf(fname,"%s/%s",path_home,"phondata-manifest"); - if((f_phcontents = fopen_log(f_phcontents,fname,"w")) == NULL) + sprintf(fname, "%s/%s", path_home, "phondata-manifest"); + if ((f_phcontents = fopen_log(f_phcontents, fname, "w")) == NULL) f_phcontents = stderr; - fprintf (f_phcontents, - "# This file lists the type of data that has been compiled into the\n" - "# phondata file\n" - "#\n" - "# The first character of a line indicates the type of data:\n" - "# S - A SPECT_SEQ structure\n" - "# W - A wavefile segment\n" - "# E - An envelope\n" - "# Q - Phoneme equivalence tables\n" - "#\n" - "# Address is the displacement within phondata of this item\n" - "#\n" - "# Address Data file\n" - "# ------- ---------\n"); + fprintf(f_phcontents, + "# This file lists the type of data that has been compiled into the\n" + "# phondata file\n" + "#\n" + "# The first character of a line indicates the type of data:\n" + "# S - A SPECT_SEQ structure\n" + "# W - A wavefile segment\n" + "# E - An envelope\n" + "# Q - Phoneme equivalence tables\n" + "#\n" + "# Address is the displacement within phondata of this item\n" + "#\n" + "# Address Data file\n" + "# ------- ---------\n"); 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); - sprintf(fname,"%s/%s",path_home,"phondata"); - f_phdata = fopen_log(f_errors,fname,"wb"); + sprintf(fname, "%s/%s", path_home, "phondata"); + f_phdata = fopen_log(f_errors, fname, "wb"); - sprintf(fname,"%s/%s",path_home,"phonindex"); - f_phindex = fopen_log(f_errors,fname,"wb"); + sprintf(fname, "%s/%s", path_home, "phonindex"); + f_phindex = fopen_log(f_errors, fname, "wb"); - sprintf(fname,"%s/%s",path_home,"phontab"); - f_phtab = fopen_log(f_errors,fname,"wb"); + sprintf(fname, "%s/%s", path_home, "phontab"); + f_phtab = fopen_log(f_errors, fname, "wb"); - if(f_phdata==NULL || f_phindex==NULL || f_phtab==NULL) - { + if (f_phdata == NULL || f_phindex == NULL || f_phtab == NULL) { return ENE_WRITE_ERROR; } - sprintf(fname,"%s/../phsource/compile_prog_log",path_home); - f_prog_log = fopen_log(f_errors,fname,"wb"); + sprintf(fname, "%s/../phsource/compile_prog_log", path_home); + f_prog_log = fopen_log(f_errors, fname, "wb"); - fprintf(log,"Compiling phoneme data: %s/../phsource\n",path_home); + fprintf(log, "Compiling phoneme data: %s/../phsource\n", path_home); // write a word so that further data doesn't start at displ=0 - Write4Bytes(f_phdata,version_phdata); - Write4Bytes(f_phdata,samplerate_native); - Write4Bytes(f_phindex,version_phdata); + Write4Bytes(f_phdata, version_phdata); + Write4Bytes(f_phdata, samplerate_native); + Write4Bytes(f_phindex, version_phdata); - memset(ref_hash_tab,0,sizeof(ref_hash_tab)); + memset(ref_hash_tab, 0, sizeof(ref_hash_tab)); n_phoneme_tabs = 0; stack_ix = 0; @@ -3374,10 +3094,10 @@ static espeak_ng_STATUS CompilePhonemeData2(const char *source, FILE *log) EndPhonemeTable(); WritePhonemeTables(); - fprintf(f_errors,"\nRefs %d, Reused %d\n",count_references,duplicate_references); + fprintf(f_errors, "\nRefs %d, Reused %d\n", count_references, duplicate_references); fclose(f_in); fclose(f_phdata); - if(f_prog_log != NULL) + if (f_prog_log != NULL) fclose(f_prog_log); fclose(f_phindex); fclose(f_phtab); @@ -3387,17 +3107,14 @@ static espeak_ng_STATUS CompilePhonemeData2(const char *source, FILE *log) CompileReport(); - if(resample_count > 0) - { + if (resample_count > 0) { fprintf(f_errors, "\n%d WAV files resampled to %d Hz\n", resample_count, samplerate_native); - fprintf(log,"Compiled phonemes: %d errors, %d files resampled to %d Hz.\n",error_count, resample_count, samplerate_native); - } - else - { - fprintf(log,"Compiled phonemes: %d errors.\n",error_count); + fprintf(log, "Compiled phonemes: %d errors, %d files resampled to %d Hz.\n", error_count, resample_count, samplerate_native); + } else { + fprintf(log, "Compiled phonemes: %d errors.\n", error_count); } - if(f_errors != stderr) + if (f_errors != stderr) fclose(f_errors); ReadPhondataManifest(); @@ -3410,38 +3127,38 @@ static const char *preset_tune_names[] = { }; static const TUNE default_tune = { - {0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0}, - {0, 40, 24, 8, 0, 0, 0, 0}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 40, 24, 8, 0, 0, 0, 0 }, 46, 57, PITCHfall, 16, 0, 0, 255, 78, 50, 255, 3, 5, - {-7,-7,-7}, {-7,-7,-7}, + { -7, -7, -7 }, { -7, -7, -7 }, PITCHfall, 64, 8, PITCHfall, 70, 18, 24, 12, PITCHfall, 70, 18, 24, 12, 0, - {0,0,0,0,0,0,0,0}, 0 + { 0, 0, 0, 0, 0, 0, 0, 0 }, 0 }; #define N_TUNE_NAMES 100 MNEM_TAB envelope_names[] = { - {"fall", 0}, - {"rise", 2}, - {"fall-rise", 4}, - {"fall-rise2", 6}, - {"rise-fall", 8}, - {"fall-rise3",10}, - {"fall-rise4",12}, - {"fall2", 14}, - {"rise2", 16}, - {"rise-fall-rise", 18}, - {NULL, -1} + { "fall", 0 }, + { "rise", 2 }, + { "fall-rise", 4 }, + { "fall-rise2", 6 }, + { "rise-fall", 8 }, + { "fall-rise3", 10 }, + { "fall-rise4", 12 }, + { "fall2", 14 }, + { "rise2", 16 }, + { "rise-fall-rise", 18 }, + { NULL, -1 } }; int LookupEnvelopeName(const char *name) { - return(LookupMnem(envelope_names, name)); + return (LookupMnem(envelope_names, name)); } @@ -3449,7 +3166,7 @@ int LookupEnvelopeName(const char *name) espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) { - if(!log) log=stderr; + if (!log) log = stderr; int ix; char *p; char c; @@ -3474,59 +3191,50 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) error_count = 0; f_errors = log; - sprintf(buf,"%s/../phsource/intonation.txt",path_home); - if((f_in = fopen(buf, "r")) == NULL) - { - sprintf(buf,"%s/../phsource/intonation",path_home); - if((f_in = fopen_log(f_errors, buf, "r")) == NULL) - { - fprintf(log,"Can't read file: %s\n",buf); + sprintf(buf, "%s/../phsource/intonation.txt", path_home); + if ((f_in = fopen(buf, "r")) == NULL) { + sprintf(buf, "%s/../phsource/intonation", path_home); + if ((f_in = fopen_log(f_errors, buf, "r")) == NULL) { + fprintf(log, "Can't read file: %s\n", buf); fclose(f_errors); return ENE_READ_ERROR; } } - for(ix=0; preset_tune_names[ix] != NULL; ix++) - { + for (ix = 0; preset_tune_names[ix] != NULL; ix++) { strcpy(tune_names[ix], preset_tune_names[ix]); } n_tune_names = ix; n_preset_tunes = ix; // make a list of the tune names - while(!feof(f_in)) - { - if(fgets(buf,sizeof(buf),f_in) == NULL) + while (!feof(f_in)) { + if (fgets(buf, sizeof(buf), f_in) == NULL) break; - if((memcmp(buf,"tune",4)==0) && isspace(buf[4])) - { + if ((memcmp(buf, "tune", 4) == 0) && isspace(buf[4])) { p = &buf[5]; - while(isspace(*p)) p++; + while (isspace(*p)) p++; ix = 0; - while((ix < (int)(sizeof(name) - 1)) && !isspace(*p)) - { + while ((ix < (int)(sizeof(name) - 1)) && !isspace(*p)) { name[ix++] = *p++; } name[ix] = 0; found = 0; - for(ix = 0; ix < n_tune_names; ix++) - { - if(strcmp(name, tune_names[ix]) == 0) - { + for (ix = 0; ix < n_tune_names; ix++) { + if (strcmp(name, tune_names[ix]) == 0) { found = 1; break; } } - if(found == 0) - { + if (found == 0) { strncpy0(tune_names[n_tune_names++], name, sizeof(name)); - if(n_tune_names >= N_TUNE_NAMES) + if (n_tune_names >= N_TUNE_NAMES) break; } } @@ -3535,33 +3243,29 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) linenum = 1; tune_data = (TUNE *)calloc(sizeof(TUNE), n_tune_names); - if(tune_data == NULL) - { + if (tune_data == NULL) { fprintf(f_errors, "Failed to allocate data for tunes\n"); fclose(f_in); fclose(f_errors); return ENE_OUT_OF_MEMORY; } - sprintf(buf,"%s/intonations",path_home); + sprintf(buf, "%s/intonations", path_home); f_out = fopen_log(f_errors, buf, "wb"); - if(f_out == NULL) - { + if (f_out == NULL) { fclose(f_in); fclose(f_errors); free(tune_data); return ENE_WRITE_ERROR; } - while(!feof(f_in)) - { + while (!feof(f_in)) { keyword = NextItem(tINTONATION); - switch(keyword) + switch (keyword) { case kTUNE: - if(compiling_tune) - { + if (compiling_tune) { } compiling_tune = 1; done_split = 0; @@ -3572,24 +3276,20 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) found = 0; tune_number = 0; - for(ix=0; ix < n_tune_names; ix++) - { - if(strcmp(new_tune.name, tune_names[ix]) == 0) - { + for (ix = 0; ix < n_tune_names; ix++) { + if (strcmp(new_tune.name, tune_names[ix]) == 0) { found = 1; tune_number = ix; - if(tune_data[ix].name[0] != 0) + if (tune_data[ix].name[0] != 0) found = 2; break; } } - if(found == 2) - { - error("Duplicate tune name: '%s'",new_tune.name); + if (found == 2) { + error("Duplicate tune name: '%s'", new_tune.name); } - if(found == 0) - { + if (found == 0) { error("Bad tune name: '%s;", new_tune.name); } break; @@ -3597,13 +3297,11 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) case kENDTUNE: compiling_tune = 0; - if(done_onset == 0) - { + if (done_onset == 0) { new_tune.unstr_start[0] = new_tune.unstr_start[1]; new_tune.unstr_end[0] = new_tune.unstr_end[1]; } - if(done_last == 0) - { + if (done_last == 0) { new_tune.unstr_start[2] = new_tune.unstr_start[1]; new_tune.unstr_end[2] = new_tune.unstr_end[1]; } @@ -3631,8 +3329,8 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) case kTUNE_HEADENV: NextItem(tSTRING); - if((ix = LookupEnvelopeName(item_string)) < 0) - error("Bad envelope name: '%s'",item_string); + if ((ix = LookupEnvelopeName(item_string)) < 0) + error("Bad envelope name: '%s'", item_string); else new_tune.stressed_env = ix; new_tune.stressed_drop = NextItem(tNUMBER); @@ -3648,9 +3346,8 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) case kTUNE_HEADEXTEND: // up to 8 numbers - for(ix=0; ix < (int)(sizeof(new_tune.head_extend)); ix++) - { - if(!isdigit(c = CheckNextChar()) && (c != '-')) + for (ix = 0; ix < (int)(sizeof(new_tune.head_extend)); ix++) { + if (!isdigit(c = CheckNextChar()) && (c != '-')) break; new_tune.head_extend[ix] = (NextItem(tSIGNEDNUMBER) * 64) / 100; // convert from percentage to 64ths @@ -3660,9 +3357,8 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) case kTUNE_NUCLEUS0: NextItem(tSTRING); - if((ix = LookupEnvelopeName(item_string)) < 0) - { - error("Bad envelope name: '%s'",item_string); + if ((ix = LookupEnvelopeName(item_string)) < 0) { + error("Bad envelope name: '%s'", item_string); break; } new_tune.nucleus0_env = ix; @@ -3672,9 +3368,8 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) case kTUNE_NUCLEUS1: NextItem(tSTRING); - if((ix = LookupEnvelopeName(item_string)) < 0) - { - error("Bad envelope name: '%s'",item_string); + if ((ix = LookupEnvelopeName(item_string)) < 0) { + error("Bad envelope name: '%s'", item_string); break; } new_tune.nucleus1_env = ix; @@ -3683,8 +3378,7 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) new_tune.tail_start = NextItem(tNUMBER); new_tune.tail_end = NextItem(tNUMBER); - if(!done_split) - { + if (!done_split) { // also this as the default setting for 'split' new_tune.split_nucleus_env = ix; new_tune.split_nucleus_max = new_tune.nucleus1_max; @@ -3696,9 +3390,8 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) case kTUNE_SPLIT: NextItem(tSTRING); - if((ix = LookupEnvelopeName(item_string)) < 0) - { - error("Bad envelope name: '%s'",item_string); + if ((ix = LookupEnvelopeName(item_string)) < 0) { + error("Bad envelope name: '%s'", item_string); break; } done_split = 1; @@ -3709,28 +3402,25 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) new_tune.split_tail_end = NextItem(tNUMBER); NextItem(tSTRING); item_string[12] = 0; - for(ix=0; ix < n_tune_names; ix++) - { - if(strcmp(item_string, tune_names[ix]) == 0) + for (ix = 0; ix < n_tune_names; ix++) { + if (strcmp(item_string, tune_names[ix]) == 0) break; } - if(ix == n_tune_names) - error("Tune '%s' not found",item_string); + if (ix == n_tune_names) + error("Tune '%s' not found", item_string); else new_tune.split_tune = ix; break; default: - error("Unexpected: '%s'",item_string); + error("Unexpected: '%s'", item_string); break; } } - for(ix = 0; ix < n_preset_tunes; ix++) - { - if(tune_data[ix].name[0] == 0) - { + for (ix = 0; ix < n_preset_tunes; ix++) { + if (tune_data[ix].name[0] == 0) { error("Tune '%s' not defined", preset_tune_names[ix]); } } @@ -3739,7 +3429,7 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) fclose(f_in); fclose(f_out); - fprintf(log,"Compiled %d intonation tunes: %d errors.\n",n_tune_names, error_count); + fprintf(log, "Compiled %d intonation tunes: %d errors.\n", n_tune_names, error_count); LoadPhData(NULL); @@ -3750,7 +3440,7 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) espeak_ng_STATUS espeak_ng_CompilePhonemeData(long rate, FILE *log) { - if(!log) log=stderr; + if (!log) log = stderr; WavegenInit(rate, 0); WavegenSetVoice(voice); return CompilePhonemeData2("phonemes", log); diff --git a/src/libespeak-ng/compiledict.c b/src/libespeak-ng/compiledict.c index a98e7580..04fc35d6 100644 --- a/src/libespeak-ng/compiledict.c +++ b/src/libespeak-ng/compiledict.c @@ -54,101 +54,101 @@ static char *hash_chains[N_HASH_DICT]; static char letterGroupsDefined[N_LETTER_GROUPS]; MNEM_TAB mnem_rules[] = { - {"unpr", DOLLAR_UNPR}, - {"noprefix", DOLLAR_NOPREFIX}, // rule fails if a prefix has been removed - {"list", DOLLAR_LIST}, // a pronunciation is given in the *_list file + { "unpr", DOLLAR_UNPR }, + { "noprefix", DOLLAR_NOPREFIX }, // rule fails if a prefix has been removed + { "list", DOLLAR_LIST }, // a pronunciation is given in the *_list file - {"w_alt1", 0x11}, - {"w_alt2", 0x12}, - {"w_alt3", 0x13}, - {"w_alt4", 0x14}, - {"w_alt5", 0x15}, - {"w_alt6", 0x16}, - {"w_alt", 0x11}, // note: put longer names before their sub-strings + { "w_alt1", 0x11 }, + { "w_alt2", 0x12 }, + { "w_alt3", 0x13 }, + { "w_alt4", 0x14 }, + { "w_alt5", 0x15 }, + { "w_alt6", 0x16 }, + { "w_alt", 0x11 }, // note: put longer names before their sub-strings - {"p_alt1", 0x21}, - {"p_alt2", 0x22}, - {"p_alt3", 0x23}, - {"p_alt4", 0x24}, - {"p_alt5", 0x25}, - {"p_alt6", 0x26}, - {"p_alt", 0x21}, - {NULL, -1} + { "p_alt1", 0x21 }, + { "p_alt2", 0x22 }, + { "p_alt3", 0x23 }, + { "p_alt4", 0x24 }, + { "p_alt5", 0x25 }, + { "p_alt6", 0x26 }, + { "p_alt", 0x21 }, + { NULL, -1 } }; MNEM_TAB mnem_flags[] = { // these in the first group put a value in bits0-3 of dictionary_flags - {"$1", 0x41}, // stress on 1st syllable - {"$2", 0x42}, // stress on 2nd syllable - {"$3", 0x43}, - {"$4", 0x44}, - {"$5", 0x45}, - {"$6", 0x46}, - {"$7", 0x47}, - {"$u", 0x48}, // reduce to unstressed - {"$u1", 0x49}, - {"$u2", 0x4a}, - {"$u3", 0x4b}, - {"$u+", 0x4c}, // reduce to unstressed, but stress at end of clause - {"$u1+", 0x4d}, - {"$u2+", 0x4e}, - {"$u3+", 0x4f}, + { "$1", 0x41 }, // stress on 1st syllable + { "$2", 0x42 }, // stress on 2nd syllable + { "$3", 0x43 }, + { "$4", 0x44 }, + { "$5", 0x45 }, + { "$6", 0x46 }, + { "$7", 0x47 }, + { "$u", 0x48 }, // reduce to unstressed + { "$u1", 0x49 }, + { "$u2", 0x4a }, + { "$u3", 0x4b }, + { "$u+", 0x4c }, // reduce to unstressed, but stress at end of clause + { "$u1+", 0x4d }, + { "$u2+", 0x4e }, + { "$u3+", 0x4f }, // these set the corresponding numbered bit if dictionary_flags - {"$pause", 8}, // ensure pause before this word - {"$strend", 9}, // full stress if at end of clause - {"$strend2", 10}, // full stress if at end of clause, or only followed by unstressed - {"$unstressend",11}, // reduce stress at end of clause - {"$accent_before",12}, // used with accent names, say this accent name before the letter name - {"$abbrev", 13}, // use this pronuciation rather than split into letters + { "$pause", 8 }, // ensure pause before this word + { "$strend", 9 }, // full stress if at end of clause + { "$strend2", 10 }, // full stress if at end of clause, or only followed by unstressed + { "$unstressend", 11 }, // reduce stress at end of clause + { "$accent_before", 12 }, // used with accent names, say this accent name before the letter name + { "$abbrev", 13 }, // use this pronuciation rather than split into letters // language specific - {"$double", 14}, // IT double the initial consonant of next word - {"$alt", 15}, // use alternative pronunciation - {"$alt1", 15}, // synonym for $alt - {"$alt2", 16}, - {"$alt3", 17}, - {"$alt4", 18}, - {"$alt5", 19}, - {"$alt6", 20}, - {"$alt7", 21}, + { "$double", 14 }, // IT double the initial consonant of next word + { "$alt", 15 }, // use alternative pronunciation + { "$alt1", 15 }, // synonym for $alt + { "$alt2", 16 }, + { "$alt3", 17 }, + { "$alt4", 18 }, + { "$alt5", 19 }, + { "$alt6", 20 }, + { "$alt7", 21 }, - {"$combine", 23}, // Combine with the next word + { "$combine", 23 }, // Combine with the next word - {"$dot", 24}, // ignore '.' after this word (abbreviation) - {"$hasdot", 25}, // use this pronunciation if there is a dot after the word + { "$dot", 24 }, // ignore '.' after this word (abbreviation) + { "$hasdot", 25 }, // use this pronunciation if there is a dot after the word - {"$max3", 27}, // limit to 3 repetitions - {"$brk", 28}, // a shorter $pause - {"$text", 29}, // word translates to replcement text, not phonemes + { "$max3", 27 }, // limit to 3 repetitions + { "$brk", 28 }, // a shorter $pause + { "$text", 29 }, // word translates to replcement text, not phonemes // flags in dictionary word 2 - {"$verbf", 0x20}, // verb follows - {"$verbsf", 0x21}, // verb follows, allow -s suffix - {"$nounf", 0x22}, // noun follows - {"$pastf", 0x23}, // past tense follows - {"$verb", 0x24}, // use this pronunciation when its a verb - {"$noun", 0x25}, // use this pronunciation when its a noun - {"$past", 0x26}, // use this pronunciation when its past tense - {"$verbextend",0x28}, // extend influence of 'verb follows' - {"$capital", 0x29}, // use this pronunciation if initial letter is upper case - {"$allcaps", 0x2a}, // use this pronunciation if initial letter is upper case - {"$accent", 0x2b}, // character name is base-character name + accent name - {"$sentence",0x2d}, // only if this clause is a sentence (i.e. terminator is {. ? !} not {, ; :} - {"$only", 0x2e}, // only match on this word without suffix - {"$onlys", 0x2f}, // only match with none, or with 's' suffix - {"$stem", 0x30}, // must have a suffix - {"$atend", 0x31}, // use this pronunciation if at end of clause - {"$atstart", 0x32}, // use this pronunciation at start of clause - {"$native", 0x33}, // not if we've switched translators + { "$verbf", 0x20 }, // verb follows + { "$verbsf", 0x21 }, // verb follows, allow -s suffix + { "$nounf", 0x22 }, // noun follows + { "$pastf", 0x23 }, // past tense follows + { "$verb", 0x24 }, // use this pronunciation when its a verb + { "$noun", 0x25 }, // use this pronunciation when its a noun + { "$past", 0x26 }, // use this pronunciation when its past tense + { "$verbextend", 0x28 }, // extend influence of 'verb follows' + { "$capital", 0x29 }, // use this pronunciation if initial letter is upper case + { "$allcaps", 0x2a }, // use this pronunciation if initial letter is upper case + { "$accent", 0x2b }, // character name is base-character name + accent name + { "$sentence", 0x2d }, // only if this clause is a sentence (i.e. terminator is {. ? !} not {, ; :} + { "$only", 0x2e }, // only match on this word without suffix + { "$onlys", 0x2f }, // only match with none, or with 's' suffix + { "$stem", 0x30 }, // must have a suffix + { "$atend", 0x31 }, // use this pronunciation if at end of clause + { "$atstart", 0x32 }, // use this pronunciation at start of clause + { "$native", 0x33 }, // not if we've switched translators // doesn't set dictionary_flags - {"$?", 100}, // conditional rule, followed by byte giving the condition number + { "$?", 100 }, // conditional rule, followed by byte giving the condition number - {"$textmode", 200}, - {"$phonememode", 201}, - {NULL, -1} + { "$textmode", 200 }, + { "$phonememode", 201 }, + { NULL, -1 } }; @@ -167,37 +167,35 @@ int isspace2(unsigned int c) // can't use isspace() because on Windows, isspace(0xe1) gives TRUE ! int c2; - if(((c2 = (c & 0xff)) == 0) || (c > ' ')) - return(0); - return(1); + if (((c2 = (c & 0xff)) == 0) || (c > ' ')) + return (0); + return (1); } -static FILE *fopen_log(const char *fname,const char *access) +static FILE *fopen_log(const char *fname, const char *access) { // performs fopen, but produces error message to f_log if it fails FILE *f; - if((f = fopen(fname,access)) == NULL) - { - if(f_log != NULL) - fprintf(f_log,"Can't access (%s) file '%s'\n",access,fname); + if ((f = fopen(fname, access)) == NULL) { + if (f_log != NULL) + fprintf(f_log, "Can't access (%s) file '%s'\n", access, fname); } - return(f); + return (f); } /* Lookup a mnemonic string in a table, return its name */ const char *LookupMnemName(MNEM_TAB *table, const int value) { - while(table->mnem != NULL) - { - if(table->value==value) - return(table->mnem); + while (table->mnem != NULL) { + if (table->value == value) + return (table->mnem); table++; } - return(""); /* not found */ + return (""); /* not found */ } @@ -210,21 +208,18 @@ void print_dictionary_flags(unsigned int *flags, char *buf, int buf_len) int total = 0; buf[0] = 0; - if((stress = flags[0] & 0xf) != 0) - { + if ((stress = flags[0] & 0xf) != 0) { sprintf(buf, "%s", LookupMnemName(mnem_flags, stress + 0x40)); total = strlen(buf); buf += total; } - for(ix=8; ix<64; ix++) - { - if(((ix < 30) && (flags[0] & (1 << ix))) || ((ix >= 0x20) && (flags[1] & (1 << (ix-0x20))))) - { + for (ix = 8; ix < 64; ix++) { + if (((ix < 30) && (flags[0] & (1 << ix))) || ((ix >= 0x20) && (flags[1] & (1 << (ix-0x20))))) { name = LookupMnemName(mnem_flags, ix); len = strlen(name) + 1; total += len; - if(total >= buf_len) + if (total >= buf_len) continue; sprintf(buf, " %s", name); buf += len; @@ -245,12 +240,12 @@ char *DecodeRule(const char *group_chars, int group_length, char *rule, int cont char *p_end; int ix; int match_type; - int finished=0; + int finished = 0; int value; - int linenum=0; + int linenum = 0; int flags; int suffix_char; - int condition_num=0; + int condition_num = 0; int at_start = 0; const char *name; char buf[200]; @@ -259,32 +254,29 @@ char *DecodeRule(const char *group_chars, int group_length, char *rule, int cont static char output[80]; static char symbols[] = - {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', - '&','%','+','#','S','D','Z','A','L','!',' ','@','?','J','N','K','V','?','T','X','?','W'}; + { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + '&', '%', '+', '#', 'S', 'D', 'Z', 'A', 'L', '!', ' ', '@', '?', 'J', 'N', 'K', 'V', '?', 'T', 'X', '?', 'W' }; - static char symbols_lg[] = {'A','B','C','H','F','G','Y'}; + static char symbols_lg[] = { 'A', 'B', 'C', 'H', 'F', 'G', 'Y' }; match_type = 0; buf_pre[0] = 0; - for(ix=0; ix> 8)) + if (flags & (SUFX_P >> 8)) suffix_char = 'P'; - sprintf(suffix,"%c%d",suffix_char,rule[2] & 0x7f); + sprintf(suffix, "%c%d", suffix_char, rule[2] & 0x7f); rule += 3; - for(ix=0; ix<9; ix++) - { - if(flags & 1) - sprintf(&suffix[strlen(suffix)],"%c",flag_chars[ix]); + for (ix = 0; ix < 9; ix++) { + if (flags & 1) + sprintf(&suffix[strlen(suffix)], "%c", flag_chars[ix]); flags = (flags >> 1); } - strcpy(p,suffix); + strcpy(p, suffix); p += strlen(suffix); c = ' '; - } - else if(rb == RULE_LETTERGP) - { + } else if (rb == RULE_LETTERGP) { c = symbols_lg[*rule++ - 'A']; - } - else if(rb == RULE_LETTERGP2) - { + } else if (rb == RULE_LETTERGP2) { value = *rule++ - 'A'; p[0] = 'L'; p[1] = (value / 10) + '0'; c = (value % 10) + '0'; - if(match_type == RULE_PRE) - { + if (match_type == RULE_PRE) { p[0] = c; c = 'L'; } - p+=2; - } - else if(rb <= RULE_LAST_RULE) + p += 2; + } else if (rb <= RULE_LAST_RULE) c = symbols[rb]; - else if(rb == RULE_SPACE) + else if (rb == RULE_SPACE) c = '_'; else c = rb; @@ -377,21 +358,18 @@ char *DecodeRule(const char *group_chars, int group_length, char *rule, int cont p = output; p_end = p + sizeof(output) - 1; - if(linenum > 0) - { - sprintf(p,"%5d:\t",linenum); + if (linenum > 0) { + sprintf(p, "%5d:\t", linenum); p += 7; } - if(condition_num > 0) - { - sprintf(p,"?%d ",condition_num); + if (condition_num > 0) { + sprintf(p, "?%d ", condition_num); p = &p[strlen(p)]; } - if(((ix = strlen(buf_pre)) > 0) || at_start) - { - if(at_start) + if (((ix = strlen(buf_pre)) > 0) || at_start) { + if (at_start) *p++ = '_'; - while((--ix >= 0) && (p < p_end-3)) + while ((--ix >= 0) && (p < p_end-3)) *p++ = buf_pre[ix]; *p++ = ')'; *p++ = ' '; @@ -399,12 +377,12 @@ char *DecodeRule(const char *group_chars, int group_length, char *rule, int cont *p = 0; buf[p_end - p] = 0; // prevent overflow in output[] - strcat(p,buf); + strcat(p, buf); ix = strlen(output); - while(ix < 8) - output[ix++]=' '; - output[ix]=0; - return(output); + while (ix < 8) + output[ix++] = ' '; + output[ix] = 0; + return (output); } @@ -439,7 +417,7 @@ static int compile_line(char *linebuf, char *dict_line, int *hash) char encoded_ph[200]; char bad_phoneme_str[4]; int bad_phoneme; - static char nullstring[] = {0}; + static char nullstring[] = { 0 }; text_not_phonemes = 0; phonetic = word = nullstring; @@ -449,31 +427,26 @@ static int compile_line(char *linebuf, char *dict_line, int *hash) step = 0; c = 0; - while(c != '\n') - { + while (c != '\n') { c = *p; - if((c == '?') && (step==0)) - { + if ((c == '?') && (step == 0)) { // conditional rule, allow only if the numbered condition is set for the voice flag_offset = 100; p++; - if(*p == '!') - { + if (*p == '!') { // allow only if the numbered condition is NOT set flag_offset = 132; p++; } ix = 0; - if(IsDigit09(*p)) - { + if (IsDigit09(*p)) { ix += (*p-'0'); p++; } - if(IsDigit09(*p)) - { + if (IsDigit09(*p)) { ix = ix*10 + (*p-'0'); p++; } @@ -481,95 +454,69 @@ static int compile_line(char *linebuf, char *dict_line, int *hash) c = *p; } - if((c == '$') && isalnum(p[1])) - { + if ((c == '$') && isalnum(p[1])) { /* read keyword parameter */ mnemptr = p; - while(!isspace2(c = *p)) p++; + while (!isspace2(c = *p)) p++; *p = 0; - flagnum = LookupMnem(mnem_flags,mnemptr); - if(flagnum > 0) - { - if(flagnum == 200) - { + flagnum = LookupMnem(mnem_flags, mnemptr); + if (flagnum > 0) { + if (flagnum == 200) { text_mode = 1; - } - else if(flagnum == 201) - { + } else if (flagnum == 201) { text_mode = 0; - } - else if(flagnum == BITNUM_FLAG_TEXTMODE) - { + } else if (flagnum == BITNUM_FLAG_TEXTMODE) { text_not_phonemes = 1; - } - else - { + } else { flag_codes[n_flag_codes++] = flagnum; } - } - else - { - fprintf(f_log,"%5d: Unknown keyword: %s\n",linenum,mnemptr); + } else { + fprintf(f_log, "%5d: Unknown keyword: %s\n", linenum, mnemptr); error_count++; } } - if((c == '/') && (p[1] == '/') && (multiple_words==0)) - { + if ((c == '/') && (p[1] == '/') && (multiple_words == 0)) { c = '\n'; /* "//" treat comment as end of line */ } - switch(step) + switch (step) { case 0: - if(c == '(') - { + if (c == '(') { multiple_words = 1; word = p+1; step = 1; - } - else if(!isspace2(c)) - { + } else if (!isspace2(c)) { word = p; step = 1; } break; case 1: - if((c == '-') && multiple_words) - { - if(IsDigit09(word[0])) - { + if ((c == '-') && multiple_words) { + if (IsDigit09(word[0])) { multiple_numeric_hyphen = 1; } flag_codes[n_flag_codes++] = BITNUM_FLAG_HYPHENATED; c = ' '; } - if(isspace2(c)) - { + if (isspace2(c)) { p[0] = 0; /* terminate english word */ - if(multiple_words) - { + if (multiple_words) { multiple_string = multiple_string_end = p+1; step = 2; - } - else - { + } else { step = 3; } - } - else if(c == ')') - { - if(multiple_words) - { + } else if (c == ')') { + if (multiple_words) { p[0] = 0; multiple_words = 0; step = 3; - } - else if(word[0] != '_') - { + } else if (word[0] != '_') { fprintf(f_log, "%5d: Missing '('\n", linenum); error_count++; step = 3; @@ -578,12 +525,9 @@ static int compile_line(char *linebuf, char *dict_line, int *hash) break; case 2: - if(isspace2(c)) - { + if (isspace2(c)) { multiple_words++; - } - else if(c == ')') - { + } else if (c == ')') { p[0] = ' '; // terminate extra string multiple_string_end = p+1; step = 3; @@ -591,16 +535,14 @@ static int compile_line(char *linebuf, char *dict_line, int *hash) break; case 3: - if(!isspace2(c)) - { + if (!isspace2(c)) { phonetic = p; step = 4; } break; case 4: - if(isspace2(c)) - { + if (isspace2(c)) { p[0] = 0; /* terminate phonetic */ step = 5; } @@ -612,104 +554,84 @@ static int compile_line(char *linebuf, char *dict_line, int *hash) p++; } - if(word[0] == 0) - { - return(0); /* blank line */ + if (word[0] == 0) { + return (0); /* blank line */ } - if(text_mode) + if (text_mode) text_not_phonemes = 1; - if(text_not_phonemes) - { - if(word[0] == '_') - { + if (text_not_phonemes) { + if (word[0] == '_') { // This is a special word, used by eSpeak. Translate this into phonemes now strcat(phonetic, " "); // need a space to indicate word-boundary // PROBLEM vowel reductions are not applied to the translated phonemes // condition rules are not applied - TranslateWord(translator,phonetic,0,NULL,NULL); + TranslateWord(translator, phonetic, 0, NULL, NULL); text_not_phonemes = 0; strncpy0(encoded_ph, word_phonemes, N_WORD_BYTES-4); - if((word_phonemes[0] == 0) && (error_need_dictionary < 3)) - { + if ((word_phonemes[0] == 0) && (error_need_dictionary < 3)) { // the dictionary was not loaded, we need a second attempt error_need_dictionary++; - fprintf(f_log,"%5d: Need to compile dictionary again\n",linenum); + fprintf(f_log, "%5d: Need to compile dictionary again\n", linenum); } - } - else - { + } else { // this is replacement text, so don't encode as phonemes. Restrict the length of the replacement word - strncpy0(encoded_ph,phonetic,N_WORD_BYTES-4); + strncpy0(encoded_ph, phonetic, N_WORD_BYTES-4); } - } - else - { - EncodePhonemes(phonetic,encoded_ph,&bad_phoneme); - if(strchr(encoded_ph,phonSWITCH) != 0) - { + } else { + EncodePhonemes(phonetic, encoded_ph, &bad_phoneme); + if (strchr(encoded_ph, phonSWITCH) != 0) { flag_codes[n_flag_codes++] = BITNUM_FLAG_ONLY_S; // don't match on suffixes (except 's') when switching languages } // check for errors in the phonemes codes - if(bad_phoneme != 0) - { + if (bad_phoneme != 0) { // unrecognised phoneme, report error bad_phoneme_str[utf8_out(bad_phoneme, bad_phoneme_str)] = 0; - fprintf(f_log,"%5d: Bad phoneme [%s] (U+%x) in: %s %s\n",linenum,bad_phoneme_str,bad_phoneme,word,phonetic); + fprintf(f_log, "%5d: Bad phoneme [%s] (U+%x) in: %s %s\n", linenum, bad_phoneme_str, bad_phoneme, word, phonetic); error_count++; } } - if(text_not_phonemes != translator->langopts.textmode) - { + if (text_not_phonemes != translator->langopts.textmode) { flag_codes[n_flag_codes++] = BITNUM_FLAG_TEXTMODE; } - if(sscanf(word,"U+%x",&wc) == 1) - { + if (sscanf(word, "U+%x", &wc) == 1) { // Character code ix = utf8_out(wc, word); word[ix] = 0; - } - else if(word[0] != '_') - { + } else if (word[0] != '_') { // convert to lower case, and note if the word is all-capitals int c2; all_upper_case = 1; p = word; - for(p=word;; ) - { + for (p = word;;) { // this assumes that the lower case char is the same length as the upper case char // OK, except for Turkish "I", but use towlower() rather than towlower2() - ix = utf8_in(&c2,p); - if(c2 == 0) + ix = utf8_in(&c2, p); + if (c2 == 0) break; - if(iswupper2(c2)) - { - utf8_out(towlower2(c2),p); - } - else - { + if (iswupper2(c2)) { + utf8_out(towlower2(c2), p); + } else { all_upper_case = 0; } p += ix; } - if(all_upper_case) - { + if (all_upper_case) { flag_codes[n_flag_codes++] = BITNUM_FLAG_ALLCAPS; } } len_word = strlen(word); - if(translator->transpose_min > 0) - { + if (translator->transpose_min > 0) { len_word = TransposeAlphabet(translator, word); } @@ -719,49 +641,40 @@ static int compile_line(char *linebuf, char *dict_line, int *hash) dict_line[1] = len_word; // bit 6 indicates whether the word has been compressed len_word &= 0x3f; - memcpy(&dict_line[2],word,len_word); + memcpy(&dict_line[2], word, len_word); - if(len_phonetic == 0) - { + if (len_phonetic == 0) { // no phonemes specified. set bit 7 dict_line[1] |= 0x80; length = len_word + 2; - } - else - { + } else { length = len_word + len_phonetic + 3; - strcpy(&dict_line[(len_word)+2],encoded_ph); + strcpy(&dict_line[(len_word)+2], encoded_ph); } - for(ix=0; ix 0)) - { - if(multiple_words > 10) - { - fprintf(f_log,"%5d: Two many parts in a multi-word entry: %d\n",linenum,multiple_words); + if ((multiple_string != NULL) && (multiple_words > 0)) { + if (multiple_words > 10) { + fprintf(f_log, "%5d: Two many parts in a multi-word entry: %d\n", linenum, multiple_words); error_count++; - } - else - { + } else { dict_line[length++] = 80 + multiple_words; ix = multiple_string_end - multiple_string; - if(multiple_numeric_hyphen) - { + if (multiple_numeric_hyphen) { dict_line[length++] = ' '; // ??? } - memcpy(&dict_line[length],multiple_string,ix); + memcpy(&dict_line[length], multiple_string, ix); length += ix; } } dict_line[0] = length; - return(length); + return (length); } @@ -773,17 +686,15 @@ static void compile_dictlist_start(void) char *p; char *p2; - for(ix=0; ix= '0') && (c <= '9')) - return(c - '0'); - if((c >= 'a') && (c <= 'f')) - return(c - 'a' + 10); - if((c >= 'A') && (c <= 'F')) - return(c - 'A' + 10); - return(-1); + if ((c >= '0') && (c <= '9')) + return (c - '0'); + if ((c >= 'a') && (c <= 'f')) + return (c - 'a' + 10); + if ((c >= 'A') && (c <= 'F')) + return (c - 'A' + 10); + return (-1); } static void copy_rule_string(char *string, int *state_out) { // state 0: conditional, 1=pre, 2=match, 3=post, 4=phonemes - static char *outbuf[5] = {rule_cond, rule_pre, rule_match, rule_post, rule_phonemes}; - static int next_state[5] = {2,2,4,4,4}; + static char *outbuf[5] = { rule_cond, rule_pre, rule_match, rule_post, rule_phonemes }; + static int next_state[5] = { 2, 2, 4, 4, 4 }; char *output; char *p; int ix; @@ -928,60 +831,49 @@ static void copy_rule_string(char *string, int *state_out) int state = *state_out; MNEM_TAB *mr; - if(string[0] == 0) return; + if (string[0] == 0) return; output = outbuf[state]; - if(state==4) - { + if (state == 4) { // append to any previous phoneme string, i.e. allow spaces in the phoneme string len = strlen(rule_phonemes); - if(len > 0) + if (len > 0) rule_phonemes[len++] = ' '; output = &rule_phonemes[len]; } sxflags = 0x808000; // to ensure non-zero bytes - for(p=string,ix=0;; ) - { + for (p = string, ix = 0;;) { literal = 0; c = *p++; - if((c == '0') && (p[0] == 'x') && (isHexDigit(p[1]) >= 0) && (isHexDigit(p[2]) >= 0)) - { + if ((c == '0') && (p[0] == 'x') && (isHexDigit(p[1]) >= 0) && (isHexDigit(p[2]) >= 0)) { hexdigit_input = 1; c = p[1]; - p+= 2; + p += 2; } - if(c == '\\') - { + if (c == '\\') { c = *p++; // treat next character literally - if((c >= '0') && (c <= '3') && (p[0] >= '0') && (p[0] <= '7') && (p[1] >= '0') && (p[1] <= '7')) - { + if ((c >= '0') && (c <= '3') && (p[0] >= '0') && (p[0] <= '7') && (p[1] >= '0') && (p[1] <= '7')) { // character code given by 3 digit octal value; c = (c-'0')*64 + (p[0]-'0')*8 + (p[1]-'0'); p += 2; } literal = 1; } - if(hexdigit_input) - { - if(((c2 = isHexDigit(c)) >= 0) && ((c3 = isHexDigit(p[0])) >= 0)) - { + if (hexdigit_input) { + if (((c2 = isHexDigit(c)) >= 0) && ((c3 = isHexDigit(p[0])) >= 0)) { c = c2 * 16 + c3; literal = 1; p++; - } - else - { + } else { hexdigit_input = 0; } } - if((state==1) || (state==3)) - { + if ((state == 1) || (state == 3)) { // replace special characters (note: 'E' is reserved for a replaced silent 'e') - if(literal == 0) - { - static const char lettergp_letters[9] = {LETTERGP_A,LETTERGP_B,LETTERGP_C,0,0,LETTERGP_F,LETTERGP_G,LETTERGP_H,LETTERGP_Y}; - switch(c) + if (literal == 0) { + static const char lettergp_letters[9] = { LETTERGP_A, LETTERGP_B, LETTERGP_C, 0, 0, LETTERGP_F, LETTERGP_G, LETTERGP_H, LETTERGP_Y }; + switch (c) { case '_': c = RULE_SPACE; @@ -995,14 +887,11 @@ static void copy_rule_string(char *string, int *state_out) case 'H': case 'F': case 'G': - if(state == 1) - { + if (state == 1) { // pre-rule, put the number before the RULE_LETTERGP; output[ix++] = lettergp_letters[c-'A'] + 'A'; c = RULE_LETTERGP; - } - else - { + } else { output[ix++] = RULE_LETTERGP; c = lettergp_letters[c-'A'] + 'A'; } @@ -1058,26 +947,20 @@ static void copy_rule_string(char *string, int *state_out) c = *p++ - '0'; value = *p++ - '0'; c = c * 10 + value; - if((value < 0) || (value > 9)) - { + if ((value < 0) || (value > 9)) { c = 0; - fprintf(f_log,"%5d: Expected 2 digits after 'L'\n",linenum); + fprintf(f_log, "%5d: Expected 2 digits after 'L'\n", linenum); error_count++; - } - else if((c <= 0) || (c >= N_LETTER_GROUPS) || (letterGroupsDefined[(int)c] == 0)) - { - fprintf(f_log,"%5d: Letter group L%.2d not defined\n",linenum,c); + } else if ((c <= 0) || (c >= N_LETTER_GROUPS) || (letterGroupsDefined[(int)c] == 0)) { + fprintf(f_log, "%5d: Letter group L%.2d not defined\n", linenum, c); error_count++; } c += 'A'; - if(state == 1) - { + if (state == 1) { // pre-rule, put the group number before the RULE_LETTERGP command output[ix++] = c; c = RULE_LETTERGP2; - } - else - { + } else { output[ix++] = RULE_LETTERGP2; } break; @@ -1085,11 +968,9 @@ static void copy_rule_string(char *string, int *state_out) case '$': value = 0; mr = mnem_rules; - while(mr->mnem != NULL) - { + while (mr->mnem != NULL) { len = strlen(mr->mnem); - if(memcmp(p, mr->mnem, len) == 0) - { + if (memcmp(p, mr->mnem, len) == 0) { value = mr->value; p += len; break; @@ -1097,21 +978,17 @@ static void copy_rule_string(char *string, int *state_out) mr++; } - if(state == 1) - { + if (state == 1) { // pre-rule, put the number before the RULE_DOLLAR output[ix++] = value; c = RULE_DOLLAR; - } - else - { + } else { output[ix++] = RULE_DOLLAR; c = value; } - if(value == 0) - { - fprintf(f_log,"%5d: $ command not recognized\n",linenum); + if (value == 0) { + fprintf(f_log, "%5d: $ command not recognized\n", linenum); error_count++; } break; @@ -1121,9 +998,8 @@ static void copy_rule_string(char *string, int *state_out) case 'S': output[ix++] = RULE_ENDING; value = 0; - while(!isspace2(c = *p++) && (c != 0)) - { - switch(c) + while (!isspace2(c = *p++) && (c != 0)) { + switch (c) { case 'e': sxflags |= SUFX_E; @@ -1159,7 +1035,7 @@ static void copy_rule_string(char *string, int *state_out) sxflags |= SUFX_M; break; default: - if(IsDigit09(c)) + if (IsDigit09(c)) value = (value*10) + (c - '0'); break; } @@ -1173,7 +1049,7 @@ static void copy_rule_string(char *string, int *state_out) } } output[ix++] = c; - if(c == 0) break; + if (c == 0) break; } *state_out = next_state[state]; @@ -1191,44 +1067,42 @@ static char *compile_rule(char *input) int len; int len_name; int start; - int state=2; - int finish=0; + int state = 2; + int finish = 0; char buf[80]; char output[150]; int bad_phoneme; char bad_phoneme_str[4]; - buf[0]=0; - rule_cond[0]=0; - rule_pre[0]=0; - rule_post[0]=0; - rule_match[0]=0; - rule_phonemes[0]=0; + buf[0] = 0; + rule_cond[0] = 0; + rule_pre[0] = 0; + rule_post[0] = 0; + rule_match[0] = 0; + rule_phonemes[0] = 0; p = buf; - for(ix=0; finish==0; ix++) - { + for (ix = 0; finish == 0; ix++) { c = input[ix]; - switch(c = input[ix]) + switch (c = input[ix]) { case ')': // end of prefix section *p = 0; state = 1; - copy_rule_string(buf,&state); + copy_rule_string(buf, &state); p = buf; break; case '(': // start of suffix section *p = 0; state = 2; - copy_rule_string(buf,&state); + copy_rule_string(buf, &state); state = 3; p = buf; - if(input[ix+1] == ' ') - { - fprintf(f_log,"%5d: Syntax error. Space after (\n",linenum); + if (input[ix+1] == ' ') { + fprintf(f_log, "%5d: Syntax error. Space after (\n", linenum); error_count++; } break; @@ -1237,20 +1111,20 @@ static char *compile_rule(char *input) case '\r': case 0: // end of line *p = 0; - copy_rule_string(buf,&state); - finish=1; + copy_rule_string(buf, &state); + finish = 1; break; case '\t': // end of section section case ' ': *p = 0; - copy_rule_string(buf,&state); + copy_rule_string(buf, &state); p = buf; break; case '?': - if(state==2) - state=0; + if (state == 2) + state = 0; else *p++ = c; break; @@ -1261,108 +1135,88 @@ static char *compile_rule(char *input) } } - if(strcmp(rule_match,"$group")==0) - strcpy(rule_match,group_name); + if (strcmp(rule_match, "$group") == 0) + strcpy(rule_match, group_name); - if(rule_match[0]==0) - { - if(rule_post[0] != 0) - { - fprintf(f_log,"%5d: Syntax error\n",linenum); + if (rule_match[0] == 0) { + if (rule_post[0] != 0) { + fprintf(f_log, "%5d: Syntax error\n", linenum); error_count++; } - return(NULL); + return (NULL); } - EncodePhonemes(rule_phonemes,buf,&bad_phoneme); - if(bad_phoneme != 0) - { + EncodePhonemes(rule_phonemes, buf, &bad_phoneme); + if (bad_phoneme != 0) { bad_phoneme_str[utf8_out(bad_phoneme, bad_phoneme_str)] = 0; - fprintf(f_log,"%5d: Bad phoneme [%s] (U+%x) in: %s\n",linenum,bad_phoneme_str,bad_phoneme,input); + fprintf(f_log, "%5d: Bad phoneme [%s] (U+%x) in: %s\n", linenum, bad_phoneme_str, bad_phoneme, input); error_count++; } - strcpy(output,buf); + strcpy(output, buf); len = strlen(buf)+1; len_name = strlen(group_name); - if((len_name > 0) && (memcmp(rule_match,group_name,len_name) != 0)) - { - utf8_in(&wc,rule_match); - if((group_name[0] == '9') && IsDigit(wc)) - { + if ((len_name > 0) && (memcmp(rule_match, group_name, len_name) != 0)) { + utf8_in(&wc, rule_match); + if ((group_name[0] == '9') && IsDigit(wc)) { // numeric group, rule_match starts with a digit, so OK - } - else - { - fprintf(f_log,"%5d: Wrong initial letters '%s' for group '%s'\n",linenum,rule_match,group_name); + } else { + fprintf(f_log, "%5d: Wrong initial letters '%s' for group '%s'\n", linenum, rule_match, group_name); error_count++; } } - strcpy(&output[len],rule_match); + strcpy(&output[len], rule_match); len += strlen(rule_match); - if(debug_flag) - { + if (debug_flag) { output[len] = RULE_LINENUM; output[len+1] = (linenum % 255) + 1; output[len+2] = (linenum / 255) + 1; - len+=3; + len += 3; } - if(rule_cond[0] != 0) - { + if (rule_cond[0] != 0) { ix = -1; - if(rule_cond[0] == '!') - { + if (rule_cond[0] == '!') { // allow the rule only if the condition number is NOT set for the voice ix = atoi(&rule_cond[1]) + 32; - } - else - { + } else { // allow the rule only if the condition number is set for the voice ix = atoi(rule_cond); } - if((ix > 0) && (ix < 255)) - { + if ((ix > 0) && (ix < 255)) { output[len++] = RULE_CONDITION; output[len++] = ix; - } - else - { - fprintf(f_log,"%5d: bad condition number ?%d\n",linenum,ix); + } else { + fprintf(f_log, "%5d: bad condition number ?%d\n", linenum, ix); error_count++; } } - if(rule_pre[0] != 0) - { + if (rule_pre[0] != 0) { start = 0; - if(rule_pre[0] == RULE_SPACE) - { + if (rule_pre[0] == RULE_SPACE) { // omit '_' at the beginning of the pre-string and imply it by using RULE_PRE_ATSTART c = RULE_PRE_ATSTART; start = 1; - } - else - { + } else { c = RULE_PRE; } output[len++] = c; // output PRE string in reverse order - for(ix = strlen(rule_pre)-1; ix>=start; ix--) + for (ix = strlen(rule_pre)-1; ix >= start; ix--) output[len++] = rule_pre[ix]; } - if(rule_post[0] != 0) - { - sprintf(&output[len],"%c%s",RULE_POST,rule_post); + if (rule_post[0] != 0) { + sprintf(&output[len], "%c%s", RULE_POST, rule_post); len += (strlen(rule_post)+1); } - output[len++]=0; + output[len++] = 0; prule = (char *)malloc(len); - memcpy(prule,output,len); - return(prule); + memcpy(prule, output, len); + return (prule); } @@ -1371,11 +1225,11 @@ int __cdecl string_sorter(char **a, char **b) char *pa, *pb; int ix; - if((ix = strcmp(pa = *a,pb = *b)) != 0) - return(ix); + if ((ix = strcmp(pa = *a, pb = *b)) != 0) + return (ix); pa += (strlen(pa)+1); pb += (strlen(pb)+1); - return(strcmp(pa,pb)); + return (strcmp(pa, pb)); } @@ -1384,10 +1238,10 @@ static int __cdecl rgroup_sorter(RGROUP *a, RGROUP *b) // Sort long names before short names int ix; ix = strlen(b->name) - strlen(a->name); - if(ix != 0) return(ix); - ix = strcmp(a->name,b->name); - if(ix != 0) return(ix); - return(a->start-b->start); + if (ix != 0) return (ix); + ix = strcmp(a->name, b->name); + if (ix != 0) return (ix); + return (a->start-b->start); } @@ -1406,26 +1260,24 @@ static void print_rule_group(FILE *f_out, int n_rules, char **rules, char *name) char buf[80]; char suffix[12]; - static unsigned char symbols[] = {'@','&','%','+','#','$','D','Z','A','B','C','F'}; + static unsigned char symbols[] = { '@', '&', '%', '+', '#', '$', 'D', 'Z', 'A', 'B', 'C', 'F' }; - fprintf(f_out,"\n$group %s\n",name); + fprintf(f_out, "\n$group %s\n", name); - for(rule=0; rule 0) - { - sprintf(buf,"?%d ",condition); + if (condition > 0) { + sprintf(buf, "?%d ", condition); spaces -= strlen(buf); - fprintf(f_out,"%s",buf); + fprintf(f_out, "%s", buf); } - if(rule_pre[0] != 0) - { + if (rule_pre[0] != 0) { p = buf; - for(ix=strlen(rule_pre)-1; ix>=0; ix--) + for (ix = strlen(rule_pre)-1; ix >= 0; ix--) *p++ = rule_pre[ix]; - sprintf(p,") "); + sprintf(p, ") "); spaces -= strlen(buf); - for(ix=0; ix 30) - printf("Group %s %c %d\n",name,ix,nextchar_count[ix]); + for (ix = 32; ix < 256; ix++) { + if (nextchar_count[ix] > 30) + printf("Group %s %c %d\n", name, ix, nextchar_count[ix]); } #endif } @@ -1579,69 +1422,61 @@ static int compile_lettergroup(char *input, FILE *f_out) char item_length[N_LETTERGP_ITEMS]; p = input; - if(!IsDigit09(p[0]) || !IsDigit09(p[1])) - { - fprintf(f_log,"%5d: Expected 2 digits after '.L'\n",linenum); + if (!IsDigit09(p[0]) || !IsDigit09(p[1])) { + fprintf(f_log, "%5d: Expected 2 digits after '.L'\n", linenum); error_count++; - return(1); + return (1); } group = atoi(&p[0]); - if(group >= N_LETTER_GROUPS) - { - fprintf(f_log,"%5d: lettergroup out of range (01-%.2d)\n",linenum,N_LETTER_GROUPS-1); + if (group >= N_LETTER_GROUPS) { + fprintf(f_log, "%5d: lettergroup out of range (01-%.2d)\n", linenum, N_LETTER_GROUPS-1); error_count++; - return(1); + return (1); } - while(!isspace2(*p)) p++; + while (!isspace2(*p)) p++; - fputc(RULE_GROUP_START,f_out); - fputc(RULE_LETTERGP2,f_out); + fputc(RULE_GROUP_START, f_out); + fputc(RULE_LETTERGP2, f_out); fputc(group + 'A', f_out); - if(letterGroupsDefined[group] != 0) - { - fprintf(f_log,"%5d: lettergroup L%.2d is already defined\n",linenum,group); + if (letterGroupsDefined[group] != 0) { + fprintf(f_log, "%5d: lettergroup L%.2d is already defined\n", linenum, group); error_count++; } letterGroupsDefined[group] = 1; n_items = 0; - while(n_items < N_LETTERGP_ITEMS) - { - while(isspace2(*p)) p++; - if(*p == 0) + while (n_items < N_LETTERGP_ITEMS) { + while (isspace2(*p)) p++; + if (*p == 0) break; items[n_items] = p_start = p; - while((*p & 0xff) > ' ') - { + while ((*p & 0xff) > ' ') { if (*p == '_') *p = ' '; // allow '_' for word break p++; } *p++ = 0; length = p - p_start; - if(length > max_length) + if (length > max_length) max_length = length; item_length[n_items++] = length; } // write out the items, longest first - while(max_length > 1) - { - for(ix=0; ix < n_items; ix++) - { - if(item_length[ix] == max_length) - { - fwrite(items[ix],1,max_length,f_out); + while (max_length > 1) { + for (ix = 0; ix < n_items; ix++) { + if (item_length[ix] == max_length) { + fwrite(items[ix], 1, max_length, f_out); } } max_length--; } - fputc(RULE_GROUP_END,f_out); + fputc(RULE_GROUP_END, f_out); - return(0); + return (0); } @@ -1653,14 +1488,14 @@ static int compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp) int c; int gp; FILE *f_temp; - int n_rules=0; - int count=0; + int n_rules = 0; + int count = 0; int different; int wc; - int err_n_rules=0; + int err_n_rules = 0; const char *prev_rgroup_name; unsigned int char_code; - int compile_mode=0; + int compile_mode = 0; char *buf; char buf1[500]; char *rules[N_RULES]; @@ -1672,31 +1507,27 @@ static int compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp) linenum = 0; group_name[0] = 0; - if((f_temp = fopen_log(fname_temp,"wb")) == NULL) - return(1); + if ((f_temp = fopen_log(fname_temp, "wb")) == NULL) + return (1); - for(;; ) - { + for (;;) { linenum++; - buf = fgets(buf1,sizeof(buf1),f_in); - if(buf != NULL) - { - if((p = (unsigned char *)strstr(buf,"//")) != NULL) + buf = fgets(buf1, sizeof(buf1), f_in); + if (buf != NULL) { + if ((p = (unsigned char *)strstr(buf, "//")) != NULL) *p = 0; - if(buf[0] == '\r') buf++; // ignore extra \r in \r\n + if (buf[0] == '\r') buf++; // ignore extra \r in \r\n } - if((buf == NULL) || (buf[0] == '.')) - { + if ((buf == NULL) || (buf[0] == '.')) { // next .group or end of file, write out the previous group - if(n_rules > 0) - { - strcpy(rgroup[n_rgroups].name,group_name); + if (n_rules > 0) { + strcpy(rgroup[n_rgroups].name, group_name); rgroup[n_rgroups].group3_ix = group3_ix; rgroup[n_rgroups].start = ftell(f_temp); - output_rule_group(f_temp,n_rules,rules,group_name); + output_rule_group(f_temp, n_rules, rules, group_name); rgroup[n_rgroups].length = ftell(f_temp) - rgroup[n_rgroups].start; n_rgroups++; @@ -1705,73 +1536,61 @@ static int compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp) n_rules = 0; err_n_rules = 0; - if(compile_mode == 2) - { + if (compile_mode == 2) { // end of the character replacements section - fwrite(&n_rules,1,4,f_out); // write a zero word to terminate the replacemenmt list + fwrite(&n_rules, 1, 4, f_out); // write a zero word to terminate the replacemenmt list compile_mode = 0; } - if(buf == NULL) break; // end of file + if (buf == NULL) break; // end of file - if(memcmp(buf,".L",2)==0) - { + if (memcmp(buf, ".L", 2) == 0) { compile_lettergroup(&buf[2], f_out); continue; } - if(memcmp(buf,".replace",8)==0) - { + if (memcmp(buf, ".replace", 8) == 0) { compile_mode = 2; - fputc(RULE_GROUP_START,f_out); - fputc(RULE_REPLACEMENTS,f_out); + fputc(RULE_GROUP_START, f_out); + fputc(RULE_REPLACEMENTS, f_out); // advance to next word boundary - while((ftell(f_out) & 3) != 0) - fputc(0,f_out); + while ((ftell(f_out) & 3) != 0) + fputc(0, f_out); } - if(memcmp(buf,".group",6)==0) - { + if (memcmp(buf, ".group", 6) == 0) { compile_mode = 1; p = (unsigned char *)&buf[6]; - while((p[0]==' ') || (p[0]=='\t')) p++; // Note: Windows isspace(0xe1) gives TRUE ! + while ((p[0] == ' ') || (p[0] == '\t')) p++; // Note: Windows isspace(0xe1) gives TRUE ! ix = 0; - while((*p > ' ') && (ix < LEN_GROUP_NAME)) + while ((*p > ' ') && (ix < LEN_GROUP_NAME)) group_name[ix++] = *p++; - group_name[ix]=0; + group_name[ix] = 0; group3_ix = 0; - if(sscanf(group_name,"0x%x",&char_code)==1) - { + if (sscanf(group_name, "0x%x", &char_code) == 1) { // group character is given as a character code (max 16 bits) p = (unsigned char *)group_name; - if(char_code > 0x100) - { + if (char_code > 0x100) { *p++ = (char_code >> 8); } *p++ = char_code; *p = 0; - } - else - { - if(translator->letter_bits_offset > 0) - { + } else { + if (translator->letter_bits_offset > 0) { utf8_in(&wc, group_name); - if(((ix = (wc - translator->letter_bits_offset)) >= 0) && (ix < 128)) - { + if (((ix = (wc - translator->letter_bits_offset)) >= 0) && (ix < 128)) { group3_ix = ix+1; // not zero } } } - if((group3_ix == 0) && (strlen(group_name) > 2)) - { - if(utf8_in(&c,group_name) < 2) - { - fprintf(f_log,"%5d: Group name longer than 2 bytes (UTF8)",linenum); + if ((group3_ix == 0) && (strlen(group_name) > 2)) { + if (utf8_in(&c, group_name) < 2) { + fprintf(f_log, "%5d: Group name longer than 2 bytes (UTF8)", linenum); error_count++; } @@ -1782,20 +1601,15 @@ static int compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp) continue; } - switch(compile_mode) + switch (compile_mode) { case 1: // .group prule = compile_rule(buf); - if(prule != NULL) - { - if(n_rules < N_RULES) - { + if (prule != NULL) { + if (n_rules < N_RULES) { rules[n_rules++] = prule; - } - else - { - if(err_n_rules == 0) - { + } else { + if (err_n_rules == 0) { fprintf(stderr, "\nExceeded limit of rules (%d) in group '%s'\n", N_RULES, group_name); error_count++; err_n_rules = 1; @@ -1814,26 +1628,23 @@ static int compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp) p = buf; replace1 = 0; replace2 = 0; - while(isspace2(*p)) p++; + while (isspace2(*p)) p++; ix = 0; - while((unsigned char)(*p) > 0x20) // not space or zero-byte - { - p += utf8_in(&c,p); + while ((unsigned char)(*p) > 0x20) { // not space or zero-byte + p += utf8_in(&c, p); replace1 += (c << ix); ix += 16; } - while(isspace2(*p)) p++; + while (isspace2(*p)) p++; ix = 0; - while((unsigned char)(*p) > 0x20) - { - p += utf8_in(&c,p); + while ((unsigned char)(*p) > 0x20) { + p += utf8_in(&c, p); replace2 += (c << ix); ix += 16; } - if(replace1 != 0) - { - Write4Bytes(f_out,replace1); // write as little-endian - Write4Bytes(f_out,replace2); // if big-endian, reverse the bytes in LoadDictionary() + if (replace1 != 0) { + Write4Bytes(f_out, replace1); // write as little-endian + Write4Bytes(f_out, replace2); // if big-endian, reverse the bytes in LoadDictionary() } } break; @@ -1841,55 +1652,48 @@ static int compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp) } fclose(f_temp); - qsort((void *)rgroup,n_rgroups,sizeof(rgroup[0]),(int (__cdecl *)(const void *,const void *))rgroup_sorter); + qsort((void *)rgroup, n_rgroups, sizeof(rgroup[0]), (int(__cdecl *)(const void *, const void *))rgroup_sorter); - if((f_temp = fopen(fname_temp,"rb"))==NULL) - return(2); + if ((f_temp = fopen(fname_temp, "rb")) == NULL) + return (2); prev_rgroup_name = "\n"; - for(gp = 0; gp < n_rgroups; gp++) - { - fseek(f_temp,rgroup[gp].start,SEEK_SET); + for (gp = 0; gp < n_rgroups; gp++) { + fseek(f_temp, rgroup[gp].start, SEEK_SET); - if((different = strcmp(rgroup[gp].name, prev_rgroup_name)) != 0) - { + if ((different = strcmp(rgroup[gp].name, prev_rgroup_name)) != 0) { // not the same as the previous group - if(gp > 0) - fputc(RULE_GROUP_END,f_out); - fputc(RULE_GROUP_START,f_out); + if (gp > 0) + fputc(RULE_GROUP_END, f_out); + fputc(RULE_GROUP_START, f_out); - if(rgroup[gp].group3_ix != 0) - { + if (rgroup[gp].group3_ix != 0) { n_groups3++; - fputc(1,f_out); + fputc(1, f_out); fputc(rgroup[gp].group3_ix, f_out); - } - else - { + } else { fprintf(f_out, "%s", prev_rgroup_name = rgroup[gp].name); } - fputc(0,f_out); + fputc(0, f_out); } - for(ix=rgroup[gp].length; ix>0; ix--) - { + for (ix = rgroup[gp].length; ix > 0; ix--) { c = fgetc(f_temp); - fputc(c,f_out); + fputc(c, f_out); } - if(different) - { + if (different) { } } - fputc(RULE_GROUP_END,f_out); - fputc(0,f_out); + fputc(RULE_GROUP_END, f_out); + fputc(0, f_out); fclose(f_temp); remove(fname_temp); - fprintf(f_log,"\t%d rules, %d groups (%d)\n\n",count,n_rgroups,n_groups3); - return(0); + fprintf(f_log, "\t%d rules, %d groups (%d)\n\n", count, n_rgroups, n_groups3); + return (0); } @@ -1901,7 +1705,7 @@ int CompileDictionary(const char *dsource, const char *dict_name, FILE *log, cha FILE *f_in; FILE *f_out; - int offset_rules=0; + int offset_rules = 0; int value; char fname_in[sizeof(path_home)+45]; char fname_out[sizeof(path_home)+15]; @@ -1910,75 +1714,69 @@ int CompileDictionary(const char *dsource, const char *dict_name, FILE *log, cha error_count = 0; error_need_dictionary = 0; - memset(letterGroupsDefined,0,sizeof(letterGroupsDefined)); + memset(letterGroupsDefined, 0, sizeof(letterGroupsDefined)); debug_flag = flags & 1; - if(dsource == NULL) + if (dsource == NULL) dsource = ""; f_log = log; - if(f_log == NULL) + if (f_log == NULL) f_log = stderr; // try with and without '.txt' extension - sprintf(path,"%s%s_",dsource,dict_name); - sprintf(fname_in,"%srules.txt",path); - if((f_in = fopen(fname_in,"r")) == NULL) - { - sprintf(fname_in,"%srules",path); - if((f_in = fopen_log(fname_in,"r")) == NULL) - { - if(fname_err) - strcpy(fname_err,fname_in); - return(-1); + sprintf(path, "%s%s_", dsource, dict_name); + sprintf(fname_in, "%srules.txt", path); + if ((f_in = fopen(fname_in, "r")) == NULL) { + sprintf(fname_in, "%srules", path); + if ((f_in = fopen_log(fname_in, "r")) == NULL) { + if (fname_err) + strcpy(fname_err, fname_in); + return (-1); } } - sprintf(fname_out,"%s%c%s_dict",path_home,PATHSEP,dict_name); - if((f_out = fopen_log(fname_out,"wb+")) == NULL) - { - if(fname_err) - strcpy(fname_err,fname_out); + sprintf(fname_out, "%s%c%s_dict", path_home, PATHSEP, dict_name); + if ((f_out = fopen_log(fname_out, "wb+")) == NULL) { + if (fname_err) + strcpy(fname_err, fname_out); fclose(f_in); - return(-1); + return (-1); } - sprintf(fname_temp,"%s%ctemp",path_home,PATHSEP); + sprintf(fname_temp, "%s%ctemp", path_home, PATHSEP); value = N_HASH_DICT; - Write4Bytes(f_out,value); - Write4Bytes(f_out,offset_rules); + Write4Bytes(f_out, value); + Write4Bytes(f_out, offset_rules); compile_dictlist_start(); - fprintf(f_log,"Using phonemetable: '%s'\n",phoneme_tab_list[phoneme_tab_number].name); - compile_dictlist_file(path,"roots"); - if(translator->langopts.listx) - { - compile_dictlist_file(path,"list"); - compile_dictlist_file(path,"listx"); + fprintf(f_log, "Using phonemetable: '%s'\n", phoneme_tab_list[phoneme_tab_number].name); + compile_dictlist_file(path, "roots"); + if (translator->langopts.listx) { + compile_dictlist_file(path, "list"); + compile_dictlist_file(path, "listx"); + } else { + compile_dictlist_file(path, "listx"); + compile_dictlist_file(path, "list"); } - else - { - compile_dictlist_file(path,"listx"); - compile_dictlist_file(path,"list"); - } - compile_dictlist_file(path,"extra"); + compile_dictlist_file(path, "extra"); compile_dictlist_end(f_out); offset_rules = ftell(f_out); - fprintf(f_log,"Compiling: '%s'\n",fname_in); + fprintf(f_log, "Compiling: '%s'\n", fname_in); - compile_dictrules(f_in,f_out,fname_temp); + compile_dictrules(f_in, f_out, fname_temp); fclose(f_in); - fseek(f_out,4,SEEK_SET); - Write4Bytes(f_out,offset_rules); + fseek(f_out, 4, SEEK_SET); + Write4Bytes(f_out, offset_rules); fclose(f_out); fflush(f_log); LoadDictionary(translator, dict_name, 0); - return(error_count); + return (error_count); } diff --git a/src/libespeak-ng/compilembrola.c b/src/libespeak-ng/compilembrola.c index 9d477899..e19e82e2 100644 --- a/src/libespeak-ng/compilembrola.c +++ b/src/libespeak-ng/compilembrola.c @@ -48,17 +48,16 @@ static unsigned int StringToWord(const char *string) unsigned char c; unsigned int word; - if(string==NULL) - return(0); + if (string == NULL) + return (0); word = 0; - for(ix=0; ix<4; ix++) - { - if(string[ix]==0) break; + for (ix = 0; ix < 4; ix++) { + if (string[ix] == 0) break; c = string[ix]; word |= (c << (ix*8)); } - return(word); + return (word); } #pragma GCC visibility push(default) @@ -82,34 +81,29 @@ espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log) int mbrola_ctrl = 20; // volume in 1/16 ths MBROLA_TAB data[N_PHONEME_TAB]; - strcpy(buf,filepath); - if((f_in = fopen(buf,"r")) == NULL) - { + strcpy(buf, filepath); + if ((f_in = fopen(buf, "r")) == NULL) { fprintf(log, "Can't read: %s\n", filepath); return ENE_READ_ERROR; } - while(fgets(buf,sizeof(phoneme),f_in) != NULL) - { + while (fgets(buf, sizeof(phoneme), f_in) != NULL) { buf[sizeof(phoneme)-1] = 0; - if((p = strstr(buf,"//")) != NULL) + if ((p = strstr(buf, "//")) != NULL) *p = 0; // truncate line at comment - if(memcmp(buf,"volume",6)==0) - { + if (memcmp(buf, "volume", 6) == 0) { mbrola_ctrl = atoi(&buf[6]); continue; } - n = sscanf(buf,"%d %s %s %d %s %s",&control,phoneme,phoneme2,&percent,name1,name2); - if(n >= 5) - { + n = sscanf(buf, "%d %s %s %d %s %s", &control, phoneme, phoneme2, &percent, name1, name2); + if (n >= 5) { data[count].name = StringToWord(phoneme); - if(strcmp(phoneme2,"NULL")==0) + if (strcmp(phoneme2, "NULL") == 0) data[count].next_phoneme = 0; - else - if(strcmp(phoneme2,"VWL")==0) + else if (strcmp(phoneme2, "VWL") == 0) data[count].next_phoneme = 2; else data[count].next_phoneme = StringToWord(phoneme2); @@ -117,9 +111,9 @@ espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log) data[count].mbr_name2 = 0; data[count].percent = percent; data[count].control = control; - if(strcmp(name1,"NULL")!=0) + if (strcmp(name1, "NULL") != 0) data[count].mbr_name = StringToWord(name1); - if(n == 6) + if (n == 6) data[count].mbr_name2 = StringToWord(name2); count++; @@ -127,10 +121,9 @@ espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log) } fclose(f_in); - strcpy(mbrola_voice,basename(filepath)); - sprintf(buf,"%s/mbrola_ph/%s_phtrans",path_home,mbrola_voice); - if((f_out = fopen(buf,"wb")) == NULL) - { + strcpy(mbrola_voice, basename(filepath)); + sprintf(buf, "%s/mbrola_ph/%s_phtrans", path_home, mbrola_voice); + if ((f_out = fopen(buf, "wb")) == NULL) { fprintf(log, "Can't write to: %s\n", buf); return ENE_WRITE_ERROR; } @@ -139,8 +132,7 @@ espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log) Write4Bytes(f_out, mbrola_ctrl); pw_end = (int *)(&data[count+1]); - for(pw = (int *)data; pw < pw_end; pw++) - { + for (pw = (int *)data; pw < pw_end; pw++) { Write4Bytes(f_out, *pw); } fclose(f_out); diff --git a/src/libespeak-ng/debug.c b/src/libespeak-ng/debug.c index 15bd6e35..33d8c6ba 100644 --- a/src/libespeak-ng/debug.c +++ b/src/libespeak-ng/debug.c @@ -27,29 +27,27 @@ #include #include -static FILE* fd_log=NULL; -static const char* FILENAME="/tmp/espeak.log"; +static FILE *fd_log = NULL; +static const char *FILENAME = "/tmp/espeak.log"; void debug_init() { - if((fd_log = fopen(FILENAME,"a")) != NULL) + if ((fd_log = fopen(FILENAME, "a")) != NULL) setvbuf(fd_log, NULL, _IONBF, 0); } -void debug_enter(const char* text) +void debug_enter(const char *text) { struct timeval tv; gettimeofday(&tv, NULL); - if (!fd_log) - { + if (!fd_log) { debug_init(); } - if (fd_log) - { - fprintf(fd_log, "%03d.%03dms > ENTER %s\n",(int)(tv.tv_sec%1000), (int)(tv.tv_usec/1000), text); + if (fd_log) { + fprintf(fd_log, "%03d.%03dms > ENTER %s\n", (int)(tv.tv_sec%1000), (int)(tv.tv_usec/1000), text); } } @@ -58,30 +56,26 @@ void debug_show(const char *format, ...) { va_list args; va_start(args, format); - if (!fd_log) - { + if (!fd_log) { debug_init(); } - if (fd_log) - { + if (fd_log) { vfprintf(fd_log, format, args); } va_end(args); } -void debug_time(const char* text) +void debug_time(const char *text) { struct timeval tv; gettimeofday(&tv, NULL); - if (!fd_log) - { + if (!fd_log) { debug_init(); } - if (fd_log) - { - fprintf(fd_log, "%03d.%03dms > %s\n",(int)(tv.tv_sec%1000), (int)(tv.tv_usec/1000), text); + if (fd_log) { + fprintf(fd_log, "%03d.%03dms > %s\n", (int)(tv.tv_sec%1000), (int)(tv.tv_usec/1000), text); } } diff --git a/src/libespeak-ng/debug.h b/src/libespeak-ng/debug.h index 45fd203d..bbedc1e0 100644 --- a/src/libespeak-ng/debug.h +++ b/src/libespeak-ng/debug.h @@ -27,18 +27,18 @@ extern "C" #ifdef DEBUG_ENABLED #define ENTER(text) debug_enter(text) -#define SHOW(format,...) debug_show(format,__VA_ARGS__); +#define SHOW(format, ...) debug_show(format, __VA_ARGS__); #define SHOW_TIME(text) debug_time(text); -extern void debug_enter(const char* text); -extern void debug_show(const char* format,...); -extern void debug_time(const char* text); +extern void debug_enter(const char *text); +extern void debug_show(const char *format, ...); +extern void debug_time(const char *text); #else #ifdef NO_VARIADIC_MACROS #define SHOW(format) // VC6 doesn't allow "..." #else -#define SHOW(format,...) +#define SHOW(format, ...) #endif #define SHOW_TIME(text) #define ENTER(text) diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index 0f683e5b..2b38a8eb 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -44,40 +44,40 @@ extern void print_dictionary_flags(unsigned int *flags, char *buf, int buf_len); extern char *DecodeRule(const char *group_chars, int group_length, char *rule, int control); // accented characters which indicate (in some languages) the start of a separate syllable -static const unsigned short diereses_list[7] = {0xe4,0xeb,0xef,0xf6,0xfc,0xff,0}; +static const unsigned short diereses_list[7] = { 0xe4, 0xeb, 0xef, 0xf6, 0xfc, 0xff, 0 }; // convert characters to an approximate 7 bit ascii equivalent // used for checking for vowels (up to 0x259=schwa) #define N_REMOVE_ACCENT 0x25e static unsigned char remove_accent[N_REMOVE_ACCENT] = { - 'a','a','a','a','a','a','a','c','e','e','e','e','i','i','i','i', // 0c0 - 'd','n','o','o','o','o','o', 0, 'o','u','u','u','u','y','t','s', // 0d0 - 'a','a','a','a','a','a','a','c','e','e','e','e','i','i','i','i', // 0e0 - 'd','n','o','o','o','o','o', 0,'o','u','u','u','u','y','t','y', // 0f0 + 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', // 0c0 + 'd', 'n', 'o', 'o', 'o', 'o', 'o', 0, 'o', 'u', 'u', 'u', 'u', 'y', 't', 's', // 0d0 + 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', // 0e0 + 'd', 'n', 'o', 'o', 'o', 'o', 'o', 0, 'o', 'u', 'u', 'u', 'u', 'y', 't', 'y', // 0f0 - 'a','a','a','a','a','a','c','c','c','c','c','c','c','c','d','d', // 100 - 'd','d','e','e','e','e','e','e','e','e','e','e','g','g','g','g', // 110 - 'g','g','g','g','h','h','h','h','i','i','i','i','i','i','i','i', // 120 - 'i','i','i','i','j','j','k','k','k','l','l','l','l','l','l','l', // 130 - 'l','l','l','n','n','n','n','n','n','n','n','n','o','o','o','o', // 140 - 'o','o','o','o','r','r','r','r','r','r','s','s','s','s','s','s', // 150 - 's','s','t','t','t','t','t','t','u','u','u','u','u','u','u','u', // 160 - 'u','u','u','u','w','w','y','y','y','z','z','z','z','z','z','s', // 170 - 'b','b','b','b', 0, 0, 'o','c','c','d','d','d','d','d','e','e', // 180 - 'e','f','f','g','g','h','i','i','k','k','l','l','m','n','n','o', // 190 - 'o','o','o','o','p','p','y', 0, 0, 's','s','t','t','t','t','u', // 1a0 - 'u','u','v','y','y','z','z','z','z','z','z','z', 0, 0, 0, 'w', // 1b0 - 't','t','t','k','d','d','d','l','l','l','n','n','n','a','a','i', // 1c0 - 'i','o','o','u','u','u','u','u','u','u','u','u','u','e','a','a', // 1d0 - 'a','a','a','a','g','g','g','g','k','k','o','o','o','o','z','z', // 1e0 - 'j','d','d','d','g','g','w','w','n','n','a','a','a','a','o','o', // 1f0 + 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'd', 'd', // 100 + 'd', 'd', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'g', 'g', 'g', 'g', // 110 + 'g', 'g', 'g', 'g', 'h', 'h', 'h', 'h', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', // 120 + 'i', 'i', 'i', 'i', 'j', 'j', 'k', 'k', 'k', 'l', 'l', 'l', 'l', 'l', 'l', 'l', // 130 + 'l', 'l', 'l', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'o', 'o', 'o', 'o', // 140 + 'o', 'o', 'o', 'o', 'r', 'r', 'r', 'r', 'r', 'r', 's', 's', 's', 's', 's', 's', // 150 + 's', 's', 't', 't', 't', 't', 't', 't', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', // 160 + 'u', 'u', 'u', 'u', 'w', 'w', 'y', 'y', 'y', 'z', 'z', 'z', 'z', 'z', 'z', 's', // 170 + 'b', 'b', 'b', 'b', 0, 0, 'o', 'c', 'c', 'd', 'd', 'd', 'd', 'd', 'e', 'e', // 180 + 'e', 'f', 'f', 'g', 'g', 'h', 'i', 'i', 'k', 'k', 'l', 'l', 'm', 'n', 'n', 'o', // 190 + 'o', 'o', 'o', 'o', 'p', 'p', 'y', 0, 0, 's', 's', 't', 't', 't', 't', 'u', // 1a0 + 'u', 'u', 'v', 'y', 'y', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 0, 0, 0, 'w', // 1b0 + 't', 't', 't', 'k', 'd', 'd', 'd', 'l', 'l', 'l', 'n', 'n', 'n', 'a', 'a', 'i', // 1c0 + 'i', 'o', 'o', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'e', 'a', 'a', // 1d0 + 'a', 'a', 'a', 'a', 'g', 'g', 'g', 'g', 'k', 'k', 'o', 'o', 'o', 'o', 'z', 'z', // 1e0 + 'j', 'd', 'd', 'd', 'g', 'g', 'w', 'w', 'n', 'n', 'a', 'a', 'a', 'a', 'o', 'o', // 1f0 - 'a','a','a','a','e','e','e','e','i','i','i','i','o','o','o','o', // 200 - 'r','r','r','r','u','u','u','u','s','s','t','t','y','y','h','h', // 210 - 'n','d','o','o','z','z','a','a','e','e','o','o','o','o','o','o', // 220 - 'o','o','y','y','l','n','t','j','d','q','a','c','c','l','t','s', // 230 - 'z', 0, 0, 'b','u','v','e','e','j','j','q','q','r','r','y','y', // 240 - 'a','a','a','b','o','c','d','d','e','e','e','e','e','e' + 'a', 'a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', // 200 + 'r', 'r', 'r', 'r', 'u', 'u', 'u', 'u', 's', 's', 't', 't', 'y', 'y', 'h', 'h', // 210 + 'n', 'd', 'o', 'o', 'z', 'z', 'a', 'a', 'e', 'e', 'o', 'o', 'o', 'o', 'o', 'o', // 220 + 'o', 'o', 'y', 'y', 'l', 'n', 't', 'j', 'd', 'q', 'a', 'c', 'c', 'l', 't', 's', // 230 + 'z', 0, 0, 'b', 'u', 'v', 'e', 'e', 'j', 'j', 'q', 'q', 'r', 'r', 'y', 'y', // 240 + 'a', 'a', 'a', 'b', 'o', 'c', 'd', 'd', 'e', 'e', 'e', 'e', 'e', 'e' }; @@ -85,10 +85,10 @@ static unsigned char remove_accent[N_REMOVE_ACCENT] = { #pragma GCC visibility push(default) -void strncpy0(char *to,const char *from, int size) +void strncpy0(char *to, const char *from, int size) { // strcpy with limit, ensures a zero terminator - strncpy(to,from,size); + strncpy(to, from, size); to[size-1] = 0; } #pragma GCC visibility pop @@ -101,27 +101,25 @@ int Reverse4Bytes(int word) int ix; int word2 = 0; - for(ix=0; ix<=24; ix+=8) - { + for (ix = 0; ix <= 24; ix += 8) { word2 = word2 << 8; word2 |= (word >> ix) & 0xff; } - return(word2); + return (word2); #else - return(word); + return (word); #endif } int LookupMnem(MNEM_TAB *table, const char *string) { - while(table->mnem != NULL) - { - if(strcmp(string,table->mnem)==0) - return(table->value); + while (table->mnem != NULL) { + if (strcmp(string, table->mnem) == 0) + return (table->value); table++; } - return(table->value); + return (table->value); } @@ -139,39 +137,33 @@ static void InitGroups(Translator *tr) int len; tr->n_groups2 = 0; - for(ix=0; ix<256; ix++) - { - tr->groups1[ix]=NULL; - tr->groups2_count[ix]=0; - tr->groups2_start[ix]=255; // indicates "not set" + for (ix = 0; ix < 256; ix++) { + tr->groups1[ix] = NULL; + tr->groups2_count[ix] = 0; + tr->groups2_start[ix] = 255; // indicates "not set" } - memset(tr->letterGroups,0,sizeof(tr->letterGroups)); - memset(tr->groups3,0,sizeof(tr->groups3)); + memset(tr->letterGroups, 0, sizeof(tr->letterGroups)); + memset(tr->groups3, 0, sizeof(tr->groups3)); p = tr->data_dictrules; - while(*p != 0) - { - if(*p != RULE_GROUP_START) - { - fprintf(stderr,"Bad rules data in '%s_dict' at 0x%x\n",dictionary_name,(unsigned int)(p - tr->data_dictrules)); + while (*p != 0) { + if (*p != RULE_GROUP_START) { + fprintf(stderr, "Bad rules data in '%s_dict' at 0x%x\n", dictionary_name, (unsigned int)(p - tr->data_dictrules)); break; } p++; - if(p[0] == RULE_REPLACEMENTS) - { + if (p[0] == RULE_REPLACEMENTS) { pw = (unsigned int *)(((intptr_t)p+4) & ~3); // advance to next word boundary tr->langopts.replace_chars = pw; - while(pw[0] != 0) - { + while (pw[0] != 0) { pw += 2; // find the end of the replacement list, each entry is 2 words. } p = (char *)(pw+1); #ifdef ARCH_BIG pw = (unsigned int *)(tr->langopts.replace_chars); - while(*pw != 0) - { + while (*pw != 0) { *pw = Reverse4Bytes(*pw); pw++; *pw = Reverse4Bytes(*pw); @@ -181,39 +173,28 @@ static void InitGroups(Translator *tr) continue; } - if(p[0] == RULE_LETTERGP2) - { + if (p[0] == RULE_LETTERGP2) { ix = p[1] - 'A'; p += 2; - if((ix >= 0) && (ix < N_LETTER_GROUPS)) - { + if ((ix >= 0) && (ix < N_LETTER_GROUPS)) { tr->letterGroups[ix] = p; } - } - else - { + } else { len = strlen(p); p_name = p; c = p_name[0]; c2 = p_name[1]; p += (len+1); - if(len == 1) - { + if (len == 1) { tr->groups1[c] = p; - } - else if(len == 0) - { + } else if (len == 0) { tr->groups1[0] = p; - } - else if(c == 1) - { + } else if (c == 1) { // index by offset from letter base tr->groups3[c2 - 1] = p; - } - else - { - if(tr->groups2_start[c] == 255) + } else { + if (tr->groups2_start[c] == 255) tr->groups2_start[c] = tr->n_groups2; tr->groups2_count[c]++; @@ -223,8 +204,7 @@ static void InitGroups(Translator *tr) } // skip over all the rules in this group - while(*p != RULE_GROUP_END) - { + while (*p != RULE_GROUP_END) { p += (strlen(p) + 1); } p++; @@ -244,52 +224,47 @@ int LoadDictionary(Translator *tr, const char *name, int no_error) unsigned int size; char fname[sizeof(path_home)+20]; - strcpy(dictionary_name,name); // currently loaded dictionary name + strcpy(dictionary_name, name); // currently loaded dictionary name strcpy(tr->dictionary_name, name); // Load a pronunciation data file into memory // bytes 0-3: offset to rules data // bytes 4-7: number of hash table entries - sprintf(fname,"%s%c%s_dict",path_home,PATHSEP,name); + sprintf(fname, "%s%c%s_dict", path_home, PATHSEP, name); size = GetFileLength(fname); - if(tr->data_dictlist != NULL) - { + if (tr->data_dictlist != NULL) { Free(tr->data_dictlist); tr->data_dictlist = NULL; } - f = fopen(fname,"rb"); - if((f == NULL) || (size <= 0)) - { - if(no_error == 0) - { - fprintf(stderr,"Can't read dictionary file: '%s'\n",fname); + f = fopen(fname, "rb"); + if ((f == NULL) || (size <= 0)) { + if (no_error == 0) { + fprintf(stderr, "Can't read dictionary file: '%s'\n", fname); } if (f != NULL) fclose(f); - return(1); + return (1); } tr->data_dictlist = Alloc(size); - size = fread(tr->data_dictlist,1,size,f); + size = fread(tr->data_dictlist, 1, size, f); fclose(f); pw = (int *)(tr->data_dictlist); length = Reverse4Bytes(pw[1]); - if(size <= (N_HASH_DICT + sizeof(int)*2)) - { - fprintf(stderr,"Empty _dict file: '%s\n",fname); - return(2); + if (size <= (N_HASH_DICT + sizeof(int)*2)) { + fprintf(stderr, "Empty _dict file: '%s\n", fname); + return (2); } - if((Reverse4Bytes(pw[0]) != N_HASH_DICT) || - (length <= 0) || (length > 0x8000000)) - { - fprintf(stderr,"Bad data: '%s' (%x length=%x)\n",fname,Reverse4Bytes(pw[0]),length); - return(2); + if ((Reverse4Bytes(pw[0]) != N_HASH_DICT) || + (length <= 0) || (length > 0x8000000)) { + fprintf(stderr, "Bad data: '%s' (%x length=%x)\n", fname, Reverse4Bytes(pw[0]), length); + return (2); } tr->data_dictrules = &(tr->data_dictlist[length]); @@ -299,22 +274,19 @@ int LoadDictionary(Translator *tr, const char *name, int no_error) // set up hash table for data_dictlist p = &(tr->data_dictlist[8]); - for(hash=0; hashdict_hashtab[hash] = p; - while((length = *p) != 0) - { + while ((length = *p) != 0) { p += length; } p++; // skip over the zero which terminates the list for this hash value } - if((tr->dict_min_size > 0) && (size < (unsigned int)tr->dict_min_size)) - { + if ((tr->dict_min_size > 0) && (size < (unsigned int)tr->dict_min_size)) { fprintf(stderr, "Full dictionary is not installed for '%s'\n", name); } - return(0); + return (0); } @@ -324,17 +296,16 @@ int LoadDictionary(Translator *tr, const char *name, int no_error) int HashDictionary(const char *string) { int c; - int chars=0; - int hash=0; + int chars = 0; + int hash = 0; - while((c = (*string++ & 0xff)) != 0) - { + while ((c = (*string++ & 0xff)) != 0) { hash = hash * 8 + c; hash = (hash & 0x3ff) ^ (hash >> 8); /* exclusive or */ chars++; } - return((hash+chars) & 0x3ff); // a 10 bit hash code + return ((hash+chars) & 0x3ff); // a 10 bit hash code } @@ -355,32 +326,27 @@ const char *EncodePhonemes(const char *p, char *outptr, int *bad_phoneme) int consumed; unsigned int mnemonic_word; - if(bad_phoneme != NULL) + if (bad_phoneme != NULL) *bad_phoneme = 0; // skip initial blanks - while(isspace(*p)) - { + while (isspace(*p)) { p++; } - while(((c = *p) != 0) && !isspace(c)) - { + while (((c = *p) != 0) && !isspace(c)) { consumed = 0; - switch(c) + switch (c) { case '|': // used to separate phoneme mnemonics if needed, to prevent characters being treated // as a multi-letter mnemonic - if((c = p[1]) == '|') - { + if ((c = p[1]) == '|') { // treat double || as a word-break symbol, drop through // to the default case with c = '|' - } - else - { + } else { p++; break; } @@ -388,67 +354,57 @@ const char *EncodePhonemes(const char *p, char *outptr, int *bad_phoneme) default: // lookup the phoneme mnemonic, find the phoneme with the highest number of // matching characters - max= -1; - max_ph= 0; + max = -1; + max_ph = 0; - for(ix=1; ixtype == phINVALID) + if (phoneme_tab[ix]->type == phINVALID) continue; // this phoneme is not defined for this language count = 0; mnemonic_word = phoneme_tab[ix]->mnemonic; - while(((c = p[count]) > ' ') && (count < 4) && - (c == ((mnemonic_word >> (count*8)) & 0xff))) + while (((c = p[count]) > ' ') && (count < 4) && + (c == ((mnemonic_word >> (count*8)) & 0xff))) count++; - if((count > max) && - ((count == 4) || (((mnemonic_word >> (count*8)) & 0xff)==0))) - { + if ((count > max) && + ((count == 4) || (((mnemonic_word >> (count*8)) & 0xff) == 0))) { max = count; max_ph = phoneme_tab[ix]->code; } } - if(max_ph == 0) - { + if (max_ph == 0) { // not recognised, report and ignore - if(bad_phoneme != NULL) - { + if (bad_phoneme != NULL) { utf8_in(bad_phoneme, p); } *outptr++ = 0; - return(p+1); + return (p+1); } - if(max <= 0) + if (max <= 0) max = 1; p += (consumed + max); *outptr++ = (char)(max_ph); - if(max_ph == phonSWITCH) - { + if (max_ph == phonSWITCH) { // Switch Language: this phoneme is followed by a text string char *p_lang = outptr; - while(!isspace(c = *p) && (c != 0)) - { + while (!isspace(c = *p) && (c != 0)) { p++; *outptr++ = tolower(c); } *outptr = 0; - if(c == 0) - { - if(strcmp(p_lang,"en")==0) - { + if (c == 0) { + if (strcmp(p_lang, "en") == 0) { *p_lang = 0; // don't need "en", it's assumed by default - return(p); + return (p); } - } - else - { + } else { *outptr++ = '|'; // more phonemes follow, terminate language string with separator } } @@ -457,7 +413,7 @@ const char *EncodePhonemes(const char *p, char *outptr, int *bad_phoneme) } /* terminate the encoded string */ *outptr = 0; - return(p); + return (p); } @@ -471,32 +427,25 @@ void DecodePhonemes(const char *inptr, char *outptr) PHONEME_TAB *ph; static const char *stress_chars = "==,,'* "; - sprintf(outptr,"* "); - while((phcode = *inptr++) > 0) - { - if(phcode == 255) + sprintf(outptr, "* "); + while ((phcode = *inptr++) > 0) { + if (phcode == 255) continue; /* indicates unrecognised phoneme */ - if((ph = phoneme_tab[phcode]) == NULL) + if ((ph = phoneme_tab[phcode]) == NULL) continue; - if((ph->type == phSTRESS) && (ph->std_length <= 4) && (ph->program == 0)) - { - if(ph->std_length > 1) + if ((ph->type == phSTRESS) && (ph->std_length <= 4) && (ph->program == 0)) { + if (ph->std_length > 1) *outptr++ = stress_chars[ph->std_length]; - } - else - { + } else { mnem = ph->mnemonic; - while((c = (mnem & 0xff)) != 0) - { + while ((c = (mnem & 0xff)) != 0) { *outptr++ = c; mnem = mnem >> 8; } - if(phcode == phonSWITCH) - { - while(isalpha(*inptr)) - { + if (phcode == phonSWITCH) { + while (isalpha(*inptr)) { *outptr++ = *inptr++; } } @@ -508,12 +457,12 @@ void DecodePhonemes(const char *inptr, char *outptr) // using Kirschenbaum to IPA translation, ascii 0x20 to 0x7f unsigned short ipa1[96] = { - 0x20,0x21,0x22,0x2b0,0x24,0x25,0x0e6,0x2c8,0x28,0x29,0x27e,0x2b,0x2cc,0x2d,0x2e,0x2f, - 0x252,0x31,0x32,0x25c,0x34,0x35,0x36,0x37,0x275,0x39,0x2d0,0x2b2,0x3c,0x3d,0x3e,0x294, - 0x259,0x251,0x3b2,0xe7,0xf0,0x25b,0x46,0x262,0x127,0x26a,0x25f,0x4b,0x26b,0x271,0x14b,0x254, - 0x3a6,0x263,0x280,0x283,0x3b8,0x28a,0x28c,0x153,0x3c7,0xf8,0x292,0x32a,0x5c,0x5d,0x5e,0x5f, - 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x261,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f, - 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x303,0x7f + 0x20, 0x21, 0x22, 0x2b0, 0x24, 0x25, 0x0e6, 0x2c8, 0x28, 0x29, 0x27e, 0x2b, 0x2cc, 0x2d, 0x2e, 0x2f, + 0x252, 0x31, 0x32, 0x25c, 0x34, 0x35, 0x36, 0x37, 0x275, 0x39, 0x2d0, 0x2b2, 0x3c, 0x3d, 0x3e, 0x294, + 0x259, 0x251, 0x3b2, 0xe7, 0xf0, 0x25b, 0x46, 0x262, 0x127, 0x26a, 0x25f, 0x4b, 0x26b, 0x271, 0x14b, 0x254, + 0x3a6, 0x263, 0x280, 0x283, 0x3b8, 0x28a, 0x28c, 0x153, 0x3c7, 0xf8, 0x292, 0x32a, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x261, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x303, 0x7f }; #define N_PHON_OUT 500 // realloc increment @@ -531,94 +480,81 @@ char *WritePhMnemonic(char *phon_out, PHONEME_TAB *ph, PHONEME_LIST *plist, int char *p; PHONEME_DATA phdata; - if(ph->code == phonEND_WORD) - { + if (ph->code == phonEND_WORD) { // ignore phon_out[0] = 0; - return(phon_out); + return (phon_out); } - if(ph->code == phonSWITCH) - { + if (ph->code == phonSWITCH) { // the tone_ph field contains a phoneme table number p = phoneme_tab_list[plist->tone_ph].name; sprintf(phon_out, "(%s)", p); - return(phon_out + strlen(phon_out)); + return (phon_out + strlen(phon_out)); } - if(use_ipa) - { + if (use_ipa) { // has an ipa name been defined for this phoneme ? phdata.ipa_string[0] = 0; - if(plist == NULL) - { + if (plist == NULL) { InterpretPhoneme2(ph->code, &phdata); - } - else - { + } else { InterpretPhoneme(NULL, 0, plist, &phdata, NULL); } p = phdata.ipa_string; - if(*p == 0x20) - { + if (*p == 0x20) { // indicates no name for this phoneme *phon_out = 0; - return(phon_out); + return (phon_out); } - if((*p != 0) && ((*p & 0xff) < 0x20)) - { + if ((*p != 0) && ((*p & 0xff) < 0x20)) { // name starts with a flags byte - if(flags != NULL) + if (flags != NULL) *flags = *p; p++; } len = strlen(p); - if(len > 0) - { + if (len > 0) { strcpy(phon_out, p); phon_out += len; *phon_out = 0; - return(phon_out); + return (phon_out); } } first = 1; - for(mnem = ph->mnemonic; (c = mnem & 0xff) != 0; mnem = mnem >> 8) - { - if((c == '/') && (option_phoneme_variants==0)) + for (mnem = ph->mnemonic; (c = mnem & 0xff) != 0; mnem = mnem >> 8) { + if ((c == '/') && (option_phoneme_variants == 0)) break; // discard phoneme variant indicator - if(use_ipa) - { + if (use_ipa) { // convert from ascii to ipa - if(first && (c == '_')) + if (first && (c == '_')) break; // don't show pause phonemes - if((c == '#') && (ph->type == phVOWEL)) + if ((c == '#') && (ph->type == phVOWEL)) break; // # is subscript-h, but only for consonants // ignore digits after the first character - if(!first && IsDigit09(c)) + if (!first && IsDigit09(c)) continue; - if((c >= 0x20) && (c < 128)) + if ((c >= 0x20) && (c < 128)) c = ipa1[c-0x20]; ix += utf8_out(c, &phon_out[ix]); - } - else - { - phon_out[ix++]= c; + } else { + phon_out[ix++] = c; } first = 0; } phon_out = &phon_out[ix]; *phon_out = 0; - return(phon_out); + return (phon_out); } @@ -637,7 +573,7 @@ const char *GetTranslatedPhonemeString(int phoneme_mode) int ix; unsigned int len; - int phon_out_ix=0; + int phon_out_ix = 0; int stress; int c; char *p; @@ -653,71 +589,56 @@ const char *GetTranslatedPhonemeString(int phoneme_mode) static const char *stress_chars = "==,,''"; - if(phon_out_buf == NULL) - { + if (phon_out_buf == NULL) { phon_out_size = N_PHON_OUT; - if((phon_out_buf = (char *)realloc(phon_out_buf, phon_out_size)) == NULL) - { + if ((phon_out_buf = (char *)realloc(phon_out_buf, phon_out_size)) == NULL) { phon_out_size = 0; - return(""); + return (""); } } use_ipa = phoneme_mode & espeakPHONEMES_IPA; - if(phoneme_mode & espeakPHONEMES_TIE) - { + if (phoneme_mode & espeakPHONEMES_TIE) { use_tie = phoneme_mode >> 8; separate_phonemes = 0; - } - else - { + } else { separate_phonemes = phoneme_mode >> 8; use_tie = 0; } - for(ix=1; ix<(n_phoneme_list-2); ix++) - { + for (ix = 1; ix < (n_phoneme_list-2); ix++) { buf = phon_buf; plist = &phoneme_list[ix]; WritePhMnemonic(phon_buf2, plist->ph, plist, use_ipa, &flags); - if(plist->newword) + if (plist->newword) *buf++ = ' '; - if((!plist->newword) || (separate_phonemes == ' ')) - { - if((separate_phonemes != 0) && (ix > 1)) - { + if ((!plist->newword) || (separate_phonemes == ' ')) { + if ((separate_phonemes != 0) && (ix > 1)) { utf8_in(&c, phon_buf2); - if((c < 0x2b0) || (c > 0x36f)) // not if the phoneme starts with a superscript letter - { + if ((c < 0x2b0) || (c > 0x36f)) { // not if the phoneme starts with a superscript letter buf += utf8_out(separate_phonemes, buf); } } } - if(plist->synthflags & SFLAG_SYLLABLE) - { - if((stress = plist->stresslevel) > 1) - { + if (plist->synthflags & SFLAG_SYLLABLE) { + if ((stress = plist->stresslevel) > 1) { c = 0; - if(stress > 5) stress = 5; + if (stress > 5) stress = 5; - if(use_ipa) - { + if (use_ipa) { c = 0x2cc; // ipa, secondary stress - if(stress > 3) + if (stress > 3) c = 0x02c8; // ipa, primary stress - } - else - { + } else { c = stress_chars[stress]; } - if(c != 0) - { + if (c != 0) { buf += utf8_out(c, buf); } } @@ -725,14 +646,11 @@ const char *GetTranslatedPhonemeString(int phoneme_mode) flags = 0; count = 0; - for(p=phon_buf2; *p != 0; ) - { + for (p = phon_buf2; *p != 0;) { p += utf8_in(&c, p); - if(use_tie != 0) - { + if (use_tie != 0) { // look for non-inital alphabetic character, but not diacritic, superscript etc. - if((count>0) && !(flags & (1 << (count-1))) && ((c < 0x2b0) || (c > 0x36f)) && iswalpha2(c)) - { + if ((count > 0) && !(flags & (1 << (count-1))) && ((c < 0x2b0) || (c > 0x36f)) && iswalpha2(c)) { buf += utf8_out(use_tie, buf); } } @@ -740,32 +658,26 @@ const char *GetTranslatedPhonemeString(int phoneme_mode) count++; } - if(plist->ph->code != phonSWITCH) - { - if(plist->synthflags & SFLAG_LENGTHEN) - { + if (plist->ph->code != phonSWITCH) { + if (plist->synthflags & SFLAG_LENGTHEN) { buf = WritePhMnemonic(buf, phoneme_tab[phonLENGTHEN], NULL, use_ipa, NULL); } - if((plist->synthflags & SFLAG_SYLLABLE) && (plist->type != phVOWEL)) - { + if ((plist->synthflags & SFLAG_SYLLABLE) && (plist->type != phVOWEL)) { // syllablic consonant buf = WritePhMnemonic(buf, phoneme_tab[phonSYLLABIC], NULL, use_ipa, NULL); } - if(plist->tone_ph > 0) - { + if (plist->tone_ph > 0) { buf = WritePhMnemonic(buf, phoneme_tab[plist->tone_ph], NULL, use_ipa, NULL); } } len = buf - phon_buf; - if((phon_out_ix + len) >= phon_out_size) - { + if ((phon_out_ix + len) >= phon_out_size) { // enlarge the phoneme buffer phon_out_size = phon_out_ix + len + N_PHON_OUT; - if((phon_out_buf = (char *)realloc(phon_out_buf, phon_out_size)) == NULL) - { + if ((phon_out_buf = (char *)realloc(phon_out_buf, phon_out_size)) == NULL) { phon_out_size = 0; - return(""); + return (""); } } @@ -775,11 +687,11 @@ const char *GetTranslatedPhonemeString(int phoneme_mode) } if (!phon_out_buf) - return(""); + return (""); phon_out_buf[phon_out_ix] = 0; - return(phon_out_buf); + return (phon_out_buf); } @@ -789,38 +701,32 @@ static int IsLetterGroup(Translator *tr, char *word, int group, int pre) // match the word against a list of utf-8 strings char *p; char *w; - int len=0; + int len = 0; p = tr->letterGroups[group]; - if(p == NULL) - return(0); + if (p == NULL) + return (0); - while(*p != RULE_GROUP_END) - { - if(pre) - { + while (*p != RULE_GROUP_END) { + if (pre) { len = strlen(p); w = word - len + 1; - } - else - { + } else { w = word; } - while((*p == *w) && (*w != 0)) - { + while ((*p == *w) && (*w != 0)) { w++; p++; } - if(*p == 0) - { - if(pre) - return(len); - return(w-word); // matched a complete string + if (*p == 0) { + if (pre) + return (len); + return (w-word); // matched a complete string } - while(*p++ != 0); // skip to end of string + while (*p++ != 0) ; // skip to end of string } - return(0); + return (0); } @@ -828,39 +734,35 @@ static int IsLetter(Translator *tr, int letter, int group) { int letter2; - if(tr->letter_groups[group] != NULL) - { - if(wcschr(tr->letter_groups[group],letter)) - return(1); - return(0); + if (tr->letter_groups[group] != NULL) { + if (wcschr(tr->letter_groups[group], letter)) + return (1); + return (0); } - if(group > 7) - return(0); + if (group > 7) + return (0); - if(tr->letter_bits_offset > 0) - { - if(((letter2 = (letter - tr->letter_bits_offset)) > 0) && (letter2 < 0x100)) + if (tr->letter_bits_offset > 0) { + if (((letter2 = (letter - tr->letter_bits_offset)) > 0) && (letter2 < 0x100)) letter = letter2; else - return(0); - } - else - { - if((letter >= 0xc0) && (letter < N_REMOVE_ACCENT)) - return(tr->letter_bits[remove_accent[letter-0xc0]] & (1L << group)); + return (0); + } else { + if ((letter >= 0xc0) && (letter < N_REMOVE_ACCENT)) + return (tr->letter_bits[remove_accent[letter-0xc0]] & (1L << group)); } - if((letter >= 0) && (letter < 0x100)) - return(tr->letter_bits[letter] & (1L << group)); + if ((letter >= 0) && (letter < 0x100)) + return (tr->letter_bits[letter] & (1L << group)); - return(0); + return (0); } int IsVowel(Translator *tr, int letter) { - return(IsLetter(tr, letter, LETTERGP_VOWEL2)); + return (IsLetter(tr, letter, LETTERGP_VOWEL2)); } @@ -877,9 +779,9 @@ static int Unpronouncable2(Translator *tr, char *word) word[-1] = ' '; // ensure there is a space before the "word" end_flags = TranslateRules(tr, word, ph_buf, sizeof(ph_buf), NULL, FLAG_UNPRON_TEST, NULL); word[-1] = c; - if((end_flags == 0) || (end_flags & SUFX_UNPRON)) - return(1); - return(0); + if ((end_flags == 0) || (end_flags & SUFX_UNPRON)) + return (1); + return (0); } @@ -892,75 +794,68 @@ int Unpronouncable(Translator *tr, char *word, int posn) */ int c; - int c1=0; - int vowel_posn=9; + int c1 = 0; + int vowel_posn = 9; int index; int count; ALPHABET *alphabet; - utf8_in(&c,word); - if((tr->letter_bits_offset > 0) && (c < 0x241)) - { + utf8_in(&c, word); + if ((tr->letter_bits_offset > 0) && (c < 0x241)) { // Latin characters for a language with a non-latin alphabet - return(0); // so we can re-translate the word as English + return (0); // so we can re-translate the word as English } - if(((alphabet = AlphabetFromChar(c)) != NULL) && (alphabet->offset != tr->letter_bits_offset)) - { + if (((alphabet = AlphabetFromChar(c)) != NULL) && (alphabet->offset != tr->letter_bits_offset)) { // Character is not in our alphabet - return(0); + return (0); } - if(tr->langopts.param[LOPT_UNPRONOUNCABLE] == 1) - return(0); + if (tr->langopts.param[LOPT_UNPRONOUNCABLE] == 1) + return (0); - if(((c = *word) == ' ') || (c == 0) || (c == '\'')) - return(0); + if (((c = *word) == ' ') || (c == 0) || (c == '\'')) + return (0); index = 0; count = 0; - for(;; ) - { - index += utf8_in(&c,&word[index]); - if((c==0) || (c==' ')) + for (;;) { + index += utf8_in(&c, &word[index]); + if ((c == 0) || (c == ' ')) break; - if((c=='\'') && ((count > 1) || (posn > 0))) + if ((c == '\'') && ((count > 1) || (posn > 0))) break; // "tv'" but not "l'" - if(count==0) + if (count == 0) c1 = c; - if((c == '\'') && (tr->langopts.param[LOPT_UNPRONOUNCABLE] == 3)) - { + if ((c == '\'') && (tr->langopts.param[LOPT_UNPRONOUNCABLE] == 3)) { // don't count apostrophe - } - else + } else count++; - if(IsVowel(tr, c)) - { + if (IsVowel(tr, c)) { vowel_posn = count; // position of the first vowel break; } - if((c != '\'') && !iswalpha2(c)) - return(0); + if ((c != '\'') && !iswalpha2(c)) + return (0); } - if((vowel_posn > 2) && (tr->langopts.param[LOPT_UNPRONOUNCABLE] == 2)) - { + if ((vowel_posn > 2) && (tr->langopts.param[LOPT_UNPRONOUNCABLE] == 2)) { // Lookup unpronounable rules in *_rules - return(Unpronouncable2(tr, word)); + return (Unpronouncable2(tr, word)); } - if(c1 == tr->langopts.param[LOPT_UNPRONOUNCABLE]) + if (c1 == tr->langopts.param[LOPT_UNPRONOUNCABLE]) vowel_posn--; // disregard this as the initial letter when counting - if(vowel_posn > (tr->langopts.max_initial_consonants+1)) - return(1); // no vowel, or no vowel in first few letters + if (vowel_posn > (tr->langopts.max_initial_consonants+1)) + return (1); // no vowel, or no vowel in first few letters - return(0); + return (0); } @@ -980,76 +875,62 @@ static int GetVowelStress(Translator *tr, unsigned char *phonemes, signed char * int primary_posn = 0; vowel_stress[0] = 1; - while(((phcode = *phonemes++) != 0) && (count < (N_WORD_PHONEMES/2)-1)) - { - if((ph = phoneme_tab[phcode]) == NULL) + while (((phcode = *phonemes++) != 0) && (count < (N_WORD_PHONEMES/2)-1)) { + if ((ph = phoneme_tab[phcode]) == NULL) continue; - if((ph->type == phSTRESS) && (ph->program == 0)) - { + if ((ph->type == phSTRESS) && (ph->program == 0)) { /* stress marker, use this for the following vowel */ - if(phcode == phonSTRESS_PREV) - { + if (phcode == phonSTRESS_PREV) { /* primary stress on preceeding vowel */ j = count - 1; - while((j > 0) && (*stressed_syllable == 0) && (vowel_stress[j] < 4)) - { - if((vowel_stress[j] != 0) && (vowel_stress[j] != 1)) - { + while ((j > 0) && (*stressed_syllable == 0) && (vowel_stress[j] < 4)) { + if ((vowel_stress[j] != 0) && (vowel_stress[j] != 1)) { // don't promote a phoneme which must be unstressed vowel_stress[j] = 4; - if(max_stress < 4) - { + if (max_stress < 4) { max_stress = 4; primary_posn = j; } /* reduce any preceding primary stress markers */ - for(ix=1; ixstd_length < 4) || (*stressed_syllable == 0)) - { + } else { + if ((ph->std_length < 4) || (*stressed_syllable == 0)) { stress = ph->std_length; - if(stress > max_stress) + if (stress > max_stress) max_stress = stress; } } continue; } - if((ph->type == phVOWEL) && !(ph->phflags & phNONSYLLABIC)) - { + if ((ph->type == phVOWEL) && !(ph->phflags & phNONSYLLABIC)) { vowel_stress[count] = (char)stress; - if((stress >= 4) && (stress >= max_stress)) - { + if ((stress >= 4) && (stress >= max_stress)) { primary_posn = count; max_stress = stress; } - if((stress < 0) && (control & 1) && (ph->phflags & phUNSTRESSED)) + if ((stress < 0) && (control & 1) && (ph->phflags & phUNSTRESSED)) vowel_stress[count] = 1; /* weak vowel, must be unstressed */ count++; stress = -1; - } - else if(phcode == phonSYLLABIC) - { + } else if (phcode == phonSYLLABIC) { // previous consonant phoneme is syllablic vowel_stress[count] = (char)stress; - if((stress == 0) && (control & 1)) + if ((stress == 0) && (control & 1)) vowel_stress[count++] = 1; // syllabic consonant, usually unstressed } @@ -1059,9 +940,8 @@ static int GetVowelStress(Translator *tr, unsigned char *phonemes, signed char * *ph_out = 0; /* has the position of the primary stress been specified by $1, $2, etc? */ - if(*stressed_syllable > 0) - { - if(*stressed_syllable >= count) + if (*stressed_syllable > 0) { + if (*stressed_syllable >= count) *stressed_syllable = count-1; // the final syllable vowel_stress[*stressed_syllable] = 4; @@ -1069,21 +949,17 @@ static int GetVowelStress(Translator *tr, unsigned char *phonemes, signed char * primary_posn = *stressed_syllable; } - if(max_stress == 5) - { + if (max_stress == 5) { // priority stress, replaces any other primary stress marker - for(ix=1; ixlangopts.stress_flags & S_PRIORITY_STRESS) + for (ix = 1; ix < count; ix++) { + if (vowel_stress[ix] == 4) { + if (tr->langopts.stress_flags & S_PRIORITY_STRESS) vowel_stress[ix] = 1; else vowel_stress[ix] = 3; } - if(vowel_stress[ix] == 5) - { + if (vowel_stress[ix] == 5) { vowel_stress[ix] = 4; primary_posn = ix; } @@ -1093,13 +969,13 @@ static int GetVowelStress(Translator *tr, unsigned char *phonemes, signed char * *stressed_syllable = primary_posn; *vowel_count = count; - return(max_stress); + return (max_stress); } -static char stress_phonemes[] = {phonSTRESS_D, phonSTRESS_U, phonSTRESS_2, phonSTRESS_3, - phonSTRESS_P, phonSTRESS_P2, phonSTRESS_TONIC}; +static char stress_phonemes[] = { phonSTRESS_D, phonSTRESS_U, phonSTRESS_2, phonSTRESS_3, + phonSTRESS_P, phonSTRESS_P2, phonSTRESS_TONIC }; void ChangeWordStress(Translator *tr, char *word, int new_stress) @@ -1108,31 +984,25 @@ void ChangeWordStress(Translator *tr, char *word, int new_stress) unsigned char *p; int max_stress; int vowel_count; // num of vowels + 1 - int stressed_syllable=0; // position of stressed syllable + int stressed_syllable = 0; // position of stressed syllable unsigned char phonetic[N_WORD_PHONEMES]; signed char vowel_stress[N_WORD_PHONEMES/2]; - strcpy((char *)phonetic,word); + strcpy((char *)phonetic, word); max_stress = GetVowelStress(tr, phonetic, vowel_stress, &vowel_count, &stressed_syllable, 0); - if(new_stress >= 4) - { + if (new_stress >= 4) { // promote to primary stress - for(ix=1; ix= max_stress) - { + for (ix = 1; ix < vowel_count; ix++) { + if (vowel_stress[ix] >= max_stress) { vowel_stress[ix] = new_stress; break; } } - } - else - { + } else { // remove primary stress - for(ix=1; ix new_stress) // >= allows for diminished stress (=1) + for (ix = 1; ix < vowel_count; ix++) { + if (vowel_stress[ix] > new_stress) // >= allows for diminished stress (=1) vowel_stress[ix] = new_stress; } } @@ -1140,11 +1010,9 @@ void ChangeWordStress(Translator *tr, char *word, int new_stress) // write out phonemes ix = 1; p = phonetic; - while(*p != 0) - { - if((phoneme_tab[*p]->type == phVOWEL) && !(phoneme_tab[*p]->phflags & phNONSYLLABIC)) - { - if((vowel_stress[ix] == 0) || (vowel_stress[ix] > 1)) + while (*p != 0) { + if ((phoneme_tab[*p]->type == phVOWEL) && !(phoneme_tab[*p]->phflags & phNONSYLLABIC)) { + if ((vowel_stress[ix] == 0) || (vowel_stress[ix] > 1)) *word++ = stress_phonemes[(unsigned char)vowel_stress[ix]]; ix++; @@ -1201,7 +1069,7 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, char vowel_length[N_WORD_PHONEMES/2]; unsigned char phonetic[N_WORD_PHONEMES]; - static char consonant_types[16] = {0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0}; + static char consonant_types[16] = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 }; /* stress numbers STRESS_BASE + @@ -1213,20 +1081,19 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, stressflags = tr->langopts.stress_flags; - if(dictionary_flags != NULL) + if (dictionary_flags != NULL) dflags = dictionary_flags[0]; /* copy input string into internal buffer */ - for(ix=0; ix= n_phoneme_tab) + if (phonetic[ix] >= n_phoneme_tab) phonetic[ix] = phonSCHWA; - if(phonetic[ix] == 0) + if (phonetic[ix] == 0) break; } - if(ix == 0) return; + if (ix == 0) return; final_ph = phonetic[ix-1]; final_ph2 = phonetic[ix-2]; @@ -1234,42 +1101,36 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, // any stress position marked in the xx_list dictionary ? stressed_syllable = dflags & 0x7; - if(dflags & 0x8) - { + if (dflags & 0x8) { // this indicates a word without a primary stress stressed_syllable = dflags & 0x3; unstressed_word = 1; } max_stress = max_stress_input = GetVowelStress(tr, phonetic, vowel_stress, &vowel_count, &stressed_syllable, 1); - if((max_stress < 0) && dictionary_flags) - { + if ((max_stress < 0) && dictionary_flags) { max_stress = 0; } // heavy or light syllables ix = 1; - for(p = phonetic; *p != 0; p++) - { - if((phoneme_tab[p[0]]->type == phVOWEL) && !(phoneme_tab[p[0]]->phflags & phNONSYLLABIC)) - { + for (p = phonetic; *p != 0; p++) { + if ((phoneme_tab[p[0]]->type == phVOWEL) && !(phoneme_tab[p[0]]->phflags & phNONSYLLABIC)) { int weight = 0; int lengthened = 0; - if(phoneme_tab[p[1]]->code == phonLENGTHEN) + if (phoneme_tab[p[1]]->code == phonLENGTHEN) lengthened = 1; - if(lengthened || (phoneme_tab[p[0]]->phflags & phLONG)) - { + if (lengthened || (phoneme_tab[p[0]]->phflags & phLONG)) { // long vowel, increase syllable weight weight++; } vowel_length[ix] = weight; - if(lengthened) p++; // advance over phonLENGTHEN + if (lengthened) p++; // advance over phonLENGTHEN - if(consonant_types[phoneme_tab[p[1]]->type] && ((phoneme_tab[p[2]]->type != phVOWEL) || (phoneme_tab[p[1]]->phflags & phLONG))) - { + if (consonant_types[phoneme_tab[p[1]]->type] && ((phoneme_tab[p[2]]->type != phVOWEL) || (phoneme_tab[p[1]]->phflags & phLONG))) { // followed by two consonants, a long consonant, or consonant and end-of-word weight++; } @@ -1279,20 +1140,18 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, } - switch(tr->langopts.stress_rule) + switch (tr->langopts.stress_rule) { case 8: // stress on first syllable, unless it is a light syllable followed by a heavy syllable - if((syllable_weight[1] > 0) || (syllable_weight[2] == 0)) + if ((syllable_weight[1] > 0) || (syllable_weight[2] == 0)) break; // else drop through to case 1 case 1: // stress on second syllable - if((stressed_syllable == 0) && (vowel_count > 2)) - { + if ((stressed_syllable == 0) && (vowel_count > 2)) { stressed_syllable = 2; - if(max_stress == 0) - { + if (max_stress == 0) { vowel_stress[stressed_syllable] = 4; } max_stress = 4; @@ -1300,10 +1159,8 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, break; case 10: // penultimate, but final if only 1 or 2 syllables - if(stressed_syllable == 0) - { - if(vowel_count < 4) - { + if (stressed_syllable == 0) { + if (vowel_count < 4) { vowel_stress[vowel_count - 1] = 4; max_stress = 4; break; @@ -1313,75 +1170,56 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, case 2: // a language with stress on penultimate vowel - if(stressed_syllable == 0) - { + if (stressed_syllable == 0) { /* no explicit stress - stress the penultimate vowel */ max_stress = 4; - if(vowel_count > 2) - { + if (vowel_count > 2) { stressed_syllable = vowel_count - 2; - if(stressflags & S_FINAL_SPANISH) - { + if (stressflags & S_FINAL_SPANISH) { // LANG=Spanish, stress on last vowel if the word ends in a consonant other than 'n' or 's' - if(phoneme_tab[final_ph]->type != phVOWEL) - { + if (phoneme_tab[final_ph]->type != phVOWEL) { mnem = phoneme_tab[final_ph]->mnemonic; - if(tr->translator_name == L('a','n')) - { - if(((mnem != 's') && (mnem !='n')) || phoneme_tab[final_ph2]->type != phVOWEL) + if (tr->translator_name == L('a', 'n')) { + if (((mnem != 's') && (mnem != 'n')) || phoneme_tab[final_ph2]->type != phVOWEL) stressed_syllable = vowel_count - 1; // stress on last syllable - } - else - if(tr->translator_name == L('i','a')) - { - if((mnem != 's') || phoneme_tab[final_ph2]->type != phVOWEL) + } else if (tr->translator_name == L('i', 'a')) { + if ((mnem != 's') || phoneme_tab[final_ph2]->type != phVOWEL) stressed_syllable = vowel_count - 1; // stress on last syllable - } - else - { - if((mnem == 's') && (phoneme_tab[final_ph2]->type == phNASAL)) - { + } else { + if ((mnem == 's') && (phoneme_tab[final_ph2]->type == phNASAL)) { // -ns stress remains on penultimate syllable - } - else if(((phoneme_tab[final_ph]->type != phNASAL) && (mnem != 's')) || (phoneme_tab[final_ph2]->type != phVOWEL)) - { + } else if (((phoneme_tab[final_ph]->type != phNASAL) && (mnem != 's')) || (phoneme_tab[final_ph2]->type != phVOWEL)) { stressed_syllable = vowel_count - 1; } } } } - if(stressflags & S_FINAL_LONG) - { + if (stressflags & S_FINAL_LONG) { // stress on last syllable if it has a long vowel, but previous syllable has a short vowel - if(vowel_length[vowel_count - 1] > vowel_length[vowel_count - 2]) - { + if (vowel_length[vowel_count - 1] > vowel_length[vowel_count - 2]) { stressed_syllable = vowel_count - 1; } } - if((vowel_stress[stressed_syllable] == 0) || (vowel_stress[stressed_syllable] == 1)) - { + if ((vowel_stress[stressed_syllable] == 0) || (vowel_stress[stressed_syllable] == 1)) { // but this vowel is explicitly marked as unstressed - if(stressed_syllable > 1) + if (stressed_syllable > 1) stressed_syllable--; else stressed_syllable++; } - } - else - { + } else { stressed_syllable = 1; } // only set the stress if it's not already marked explicitly - if(vowel_stress[stressed_syllable] < 0) - { + if (vowel_stress[stressed_syllable] < 0) { // don't stress if next and prev syllables are stressed - if((vowel_stress[stressed_syllable-1] < 4) || (vowel_stress[stressed_syllable+1] < 4)) + if ((vowel_stress[stressed_syllable-1] < 4) || (vowel_stress[stressed_syllable+1] < 4)) vowel_stress[stressed_syllable] = max_stress; } } @@ -1389,20 +1227,16 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, case 3: // stress on last vowel - if(stressed_syllable == 0) - { + if (stressed_syllable == 0) { /* no explicit stress - stress the final vowel */ stressed_syllable = vowel_count - 1; - while(stressed_syllable > 0) - { + while (stressed_syllable > 0) { // find the last vowel which is not unstressed - if(vowel_stress[stressed_syllable] < 0) - { + if (vowel_stress[stressed_syllable] < 0) { vowel_stress[stressed_syllable] = 4; break; - } - else + } else stressed_syllable--; } max_stress = 4; @@ -1410,14 +1244,12 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, break; case 4: // stress on antipenultimate vowel - if(stressed_syllable == 0) - { + if (stressed_syllable == 0) { stressed_syllable = vowel_count - 3; - if(stressed_syllable < 1) + if (stressed_syllable < 1) stressed_syllable = 1; - if(max_stress == 0) - { + if (max_stress == 0) { vowel_stress[stressed_syllable] = 4; } max_stress = 4; @@ -1426,19 +1258,17 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, case 5: // LANG=Russian - if(stressed_syllable == 0) - { + if (stressed_syllable == 0) { /* no explicit stress - guess the stress from the number of syllables */ - static char guess_ru[16] = {0,0,1,1,2,3,3,4,5,6,7,7,8,9,10,11}; - static char guess_ru_v[16] = {0,0,1,1,2,2,3,3,4,5,6,7,7,8,9,10}; // for final phoneme is a vowel - static char guess_ru_t[16] = {0,0,1,2,3,3,3,4,5,6,7,7,7,8,9,10}; // for final phoneme is an unvoiced stop + static char guess_ru[16] = { 0, 0, 1, 1, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10, 11 }; + static char guess_ru_v[16] = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10 }; // for final phoneme is a vowel + static char guess_ru_t[16] = { 0, 0, 1, 2, 3, 3, 3, 4, 5, 6, 7, 7, 7, 8, 9, 10 }; // for final phoneme is an unvoiced stop stressed_syllable = vowel_count - 3; - if(vowel_count < 16) - { - if(phoneme_tab[final_ph]->type == phVOWEL) + if (vowel_count < 16) { + if (phoneme_tab[final_ph]->type == phVOWEL) stressed_syllable = guess_ru_v[vowel_count]; - else if(phoneme_tab[final_ph]->type == phSTOP) + else if (phoneme_tab[final_ph]->type == phSTOP) stressed_syllable = guess_ru_t[vowel_count]; else stressed_syllable = guess_ru[vowel_count]; @@ -1449,31 +1279,24 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, break; case 6: // LANG=hi stress on the last heaviest syllable - if(stressed_syllable == 0) - { + if (stressed_syllable == 0) { int wt; int max_weight = -1; // find the heaviest syllable, excluding the final syllable - for(ix = 1; ix < (vowel_count-1); ix++) - { - if(vowel_stress[ix] < 0) - { - if((wt = syllable_weight[ix]) >= max_weight) - { + for (ix = 1; ix < (vowel_count-1); ix++) { + if (vowel_stress[ix] < 0) { + if ((wt = syllable_weight[ix]) >= max_weight) { max_weight = wt; stressed_syllable = ix; } } } - if((syllable_weight[vowel_count-1] == 2) && (max_weight< 2)) - { + if ((syllable_weight[vowel_count-1] == 2) && (max_weight < 2)) { // the only double=heavy syllable is the final syllable, so stress this stressed_syllable = vowel_count-1; - } - else if(max_weight <= 0) - { + } else if (max_weight <= 0) { // all syllables, exclusing the last, are light. Stress the first syllable stressed_syllable = 1; } @@ -1484,13 +1307,10 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, break; case 7: // LANG=tr, the last syllable for any vowel marked explicitly as unstressed - if(stressed_syllable == 0) - { + if (stressed_syllable == 0) { stressed_syllable = vowel_count - 1; - for(ix=1; ix < vowel_count; ix++) - { - if(vowel_stress[ix] == 1) - { + for (ix = 1; ix < vowel_count; ix++) { + if (vowel_stress[ix] == 1) { stressed_syllable = ix-1; break; } @@ -1501,37 +1321,32 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, break; case 9: // mark all as stressed - for(ix=1; ix 0) - { + if (vowel_length[ix] > 0) { long_vowel = ix; vowel_stress[ix] = 3; // give secondary stress to all long vowels } } // 'stressed_syllable' gives the last marked stress - if(stressed_syllable == 0) - { + if (stressed_syllable == 0) { // no marked stress, choose the last long vowel - if(long_vowel > 0) + if (long_vowel > 0) stressed_syllable = long_vowel; - else - { + else { // no long vowels or consonant clusters - if(vowel_count > 5) + if (vowel_count > 5) stressed_syllable = vowel_count - 3; // more than 4 syllables else stressed_syllable = vowel_count - 1; @@ -1542,10 +1357,9 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, break; case 13: // LANG=ml, 1st unless 1st vowel is short and 2nd is long - if(stressed_syllable == 0) - { + if (stressed_syllable == 0) { stressed_syllable = 1; - if((vowel_length[1] == 0) && (vowel_count > 2) && (vowel_length[2] > 0)) + if ((vowel_length[1] == 0) && (vowel_count > 2) && (vowel_length[2] > 0)) stressed_syllable = 2; vowel_stress[stressed_syllable] = 4; max_stress = 4; @@ -1553,40 +1367,34 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, break; } - if((stressflags & S_FINAL_VOWEL_UNSTRESSED) && ((control & 2) == 0) && (vowel_count > 2) && (max_stress_input < 3) && (vowel_stress[vowel_count - 1] == 4)) - { + if ((stressflags & S_FINAL_VOWEL_UNSTRESSED) && ((control & 2) == 0) && (vowel_count > 2) && (max_stress_input < 3) && (vowel_stress[vowel_count - 1] == 4)) { // Don't allow stress on a word-final vowel // Only do this if there is no suffix phonemes to be added, and if a stress position was not given explicitly - if(phoneme_tab[final_ph]->type == phVOWEL) - { + if (phoneme_tab[final_ph]->type == phVOWEL) { vowel_stress[vowel_count - 1] = 1; vowel_stress[vowel_count - 2] = 4; } } /* now guess the complete stress pattern */ - if(max_stress < 4) + if (max_stress < 4) stress = 4; /* no primary stress marked, use for 1st syllable */ else stress = 3; - if(unstressed_word == 0) - { - if((stressflags & S_2_SYL_2) && (vowel_count == 3)) - { + if (unstressed_word == 0) { + if ((stressflags & S_2_SYL_2) && (vowel_count == 3)) { // Two syllable word, if one syllable has primary stress, then give the other secondary stress - if(vowel_stress[1] == 4) + if (vowel_stress[1] == 4) vowel_stress[2] = 3; - if(vowel_stress[2] == 4) + if (vowel_stress[2] == 4) vowel_stress[1] = 3; } - if((stressflags & S_INITIAL_2) && (vowel_stress[1] < 0)) - { + if ((stressflags & S_INITIAL_2) && (vowel_stress[1] < 0)) { // If there is only one syllable before the primary stress, give it a secondary stress - if((vowel_count > 3) && (vowel_stress[2] >= 4)) - { + if ((vowel_count > 3) && (vowel_stress[2] >= 4)) { vowel_stress[1] = 3; } } @@ -1594,29 +1402,21 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, done = 0; first_primary = 0; - for(v=1; v 1) && (stressflags & S_2_TO_HEAVY) && (syllable_weight[v]==0) && (syllable_weight[v+1]>0)) - { + if ((v > 1) && (stressflags & S_2_TO_HEAVY) && (syllable_weight[v] == 0) && (syllable_weight[v+1] > 0)) { // don't put secondary stress on a light syllable which is followed by a heavy syllable continue; } @@ -1624,26 +1424,23 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, // should start with secondary stress on the first syllable, or should it count back from // the primary stress and put secondary stress on alternate syllables? vowel_stress[v] = (char)stress; - done =1; + done = 1; stress = 3; /* use secondary stress for remaining syllables */ } } - if(vowel_stress[v] >= 4) - { - if(first_primary == 0) + if (vowel_stress[v] >= 4) { + if (first_primary == 0) first_primary = v; - else if(stressflags & S_FIRST_PRIMARY) - { + else if (stressflags & S_FIRST_PRIMARY) { // reduce primary stresses after the first to secondary vowel_stress[v] = 3; } } } - if((unstressed_word) && (tonic < 0)) - { - if(vowel_count <= 2) + if ((unstressed_word) && (tonic < 0)) { + if (vowel_count <= 2) tonic = tr->langopts.unstressed_wd1; /* monosyllable - unstressed */ else tonic = tr->langopts.unstressed_wd2; /* more than one syllable, used secondary stress as the main stress */ @@ -1651,21 +1448,18 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, max_stress = 0; max_stress_posn = 0; - for(v=1; v= max_stress) - { + for (v = 1; v < vowel_count; v++) { + if (vowel_stress[v] >= max_stress) { max_stress = vowel_stress[v]; max_stress_posn = v; } } - if(tonic >= 0) - { + if (tonic >= 0) { /* find position of highest stress, and replace it by 'tonic' */ /* don't disturb an explicitly set stress by 'unstress-at-end' flag */ - if((tonic > max_stress) || (max_stress <= 4)) + if ((tonic > max_stress) || (max_stress <= 4)) vowel_stress[max_stress_posn] = (char)tonic; max_stress = tonic; } @@ -1675,110 +1469,84 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, p = phonetic; v = 1; - if(!(control & 1) && ((ph = phoneme_tab[*p]) != NULL)) - { + if (!(control & 1) && ((ph = phoneme_tab[*p]) != NULL)) { - while((ph->type == phSTRESS) || (*p == phonEND_WORD)) - { + while ((ph->type == phSTRESS) || (*p == phonEND_WORD)) { p++; ph = phoneme_tab[p[0]]; } - if((tr->langopts.vowel_pause & 0x30) && (ph->type == phVOWEL)) - { + if ((tr->langopts.vowel_pause & 0x30) && (ph->type == phVOWEL)) { // word starts with a vowel - if((tr->langopts.vowel_pause & 0x20) && (vowel_stress[1] >= 4)) - { + if ((tr->langopts.vowel_pause & 0x20) && (vowel_stress[1] >= 4)) { *output++ = phonPAUSE_NOLINK; // not to be replaced by link - } - else - { + } else { *output++ = phonPAUSE_VSHORT; // break, but no pause } } } p = phonetic; - while(((phcode = *p++) != 0) && (output < max_output)) - { - if((ph = phoneme_tab[phcode]) == NULL) + while (((phcode = *p++) != 0) && (output < max_output)) { + if ((ph = phoneme_tab[phcode]) == NULL) continue; - if(ph->type == phPAUSE) - { + if (ph->type == phPAUSE) { tr->prev_last_stress = 0; - } - else if(((ph->type == phVOWEL) && !(ph->phflags & phNONSYLLABIC)) || (*p == phonSYLLABIC)) - { + } else if (((ph->type == phVOWEL) && !(ph->phflags & phNONSYLLABIC)) || (*p == phonSYLLABIC)) { // a vowel, or a consonant followed by a syllabic consonant marker v_stress = vowel_stress[v]; tr->prev_last_stress = v_stress; - if(v_stress <= 1) - { - if((v > 1) && (max_stress >= 2) && (stressflags & S_FINAL_DIM) && (v == (vowel_count-1))) - { + if (v_stress <= 1) { + if ((v > 1) && (max_stress >= 2) && (stressflags & S_FINAL_DIM) && (v == (vowel_count-1))) { // option: mark unstressed final syllable as diminished v_stress = 0; - } - else if((stressflags & S_NO_DIM) || (v == 1) || (v == (vowel_count-1))) - { + } else if ((stressflags & S_NO_DIM) || (v == 1) || (v == (vowel_count-1))) { // first or last syllable, or option 'don't set diminished stress' v_stress = 1; - } - else if((v == (vowel_count-2)) && (vowel_stress[vowel_count-1] <= 1)) - { + } else if ((v == (vowel_count-2)) && (vowel_stress[vowel_count-1] <= 1)) { // penultimate syllable, followed by an unstressed final syllable v_stress = 1; - } - else - { + } else { // unstressed syllable within a word - if((vowel_stress[v-1] < 0) || ((stressflags & S_MID_DIM) == 0)) - { + if ((vowel_stress[v-1] < 0) || ((stressflags & S_MID_DIM) == 0)) { v_stress = 0; /* change to 0 (diminished stress) */ vowel_stress[v] = v_stress; } } } - if((v_stress == 0) || (v_stress > 1)) + if ((v_stress == 0) || (v_stress > 1)) *output++ = stress_phonemes[v_stress]; // mark stress of all vowels except 1 (unstressed) - if(vowel_stress[v] > max_stress) - { + if (vowel_stress[v] > max_stress) { max_stress = vowel_stress[v]; } - if((*p == phonLENGTHEN) && ((opt_length = tr->langopts.param[LOPT_IT_LENGTHEN]) & 1)) - { + if ((*p == phonLENGTHEN) && ((opt_length = tr->langopts.param[LOPT_IT_LENGTHEN]) & 1)) { // remove lengthen indicator from non-stressed syllables - int shorten=0; + int shorten = 0; - if(opt_length & 0x10) - { + if (opt_length & 0x10) { // only allow lengthen indicator on the highest stress syllable in the word - if(v != max_stress_posn) + if (v != max_stress_posn) shorten = 1; - } - else if(v_stress < 4) - { + } else if (v_stress < 4) { // only allow lengthen indicator if stress >= 4. shorten = 1; } - if(shorten) + if (shorten) p++; } - if((v_stress >= 4) && (tr->langopts.param[LOPT_IT_LENGTHEN] == 2)) - { + if ((v_stress >= 4) && (tr->langopts.param[LOPT_IT_LENGTHEN] == 2)) { // LANG=Italian, lengthen penultimate stressed vowels, unless followed by 2 consonants - if((v == (vowel_count - 2)) && (syllable_weight[v] == 0)) - { + if ((v == (vowel_count - 2)) && (syllable_weight[v] == 0)) { *output++ = phcode; phcode = phonLENGTHEN; } @@ -1787,7 +1555,7 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags, v++; } - if(phcode != 1) + if (phcode != 1) *output++ = phcode; } *output++ = 0; @@ -1809,30 +1577,23 @@ void AppendPhonemes(Translator *tr, char *string, int size, const char *ph) int length; length = strlen(ph) + strlen(string); - if(length >= size) - { + if (length >= size) { return; } /* any stressable vowel ? */ unstress_mark = 0; p = ph; - while((c = *p++) != 0) - { - if(c >= n_phoneme_tab) continue; + while ((c = *p++) != 0) { + if (c >= n_phoneme_tab) continue; - if(phoneme_tab[c]->type == phSTRESS) - { - if(phoneme_tab[c]->std_length < 4) + if (phoneme_tab[c]->type == phSTRESS) { + if (phoneme_tab[c]->std_length < 4) unstress_mark = 1; - } - else - { - if(phoneme_tab[c]->type == phVOWEL) - { - if(((phoneme_tab[c]->phflags & phUNSTRESSED) == 0) && - (unstress_mark == 0)) - { + } else { + if (phoneme_tab[c]->type == phVOWEL) { + if (((phoneme_tab[c]->phflags & phUNSTRESSED) == 0) && + (unstress_mark == 0)) { tr->word_stressed_count++; } unstress_mark = 0; @@ -1841,8 +1602,8 @@ void AppendPhonemes(Translator *tr, char *string, int size, const char *ph) } } - if(string != NULL) - strcat(string,ph); + if (string != NULL) + strcat(string, ph); } @@ -1905,8 +1666,7 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ group_chars = *word; - if(rule == NULL) - { + if (rule == NULL) { match_out->points = 0; (*word)++; return; @@ -1923,14 +1683,13 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ best.del_fwd = NULL; /* search through dictionary rules */ - while(rule[0] != RULE_GROUP_END) - { + while (rule[0] != RULE_GROUP_END) { unpron_ignore = word_flags & FLAG_UNPRON_TEST; - match_type=0; + match_type = 0; consumed = 0; letter = 0; - distance_right= -6; /* used to reduce points for matches further away the current letter */ - distance_left= -2; + distance_right = -6; /* used to reduce points for matches further away the current letter */ + distance_left = -2; check_atstart = 0; match.points = 1; @@ -1944,32 +1703,26 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ rule_start = rule; failed = 0; - while(!failed) - { + while (!failed) { rb = *rule++; - if(rb <= RULE_LINENUM) - { - switch(rb) + if (rb <= RULE_LINENUM) { + switch (rb) { case 0: // no phoneme string for this rule, use previous common rule - if(common_phonemes != NULL) - { + if (common_phonemes != NULL) { match.phonemes = common_phonemes; - while(((rb = *match.phonemes++) != 0) && (rb != RULE_PHONEMES)) - { - if(rb == RULE_CONDITION) + while (((rb = *match.phonemes++) != 0) && (rb != RULE_PHONEMES)) { + if (rb == RULE_CONDITION) match.phonemes++; // skip over condition number - if(rb == RULE_LINENUM) + if (rb == RULE_LINENUM) match.phonemes += 2; // skip over line number } - } - else - { + } else { match.phonemes = ""; } rule--; // so we are still pointing at the 0 - failed=2; // matched OK + failed = 2; // matched OK break; case RULE_PRE_ATSTART: // pre rule with implied 'start of word' @@ -1980,8 +1733,7 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ case RULE_PRE: match_type = RULE_PRE; - if(word_flags & FLAG_UNPRON_TEST) - { + if (word_flags & FLAG_UNPRON_TEST) { // checking the start of the word for unpronouncable character sequences, only // consider rules which explicitly match the start of a word // Note: Those rules now use RULE_PRE_ATSTART @@ -1994,7 +1746,7 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ break; case RULE_PHONEMES: match.phonemes = rule; - failed=2; // matched OK + failed = 2; // matched OK break; case RULE_PH_COMMON: common_phonemes = rule; @@ -2003,24 +1755,21 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ /* conditional rule, next byte gives condition number */ condition_num = *rule++; - if(condition_num >= 32) - { + if (condition_num >= 32) { // allow the rule only if the condition number is NOT set - if((tr->dict_condition & (1L << (condition_num-32))) != 0) + if ((tr->dict_condition & (1L << (condition_num-32))) != 0) failed = 1; - } - else - { + } else { // allow the rule only if the condition number is set - if((tr->dict_condition & (1L << condition_num)) == 0) + if ((tr->dict_condition & (1L << condition_num)) == 0) failed = 1; } - if(!failed) + if (!failed) match.points++; // add one point for a matched conditional rule break; case RULE_LINENUM: - rule+=2; + rule += 2; break; } continue; @@ -2028,20 +1777,18 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ add_points = 0; - switch(match_type) + switch (match_type) { case 0: /* match and consume this letter */ last_letter = letter; letter = *post_ptr++; - if((letter == rb) || ((letter==(unsigned char)REPLACED_E) && (rb=='e'))) - { - if((letter & 0xc0) != 0x80) + if ((letter == rb) || ((letter == (unsigned char)REPLACED_E) && (rb == 'e'))) { + if ((letter & 0xc0) != 0x80) add_points = 21; // don't add point for non-initial UTF-8 bytes consumed++; - } - else + } else failed = 1; break; @@ -2049,79 +1796,66 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ case RULE_POST: /* continue moving fowards */ distance_right += 6; - if(distance_right > 18) + if (distance_right > 18) distance_right = 19; last_letter = letter; - letter_xbytes = utf8_in(&letter_w,post_ptr)-1; + letter_xbytes = utf8_in(&letter_w, post_ptr)-1; letter = *post_ptr++; - switch(rb) + switch (rb) { case RULE_LETTERGP: letter_group = *rule++ - 'A'; - if(IsLetter(tr, letter_w, letter_group)) - { + if (IsLetter(tr, letter_w, letter_group)) { lg_pts = 20; - if(letter_group==2) + if (letter_group == 2) lg_pts = 19; // fewer points for C, general consonant add_points = (lg_pts-distance_right); post_ptr += letter_xbytes; - } - else + } else failed = 1; break; case RULE_LETTERGP2: // match against a list of utf-8 strings letter_group = *rule++ - 'A'; - if((n_bytes = IsLetterGroup(tr, post_ptr-1,letter_group,0)) >0) - { + if ((n_bytes = IsLetterGroup(tr, post_ptr-1, letter_group, 0)) > 0) { add_points = (20-distance_right); post_ptr += (n_bytes-1); - } - else - failed =1; + } else + failed = 1; break; case RULE_NOTVOWEL: - if(IsLetter(tr, letter_w, 0) || ((letter_w == ' ') && (word_flags & FLAG_SUFFIX_VOWEL))) - { + if (IsLetter(tr, letter_w, 0) || ((letter_w == ' ') && (word_flags & FLAG_SUFFIX_VOWEL))) { failed = 1; - } - else - { + } else { add_points = (20-distance_right); post_ptr += letter_xbytes; } break; case RULE_DIGIT: - if(IsDigit(letter_w)) - { + if (IsDigit(letter_w)) { add_points = (20-distance_right); post_ptr += letter_xbytes; - } - else if(tr->langopts.tone_numbers) - { + } else if (tr->langopts.tone_numbers) { // also match if there is no digit add_points = (20-distance_right); post_ptr--; - } - else + } else failed = 1; break; case RULE_NONALPHA: - if(!iswalpha2(letter_w)) - { + if (!iswalpha2(letter_w)) { add_points = (21-distance_right); post_ptr += letter_xbytes; - } - else + } else failed = 1; break; case RULE_DOUBLE: - if(letter == last_letter) + if (letter == last_letter) add_points = (21-distance_right); else failed = 1; @@ -2129,27 +1863,20 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ case RULE_DOLLAR: command = *rule++; - if(command == DOLLAR_UNPR) - { + if (command == DOLLAR_UNPR) { match.end_type = SUFX_UNPRON; // $unpron - } - else if(command == DOLLAR_NOPREFIX) // $noprefix - { - if(word_flags & FLAG_PREFIX_REMOVED) + } else if (command == DOLLAR_NOPREFIX) { // $noprefix + if (word_flags & FLAG_PREFIX_REMOVED) failed = 1; // a prefix has been removed else add_points = 1; - } - else if((command & 0xf0) == 0x10) - { + } else if ((command & 0xf0) == 0x10) { // $w_alt - if(dict_flags & (1 << (BITNUM_FLAG_ALT + (command & 0xf)))) + if (dict_flags & (1 << (BITNUM_FLAG_ALT + (command & 0xf)))) add_points = 23; else failed = 1; - } - else if(((command & 0xf0) == 0x20) || (command == DOLLAR_LIST)) - { + } else if (((command & 0xf0) == 0x20) || (command == DOLLAR_LIST)) { // $list or $p_alt // make a copy of the word up to the post-match characters ix = *word - word_start + consumed + group_length + 1; @@ -2158,10 +1885,9 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ word_buf[ix+1] = 0; LookupFlags(tr, &word_buf[1], &flags); - if((command == DOLLAR_LIST) && (flags[0] & FLAG_FOUND) && !(flags[1] & FLAG_ONLY)) + if ((command == DOLLAR_LIST) && (flags[0] & FLAG_FOUND) && !(flags[1] & FLAG_ONLY)) add_points = 23; - else - if(flags[0] & (1 << (BITNUM_FLAG_ALT + (command & 0xf)))) + else if (flags[0] & (1 << (BITNUM_FLAG_ALT + (command & 0xf)))) add_points = 23; else failed = 1; @@ -2169,11 +1895,9 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ break; case '-': - if((letter == '-') || ((letter == ' ') && (word_flags & FLAG_HYPHEN_AFTER))) - { + if ((letter == '-') || ((letter == ' ') && (word_flags & FLAG_HYPHEN_AFTER))) { add_points = (22-distance_right); // one point more than match against space - } - else + } else failed = 1; break; @@ -2181,26 +1905,23 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ { /* more than specified number of vowel letters to the right */ char *p = post_ptr + letter_xbytes; - int vowel_count=0; + int vowel_count = 0; syllable_count = 1; - while(*rule == RULE_SYLLABLE) - { + while (*rule == RULE_SYLLABLE) { rule++; - syllable_count+=1; /* number of syllables to match */ + syllable_count += 1; /* number of syllables to match */ } vowel = 0; - while(letter_w != RULE_SPACE) - { - if((vowel==0) && IsLetter(tr, letter_w,LETTERGP_VOWEL2)) - { + while (letter_w != RULE_SPACE) { + if ((vowel == 0) && IsLetter(tr, letter_w, LETTERGP_VOWEL2)) { // this is counting vowels which are separated by non-vowel letters vowel_count++; } - vowel = IsLetter(tr, letter_w,LETTERGP_VOWEL2); - p += utf8_in(&letter_w,p); + vowel = IsLetter(tr, letter_w, LETTERGP_VOWEL2); + p += utf8_in(&letter_w, p); } - if(syllable_count <= vowel_count) + if (syllable_count <= vowel_count) add_points = (18+syllable_count-distance_right); else failed = 1; @@ -2210,16 +1931,14 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ case RULE_NOVOWELS: { char *p = post_ptr + letter_xbytes; - while(letter_w != RULE_SPACE) - { - if(IsLetter(tr, letter_w,LETTERGP_VOWEL2)) - { + while (letter_w != RULE_SPACE) { + if (IsLetter(tr, letter_w, LETTERGP_VOWEL2)) { failed = 1; break; } - p += utf8_in(&letter_w,p); + p += utf8_in(&letter_w, p); } - if(!failed) + if (!failed) add_points = (19-distance_right); } break; @@ -2232,14 +1951,12 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ char *p = post_ptr + letter_xbytes; char *p2 = p; int rule_w; // skip characters until this - utf8_in(&rule_w,rule); - while((letter_w != rule_w) && (letter_w != RULE_SPACE)) - { + utf8_in(&rule_w, rule); + while ((letter_w != rule_w) && (letter_w != RULE_SPACE)) { p2 = p; - p += utf8_in(&letter_w,p); + p += utf8_in(&letter_w, p); } - if(letter_w == rule_w) - { + if (letter_w == rule_w) { post_ptr = p2; } } @@ -2251,10 +1968,8 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ case RULE_DEL_FWD: // find the next 'e' in the word and replace by 'E' - for(p = *word + group_length; p < post_ptr; p++) - { - if(*p == 'e') - { + for (p = *word + group_length; p < post_ptr; p++) { + if (*p == 'e') { match.del_fwd = p; break; } @@ -2267,10 +1982,9 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ // next 3 bytes are a (non-zero) ending type. 2 bytes of flags + suffix length end_type = (rule[0] << 16) + ((rule[1] & 0x7f) << 8) + (rule[2] & 0x7f); - if((tr->word_vowel_count == 0) && !(end_type & SUFX_P) && (tr->langopts.param[LOPT_SUFFIX] & 1)) + if ((tr->word_vowel_count == 0) && !(end_type & SUFX_P) && (tr->langopts.param[LOPT_SUFFIX] & 1)) failed = 1; // don't match a suffix rule if there are no previous syllables (needed for lang=tr). - else - { + else { match.end_type = end_type; rule += 3; } @@ -2278,22 +1992,19 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ break; case RULE_NO_SUFFIX: - if(word_flags & FLAG_SUFFIX_REMOVED) + if (word_flags & FLAG_SUFFIX_REMOVED) failed = 1; // a suffix has been removed else add_points = 1; break; default: - if(letter == rb) - { - if((letter & 0xc0) != 0x80) - { + if (letter == rb) { + if ((letter & 0xc0) != 0x80) { // not for non-initial UTF-8 bytes add_points = (21-distance_right); } - } - else + } else failed = 1; break; } @@ -2303,82 +2014,71 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ case RULE_PRE: /* match backwards from start of current group */ distance_left += 2; - if(distance_left > 18) + if (distance_left > 18) distance_left = 19; last_letter = *pre_ptr; pre_ptr--; - letter_xbytes = utf8_in2(&letter_w,pre_ptr,1)-1; + letter_xbytes = utf8_in2(&letter_w, pre_ptr, 1)-1; letter = *pre_ptr; - switch(rb) + switch (rb) { case RULE_LETTERGP: letter_group = *rule++ - 'A'; - if(IsLetter(tr, letter_w,letter_group)) - { + if (IsLetter(tr, letter_w, letter_group)) { lg_pts = 20; - if(letter_group==2) + if (letter_group == 2) lg_pts = 19; // fewer points for C, general consonant add_points = (lg_pts-distance_left); pre_ptr -= letter_xbytes; - } - else + } else failed = 1; break; case RULE_LETTERGP2: // match against a list of utf-8 strings letter_group = *rule++ - 'A'; - if((n_bytes = IsLetterGroup(tr, pre_ptr,letter_group,1)) >0) - { + if ((n_bytes = IsLetterGroup(tr, pre_ptr, letter_group, 1)) > 0) { add_points = (20-distance_right); pre_ptr -= (n_bytes-1); - } - else - failed =1; + } else + failed = 1; break; case RULE_NOTVOWEL: - if(!IsLetter(tr, letter_w,0)) - { + if (!IsLetter(tr, letter_w, 0)) { add_points = (20-distance_left); pre_ptr -= letter_xbytes; - } - else + } else failed = 1; break; case RULE_DOUBLE: - if(letter == last_letter) + if (letter == last_letter) add_points = (21-distance_left); else failed = 1; break; case RULE_DIGIT: - if(IsDigit(letter_w)) - { + if (IsDigit(letter_w)) { add_points = (21-distance_left); pre_ptr -= letter_xbytes; - } - else + } else failed = 1; break; case RULE_NONALPHA: - if(!iswalpha2(letter_w)) - { + if (!iswalpha2(letter_w)) { add_points = (21-distance_right); pre_ptr -= letter_xbytes; - } - else + } else failed = 1; break; case RULE_DOLLAR: command = *rule++; - if((command==DOLLAR_LIST) || ((command & 0xf0) == 0x20)) - { + if ((command == DOLLAR_LIST) || ((command & 0xf0) == 0x20)) { // $list or $p_alt // make a copy of the word up to the current character ix = *word - word_start + 1; @@ -2387,10 +2087,9 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ word_buf[ix+1] = 0; LookupFlags(tr, &word_buf[1], &flags); - if((command==DOLLAR_LIST) && (flags[0] & FLAG_FOUND) && !(flags[1] & FLAG_ONLY)) + if ((command == DOLLAR_LIST) && (flags[0] & FLAG_FOUND) && !(flags[1] & FLAG_ONLY)) add_points = 23; - else - if(flags[0] & (1 << (BITNUM_FLAG_ALT + (command & 0xf)))) + else if (flags[0] & (1 << (BITNUM_FLAG_ALT + (command & 0xf)))) add_points = 23; else failed = 1; @@ -2400,19 +2099,18 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ case RULE_SYLLABLE: /* more than specified number of vowels to the left */ syllable_count = 1; - while(*rule == RULE_SYLLABLE) - { + while (*rule == RULE_SYLLABLE) { rule++; syllable_count++; /* number of syllables to match */ } - if(syllable_count <= tr->word_vowel_count) + if (syllable_count <= tr->word_vowel_count) add_points = (18+syllable_count-distance_left); else failed = 1; break; case RULE_STRESSED: - if(tr->word_stressed_count > 0) + if (tr->word_stressed_count > 0) add_points = 19; else failed = 1; @@ -2421,29 +2119,27 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ case RULE_NOVOWELS: { char *p = pre_ptr - letter_xbytes - 1; - while(letter_w != RULE_SPACE) - { - if(IsLetter(tr, letter_w,LETTERGP_VOWEL2)) - { + while (letter_w != RULE_SPACE) { + if (IsLetter(tr, letter_w, LETTERGP_VOWEL2)) { failed = 1; break; } - p -= utf8_in2(&letter_w,p,1); + p -= utf8_in2(&letter_w, p, 1); } - if(!failed) + if (!failed) add_points = 3; } break; case RULE_IFVERB: - if(tr->expect_verb) + if (tr->expect_verb) add_points = 1; else failed = 1; break; case RULE_CAPITAL: - if(word_flags & FLAG_FIRST_UPPER) + if (word_flags & FLAG_FIRST_UPPER) add_points = 1; else failed = 1; @@ -2451,96 +2147,84 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ case '.': // dot in pre- section, match on any dot before this point in the word - for(p=pre_ptr; *p != ' '; p--) - { - if(*p == '.') - { + for (p = pre_ptr; *p != ' '; p--) { + if (*p == '.') { add_points = 50; break; } } - if(*p == ' ') + if (*p == ' ') failed = 1; break; case '-': - if((letter == '-') || ((letter == ' ') && (word_flags & FLAG_HYPHEN))) - { + if ((letter == '-') || ((letter == ' ') && (word_flags & FLAG_HYPHEN))) { add_points = (22-distance_right); // one point more than match against space - } - else + } else failed = 1; break; default: - if(letter == rb) - { - if(letter == RULE_SPACE) + if (letter == rb) { + if (letter == RULE_SPACE) add_points = 4; - else - { - if((letter & 0xc0) != 0x80) - { + else { + if ((letter & 0xc0) != 0x80) { // not for non-initial UTF-8 bytes add_points = (21-distance_left); } } - } - else + } else failed = 1; break; } break; } - if(failed == 0) + if (failed == 0) match.points += add_points; } - if((failed == 2) && (unpron_ignore == 0)) - { + if ((failed == 2) && (unpron_ignore == 0)) { // do we also need to check for 'start of word' ? - if((check_atstart==0) || (pre_ptr[-1] == ' ')) - { - if(check_atstart) + if ((check_atstart == 0) || (pre_ptr[-1] == ' ')) { + if (check_atstart) match.points += 4; /* matched OK, is this better than the last best match ? */ - if(match.points >= best.points) - { - memcpy(&best,&match,sizeof(match)); + if (match.points >= best.points) { + memcpy(&best, &match, sizeof(match)); total_consumed = consumed; } - if((option_phonemes & espeakPHONEMES_TRACE) && (match.points > 0) && ((word_flags & FLAG_NO_TRACE) == 0)) - { + if ((option_phonemes & espeakPHONEMES_TRACE) && (match.points > 0) && ((word_flags & FLAG_NO_TRACE) == 0)) { // show each rule that matches, and it's points score int pts; char decoded_phonemes[80]; pts = match.points; - if(group_length > 1) + if (group_length > 1) pts += 35; // to account for an extra letter matching - DecodePhonemes(match.phonemes,decoded_phonemes); - fprintf(f_trans,"%3d\t%s [%s]\n",pts,DecodeRule(group_chars, group_length, rule_start, word_flags), decoded_phonemes); + DecodePhonemes(match.phonemes, decoded_phonemes); + fprintf(f_trans, "%3d\t%s [%s]\n", pts, DecodeRule(group_chars, group_length, rule_start, word_flags), decoded_phonemes); } } } /* skip phoneme string to reach start of next template */ - while(*rule++ != 0); + while (*rule++ != 0) ; } /* advance input data pointer */ total_consumed += group_length; - if(total_consumed == 0) + if (total_consumed == 0) total_consumed = 1; /* always advance over 1st letter */ *word += total_consumed; - if(best.points == 0) + if (best.points == 0) best.phonemes = ""; - memcpy(match_out,&best,sizeof(MatchRecord)); + memcpy(match_out, &best, sizeof(MatchRecord)); } @@ -2553,7 +2237,7 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c unsigned char c, c2; unsigned int c12; - int wc=0; + int wc = 0; int wc_bytes; char *p2; /* copy of p for use in double letter chain match */ int found; @@ -2561,177 +2245,153 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c int g1; /* first group for this letter */ int n; int letter; - int any_alpha=0; + int any_alpha = 0; int ix; - unsigned int digit_count=0; + unsigned int digit_count = 0; char *p; ALPHABET *alphabet; - int dict_flags0=0; + int dict_flags0 = 0; MatchRecord match1; MatchRecord match2; char ph_buf[40]; char word_copy[N_WORD_BYTES]; - static const char str_pause[2] = {phonPAUSE_NOLINK,0}; + static const char str_pause[2] = { phonPAUSE_NOLINK, 0 }; - if(tr->data_dictrules == NULL) - return(0); + if (tr->data_dictrules == NULL) + return (0); - if(dict_flags != NULL) + if (dict_flags != NULL) dict_flags0 = dict_flags[0]; - for(ix=0; ix<(N_WORD_BYTES-1); ) - { + for (ix = 0; ix < (N_WORD_BYTES-1);) { c = p_start[ix]; word_copy[ix++] = c; - if(c == 0) + if (c == 0) break; } word_copy[ix] = 0; - if((option_phonemes & espeakPHONEMES_TRACE) && ((word_flags & FLAG_NO_TRACE)==0)) - { + if ((option_phonemes & espeakPHONEMES_TRACE) && ((word_flags & FLAG_NO_TRACE) == 0)) { char wordbuf[120]; unsigned int ix; - for(ix=0; ((c = p_start[ix]) != ' ') && (c != 0) && (ix < (sizeof(wordbuf)-1)); ix++) - { + for (ix = 0; ((c = p_start[ix]) != ' ') && (c != 0) && (ix < (sizeof(wordbuf)-1)); ix++) { wordbuf[ix] = c; } wordbuf[ix] = 0; - if(word_flags & FLAG_UNPRON_TEST) - fprintf(f_trans,"Unpronouncable? '%s'\n",wordbuf); + if (word_flags & FLAG_UNPRON_TEST) + fprintf(f_trans, "Unpronouncable? '%s'\n", wordbuf); else - fprintf(f_trans,"Translate '%s'\n",wordbuf); + fprintf(f_trans, "Translate '%s'\n", wordbuf); } p = p_start; tr->word_vowel_count = 0; tr->word_stressed_count = 0; - if(end_phonemes != NULL) + if (end_phonemes != NULL) end_phonemes[0] = 0; - while(((c = *p) != ' ') && (c != 0)) - { - wc_bytes = utf8_in(&wc,p); - if(IsAlpha(wc)) + while (((c = *p) != ' ') && (c != 0)) { + wc_bytes = utf8_in(&wc, p); + if (IsAlpha(wc)) any_alpha++; n = tr->groups2_count[c]; - if(IsDigit(wc) && ((tr->langopts.tone_numbers == 0) || !any_alpha)) - { + if (IsDigit(wc) && ((tr->langopts.tone_numbers == 0) || !any_alpha)) { // lookup the number in *_list not *_rules char string[8]; char buf[40]; string[0] = '_'; - memcpy(&string[1],p,wc_bytes); + memcpy(&string[1], p, wc_bytes); string[1+wc_bytes] = 0; - Lookup(tr, string,buf); - if(++digit_count >= 2) - { - strcat(buf,str_pause); - digit_count=0; + Lookup(tr, string, buf); + if (++digit_count >= 2) { + strcat(buf, str_pause); + digit_count = 0; } - AppendPhonemes(tr,phonemes,ph_size,buf); + AppendPhonemes(tr, phonemes, ph_size, buf); p += wc_bytes; continue; - } - else - { + } else { digit_count = 0; found = 0; - if(((ix = wc - tr->letter_bits_offset) >= 0) && (ix < 128)) - { - if(tr->groups3[ix] != NULL) - { + if (((ix = wc - tr->letter_bits_offset) >= 0) && (ix < 128)) { + if (tr->groups3[ix] != NULL) { MatchRule(tr, &p, p_start, wc_bytes, tr->groups3[ix], &match1, word_flags, dict_flags0); found = 1; } } - if(!found && (n > 0)) - { + if (!found && (n > 0)) { /* there are some 2 byte chains for this initial letter */ c2 = p[1]; c12 = c + (c2 << 8); /* 2 characters */ g1 = tr->groups2_start[c]; - for(g=g1; g < (g1+n); g++) - { - if(tr->groups2_name[g] == c12) - { + for (g = g1; g < (g1+n); g++) { + if (tr->groups2_name[g] == c12) { found = 1; p2 = p; MatchRule(tr, &p2, p_start, 2, tr->groups2[g], &match2, word_flags, dict_flags0); - if(match2.points > 0) + if (match2.points > 0) match2.points += 35; /* to acount for 2 letters matching */ /* now see whether single letter chain gives a better match ? */ MatchRule(tr, &p, p_start, 1, tr->groups1[c], &match1, word_flags, dict_flags0); - if(match2.points >= match1.points) - { + if (match2.points >= match1.points) { // use match from the 2-letter group - memcpy(&match1,&match2,sizeof(MatchRecord)); + memcpy(&match1, &match2, sizeof(MatchRecord)); p = p2; } } } } - if(!found) - { + if (!found) { /* alphabetic, single letter chain */ - if(tr->groups1[c] != NULL) + if (tr->groups1[c] != NULL) MatchRule(tr, &p, p_start, 1, tr->groups1[c], &match1, word_flags, dict_flags0); - else - { + else { // no group for this letter, use default group MatchRule(tr, &p, p_start, 0, tr->groups1[0], &match1, word_flags, dict_flags0); - if((match1.points == 0) && ((option_sayas & 0x10) == 0)) - { - n = utf8_in(&letter,p-1)-1; + if ((match1.points == 0) && ((option_sayas & 0x10) == 0)) { + n = utf8_in(&letter, p-1)-1; - if(tr->letter_bits_offset > 0) - { + if (tr->letter_bits_offset > 0) { // not a Latin alphabet, switch to the default Latin alphabet language - if((letter <= 0x241) && iswalpha2(letter)) - { - sprintf(phonemes,"%c%s",phonSWITCH,tr->langopts.ascii_language); - return(0); + if ((letter <= 0x241) && iswalpha2(letter)) { + sprintf(phonemes, "%c%s", phonSWITCH, tr->langopts.ascii_language); + return (0); } } // is it a bracket ? - if(letter == 0xe000+'(') - { - if(pre_pause < tr->langopts.param2[LOPT_BRACKET_PAUSE]) + if (letter == 0xe000+'(') { + if (pre_pause < tr->langopts.param2[LOPT_BRACKET_PAUSE]) pre_pause = tr->langopts.param2[LOPT_BRACKET_PAUSE]; // a bracket, aleady spoken by AnnouncePunctuation() } - if(IsBracket(letter)) - { - if(pre_pause < tr->langopts.param[LOPT_BRACKET_PAUSE]) + if (IsBracket(letter)) { + if (pre_pause < tr->langopts.param[LOPT_BRACKET_PAUSE]) pre_pause = tr->langopts.param[LOPT_BRACKET_PAUSE]; } // no match, try removing the accent and re-translating the word - if((letter >= 0xc0) && (letter < N_REMOVE_ACCENT) && ((ix = remove_accent[letter-0xc0]) != 0)) - { + if ((letter >= 0xc0) && (letter < N_REMOVE_ACCENT) && ((ix = remove_accent[letter-0xc0]) != 0)) { // within range of the remove_accent table - if((p[-2] != ' ') || (p[n] != ' ')) - { + if ((p[-2] != ' ') || (p[n] != ' ')) { // not the only letter in the word p2 = p-1; p[-1] = ix; - while((p[0] = p[n]) != ' ') p++; - while(n-- > 0) *p++ = ' '; // replacement character must be no longer than original + while ((p[0] = p[n]) != ' ') p++; + while (n-- > 0) *p++ = ' '; // replacement character must be no longer than original - if(tr->langopts.param[LOPT_DIERESES] && (lookupwchar(diereses_list,letter) > 0)) - { + if (tr->langopts.param[LOPT_DIERESES] && (lookupwchar(diereses_list, letter) > 0)) { // vowel with dieresis, replace and continue from this point p = p2; continue; @@ -2745,108 +2405,87 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c } } - if(((alphabet = AlphabetFromChar(letter)) != NULL) && (alphabet->offset != tr->letter_bits_offset)) - { - if(tr->langopts.alt_alphabet == alphabet->offset) - { - sprintf(phonemes,"%c%s",phonSWITCH, WordToString2(tr->langopts.alt_alphabet_lang)); - return(0); + if (((alphabet = AlphabetFromChar(letter)) != NULL) && (alphabet->offset != tr->letter_bits_offset)) { + if (tr->langopts.alt_alphabet == alphabet->offset) { + sprintf(phonemes, "%c%s", phonSWITCH, WordToString2(tr->langopts.alt_alphabet_lang)); + return (0); } - if(alphabet->flags & AL_WORDS) - { + if (alphabet->flags & AL_WORDS) { // switch to the nominated language for this alphabet - sprintf(phonemes,"%c%s",phonSWITCH, WordToString2(alphabet->language)); - return(0); + sprintf(phonemes, "%c%s", phonSWITCH, WordToString2(alphabet->language)); + return (0); } } } } - if(match1.points == 0) - { - if((wc >= 0x300) && (wc <= 0x36f)) - { + if (match1.points == 0) { + if ((wc >= 0x300) && (wc <= 0x36f)) { // combining accent inside a word, ignore - } - else if(IsAlpha(wc)) - { - if((any_alpha > 1) || (p[wc_bytes-1] > ' ')) - { + } else if (IsAlpha(wc)) { + if ((any_alpha > 1) || (p[wc_bytes-1] > ' ')) { // an unrecognised character in a word, abort and then spell the word phonemes[0] = 0; - if(dict_flags != NULL) + if (dict_flags != NULL) dict_flags[0] |= FLAG_SPELLWORD; break; } - } - else - { + } else { LookupLetter(tr, wc, -1, ph_buf, 0); - if(ph_buf[0]) - { + if (ph_buf[0]) { match1.phonemes = ph_buf; match1.points = 1; } } p += (wc_bytes-1); - } - else - { + } else { tr->phonemes_repeat_count = 0; } } } - if(match1.phonemes == NULL) + if (match1.phonemes == NULL) match1.phonemes = ""; - if(match1.points > 0) - { - if(word_flags & FLAG_UNPRON_TEST) - return(match1.end_type | 1); + if (match1.points > 0) { + if (word_flags & FLAG_UNPRON_TEST) + return (match1.end_type | 1); - if((match1.phonemes[0] == phonSWITCH) && ((word_flags & FLAG_DONT_SWITCH_TRANSLATOR)==0)) - { + if ((match1.phonemes[0] == phonSWITCH) && ((word_flags & FLAG_DONT_SWITCH_TRANSLATOR) == 0)) { // an instruction to switch language, return immediately so we can re-translate - strcpy(phonemes,match1.phonemes); - return(0); + strcpy(phonemes, match1.phonemes); + return (0); } - if((option_phonemes & espeakPHONEMES_TRACE) && ((word_flags & FLAG_NO_TRACE)==0)) - { - fprintf(f_trans,"\n"); + if ((option_phonemes & espeakPHONEMES_TRACE) && ((word_flags & FLAG_NO_TRACE) == 0)) { + fprintf(f_trans, "\n"); } match1.end_type &= ~SUFX_UNPRON; - if((match1.end_type != 0) && (end_phonemes != NULL)) - { + if ((match1.end_type != 0) && (end_phonemes != NULL)) { /* a standard ending has been found, re-translate the word without it */ - if((match1.end_type & SUFX_P) && (word_flags & FLAG_NO_PREFIX)) - { + if ((match1.end_type & SUFX_P) && (word_flags & FLAG_NO_PREFIX)) { // ignore the match on a prefix - } - else - { - if((match1.end_type & SUFX_P) && ((match1.end_type & 0x7f) == 0)) - { + } else { + if ((match1.end_type & SUFX_P) && ((match1.end_type & 0x7f) == 0)) { // no prefix length specified match1.end_type |= p - p_start; } - strcpy(end_phonemes,match1.phonemes); - memcpy(p_start,word_copy,strlen(word_copy)); - return(match1.end_type); + strcpy(end_phonemes, match1.phonemes); + memcpy(p_start, word_copy, strlen(word_copy)); + return (match1.end_type); } } - if(match1.del_fwd != NULL) + if (match1.del_fwd != NULL) *match1.del_fwd = REPLACED_E; - AppendPhonemes(tr,phonemes,ph_size,match1.phonemes); + AppendPhonemes(tr, phonemes, ph_size, match1.phonemes); } } - memcpy(p_start,word_copy,strlen(word_copy)); + memcpy(p_start, word_copy, strlen(word_copy)); - return(0); + return (0); } @@ -2859,25 +2498,19 @@ void ApplySpecialAttribute2(Translator *tr, char *phonemes, int dict_flags) len = strlen(phonemes); - if(tr->langopts.param[LOPT_ALT] & 2) - { - for(ix=0; ix<(len-1); ix++) - { - if(phonemes[ix] == phonSTRESS_P) - { + if (tr->langopts.param[LOPT_ALT] & 2) { + for (ix = 0; ix < (len-1); ix++) { + if (phonemes[ix] == phonSTRESS_P) { p = &phonemes[ix+1]; - if((dict_flags & FLAG_ALT2_TRANS) != 0) - { - if(*p == PhonemeCode('E')) + if ((dict_flags & FLAG_ALT2_TRANS) != 0) { + if (*p == PhonemeCode('E')) *p = PhonemeCode('e'); - if(*p == PhonemeCode('O')) + if (*p == PhonemeCode('O')) *p = PhonemeCode('o'); - } - else - { - if(*p == PhonemeCode('e')) + } else { + if (*p == PhonemeCode('e')) *p = PhonemeCode('E'); - if(*p == PhonemeCode('o')) + if (*p == PhonemeCode('o')) *p = PhonemeCode('O'); } break; @@ -2901,7 +2534,7 @@ int TransposeAlphabet(Translator *tr, char *text) const char *map; char *p = text; char *p2; - int all_alpha=1; + int all_alpha = 1; int bits; int acc; int pairs_start; @@ -2919,55 +2552,40 @@ int TransposeAlphabet(Translator *tr, char *text) bufix = 0; do { - p += utf8_in(&c,p); - if(c != 0) - { - if((c >= min) && (c <= max)) - { - if(map == NULL) - { + p += utf8_in(&c, p); + if (c != 0) { + if ((c >= min) && (c <= max)) { + if (map == NULL) { buf[bufix++] = c - offset; - } - else - { + } else { // get the code from the transpose map - if(map[c - min] > 0) - { + if (map[c - min] > 0) { buf[bufix++] = map[c - min]; - } - else - { - all_alpha=0; + } else { + all_alpha = 0; break; } } - } - else - { - all_alpha=0; + } else { + all_alpha = 0; break; } } } while ((c != 0) && (bufix < N_WORD_BYTES)); buf[bufix] = 0; - if(all_alpha) - { + if (all_alpha) { // compress to 6 bits per character - acc=0; - bits=0; + acc = 0; + bits = 0; p = buf; p2 = buf; - while((c = *p++) != 0) - { - if((pairs_list = tr->frequent_pairs) != NULL) - { + while ((c = *p++) != 0) { + if ((pairs_list = tr->frequent_pairs) != NULL) { c2 = c + (*p << 8); - for(ix=0; c2 >= pairs_list[ix]; ix++) - { - if(c2 == pairs_list[ix]) - { + for (ix = 0; c2 >= pairs_list[ix]; ix++) { + if (c2 == pairs_list[ix]) { // found an encoding for a 2-character pair c = ix + pairs_start; // 2-character codes start after the single letter codes p++; @@ -2978,24 +2596,20 @@ int TransposeAlphabet(Translator *tr, char *text) acc = (acc << 6) + (c & 0x3f); bits += 6; - if(bits >= 8) - { + if (bits >= 8) { bits -= 8; *p2++ = (acc >> bits); } } - if(bits > 0) - { + if (bits > 0) { *p2++ = (acc << (8-bits)); } *p2 = 0; ix = p2 - buf; memcpy(text, buf, ix); - return(ix | 0x40); // bit 6 indicates compressed characters - } - else - { - return(strlen(text)); + return (ix | 0x40); // bit 6 indicates compressed characters + } else { + return (strlen(text)); } } @@ -3023,7 +2637,7 @@ static const char *LookupDict2(Translator *tr, const char *word, const char *wor unsigned char flag; unsigned int dictionary_flags; unsigned int dictionary_flags2; - int condition_failed=0; + int condition_failed = 0; int n_chars; int no_phonemes; int skipwords; @@ -3036,43 +2650,36 @@ static const char *LookupDict2(Translator *tr, const char *word, const char *wor char word_buf[N_WORD_BYTES+1]; char dict_flags_buf[80]; - if(wtab != NULL) - { + if (wtab != NULL) { wflags = wtab->flags; } lookup_symbol = flags[1] & FLAG_LOOKUP_SYMBOL; word1 = word; - if(tr->transpose_min > 0) - { - strncpy0(word_buf,word, N_WORD_BYTES); + if (tr->transpose_min > 0) { + strncpy0(word_buf, word, N_WORD_BYTES); wlen = TransposeAlphabet(tr, word_buf); // bit 6 indicates compressed characters word = word_buf; - } - else - { + } else { wlen = strlen(word); } hash = HashDictionary(word); p = tr->dict_hashtab[hash]; - if(p == NULL) - { - if(flags != NULL) + if (p == NULL) { + if (flags != NULL) *flags = 0; - return(0); + return (0); } // Find the first entry in the list for this hash value which matches. // This corresponds to the last matching entry in the *_list file. - while(*p != 0) - { + while (*p != 0) { next = p + p[0]; - if(((p[1] & 0x7f) != wlen) || (memcmp(word,&p[2],wlen & 0x3f) != 0)) - { + if (((p[1] & 0x7f) != wlen) || (memcmp(word, &p[2], wlen & 0x3f) != 0)) { // bit 6 of wlen indicates whether the word has been compressed; so we need to match on this also. p = next; continue; @@ -3087,41 +2694,31 @@ static const char *LookupDict2(Translator *tr, const char *word, const char *wor p += ((p[1] & 0x3f) + 2); - if(no_phonemes) - { + if (no_phonemes) { phonetic[0] = 0; phoneme_len = 0; - } - else - { - strcpy(phonetic,p); + } else { + strcpy(phonetic, p); phoneme_len = strlen(p); p += (phoneme_len + 1); } - while(p < next) - { + while (p < next) { // examine the flags which follow the phoneme string flag = *p++; - if(flag >= 100) - { + if (flag >= 100) { // conditional rule - if(flag >= 132) - { + if (flag >= 132) { // fail if this condition is set - if((tr->dict_condition & (1 << (flag-132))) != 0) + if ((tr->dict_condition & (1 << (flag-132))) != 0) condition_failed = 1; - } - else - { + } else { // allow only if this condition is set - if((tr->dict_condition & (1 << (flag-100))) == 0) + if ((tr->dict_condition & (1 << (flag-100))) == 0) condition_failed = 1; } - } - else if(flag > 80) - { + } else if (flag > 80) { // flags 81 to 90 match more than one word // This comes after the other flags n_chars = next - p; @@ -3129,22 +2726,18 @@ static const char *LookupDict2(Translator *tr, const char *word, const char *wor // don't use the contraction if any of the words are emphasized // or has an embedded command, such as MARK - if(wtab != NULL) - { - for(ix=0; ix <= skipwords; ix++) - { - if(wtab[ix].flags & FLAG_EMPHASIZED2) - { + if (wtab != NULL) { + for (ix = 0; ix <= skipwords; ix++) { + if (wtab[ix].flags & FLAG_EMPHASIZED2) { condition_failed = 1; } } } - if(memcmp(word2,p,n_chars) != 0) + if (memcmp(word2, p, n_chars) != 0) condition_failed = 1; - if(condition_failed) - { + if (condition_failed) { p = next; break; } @@ -3153,208 +2746,168 @@ static const char *LookupDict2(Translator *tr, const char *word, const char *wor dictionary_skipwords = skipwords; p = next; word_end = word2 + n_chars; - } - else if(flag > 64) - { + } else if (flag > 64) { // stressed syllable information, put in bits 0-3 dictionary_flags = (dictionary_flags & ~0xf) | (flag & 0xf); - if((flag & 0xc) == 0xc) + if ((flag & 0xc) == 0xc) dictionary_flags |= FLAG_STRESS_END; - } - else if(flag >= 32) - { + } else if (flag >= 32) { dictionary_flags2 |= (1L << (flag-32)); - } - else - { + } else { dictionary_flags |= (1L << flag); } } - if(condition_failed) - { - condition_failed=0; + if (condition_failed) { + condition_failed = 0; continue; } - if((end_flags & FLAG_SUFX)==0) - { + if ((end_flags & FLAG_SUFX) == 0) { // no suffix has been removed - if(dictionary_flags2 & FLAG_STEM) + if (dictionary_flags2 & FLAG_STEM) continue; // this word must have a suffix } - if((end_flags & SUFX_P) && (dictionary_flags2 & (FLAG_ONLY | FLAG_ONLY_S))) + if ((end_flags & SUFX_P) && (dictionary_flags2 & (FLAG_ONLY | FLAG_ONLY_S))) continue; // $only or $onlys, don't match if a prefix has been removed - if(end_flags & FLAG_SUFX) - { + if (end_flags & FLAG_SUFX) { // a suffix was removed from the word - if(dictionary_flags2 & FLAG_ONLY) + if (dictionary_flags2 & FLAG_ONLY) continue; // no match if any suffix - if((dictionary_flags2 & FLAG_ONLY_S) && ((end_flags & FLAG_SUFX_S)==0)) - { + if ((dictionary_flags2 & FLAG_ONLY_S) && ((end_flags & FLAG_SUFX_S) == 0)) { // only a 's' suffix allowed, but the suffix wasn't 's' continue; } } - if(dictionary_flags2 & FLAG_HYPHENATED) - { - if(!(wflags & FLAG_HYPHEN_AFTER)) - { + if (dictionary_flags2 & FLAG_HYPHENATED) { + if (!(wflags & FLAG_HYPHEN_AFTER)) { continue; } } - if(dictionary_flags2 & FLAG_CAPITAL) - { - if(!(wflags & FLAG_FIRST_UPPER)) - { + if (dictionary_flags2 & FLAG_CAPITAL) { + if (!(wflags & FLAG_FIRST_UPPER)) { continue; } } - if(dictionary_flags2 & FLAG_ALLCAPS) - { - if(!(wflags & FLAG_ALL_UPPER)) - { + if (dictionary_flags2 & FLAG_ALLCAPS) { + if (!(wflags & FLAG_ALL_UPPER)) { continue; } } - if(dictionary_flags & FLAG_NEEDS_DOT) - { - if(!(wflags & FLAG_HAS_DOT)) + if (dictionary_flags & FLAG_NEEDS_DOT) { + if (!(wflags & FLAG_HAS_DOT)) continue; } - if((dictionary_flags2 & FLAG_ATEND) && (word_end < translator->clause_end) && (lookup_symbol==0)) - { + if ((dictionary_flags2 & FLAG_ATEND) && (word_end < translator->clause_end) && (lookup_symbol == 0)) { // only use this pronunciation if it's the last word of the clause, or called from Lookup() continue; } - if((dictionary_flags2 & FLAG_ATSTART) && !(wtab->flags & FLAG_FIRST_WORD)) - { + if ((dictionary_flags2 & FLAG_ATSTART) && !(wtab->flags & FLAG_FIRST_WORD)) { // only use this pronunciation if it's the first word of a clause continue; } - if((dictionary_flags2 & FLAG_SENTENCE) && !(translator->clause_terminator & CLAUSE_BIT_SENTENCE)) - { + if ((dictionary_flags2 & FLAG_SENTENCE) && !(translator->clause_terminator & CLAUSE_BIT_SENTENCE)) { // only if this clause is a sentence , i.e. terminator is {. ? !} not {, : :} continue; } - if(dictionary_flags2 & FLAG_VERB) - { + if (dictionary_flags2 & FLAG_VERB) { // this is a verb-form pronunciation - if(tr->expect_verb || (tr->expect_verb_s && (end_flags & FLAG_SUFX_S))) - { + if (tr->expect_verb || (tr->expect_verb_s && (end_flags & FLAG_SUFX_S))) { // OK, we are expecting a verb - if((tr->translator_name == L('e','n')) && (tr->prev_dict_flags[0] & FLAG_ALT7_TRANS) && (end_flags & FLAG_SUFX_S)) - { + if ((tr->translator_name == L('e', 'n')) && (tr->prev_dict_flags[0] & FLAG_ALT7_TRANS) && (end_flags & FLAG_SUFX_S)) { // lang=en, don't use verb form after 'to' if the word has 's' suffix continue; } - } - else - { + } else { /* don't use the 'verb' pronunciation unless we are expecting a verb */ continue; } } - if(dictionary_flags2 & FLAG_PAST) - { - if(!tr->expect_past) - { + if (dictionary_flags2 & FLAG_PAST) { + if (!tr->expect_past) { /* don't use the 'past' pronunciation unless we are expecting past tense */ continue; } } - if(dictionary_flags2 & FLAG_NOUN) - { - if((!tr->expect_noun) || (end_flags & SUFX_V)) - { + if (dictionary_flags2 & FLAG_NOUN) { + if ((!tr->expect_noun) || (end_flags & SUFX_V)) { /* don't use the 'noun' pronunciation unless we are expecting a noun */ continue; } } - if(dictionary_flags2 & FLAG_NATIVE) - { - if(tr != translator) + if (dictionary_flags2 & FLAG_NATIVE) { + if (tr != translator) continue; // don't use if we've switched translators } - if(dictionary_flags & FLAG_ALT2_TRANS) - { + if (dictionary_flags & FLAG_ALT2_TRANS) { // language specific - if((tr->translator_name == L('h','u')) && !(tr->prev_dict_flags[0] & FLAG_ALT_TRANS)) + if ((tr->translator_name == L('h', 'u')) && !(tr->prev_dict_flags[0] & FLAG_ALT_TRANS)) continue; } - if(flags != NULL) - { + if (flags != NULL) { flags[0] = dictionary_flags | FLAG_FOUND_ATTRIBUTES; flags[1] = dictionary_flags2; } - if(phoneme_len == 0) - { - if(option_phonemes & espeakPHONEMES_TRACE) - { + if (phoneme_len == 0) { + if (option_phonemes & espeakPHONEMES_TRACE) { print_dictionary_flags(flags, dict_flags_buf, sizeof(dict_flags_buf)); - fprintf(f_trans,"Flags: %s %s\n", word1, dict_flags_buf); + fprintf(f_trans, "Flags: %s %s\n", word1, dict_flags_buf); } - return(0); // no phoneme translation found here, only flags. So use rules + return (0); // no phoneme translation found here, only flags. So use rules } - if(flags != NULL) + if (flags != NULL) flags[0] |= FLAG_FOUND; // this flag indicates word was found in dictionary - if(option_phonemes & espeakPHONEMES_TRACE) - { + if (option_phonemes & espeakPHONEMES_TRACE) { char ph_decoded[N_WORD_PHONEMES]; int textmode; - DecodePhonemes(phonetic,ph_decoded); + DecodePhonemes(phonetic, ph_decoded); - if((dictionary_flags & FLAG_TEXTMODE) == 0) + if ((dictionary_flags & FLAG_TEXTMODE) == 0) textmode = 0; else textmode = 1; - if(textmode == translator->langopts.textmode) - { + if (textmode == translator->langopts.textmode) { // only show this line if the word translates to phonemes, not replacement text - if((dictionary_flags & FLAG_SKIPWORDS) && (wtab != NULL)) - { + if ((dictionary_flags & FLAG_SKIPWORDS) && (wtab != NULL)) { // matched more than one word // (check for wtab prevents showing RULE_SPELLING byte when speaking individual letters) - memcpy(word_buf,word2,word_end-word2); + memcpy(word_buf, word2, word_end-word2); word_buf[word_end-word2-1] = 0; - fprintf(f_trans,"Found: '%s %s\n",word1,word_buf); - } - else - { - fprintf(f_trans,"Found: '%s",word1); + fprintf(f_trans, "Found: '%s %s\n", word1, word_buf); + } else { + fprintf(f_trans, "Found: '%s", word1); } print_dictionary_flags(flags, dict_flags_buf, sizeof(dict_flags_buf)); - fprintf(f_trans,"' [%s] %s\n", ph_decoded,dict_flags_buf); + fprintf(f_trans, "' [%s] %s\n", ph_decoded, dict_flags_buf); } } ix = utf8_in(&c, word); - if((word[ix] == 0) && !IsAlpha(c)) - { + if ((word[ix] == 0) && !IsAlpha(c)) { flags[0] |= FLAG_MAX3; } - return(word_end); + return (word_end); } - return(0); + return (0); } @@ -3379,41 +2932,36 @@ int LookupDictList(Translator *tr, char **wordptr, char *ph_out, unsigned int *f length = 0; word2 = word1 = *wordptr; - while((word2[nbytes = utf8_nbytes(word2)]==' ') && (word2[nbytes+1]=='.')) - { + while ((word2[nbytes = utf8_nbytes(word2)] == ' ') && (word2[nbytes+1] == '.')) { // look for an abbreviation of the form a.b.c // try removing the spaces between the dots and looking for a match - memcpy(&word[length],word2,nbytes); + memcpy(&word[length], word2, nbytes); length += nbytes; word[length++] = '.'; word2 += nbytes+3; } - if(length > 0) - { + if (length > 0) { // found an abbreviation containing dots nbytes = 0; - while(((c = word2[nbytes]) != 0) && (c != ' ')) - { + while (((c = word2[nbytes]) != 0) && (c != ' ')) { nbytes++; } - memcpy(&word[length],word2,nbytes); + memcpy(&word[length], word2, nbytes); word[length+nbytes] = 0; found = LookupDict2(tr, word, word2, ph_out, flags, end_flags, wtab); - if(found) - { + if (found) { // set the skip words flag flags[0] |= FLAG_SKIPWORDS; dictionary_skipwords = length; - return(1); + return (1); } } - for(length=0; length<(N_WORD_BYTES-1); length++) - { - if(((c = *word1++)==0) || (c == ' ')) + for (length = 0; length < (N_WORD_BYTES-1); length++) { + if (((c = *word1++) == 0) || (c == ' ')) break; - if((c=='.') && (length > 0) && (IsDigit09(word[length-1]))) + if ((c == '.') && (length > 0) && (IsDigit09(word[length-1]))) break; // needed for lang=hu, eg. "december 2.-ig" word[length] = c; @@ -3423,96 +2971,80 @@ int LookupDictList(Translator *tr, char **wordptr, char *ph_out, unsigned int *f found = LookupDict2(tr, word, word1, ph_out, flags, end_flags, wtab); - if(flags[0] & FLAG_MAX3) - { - if(strcmp(ph_out, tr->phonemes_repeat) == 0) - { + if (flags[0] & FLAG_MAX3) { + if (strcmp(ph_out, tr->phonemes_repeat) == 0) { tr->phonemes_repeat_count++; - if(tr->phonemes_repeat_count > 3) - { + if (tr->phonemes_repeat_count > 3) { ph_out[0] = 0; } - } - else - { + } else { strncpy0(tr->phonemes_repeat, ph_out, sizeof(tr->phonemes_repeat)); tr->phonemes_repeat_count = 1; } - } - else - { + } else { tr->phonemes_repeat_count = 0; } - if((found == 0) && (flags[1] & FLAG_ACCENT)) - { + if ((found == 0) && (flags[1] & FLAG_ACCENT)) { int letter; word2 = word; - if(*word2 == '_') word2++; + if (*word2 == '_') word2++; len = utf8_in(&letter, word2); - LookupAccentedLetter(tr,letter, ph_out); + LookupAccentedLetter(tr, letter, ph_out); found = word2 + len; } - if(found == 0) - { + if (found == 0) { ph_out[0] = 0; // try modifications to find a recognised word - if((end_flags & FLAG_SUFX_E_ADDED) && (word[length-1] == 'e')) - { + if ((end_flags & FLAG_SUFX_E_ADDED) && (word[length-1] == 'e')) { // try removing an 'e' which has been added by RemoveEnding word[length-1] = 0; found = LookupDict2(tr, word, word1, ph_out, flags, end_flags, wtab); - } - else if((end_flags & SUFX_D) && (word[length-1] == word[length-2])) - { + } else if ((end_flags & SUFX_D) && (word[length-1] == word[length-2])) { // try removing a double letter word[length-1] = 0; found = LookupDict2(tr, word, word1, ph_out, flags, end_flags, wtab); } } - if(found) - { + if (found) { // if textmode is the default, then words which have phonemes are marked. - if(tr->langopts.textmode) + if (tr->langopts.textmode) *flags ^= FLAG_TEXTMODE; - if(*flags & FLAG_TEXTMODE) - { + if (*flags & FLAG_TEXTMODE) { // the word translates to replacement text, not to phonemes - if(end_flags & FLAG_ALLOW_TEXTMODE) - { + if (end_flags & FLAG_ALLOW_TEXTMODE) { // only use replacement text if this is the original word, not if a prefix or suffix has been removed word_replacement[0] = 0; word_replacement[1] = ' '; - sprintf(&word_replacement[2],"%s ",ph_out); // replacement word, preceded by zerochar and space + sprintf(&word_replacement[2], "%s ", ph_out); // replacement word, preceded by zerochar and space word1 = *wordptr; *wordptr = &word_replacement[2]; - if(option_phonemes & espeakPHONEMES_TRACE) - { + if (option_phonemes & espeakPHONEMES_TRACE) { len = found - word1; - memcpy(word,word1,len); // include multiple matching words + memcpy(word, word1, len); // include multiple matching words word[len] = 0; - fprintf(f_trans,"Replace: %s %s\n",word,*wordptr); + fprintf(f_trans, "Replace: %s %s\n", word, *wordptr); } } ph_out[0] = 0; - return(0); + return (0); } - return(1); + return (1); } ph_out[0] = 0; - return(0); + return (0); } @@ -3530,13 +3062,11 @@ int Lookup(Translator *tr, const char *word, char *ph_out) flags[0] = 0; flags[1] = FLAG_LOOKUP_SYMBOL; - if((flags0 = LookupDictList(tr, &word1, ph_out, flags, FLAG_ALLOW_TEXTMODE, NULL)) != 0) - { + if ((flags0 = LookupDictList(tr, &word1, ph_out, flags, FLAG_ALLOW_TEXTMODE, NULL)) != 0) { flags0 = flags[0]; } - if(flags[0] & FLAG_TEXTMODE) - { + if (flags[0] & FLAG_TEXTMODE) { say_as = option_sayas; option_sayas = 0; // don't speak replacement word as letter names text[0] = 0; @@ -3545,7 +3075,7 @@ int Lookup(Translator *tr, const char *word, char *ph_out) strcpy(ph_out, word_phonemes); option_sayas = say_as; } - return(flags0); + return (flags0); } @@ -3558,7 +3088,7 @@ int LookupFlags(Translator *tr, const char *word, unsigned int **flags_out) flags[0] = flags[1] = 0; LookupDictList(tr, &word1, buf, flags, 0, NULL); *flags_out = flags; - return(flags[0]); + return (flags[0]); } @@ -3591,34 +3121,29 @@ int RemoveEnding(Translator *tr, char *word, int end_type, char *word_copy) "c", "rs", "ir", "ur", "ath", "ns", "u", NULL }; - for(word_end = word; *word_end != ' '; word_end++) - { + for (word_end = word; *word_end != ' '; word_end++) { /* replace discarded 'e's */ - if(*word_end == REPLACED_E) + if (*word_end == REPLACED_E) *word_end = 'e'; } i = word_end - word; - if(word_copy != NULL) - { - memcpy(word_copy,word,i); + if (word_copy != NULL) { + memcpy(word_copy, word, i); word_copy[i] = 0; } // look for multibyte characters to increase the number of bytes to remove - for(len_ending = i = (end_type & 0x3f); i>0; i--) // num.of characters of the suffix - { + for (len_ending = i = (end_type & 0x3f); i > 0; i--) { // num.of characters of the suffix word_end--; - while((*word_end & 0xc0) == 0x80) - { + while ((*word_end & 0xc0) == 0x80) { word_end--; // for multibyte characters len_ending++; } } // remove bytes from the end of the word and replace them by spaces - for(i=0; (itranslator_name == L('n','l')) - { - if(((word_end[0] & 0x80) == 0) && ((word_end[-1] & 0x80) == 0) && IsVowel(tr, word_end[-1]) && IsLetter(tr, word_end[0], LETTERGP_C) && !IsVowel(tr, word_end[-2])) - { - //double the vowel before the (ascii) final consonant + if (end_type & SUFX_E) { + if (tr->translator_name == L('n', 'l')) { + if (((word_end[0] & 0x80) == 0) && ((word_end[-1] & 0x80) == 0) && IsVowel(tr, word_end[-1]) && IsLetter(tr, word_end[0], LETTERGP_C) && !IsVowel(tr, word_end[-2])) { + // double the vowel before the (ascii) final consonant word_end[1] = word_end[0]; word_end[0] = word_end[-1]; word_end[2] = ' '; } - } - else if(tr->translator_name == L('e','n')) - { + } else if (tr->translator_name == L('e', 'n')) { // add 'e' to end of stem - if(IsLetter(tr, word_end[-1],LETTERGP_VOWEL2) && IsLetter(tr, word_end[0],1)) - { + if (IsLetter(tr, word_end[-1], LETTERGP_VOWEL2) && IsLetter(tr, word_end[0], 1)) { // vowel(incl.'y') + hard.consonant - for(i=0; (p = add_e_exceptions[i]) != NULL; i++) - { + for (i = 0; (p = add_e_exceptions[i]) != NULL; i++) { len = strlen(p); - if(memcmp(p,&word_end[1-len],len)==0) - { + if (memcmp(p, &word_end[1-len], len) == 0) { break; } } - if(p == NULL) + if (p == NULL) end_flags |= FLAG_SUFX_E_ADDED; // no exception found - } - else - { - for(i=0; (p = add_e_additions[i]) != NULL; i++) - { + } else { + for (i = 0; (p = add_e_additions[i]) != NULL; i++) { len = strlen(p); - if(memcmp(p,&word_end[1-len],len)==0) - { + if (memcmp(p, &word_end[1-len], len) == 0) { end_flags |= FLAG_SUFX_E_ADDED; break; } } } - } - else if(tr->langopts.suffix_add_e != 0) - { + } else if (tr->langopts.suffix_add_e != 0) { end_flags |= FLAG_SUFX_E_ADDED; } - if(end_flags & FLAG_SUFX_E_ADDED) - { + if (end_flags & FLAG_SUFX_E_ADDED) { utf8_out(tr->langopts.suffix_add_e, &word_end[1]); - if(option_phonemes & espeakPHONEMES_TRACE) - { - fprintf(f_trans,"add e\n"); + if (option_phonemes & espeakPHONEMES_TRACE) { + fprintf(f_trans, "add e\n"); } } } - if((end_type & SUFX_V) && (tr->expect_verb==0)) + if ((end_type & SUFX_V) && (tr->expect_verb == 0)) tr->expect_verb = 1; // this suffix indicates the verb pronunciation - if((strcmp(ending,"s")==0) || (strcmp(ending,"es")==0)) + if ((strcmp(ending, "s") == 0) || (strcmp(ending, "es") == 0)) end_flags |= FLAG_SUFX_S; - if(ending[0] == '\'') + if (ending[0] == '\'') end_flags &= ~FLAG_SUFX; // don't consider 's as an added suffix - return(end_flags); + return (end_flags); } diff --git a/src/libespeak-ng/espeak_command.c b/src/libespeak-ng/espeak_command.c index 26e512ff..5901019d 100644 --- a/src/libespeak-ng/espeak_command.c +++ b/src/libespeak-ng/espeak_command.c @@ -27,24 +27,22 @@ #include "debug.h" -static unsigned int my_current_text_id=0; +static unsigned int my_current_text_id = 0; -t_espeak_command* create_espeak_text(const void *text, size_t size, unsigned int position, espeak_POSITION_TYPE position_type, unsigned int end_position, unsigned int flags, void* user_data) +t_espeak_command *create_espeak_text(const void *text, size_t size, unsigned int position, espeak_POSITION_TYPE position_type, unsigned int end_position, unsigned int flags, void *user_data) { ENTER("create_espeak_text"); - int a_error=1; - void* a_text = NULL; - t_espeak_text* data = NULL; - t_espeak_command* a_command = (t_espeak_command*)malloc(sizeof(t_espeak_command)); + int a_error = 1; + void *a_text = NULL; + t_espeak_text *data = NULL; + t_espeak_command *a_command = (t_espeak_command *)malloc(sizeof(t_espeak_command)); - if (!text || !size || !a_command) - { + if (!text || !size || !a_command) { goto text_error; } - a_text = malloc( size+1 ); - if (!a_text) - { + a_text = malloc(size+1); + if (!a_text) { goto text_error; } memcpy(a_text, text, size); @@ -60,20 +58,17 @@ t_espeak_command* create_espeak_text(const void *text, size_t size, unsigned int data->end_position = end_position; data->flags = flags; data->user_data = user_data; - a_error=0; + a_error = 0; SHOW("ET_TEXT malloc text=%x, command=%x (uid=%d)\n", a_text, a_command, data->unique_identifier); text_error: - if (a_error) - { - if (a_text) - { - free (a_text); + if (a_error) { + if (a_text) { + free(a_text); } - if (a_command) - { - free (a_command); + if (a_command) { + free(a_command); } a_command = NULL; } @@ -83,15 +78,14 @@ text_error: return a_command; } -t_espeak_command* create_espeak_terminated_msg(unsigned int unique_identifier, void* user_data) +t_espeak_command *create_espeak_terminated_msg(unsigned int unique_identifier, void *user_data) { ENTER("create_espeak_terminated_msg"); - int a_error=1; - t_espeak_terminated_msg* data = NULL; - t_espeak_command* a_command = (t_espeak_command*)malloc(sizeof(t_espeak_command)); + int a_error = 1; + t_espeak_terminated_msg *data = NULL; + t_espeak_command *a_command = (t_espeak_command *)malloc(sizeof(t_espeak_command)); - if (!a_command) - { + if (!a_command) { goto msg_error; } @@ -100,16 +94,14 @@ t_espeak_command* create_espeak_terminated_msg(unsigned int unique_identifier, v data = &(a_command->u.my_terminated_msg); data->unique_identifier = unique_identifier; data->user_data = user_data; - a_error=0; + a_error = 0; SHOW("ET_TERMINATED_MSG command=%x (uid=%d, user_data=0x%x)\n", a_command, unique_identifier, (int)user_data); msg_error: - if (a_error) - { - if (a_command) - { - free (a_command); + if (a_error) { + if (a_command) { + free(a_command); } a_command = NULL; } @@ -120,28 +112,26 @@ msg_error: } -t_espeak_command* create_espeak_mark(const void *text, size_t size, const char *index_mark, unsigned int end_position, unsigned int flags, void* user_data) +t_espeak_command *create_espeak_mark(const void *text, size_t size, const char *index_mark, unsigned int end_position, unsigned int flags, void *user_data) { ENTER("create_espeak_mark"); - int a_error=1; - void* a_text = NULL; + int a_error = 1; + void *a_text = NULL; char *a_index_mark = NULL; - t_espeak_mark* data = NULL; - t_espeak_command* a_command = (t_espeak_command*)malloc(sizeof(t_espeak_command)); + t_espeak_mark *data = NULL; + t_espeak_command *a_command = (t_espeak_command *)malloc(sizeof(t_espeak_command)); - if (!text || !size || !index_mark || !a_command) - { + if (!text || !size || !index_mark || !a_command) { goto mark_error; } - a_text = malloc( size ); - if (!a_text) - { + a_text = malloc(size); + if (!a_text) { goto mark_error; } memcpy(a_text, text, size); - a_index_mark = strdup( index_mark); + a_index_mark = strdup(index_mark); a_command->type = ET_MARK; a_command->state = CS_UNDEFINED; @@ -153,23 +143,19 @@ t_espeak_command* create_espeak_mark(const void *text, size_t size, const char * data->end_position = end_position; data->flags = flags; data->user_data = user_data; - a_error=0; + a_error = 0; mark_error: - if (a_error) - { - if (a_text) - { - free (a_text); + if (a_error) { + if (a_text) { + free(a_text); } - if (a_command) - { - free (a_command); + if (a_command) { + free(a_command); } a_command = NULL; - if (a_index_mark) - { - free (a_index_mark); + if (a_index_mark) { + free(a_index_mark); } } @@ -178,14 +164,13 @@ mark_error: return a_command; } -t_espeak_command* create_espeak_key(const char *key_name, void *user_data) +t_espeak_command *create_espeak_key(const char *key_name, void *user_data) { ENTER("create_espeak_key"); - int a_error=1; - t_espeak_command* a_command = (t_espeak_command*)malloc(sizeof(t_espeak_command)); + int a_error = 1; + t_espeak_command *a_command = (t_espeak_command *)malloc(sizeof(t_espeak_command)); - if (!key_name || !a_command) - { + if (!key_name || !a_command) { goto key_error; } @@ -193,15 +178,13 @@ t_espeak_command* create_espeak_key(const char *key_name, void *user_data) a_command->state = CS_UNDEFINED; a_command->u.my_key.user_data = user_data; a_command->u.my_key.unique_identifier = ++my_current_text_id; - a_command->u.my_key.key_name = strdup( key_name); - a_error=0; + a_command->u.my_key.key_name = strdup(key_name); + a_error = 0; key_error: - if (a_error) - { - if (a_command) - { - free (a_command); + if (a_error) { + if (a_command) { + free(a_command); } a_command = NULL; } @@ -211,13 +194,12 @@ key_error: return a_command; } -t_espeak_command* create_espeak_char(wchar_t character, void* user_data) +t_espeak_command *create_espeak_char(wchar_t character, void *user_data) { ENTER("create_espeak_char"); - int a_error=1; - t_espeak_command* a_command = (t_espeak_command*)malloc(sizeof(t_espeak_command)); - if (!a_command) - { + int a_error = 1; + t_espeak_command *a_command = (t_espeak_command *)malloc(sizeof(t_espeak_command)); + if (!a_command) { goto char_error; } @@ -226,14 +208,12 @@ t_espeak_command* create_espeak_char(wchar_t character, void* user_data) a_command->u.my_char.user_data = user_data; a_command->u.my_char.unique_identifier = ++my_current_text_id; a_command->u.my_char.character = character; - a_error=0; + a_error = 0; char_error: - if (a_error) - { - if (a_command) - { - free (a_command); + if (a_error) { + if (a_command) { + free(a_command); } a_command = NULL; } @@ -243,14 +223,13 @@ char_error: return a_command; } -t_espeak_command* create_espeak_parameter(espeak_PARAMETER parameter, int value, int relative) +t_espeak_command *create_espeak_parameter(espeak_PARAMETER parameter, int value, int relative) { ENTER("create_espeak_parameter"); - int a_error=1; - t_espeak_parameter* data = NULL; - t_espeak_command* a_command = (t_espeak_command*)malloc(sizeof(t_espeak_command)); - if (!a_command) - { + int a_error = 1; + t_espeak_parameter *data = NULL; + t_espeak_command *a_command = (t_espeak_command *)malloc(sizeof(t_espeak_command)); + if (!a_command) { goto param_error; } @@ -260,14 +239,12 @@ t_espeak_command* create_espeak_parameter(espeak_PARAMETER parameter, int value, data->parameter = parameter; data->value = value; data->relative = relative; - a_error=0; + a_error = 0; param_error: - if (a_error) - { - if (a_command) - { - free (a_command); + if (a_error) { + if (a_command) { + free(a_command); } a_command = NULL; } @@ -277,14 +254,13 @@ param_error: return a_command; } -t_espeak_command* create_espeak_punctuation_list(const wchar_t *punctlist) +t_espeak_command *create_espeak_punctuation_list(const wchar_t *punctlist) { ENTER("create_espeak_punctuation_list"); - int a_error=1; - t_espeak_command* a_command = (t_espeak_command*)malloc(sizeof(t_espeak_command)); + int a_error = 1; + t_espeak_command *a_command = (t_espeak_command *)malloc(sizeof(t_espeak_command)); - if (!punctlist || !a_command) - { + if (!punctlist || !a_command) { goto list_error; } @@ -293,19 +269,17 @@ t_espeak_command* create_espeak_punctuation_list(const wchar_t *punctlist) { size_t len = (wcslen(punctlist) + 1)*sizeof(wchar_t); - wchar_t* a_list = (wchar_t*)malloc(len); + wchar_t *a_list = (wchar_t *)malloc(len); memcpy(a_list, punctlist, len); a_command->u.my_punctuation_list = a_list; } - a_error=0; + a_error = 0; list_error: - if (a_error) - { - if (a_command) - { - free (a_command); + if (a_error) { + if (a_command) { + free(a_command); } a_command = NULL; } @@ -315,29 +289,26 @@ list_error: return a_command; } -t_espeak_command* create_espeak_voice_name(const char *name) +t_espeak_command *create_espeak_voice_name(const char *name) { ENTER("create_espeak_voice_name"); - int a_error=1; - t_espeak_command* a_command = (t_espeak_command*)malloc(sizeof(t_espeak_command)); + int a_error = 1; + t_espeak_command *a_command = (t_espeak_command *)malloc(sizeof(t_espeak_command)); - if (!name || !a_command) - { + if (!name || !a_command) { goto name_error; } a_command->type = ET_VOICE_NAME; a_command->state = CS_UNDEFINED; - a_command->u.my_voice_name = strdup( name); - a_error=0; + a_command->u.my_voice_name = strdup(name); + a_error = 0; name_error: - if (a_error) - { - if (a_command) - { - free (a_command); + if (a_error) { + if (a_command) { + free(a_command); } a_command = NULL; } @@ -347,47 +318,41 @@ name_error: return a_command; } -t_espeak_command* create_espeak_voice_spec(espeak_VOICE *voice) +t_espeak_command *create_espeak_voice_spec(espeak_VOICE *voice) { ENTER("create_espeak_voice_spec"); - int a_error=1; - t_espeak_command* a_command = (t_espeak_command*)malloc(sizeof(t_espeak_command)); + int a_error = 1; + t_espeak_command *a_command = (t_espeak_command *)malloc(sizeof(t_espeak_command)); - if (!voice || !a_command) - { + if (!voice || !a_command) { goto spec_error; } a_command->type = ET_VOICE_SPEC; a_command->state = CS_UNDEFINED; { - espeak_VOICE* data = &(a_command->u.my_voice_spec); + espeak_VOICE *data = &(a_command->u.my_voice_spec); memcpy(data, voice, sizeof(espeak_VOICE)); - if (voice->name) - { + if (voice->name) { data->name = strdup(voice->name); } - if (voice->languages) - { + if (voice->languages) { data->languages = strdup(voice->languages); } - if (voice->identifier) - { + if (voice->identifier) { data->identifier = strdup(voice->identifier); } - a_error=0; + a_error = 0; } spec_error: - if (a_error) - { - if (a_command) - { - free (a_command); + if (a_error) { + if (a_command) { + free(a_command); } a_command = NULL; } @@ -397,30 +362,26 @@ spec_error: return a_command; } -int delete_espeak_command( t_espeak_command* the_command) +int delete_espeak_command(t_espeak_command *the_command) { ENTER("delete_espeak_command"); int a_status = 0; - if (the_command) - { - switch(the_command->type) + if (the_command) { + switch (the_command->type) { case ET_TEXT: - if (the_command->u.my_text.text) - { + if (the_command->u.my_text.text) { SHOW("delete_espeak_command > ET_TEXT free text=%x, command=%x, uid=%d\n", the_command->u.my_text.text, the_command, the_command->u.my_text.unique_identifier); free(the_command->u.my_text.text); } break; case ET_MARK: - if (the_command->u.my_mark.text) - { + if (the_command->u.my_mark.text) { free(the_command->u.my_mark.text); } - if (the_command->u.my_mark.index_mark) - { - free((void*)(the_command->u.my_mark.index_mark)); + if (the_command->u.my_mark.index_mark) { + free((void *)(the_command->u.my_mark.index_mark)); } break; @@ -430,20 +391,18 @@ int delete_espeak_command( t_espeak_command* the_command) // it must be processed here for informing the calling program // that its message is finished. // This can be important for cleaning the related user data. - t_espeak_terminated_msg* data = &(the_command->u.my_terminated_msg); - if (the_command->state == CS_PENDING) - { + t_espeak_terminated_msg *data = &(the_command->u.my_terminated_msg); + if (the_command->state == CS_PENDING) { the_command->state = CS_PROCESSED; SHOW("delete_espeak_command > ET_TERMINATED_MSG callback (command=0x%x, uid=%d) \n", the_command, data->unique_identifier); - sync_espeak_terminated_msg( data->unique_identifier, data->user_data); + sync_espeak_terminated_msg(data->unique_identifier, data->user_data); } } break; case ET_KEY: - if (the_command->u.my_key.key_name) - { - free((void*)(the_command->u.my_key.key_name)); + if (the_command->u.my_key.key_name) { + free((void *)(the_command->u.my_key.key_name)); } break; @@ -453,35 +412,30 @@ int delete_espeak_command( t_espeak_command* the_command) break; case ET_PUNCTUATION_LIST: - if (the_command->u.my_punctuation_list) - { - free((void*)(the_command->u.my_punctuation_list)); + if (the_command->u.my_punctuation_list) { + free((void *)(the_command->u.my_punctuation_list)); } break; case ET_VOICE_NAME: - if (the_command->u.my_voice_name) - { - free((void*)(the_command->u.my_voice_name)); + if (the_command->u.my_voice_name) { + free((void *)(the_command->u.my_voice_name)); } break; case ET_VOICE_SPEC: { - espeak_VOICE* data = &(the_command->u.my_voice_spec); + espeak_VOICE *data = &(the_command->u.my_voice_spec); - if (data->name) - { + if (data->name) { free((void *)data->name); } - if (data->languages) - { + if (data->languages) { free((void *)data->languages); } - if (data->identifier) - { + if (data->identifier) { free((void *)data->identifier); } } @@ -497,49 +451,48 @@ int delete_espeak_command( t_espeak_command* the_command) return a_status; } -void process_espeak_command( t_espeak_command* the_command) +void process_espeak_command(t_espeak_command *the_command) { ENTER("process_espeak_command"); SHOW("command=0x%x\n", the_command); - if (the_command == NULL) - { + if (the_command == NULL) { return; } the_command->state = CS_PROCESSED; - switch(the_command->type) + switch (the_command->type) { case ET_TEXT: { - t_espeak_text* data = &(the_command->u.my_text); - sync_espeak_Synth( data->unique_identifier, data->text, data->size, - data->position, data->position_type, - data->end_position, data->flags, data->user_data); + t_espeak_text *data = &(the_command->u.my_text); + sync_espeak_Synth(data->unique_identifier, data->text, data->size, + data->position, data->position_type, + data->end_position, data->flags, data->user_data); } break; case ET_MARK: { - t_espeak_mark* data = &(the_command->u.my_mark); - sync_espeak_Synth_Mark( data->unique_identifier, data->text, data->size, - data->index_mark, data->end_position, data->flags, - data->user_data); + t_espeak_mark *data = &(the_command->u.my_mark); + sync_espeak_Synth_Mark(data->unique_identifier, data->text, data->size, + data->index_mark, data->end_position, data->flags, + data->user_data); } break; case ET_TERMINATED_MSG: { - t_espeak_terminated_msg* data = &(the_command->u.my_terminated_msg); - sync_espeak_terminated_msg( data->unique_identifier, data->user_data); + t_espeak_terminated_msg *data = &(the_command->u.my_terminated_msg); + sync_espeak_terminated_msg(data->unique_identifier, data->user_data); } break; case ET_KEY: { - const char* data = the_command->u.my_key.key_name; + const char *data = the_command->u.my_key.key_name; sync_espeak_Key(data); } break; @@ -547,34 +500,34 @@ void process_espeak_command( t_espeak_command* the_command) case ET_CHAR: { const wchar_t data = the_command->u.my_char.character; - sync_espeak_Char( data); + sync_espeak_Char(data); } break; case ET_PARAMETER: { - t_espeak_parameter* data = &(the_command->u.my_param); - SetParameter( data->parameter, data->value, data->relative); + t_espeak_parameter *data = &(the_command->u.my_param); + SetParameter(data->parameter, data->value, data->relative); } break; case ET_PUNCTUATION_LIST: { - const wchar_t* data = the_command->u.my_punctuation_list; - sync_espeak_SetPunctuationList( data); + const wchar_t *data = the_command->u.my_punctuation_list; + sync_espeak_SetPunctuationList(data); } break; case ET_VOICE_NAME: { - const char* data = the_command->u.my_voice_name; - SetVoiceByName( data); + const char *data = the_command->u.my_voice_name; + SetVoiceByName(data); } break; case ET_VOICE_SPEC: { - espeak_VOICE* data = &(the_command->u.my_voice_spec); + espeak_VOICE *data = &(the_command->u.my_voice_spec); SetVoiceByProperties(data); } break; @@ -585,44 +538,43 @@ void process_espeak_command( t_espeak_command* the_command) } } -void display_espeak_command( t_espeak_command* the_command) +void display_espeak_command(t_espeak_command *the_command) { ENTER("display_espeak_command"); #ifdef DEBUG_ENABLED - if (the_command == NULL) - { - SHOW("display_espeak_command > command=%s\n","NULL"); + if (the_command == NULL) { + SHOW("display_espeak_command > command=%s\n", "NULL"); return; } - SHOW("display_espeak_command > state=%d\n",the_command->state); + SHOW("display_espeak_command > state=%d\n", the_command->state); - switch(the_command->type) + switch (the_command->type) { case ET_TEXT: { - t_espeak_text* data = &(the_command->u.my_text); - SHOW("display_espeak_command > (0x%x) uid=%d, TEXT=%s, user_data=0x%x\n", the_command, data->unique_identifier, (char*)data->text, (int)(data->user_data)); + t_espeak_text *data = &(the_command->u.my_text); + SHOW("display_espeak_command > (0x%x) uid=%d, TEXT=%s, user_data=0x%x\n", the_command, data->unique_identifier, (char *)data->text, (int)(data->user_data)); } break; case ET_MARK: { - t_espeak_mark* data = &(the_command->u.my_mark); - SHOW("display_espeak_command > (0x%x) uid=%d, MARK=%s, user_data=0x%x\n", the_command, data->unique_identifier, (char*)data->text, (int)(data->user_data)); + t_espeak_mark *data = &(the_command->u.my_mark); + SHOW("display_espeak_command > (0x%x) uid=%d, MARK=%s, user_data=0x%x\n", the_command, data->unique_identifier, (char *)data->text, (int)(data->user_data)); } break; case ET_KEY: { - const char* data = the_command->u.my_key.key_name; + const char *data = the_command->u.my_key.key_name; SHOW("display_espeak_command > (0x%x) KEY=%c\n", the_command, data); } break; case ET_TERMINATED_MSG: { - t_espeak_terminated_msg* data = &(the_command->u.my_terminated_msg); + t_espeak_terminated_msg *data = &(the_command->u.my_terminated_msg); SHOW("display_espeak_command > (0x%x) TERMINATED_MSG uid=%d, user_data=0x%x, state=%d\n", the_command, data->unique_identifier, data->user_data, @@ -639,7 +591,7 @@ void display_espeak_command( t_espeak_command* the_command) case ET_PARAMETER: { - t_espeak_parameter* data = &(the_command->u.my_param); + t_espeak_parameter *data = &(the_command->u.my_param); SHOW("display_espeak_command > (0x%x) PARAMETER=%d, value=%d, relative=%d\n", the_command, data->parameter, data->value, data->relative); } @@ -647,15 +599,15 @@ void display_espeak_command( t_espeak_command* the_command) case ET_PUNCTUATION_LIST: { - const wchar_t* data = the_command->u.my_punctuation_list; - sync_espeak_SetPunctuationList( data); - SHOW("display_espeak_command > (0x%x) PUNCTLIST=%s\n", the_command, (char*)data); + const wchar_t *data = the_command->u.my_punctuation_list; + sync_espeak_SetPunctuationList(data); + SHOW("display_espeak_command > (0x%x) PUNCTLIST=%s\n", the_command, (char *)data); } break; case ET_VOICE_NAME: { - const char* data = the_command->u.my_voice_name; + const char *data = the_command->u.my_voice_name; SHOW("display_espeak_command > (0x%x) VOICE_NAME=%s\n", the_command, data); } break; diff --git a/src/libespeak-ng/espeak_command.h b/src/libespeak-ng/espeak_command.h index 0dde422e..b41f852f 100644 --- a/src/libespeak-ng/espeak_command.h +++ b/src/libespeak-ng/espeak_command.h @@ -29,8 +29,7 @@ extern "C" { #endif -typedef enum -{ +typedef enum { ET_TEXT, ET_MARK, ET_KEY, @@ -42,78 +41,69 @@ typedef enum ET_TERMINATED_MSG } t_espeak_type; -typedef struct -{ +typedef struct { unsigned int unique_identifier; - void* text; + void *text; size_t size; unsigned int position; espeak_POSITION_TYPE position_type; unsigned int end_position; unsigned int flags; - void* user_data; + void *user_data; } t_espeak_text; -typedef struct -{ +typedef struct { unsigned int unique_identifier; - void* text; + void *text; size_t size; - const char* index_mark; + const char *index_mark; unsigned int end_position; unsigned int flags; - void* user_data; + void *user_data; } t_espeak_mark; -typedef struct -{ +typedef struct { unsigned int unique_identifier; - void* user_data; + void *user_data; wchar_t character; } t_espeak_character; -typedef struct -{ +typedef struct { unsigned int unique_identifier; - void* user_data; - const char* key_name; + void *user_data; + const char *key_name; } t_espeak_key; -typedef struct -{ +typedef struct { unsigned int unique_identifier; - void* user_data; + void *user_data; } t_espeak_terminated_msg; -typedef struct -{ +typedef struct { espeak_PARAMETER parameter; int value; int relative; } t_espeak_parameter; -typedef enum -{ +typedef enum { CS_UNDEFINED, // The command has just been created CS_PENDING, // stored in the fifo CS_PROCESSED // processed } t_command_state; -typedef struct -{ +typedef struct { t_espeak_type type; t_command_state state; - union command - { + union command { t_espeak_text my_text; t_espeak_mark my_mark; t_espeak_key my_key; t_espeak_character my_char; t_espeak_parameter my_param; - const wchar_t* my_punctuation_list; + const wchar_t *my_punctuation_list; const char *my_voice_name; espeak_VOICE my_voice_spec; t_espeak_terminated_msg my_terminated_msg; @@ -121,37 +111,37 @@ typedef struct } t_espeak_command; -t_espeak_command* create_espeak_text(const void *text, size_t size, unsigned int position, espeak_POSITION_TYPE position_type, unsigned int end_position, unsigned int flags, void* user_data); +t_espeak_command *create_espeak_text(const void *text, size_t size, unsigned int position, espeak_POSITION_TYPE position_type, unsigned int end_position, unsigned int flags, void *user_data); -t_espeak_command* create_espeak_mark(const void *text, size_t size, const char *index_mark, unsigned int end_position, unsigned int flags, void* user_data); +t_espeak_command *create_espeak_mark(const void *text, size_t size, const char *index_mark, unsigned int end_position, unsigned int flags, void *user_data); -t_espeak_command* create_espeak_terminated_msg(unsigned int unique_identifier, void* user_data); +t_espeak_command *create_espeak_terminated_msg(unsigned int unique_identifier, void *user_data); -t_espeak_command* create_espeak_key(const char *key_name, void *user_data); +t_espeak_command *create_espeak_key(const char *key_name, void *user_data); -t_espeak_command* create_espeak_char(wchar_t character, void *user_data); +t_espeak_command *create_espeak_char(wchar_t character, void *user_data); -t_espeak_command* create_espeak_parameter(espeak_PARAMETER parameter, int value, int relative); +t_espeak_command *create_espeak_parameter(espeak_PARAMETER parameter, int value, int relative); -t_espeak_command* create_espeak_punctuation_list(const wchar_t *punctlist); +t_espeak_command *create_espeak_punctuation_list(const wchar_t *punctlist); -t_espeak_command* create_espeak_voice_name(const char *name); +t_espeak_command *create_espeak_voice_name(const char *name); -t_espeak_command* create_espeak_voice_spec(espeak_VOICE *voice_spec); +t_espeak_command *create_espeak_voice_spec(espeak_VOICE *voice_spec); -void process_espeak_command( t_espeak_command* the_command); +void process_espeak_command(t_espeak_command *the_command); -int delete_espeak_command( t_espeak_command* the_command); +int delete_espeak_command(t_espeak_command *the_command); -void display_espeak_command(t_espeak_command* the_command); +void display_espeak_command(t_espeak_command *the_command); espeak_ERROR sync_espeak_Synth(unsigned int unique_identifier, const void *text, size_t size, unsigned int position, espeak_POSITION_TYPE position_type, - unsigned int end_position, unsigned int flags, void* user_data); + unsigned int end_position, unsigned int flags, void *user_data); espeak_ERROR sync_espeak_Synth_Mark(unsigned int unique_identifier, const void *text, size_t size, const char *index_mark, unsigned int end_position, - unsigned int flags, void* user_data); + unsigned int flags, void *user_data); void sync_espeak_Key(const char *key); void sync_espeak_Char(wchar_t character); void sync_espeak_SetPunctuationList(const wchar_t *punctlist); @@ -162,11 +152,11 @@ espeak_ERROR SetVoiceByName(const char *name); espeak_ERROR SetVoiceByProperties(espeak_VOICE *voice_selector); void SetParameter(int parameter, int value, int relative); -int sync_espeak_terminated_msg(unsigned int unique_identifier, void* user_data); +int sync_espeak_terminated_msg(unsigned int unique_identifier, void *user_data); #ifdef __cplusplus } #endif -//> +// > #endif diff --git a/src/libespeak-ng/event.c b/src/libespeak-ng/event.c index 879be7b9..9cfb287b 100644 --- a/src/libespeak-ng/event.c +++ b/src/libespeak-ng/event.c @@ -47,29 +47,28 @@ static sem_t my_sem_stop_is_acknowledged; static pthread_t my_thread; static bool thread_inited; -static t_espeak_callback* my_callback = NULL; -static int my_event_is_running=0; +static t_espeak_callback *my_callback = NULL; +static int my_event_is_running = 0; -enum {MIN_TIMEOUT_IN_MS=10, - ACTIVITY_TIMEOUT=50, // in ms, check that the stream is active - MAX_ACTIVITY_CHECK=6}; +enum { MIN_TIMEOUT_IN_MS = 10, + ACTIVITY_TIMEOUT = 50, // in ms, check that the stream is active + MAX_ACTIVITY_CHECK = 6 }; -typedef struct t_node -{ - void* data; +typedef struct t_node { + void *data; struct t_node *next; } node; -static node* head=NULL; -static node* tail=NULL; -static int node_counter=0; -static espeak_ERROR push(void* data); -static void* pop(); +static node *head = NULL; +static node *tail = NULL; +static int node_counter = 0; +static espeak_ERROR push(void *data); +static void *pop(); static void init(); -static void* polling_thread(void*); +static void *polling_thread(void *); -void event_set_callback(t_espeak_callback* SynthCallback) +void event_set_callback(t_espeak_callback *SynthCallback) { my_callback = SynthCallback; } @@ -78,10 +77,10 @@ void event_init(void) { ENTER("event_init"); - my_event_is_running=0; + my_event_is_running = 0; // security - pthread_mutex_init( &my_mutex, (const pthread_mutexattr_t *)NULL); + pthread_mutex_init(&my_mutex, (const pthread_mutexattr_t *)NULL); init(); assert(-1 != sem_init(&my_sem_start_is_required, 0, 0)); @@ -90,30 +89,26 @@ void event_init(void) pthread_attr_t a_attrib; - if (pthread_attr_init (&a_attrib) == 0 - && pthread_attr_setdetachstate(&a_attrib, PTHREAD_CREATE_JOINABLE) == 0) - { + if (pthread_attr_init(&a_attrib) == 0 + && pthread_attr_setdetachstate(&a_attrib, PTHREAD_CREATE_JOINABLE) == 0) { thread_inited = (0 == pthread_create(&my_thread, &a_attrib, polling_thread, - (void*)NULL)); + (void *)NULL)); } assert(thread_inited); pthread_attr_destroy(&a_attrib); } -static void event_display(espeak_EVENT* event) +static void event_display(espeak_EVENT *event) { ENTER("event_display"); #ifdef DEBUG_ENABLED - if (event==NULL) - { - SHOW("event_display > event=%s\n","NULL"); - } - else - { - static const char* label[] = { + if (event == NULL) { + SHOW("event_display > event=%s\n", "NULL"); + } else { + static const char *label[] = { "LIST_TERMINATED", "WORD", "SENTENCE", @@ -126,38 +121,35 @@ static void event_display(espeak_EVENT* event) "??" }; - SHOW("event_display > event=0x%x\n",event); - SHOW("event_display > type=%s\n",label[event->type]); - SHOW("event_display > uid=%d\n",event->unique_identifier); - SHOW("event_display > text_position=%d\n",event->text_position); - SHOW("event_display > length=%d\n",event->length); - SHOW("event_display > audio_position=%d\n",event->audio_position); - SHOW("event_display > sample=%d\n",event->sample); - SHOW("event_display > user_data=0x%x\n",event->user_data); + SHOW("event_display > event=0x%x\n", event); + SHOW("event_display > type=%s\n", label[event->type]); + SHOW("event_display > uid=%d\n", event->unique_identifier); + SHOW("event_display > text_position=%d\n", event->text_position); + SHOW("event_display > length=%d\n", event->length); + SHOW("event_display > audio_position=%d\n", event->audio_position); + SHOW("event_display > sample=%d\n", event->sample); + SHOW("event_display > user_data=0x%x\n", event->user_data); } #endif } -static espeak_EVENT* event_copy (espeak_EVENT* event) +static espeak_EVENT *event_copy(espeak_EVENT *event) { ENTER("event_copy"); - if (event==NULL) - { + if (event == NULL) { return NULL; } - espeak_EVENT* a_event=(espeak_EVENT*)malloc(sizeof(espeak_EVENT)); - if (a_event) - { + espeak_EVENT *a_event = (espeak_EVENT *)malloc(sizeof(espeak_EVENT)); + if (a_event) { memcpy(a_event, event, sizeof(espeak_EVENT)); - switch(event->type) + switch (event->type) { case espeakEVENT_MARK: case espeakEVENT_PLAY: - if (event->id.name) - { + if (event->id.name) { a_event->id.name = strdup(event->id.name); } break; @@ -181,21 +173,20 @@ static espeak_EVENT* event_copy (espeak_EVENT* event) // * Last call: event->type = espeakEVENT_MSG_TERMINATED // -static void event_notify(espeak_EVENT* event) +static void event_notify(espeak_EVENT *event) { ENTER("event_notify"); static unsigned int a_old_uid = 0; espeak_EVENT events[2]; - memcpy(&events[0],event,sizeof(espeak_EVENT)); // the event parameter in the callback function should be an array of eventd - memcpy(&events[1],event,sizeof(espeak_EVENT)); + memcpy(&events[0], event, sizeof(espeak_EVENT)); // the event parameter in the callback function should be an array of eventd + memcpy(&events[1], event, sizeof(espeak_EVENT)); events[1].type = espeakEVENT_LIST_TERMINATED; // ... terminated by an event type=0 - if (event && my_callback) - { + if (event && my_callback) { event_display(event); - switch(event->type) + switch (event->type) { case espeakEVENT_SENTENCE: my_callback(NULL, 0, events); @@ -208,8 +199,7 @@ static void event_notify(espeak_EVENT* event) case espeakEVENT_END: case espeakEVENT_PHONEME: { - if (a_old_uid != event->unique_identifier) - { + if (a_old_uid != event->unique_identifier) { espeak_EVENT_TYPE a_new_type = events[0].type; events[0].type = espeakEVENT_SENTENCE; my_callback(NULL, 0, events); @@ -229,18 +219,17 @@ static void event_notify(espeak_EVENT* event) } } -static int event_delete(espeak_EVENT* event) +static int event_delete(espeak_EVENT *event) { ENTER("event_delete"); event_display(event); - if(event==NULL) - { + if (event == NULL) { return 0; } - switch(event->type) + switch (event->type) { case espeakEVENT_MSG_TERMINATED: event_notify(event); @@ -248,9 +237,8 @@ static int event_delete(espeak_EVENT* event) case espeakEVENT_MARK: case espeakEVENT_PLAY: - if(event->id.name) - { - free((void*)(event->id.name)); + if (event->id.name) { + free((void *)(event->id.name)); } break; @@ -262,27 +250,24 @@ static int event_delete(espeak_EVENT* event) return 1; } -espeak_ERROR event_declare (espeak_EVENT* event) +espeak_ERROR event_declare(espeak_EVENT *event) { ENTER("event_declare"); event_display(event); - if (!event) - { + if (!event) { return EE_INTERNAL_ERROR; } int a_status = pthread_mutex_lock(&my_mutex); espeak_ERROR a_error = EE_OK; - if (!a_status) - { + if (!a_status) { SHOW_TIME("event_declare > locked\n"); - espeak_EVENT* a_event = event_copy(event); + espeak_EVENT *a_event = event_copy(event); a_error = push(a_event); - if (a_error != EE_OK) - { + if (a_error != EE_OK) { event_delete(a_event); } SHOW_TIME("event_declare > unlocking\n"); @@ -292,15 +277,14 @@ espeak_ERROR event_declare (espeak_EVENT* event) SHOW_TIME("event_declare > post my_sem_start_is_required\n"); sem_post(&my_sem_start_is_required); - if (a_status != 0) - { + if (a_status != 0) { a_error = EE_INTERNAL_ERROR; } return a_error; } -espeak_ERROR event_clear_all () +espeak_ERROR event_clear_all() { ENTER("event_clear_all"); @@ -308,33 +292,26 @@ espeak_ERROR event_clear_all () int a_event_is_running = 0; SHOW_TIME("event_stop > locked\n"); - if (a_status != 0) - { + if (a_status != 0) { return EE_INTERNAL_ERROR; } - if (my_event_is_running) - { + if (my_event_is_running) { SHOW_TIME("event_stop > post my_sem_stop_is_required\n"); sem_post(&my_sem_stop_is_required); a_event_is_running = 1; - } - else - { + } else { init(); // clear pending events } SHOW_TIME("event_stop > unlocking\n"); a_status = pthread_mutex_unlock(&my_mutex); - if (a_status != 0) - { + if (a_status != 0) { return EE_INTERNAL_ERROR; } - if (a_event_is_running) - { + if (a_event_is_running) { SHOW_TIME("event_stop > wait for my_sem_stop_is_acknowledged\n"); - while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR) - { + while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR) { continue; // Restart when interrupted by handler } SHOW_TIME("event_stop > get my_sem_stop_is_acknowledged\n"); @@ -349,12 +326,12 @@ static int sleep_until_timeout_or_stop_request(uint32_t time_in_ms) { ENTER("sleep_until_timeout_or_stop_request"); - int a_stop_is_required=0; + int a_stop_is_required = 0; struct timespec ts; struct timeval tv; - int err=0; + int err = 0; - clock_gettime2( &ts); + clock_gettime2(&ts); #ifdef DEBUG_ENABLED struct timespec to; @@ -362,26 +339,24 @@ static int sleep_until_timeout_or_stop_request(uint32_t time_in_ms) to.tv_nsec = ts.tv_nsec; #endif - add_time_in_ms( &ts, time_in_ms); + add_time_in_ms(&ts, time_in_ms); SHOW("polling_thread > sleep_until_timeout_or_stop_request > start sem_timedwait from %d.%09lu to %d.%09lu \n", to.tv_sec, to.tv_nsec, ts.tv_sec, ts.tv_nsec); while ((err = sem_timedwait(&my_sem_stop_is_required, &ts)) == -1 - && errno == EINTR) - { + && errno == EINTR) { continue; // Restart when interrupted by handler } - assert (gettimeofday(&tv, NULL) != -1); + assert(gettimeofday(&tv, NULL) != -1); SHOW("polling_thread > sleep_until_timeout_or_stop_request > stop sem_timedwait %d.%09lu \n", tv.tv_sec, tv.tv_usec*1000); - if (err == 0) - { - SHOW("polling_thread > sleep_until_timeout_or_stop_request > %s\n","stop required!"); - a_stop_is_required=1; // stop required + if (err == 0) { + SHOW("polling_thread > sleep_until_timeout_or_stop_request > %s\n", "stop required!"); + a_stop_is_required = 1; // stop required } return a_stop_is_required; } @@ -390,22 +365,20 @@ static int sleep_until_timeout_or_stop_request(uint32_t time_in_ms) // If the stream is opened but the audio samples are not played, // a timeout is started. -static int get_remaining_time(uint32_t sample, uint32_t* time_in_ms, int* stop_is_required) +static int get_remaining_time(uint32_t sample, uint32_t *time_in_ms, int *stop_is_required) { ENTER("get_remaining_time"); int err = 0; *stop_is_required = 0; - int i=0; + int i = 0; - for (i=0; i < MAX_ACTIVITY_CHECK && (*stop_is_required == 0); i++) - { - err = wave_get_remaining_time( sample, time_in_ms); + for (i = 0; i < MAX_ACTIVITY_CHECK && (*stop_is_required == 0); i++) { + err = wave_get_remaining_time(sample, time_in_ms); - if (err || wave_is_busy(NULL) || (*time_in_ms == 0)) - { // if err, stream not available: quit - // if wave is busy, time_in_ms is known: quit - // if wave is not busy but remaining time == 0, event is reached: quit + if (err || wave_is_busy(NULL) || (*time_in_ms == 0)) { // if err, stream not available: quit + // if wave is busy, time_in_ms is known: quit + // if wave is not busy but remaining time == 0, event is reached: quit break; } @@ -422,19 +395,18 @@ static int get_remaining_time(uint32_t sample, uint32_t* time_in_ms, int* stop_i // // wait for the close of stream - *stop_is_required = sleep_until_timeout_or_stop_request( ACTIVITY_TIMEOUT); + *stop_is_required = sleep_until_timeout_or_stop_request(ACTIVITY_TIMEOUT); } return err; } -static void* polling_thread(void*p) +static void *polling_thread(void *p) { ENTER("polling_thread"); - while(1) - { - int a_stop_is_required=0; + while (1) { + int a_stop_is_required = 0; SHOW_TIME("polling_thread > locking\n"); int a_status = pthread_mutex_lock(&my_mutex); @@ -445,8 +417,7 @@ static void* polling_thread(void*p) SHOW_TIME("polling_thread > wait for my_sem_start_is_required\n"); - while ((sem_wait(&my_sem_start_is_required) == -1) && errno == EINTR) - { + while ((sem_wait(&my_sem_start_is_required) == -1) && errno == EINTR) { continue; // Restart when interrupted by handler } @@ -458,29 +429,25 @@ static void* polling_thread(void*p) pthread_mutex_unlock(&my_mutex); SHOW_TIME("polling_thread > unlocked\n"); - a_stop_is_required=0; + a_stop_is_required = 0; a_status = sem_getvalue(&my_sem_stop_is_required, &a_stop_is_required); // NOTE: may set a_stop_is_required to -1 - if ((a_status==0) && (a_stop_is_required > 0)) - { + if ((a_status == 0) && (a_stop_is_required > 0)) { SHOW("polling_thread > stop required (%d)\n", __LINE__); - while(0 == sem_trywait(&my_sem_stop_is_required)) - { - }; - } - else - { - a_stop_is_required=0; + while (0 == sem_trywait(&my_sem_stop_is_required)) { + } + ; + } else { + a_stop_is_required = 0; } // In this loop, my_event_is_running = 1 - while (head && (a_stop_is_required <= 0)) - { + while (head && (a_stop_is_required <= 0)) { SHOW_TIME("polling_thread > check head\n"); - while(0 == sem_trywait(&my_sem_start_is_required)) - { - }; + while (0 == sem_trywait(&my_sem_start_is_required)) { + } + ; - espeak_EVENT* event = (espeak_EVENT*)(head->data); + espeak_EVENT *event = (espeak_EVENT *)(head->data); assert(event); uint32_t time_in_ms = 0; @@ -488,54 +455,43 @@ static void* polling_thread(void*p) int err = get_remaining_time((uint32_t)event->sample, &time_in_ms, &a_stop_is_required); - if (a_stop_is_required > 0) - { + if (a_stop_is_required > 0) { break; - } - else if (err != 0) - { + } else if (err != 0) { // No available time: the event is deleted. - SHOW("polling_thread > %s\n","audio device down"); + SHOW("polling_thread > %s\n", "audio device down"); a_status = pthread_mutex_lock(&my_mutex); SHOW_TIME("polling_thread > locked\n"); - event_delete( (espeak_EVENT*)pop()); + event_delete((espeak_EVENT *)pop()); a_status = pthread_mutex_unlock(&my_mutex); SHOW_TIME("polling_thread > unlocked\n"); - } - else if (time_in_ms==0) - { // the event is already reached. - if (my_callback) - { + } else if (time_in_ms == 0) { // the event is already reached. + if (my_callback) { event_notify(event); // the user_data (and the type) are cleaned to be sure // that MSG_TERMINATED is called twice (at delete time too). - event->type=espeakEVENT_LIST_TERMINATED; - event->user_data=NULL; + event->type = espeakEVENT_LIST_TERMINATED; + event->user_data = NULL; } a_status = pthread_mutex_lock(&my_mutex); SHOW_TIME("polling_thread > locked\n"); - event_delete( (espeak_EVENT*)pop()); + event_delete((espeak_EVENT *)pop()); a_status = pthread_mutex_unlock(&my_mutex); SHOW_TIME("polling_thread > unlocked\n"); - a_stop_is_required=0; + a_stop_is_required = 0; a_status = sem_getvalue(&my_sem_stop_is_required, &a_stop_is_required); - if ((a_status==0) && (a_stop_is_required > 0)) - { + if ((a_status == 0) && (a_stop_is_required > 0)) { SHOW("polling_thread > stop required (%d)\n", __LINE__); - while(0 == sem_trywait(&my_sem_stop_is_required)) - { - }; + while (0 == sem_trywait(&my_sem_stop_is_required)) { + } + ; + } else { + a_stop_is_required = 0; } - else - { - a_stop_is_required=0; - } - } - else - { // The event will be notified soon: sleep until timeout or stop request + } else { // The event will be notified soon: sleep until timeout or stop request a_stop_is_required = sleep_until_timeout_or_stop_request(time_in_ms); } } @@ -546,28 +502,23 @@ static void* polling_thread(void*p) SHOW_TIME("polling_thread > my_event_is_running = 0\n"); my_event_is_running = 0; - if(a_stop_is_required <= 0) - { + if (a_stop_is_required <= 0) { a_status = sem_getvalue(&my_sem_stop_is_required, &a_stop_is_required); - if ((a_status==0) && (a_stop_is_required > 0)) - { + if ((a_status == 0) && (a_stop_is_required > 0)) { SHOW("polling_thread > stop required (%d)\n", __LINE__); - while(0 == sem_trywait(&my_sem_stop_is_required)) - { - }; - } - else - { - a_stop_is_required=0; + while (0 == sem_trywait(&my_sem_stop_is_required)) { + } + ; + } else { + a_stop_is_required = 0; } } a_status = pthread_mutex_unlock(&my_mutex); SHOW_TIME("polling_thread > unlocked\n"); - if (a_stop_is_required > 0) - { - SHOW("polling_thread > %s\n","stop required!"); + if (a_stop_is_required > 0) { + SHOW("polling_thread > %s\n", "stop required!"); // no mutex required since the stop command is synchronous // and waiting for my_sem_stop_is_acknowledged init(); @@ -581,39 +532,33 @@ static void* polling_thread(void*p) return NULL; } -enum {MAX_NODE_COUNTER=1000}; +enum { MAX_NODE_COUNTER = 1000 }; -static espeak_ERROR push(void* the_data) +static espeak_ERROR push(void *the_data) { ENTER("event > push"); assert((!head && !tail) || (head && tail)); - if (the_data == NULL) - { + if (the_data == NULL) { SHOW("event > push > event=0x%x\n", NULL); return EE_INTERNAL_ERROR; } - if (node_counter >= MAX_NODE_COUNTER) - { + if (node_counter >= MAX_NODE_COUNTER) { SHOW("event > push > %s\n", "EE_BUFFER_FULL"); return EE_BUFFER_FULL; } node *n = (node *)malloc(sizeof(node)); - if (n == NULL) - { + if (n == NULL) { return EE_INTERNAL_ERROR; } - if (head == NULL) - { + if (head == NULL) { head = n; tail = n; - } - else - { + } else { tail->next = n; tail = n; } @@ -622,30 +567,28 @@ static espeak_ERROR push(void* the_data) tail->data = the_data; node_counter++; - SHOW("event > push > counter=%d (uid=%d)\n",node_counter,((espeak_EVENT*)the_data)->unique_identifier); + SHOW("event > push > counter=%d (uid=%d)\n", node_counter, ((espeak_EVENT *)the_data)->unique_identifier); return EE_OK; } -static void* pop() +static void *pop() { ENTER("event > pop"); - void* the_data = NULL; + void *the_data = NULL; assert((!head && !tail) || (head && tail)); - if (head != NULL) - { - node* n = head; + if (head != NULL) { + node *n = head; the_data = n->data; head = n->next; free(n); node_counter--; - SHOW("event > pop > event=0x%x (counter=%d, uid=%d)\n",the_data, node_counter,((espeak_EVENT*)the_data)->unique_identifier); + SHOW("event > pop > event=0x%x (counter=%d, uid=%d)\n", the_data, node_counter, ((espeak_EVENT *)the_data)->unique_identifier); } - if(head == NULL) - { + if (head == NULL) { tail = NULL; } @@ -657,8 +600,8 @@ static void init() { ENTER("event > init"); - while (event_delete( (espeak_EVENT*)pop() )) - {} + while (event_delete((espeak_EVENT *)pop())) { + } node_counter = 0; } @@ -667,10 +610,9 @@ void event_terminate() { ENTER("event_terminate"); - if (thread_inited) - { + if (thread_inited) { pthread_cancel(my_thread); - pthread_join(my_thread,NULL); + pthread_join(my_thread, NULL); pthread_mutex_destroy(&my_mutex); sem_destroy(&my_sem_start_is_required); sem_destroy(&my_sem_stop_is_required); diff --git a/src/libespeak-ng/event.h b/src/libespeak-ng/event.h index c871024e..29854f4d 100644 --- a/src/libespeak-ng/event.h +++ b/src/libespeak-ng/event.h @@ -51,13 +51,13 @@ extern "C" // the callback will be called when the event actually occurs. // The callback is detailled in speak_lib.h . void event_init(void); -void event_set_callback(t_espeak_callback* cb); +void event_set_callback(t_espeak_callback *cb); // Clear any pending event. // // Return: EE_OK: operation achieved // EE_INTERNAL_ERROR. -espeak_ERROR event_clear_all (); +espeak_ERROR event_clear_all(); // Declare a future event // @@ -65,7 +65,7 @@ espeak_ERROR event_clear_all (); // EE_BUFFER_FULL: the event can not be buffered; // you may try after a while to call the function again. // EE_INTERNAL_ERROR. -espeak_ERROR event_declare (espeak_EVENT* event); +espeak_ERROR event_declare(espeak_EVENT *event); // Terminate the event component. // Last function to be called. diff --git a/src/libespeak-ng/fifo.c b/src/libespeak-ng/fifo.c index 93302d55..7d03d018 100644 --- a/src/libespeak-ng/fifo.c +++ b/src/libespeak-ng/fifo.c @@ -52,35 +52,34 @@ static pthread_t my_thread; static sem_t my_sem_start_is_required; static sem_t my_sem_stop_is_acknowledged; -static void* say_thread(void*); +static void *say_thread(void *); -static espeak_ERROR push(t_espeak_command* the_command); -static t_espeak_command* pop(); +static espeak_ERROR push(t_espeak_command *the_command); +static t_espeak_command *pop(); static void init(int process_parameters); -static int node_counter=0; -enum {MAX_NODE_COUNTER=400, - INACTIVITY_TIMEOUT=50, // in ms, check that the stream is inactive - MAX_INACTIVITY_CHECK=2}; +static int node_counter = 0; +enum { MAX_NODE_COUNTER = 400, + INACTIVITY_TIMEOUT = 50, // in ms, check that the stream is inactive + MAX_INACTIVITY_CHECK = 2 }; void fifo_init() { ENTER("fifo_init"); // security - pthread_mutex_init( &my_mutex, (const pthread_mutexattr_t *)NULL); + pthread_mutex_init(&my_mutex, (const pthread_mutexattr_t *)NULL); init(0); assert(-1 != sem_init(&my_sem_start_is_required, 0, 0)); assert(-1 != sem_init(&my_sem_stop_is_acknowledged, 0, 0)); pthread_attr_t a_attrib; - if (pthread_attr_init (&a_attrib) + if (pthread_attr_init(&a_attrib) || pthread_attr_setdetachstate(&a_attrib, PTHREAD_CREATE_JOINABLE) - || pthread_create( &my_thread, - &a_attrib, - say_thread, - (void*)NULL)) - { + || pthread_create(&my_thread, + &a_attrib, + say_thread, + (void *)NULL)) { assert(0); } @@ -88,44 +87,39 @@ void fifo_init() // leave once the thread is actually started SHOW_TIME("fifo > wait for my_sem_stop_is_acknowledged\n"); - while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR) - { + while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR) { continue; // Restart when interrupted by handler } SHOW_TIME("fifo > get my_sem_stop_is_acknowledged\n"); } -espeak_ERROR fifo_add_command (t_espeak_command* the_command) +espeak_ERROR fifo_add_command(t_espeak_command *the_command) { ENTER("fifo_add_command"); int a_status = pthread_mutex_lock(&my_mutex); espeak_ERROR a_error = EE_OK; - if (!a_status) - { + if (!a_status) { SHOW_TIME("fifo_add_command > locked\n"); a_error = push(the_command); SHOW_TIME("fifo_add_command > unlocking\n"); a_status = pthread_mutex_unlock(&my_mutex); } - if (!a_status && !my_command_is_running && (a_error == EE_OK)) - { + if (!a_status && !my_command_is_running && (a_error == EE_OK)) { // quit when command is actually started // (for possible forthcoming 'end of command' checks) SHOW_TIME("fifo_add_command > post my_sem_start_is_required\n"); sem_post(&my_sem_start_is_required); - int val=1; - while (val > 0) - { + int val = 1; + while (val > 0) { usleep(50000); // TBD: event? sem_getvalue(&my_sem_start_is_required, &val); } } - if (a_status != 0) - { + if (a_status != 0) { a_error = EE_INTERNAL_ERROR; } @@ -133,24 +127,20 @@ espeak_ERROR fifo_add_command (t_espeak_command* the_command) return a_error; } -espeak_ERROR fifo_add_commands (t_espeak_command* command1, t_espeak_command* command2) +espeak_ERROR fifo_add_commands(t_espeak_command *command1, t_espeak_command *command2) { ENTER("fifo_add_command"); int a_status = pthread_mutex_lock(&my_mutex); espeak_ERROR a_error = EE_OK; - if (!a_status) - { + if (!a_status) { SHOW_TIME("fifo_add_commands > locked\n"); - if (node_counter+1 >= MAX_NODE_COUNTER) - { + if (node_counter+1 >= MAX_NODE_COUNTER) { SHOW("push > %s\n", "EE_BUFFER_FULL"); a_error = EE_BUFFER_FULL; - } - else - { + } else { push(command1); push(command2); } @@ -158,22 +148,19 @@ espeak_ERROR fifo_add_commands (t_espeak_command* command1, t_espeak_command* co a_status = pthread_mutex_unlock(&my_mutex); } - if (!a_status && !my_command_is_running && (a_error == EE_OK)) - { + if (!a_status && !my_command_is_running && (a_error == EE_OK)) { // quit when one command is actually started // (for possible forthcoming 'end of command' checks) SHOW_TIME("fifo_add_command > post my_sem_start_is_required\n"); sem_post(&my_sem_start_is_required); - int val=1; - while (val > 0) - { + int val = 1; + while (val > 0) { usleep(50000); // TBD: event? sem_getvalue(&my_sem_start_is_required, &val); } } - if (a_status != 0) - { + if (a_status != 0) { a_error = EE_INTERNAL_ERROR; } @@ -181,36 +168,31 @@ espeak_ERROR fifo_add_commands (t_espeak_command* command1, t_espeak_command* co return a_error; } -espeak_ERROR fifo_stop () +espeak_ERROR fifo_stop() { ENTER("fifo_stop"); int a_command_is_running = 0; int a_status = pthread_mutex_lock(&my_mutex); SHOW_TIME("fifo_stop > locked\n"); - if (a_status != 0) - { + if (a_status != 0) { return EE_INTERNAL_ERROR; } - if (my_command_is_running) - { + if (my_command_is_running) { a_command_is_running = 1; my_stop_is_required = 1; SHOW_TIME("fifo_stop > my_stop_is_required = 1\n"); } SHOW_TIME("fifo_stop > unlocking\n"); a_status = pthread_mutex_unlock(&my_mutex); - if (a_status != 0) - { + if (a_status != 0) { return EE_INTERNAL_ERROR; } - if (a_command_is_running) - { + if (a_command_is_running) { SHOW_TIME("fifo_stop > wait for my_sem_stop_is_acknowledged\n"); - while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR) - { + while ((sem_wait(&my_sem_stop_is_acknowledged) == -1) && errno == EINTR) { continue; // Restart when interrupted by handler } SHOW_TIME("fifo_stop > get my_sem_stop_is_acknowledged\n"); @@ -223,16 +205,16 @@ espeak_ERROR fifo_stop () return EE_OK; } -int fifo_is_busy () +int fifo_is_busy() { - SHOW("fifo_is_busy > aResult = %d\n",my_command_is_running); + SHOW("fifo_is_busy > aResult = %d\n", my_command_is_running); return my_command_is_running; } static int sleep_until_start_request_or_inactivity() { SHOW_TIME("fifo > sleep_until_start_request_or_inactivity > ENTER"); - int a_start_is_required=0; + int a_start_is_required = 0; // Wait for the start request (my_sem_start_is_required). // Besides this, if the audio stream is still busy, @@ -240,23 +222,19 @@ static int sleep_until_start_request_or_inactivity() // The end of the stream is confirmed by several checks // for filtering underflow. // - int i=0; - while((i<= MAX_INACTIVITY_CHECK) && !a_start_is_required) - { - if (wave_is_busy( NULL) ) - { + int i = 0; + while ((i <= MAX_INACTIVITY_CHECK) && !a_start_is_required) { + if (wave_is_busy(NULL)) { i = 0; - } - else - { + } else { i++; } - int err=0; + int err = 0; struct timespec ts; struct timeval tv; - clock_gettime2( &ts); + clock_gettime2(&ts); #ifdef DEBUG_ENABLED struct timespec to; @@ -264,24 +242,22 @@ static int sleep_until_start_request_or_inactivity() to.tv_nsec = ts.tv_nsec; #endif - add_time_in_ms( &ts, INACTIVITY_TIMEOUT); + add_time_in_ms(&ts, INACTIVITY_TIMEOUT); SHOW("fifo > sleep_until_start_request_or_inactivity > start sem_timedwait (start_is_required) from %d.%09lu to %d.%09lu \n", to.tv_sec, to.tv_nsec, ts.tv_sec, ts.tv_nsec); while ((err = sem_timedwait(&my_sem_start_is_required, &ts)) == -1 - && errno == EINTR) - { + && errno == EINTR) { continue; } - assert (gettimeofday(&tv, NULL) != -1); + assert(gettimeofday(&tv, NULL) != -1); SHOW("fifo > sleep_until_start_request_or_inactivity > stop sem_timedwait (start_is_required, err=%d) %d.%09lu \n", err, tv.tv_sec, tv.tv_usec*1000); - if (err==0) - { + if (err == 0) { a_start_is_required = 1; } } @@ -298,38 +274,35 @@ static void close_stream() // my_stop_is_required = 1; int a_status = pthread_mutex_lock(&my_mutex); - assert (!a_status); + assert(!a_status); int a_stop_is_required = my_stop_is_required; - if (!a_stop_is_required) - { + if (!a_stop_is_required) { my_command_is_running = 1; } a_status = pthread_mutex_unlock(&my_mutex); - if (!a_stop_is_required) - { + if (!a_stop_is_required) { wave_close(NULL); int a_status = pthread_mutex_lock(&my_mutex); - assert (!a_status); + assert(!a_status); my_command_is_running = 0; a_stop_is_required = my_stop_is_required; a_status = pthread_mutex_unlock(&my_mutex); - if (a_stop_is_required) - { + if (a_stop_is_required) { // acknowledge the stop request SHOW_TIME("fifo > close_stream > post my_sem_stop_is_acknowledged\n"); int a_status = sem_post(&my_sem_stop_is_acknowledged); - assert( a_status != -1); + assert(a_status != -1); } } SHOW_TIME("fifo > close_stream > LEAVE\n"); } -static void* say_thread(void*p) +static void *say_thread(void *p) { ENTER("say_thread"); @@ -338,27 +311,22 @@ static void* say_thread(void*p) // announce that thread is started sem_post(&my_sem_stop_is_acknowledged); - int look_for_inactivity=0; + int look_for_inactivity = 0; - while(1) - { + while (1) { SHOW_TIME("say_thread > wait for my_sem_start_is_required\n"); int a_start_is_required = 0; - if (look_for_inactivity) - { + if (look_for_inactivity) { a_start_is_required = sleep_until_start_request_or_inactivity(); - if (!a_start_is_required) - { + if (!a_start_is_required) { close_stream(); } } look_for_inactivity = 1; - if (!a_start_is_required) - { - while ((sem_wait(&my_sem_start_is_required) == -1) && errno == EINTR) - { + if (!a_start_is_required) { + while ((sem_wait(&my_sem_start_is_required) == -1) && errno == EINTR) { continue; // Restart when interrupted by handler } } @@ -367,62 +335,55 @@ static void* say_thread(void*p) SHOW_TIME("say_thread > my_command_is_running = 1\n"); my_command_is_running = 1; - while( my_command_is_running) - { + while (my_command_is_running) { SHOW_TIME("say_thread > locking\n"); int a_status = pthread_mutex_lock(&my_mutex); - assert (!a_status); - t_espeak_command* a_command = (t_espeak_command*)pop(); + assert(!a_status); + t_espeak_command *a_command = (t_espeak_command *)pop(); - if (a_command == NULL) - { + if (a_command == NULL) { SHOW_TIME("say_thread > text empty (talking=0) \n"); a_status = pthread_mutex_unlock(&my_mutex); SHOW_TIME("say_thread > unlocked\n"); SHOW_TIME("say_thread > my_command_is_running = 0\n"); my_command_is_running = 0; - } - else - { + } else { display_espeak_command(a_command); // purge start semaphore SHOW_TIME("say_thread > purge my_sem_start_is_required\n"); - while(0 == sem_trywait(&my_sem_start_is_required)) - { - }; + while (0 == sem_trywait(&my_sem_start_is_required)) { + } + ; - if (my_stop_is_required) - { + if (my_stop_is_required) { SHOW_TIME("say_thread > my_command_is_running = 0\n"); my_command_is_running = 0; } SHOW_TIME("say_thread > unlocking\n"); a_status = pthread_mutex_unlock(&my_mutex); - if (my_command_is_running) - { + if (my_command_is_running) { process_espeak_command(a_command); } delete_espeak_command(a_command); } } - if (my_stop_is_required) - { + if (my_stop_is_required) { // no mutex required since the stop command is synchronous // and waiting for my_sem_stop_is_acknowledged init(1); // purge start semaphore SHOW_TIME("say_thread > purge my_sem_start_is_required\n"); - while(0==sem_trywait(&my_sem_start_is_required)) - { - }; + while (0 == sem_trywait(&my_sem_start_is_required)) { + } + ; // acknowledge the stop request SHOW_TIME("say_thread > post my_sem_stop_is_acknowledged\n"); int a_status = sem_post(&my_sem_stop_is_acknowledged); - assert( a_status != -1); + assert(a_status != -1); } // and wait for the next start SHOW_TIME("say_thread > wait for my_sem_start_is_required\n"); @@ -433,50 +394,43 @@ static void* say_thread(void*p) int fifo_is_command_enabled() { - SHOW("ENTER fifo_is_command_enabled=%d\n",(int)(0 == my_stop_is_required)); + SHOW("ENTER fifo_is_command_enabled=%d\n", (int)(0 == my_stop_is_required)); return (0 == my_stop_is_required); } -typedef struct t_node -{ - t_espeak_command* data; +typedef struct t_node { + t_espeak_command *data; struct t_node *next; } node; -static node* head=NULL; -static node* tail=NULL; +static node *head = NULL; +static node *tail = NULL; -static espeak_ERROR push(t_espeak_command* the_command) +static espeak_ERROR push(t_espeak_command *the_command) { ENTER("fifo > push"); assert((!head && !tail) || (head && tail)); - if (the_command == NULL) - { + if (the_command == NULL) { SHOW("push > command=0x%x\n", NULL); return EE_INTERNAL_ERROR; } - if (node_counter >= MAX_NODE_COUNTER) - { + if (node_counter >= MAX_NODE_COUNTER) { SHOW("push > %s\n", "EE_BUFFER_FULL"); return EE_BUFFER_FULL; } node *n = (node *)malloc(sizeof(node)); - if (n == NULL) - { + if (n == NULL) { return EE_INTERNAL_ERROR; } - if (head == NULL) - { + if (head == NULL) { head = n; tail = n; - } - else - { + } else { tail->next = n; tail = n; } @@ -485,7 +439,7 @@ static espeak_ERROR push(t_espeak_command* the_command) tail->data = the_command; node_counter++; - SHOW("push > counter=%d\n",node_counter); + SHOW("push > counter=%d\n", node_counter); the_command->state = CS_PENDING; display_espeak_command(the_command); @@ -493,25 +447,23 @@ static espeak_ERROR push(t_espeak_command* the_command) return EE_OK; } -static t_espeak_command* pop() +static t_espeak_command *pop() { ENTER("fifo > pop"); - t_espeak_command* the_command = NULL; + t_espeak_command *the_command = NULL; assert((!head && !tail) || (head && tail)); - if (head != NULL) - { - node* n = head; + if (head != NULL) { + node *n = head; the_command = n->data; head = n->next; free(n); node_counter--; - SHOW("pop > command=0x%x (counter=%d)\n",the_command, node_counter); + SHOW("pop > command=0x%x (counter=%d)\n", the_command, node_counter); } - if(head == NULL) - { + if (head == NULL) { tail = NULL; } @@ -526,8 +478,7 @@ static void init(int process_parameters) ENTER("fifo > init"); c = pop(); while (c != NULL) { - if (process_parameters && (c->type == ET_PARAMETER || c->type == ET_VOICE_NAME || c->type == ET_VOICE_SPEC)) - { + if (process_parameters && (c->type == ET_PARAMETER || c->type == ET_VOICE_NAME || c->type == ET_VOICE_SPEC)) { process_espeak_command(c); } delete_espeak_command(c); @@ -541,7 +492,7 @@ void fifo_terminate() ENTER("fifo_terminate"); pthread_cancel(my_thread); - pthread_join(my_thread,NULL); + pthread_join(my_thread, NULL); pthread_mutex_destroy(&my_mutex); sem_destroy(&my_sem_start_is_required); sem_destroy(&my_sem_stop_is_acknowledged); diff --git a/src/libespeak-ng/fifo.h b/src/libespeak-ng/fifo.h index da06a5f4..dd86dc59 100644 --- a/src/libespeak-ng/fifo.h +++ b/src/libespeak-ng/fifo.h @@ -43,7 +43,7 @@ void fifo_init(); // EE_BUFFER_FULL: the command can not be buffered; // you may try after a while to call the function again. // EE_INTERNAL_ERROR. -espeak_ERROR fifo_add_command (t_espeak_command* c); +espeak_ERROR fifo_add_command(t_espeak_command *c); // Add two espeak commands in a single transaction. // @@ -54,16 +54,16 @@ espeak_ERROR fifo_add_command (t_espeak_command* c); // EE_BUFFER_FULL: at least one command can not be buffered; // you may try after a while to call the function again. // EE_INTERNAL_ERROR. -espeak_ERROR fifo_add_commands (t_espeak_command* c1, t_espeak_command* c2); +espeak_ERROR fifo_add_commands(t_espeak_command *c1, t_espeak_command *c2); // The current running command must be stopped and the awaiting commands are cleared. // Return: EE_OK: operation achieved // EE_INTERNAL_ERROR. -espeak_ERROR fifo_stop (); +espeak_ERROR fifo_stop(); // Is there a running command? // Returns 1 if yes; 0 otherwise. -int fifo_is_busy (); +int fifo_is_busy(); // Terminate the fifo component. // Last function to be called. diff --git a/src/libespeak-ng/intonation.c b/src/libespeak-ng/intonation.c index 8966e98c..a89d4694 100644 --- a/src/libespeak-ng/intonation.c +++ b/src/libespeak-ng/intonation.c @@ -47,7 +47,7 @@ typedef struct { char stress; char env; - char flags; //bit 0=pitch rising, bit1=emnphasized, bit2=end of clause + char flags; // bit 0=pitch rising, bit1=emnphasized, bit2=end of clause char nextph_type; unsigned char pitch1; unsigned char pitch2; @@ -224,15 +224,15 @@ unsigned char *envelope_data[N_ENVELOPE_DATA] = { /* indexed by stress */ -static int min_drop[] = {6,7,9,9,20,20,20,25}; +static int min_drop[] = { 6, 7, 9, 9, 20, 20, 20, 25 }; // pitch change during the main part of the clause -static int drops_0[8] = {9,9,16,16,16,23,55,32}; +static int drops_0[8] = { 9, 9, 16, 16, 16, 23, 55, 32 }; // overflow table values are 64ths of the body pitch range (between body_start and body_end) -static signed char oflow[] = {0, 40, 24, 8, 0}; -static signed char oflow_emf[] = {10, 52, 32, 20, 10}; -static signed char oflow_less[] = {6, 38, 24, 14, 4}; +static signed char oflow[] = { 0, 40, 24, 8, 0 }; +static signed char oflow_emf[] = { 10, 52, 32, 20, 10 }; +static signed char oflow_less[] = { 6, 38, 24, 14, 4 }; #define N_TONE_HEAD_TABLE 13 @@ -274,50 +274,50 @@ typedef struct { #define T_EMPH 1 static TONE_HEAD tone_head_table[N_TONE_HEAD_TABLE] = { - {46, 57, 78, 50, drops_0, 3, 7, 5, oflow}, // 0 statement - {46, 57, 78, 46, drops_0, 3, 7, 5, oflow}, // 1 comma - {46, 57, 78, 46, drops_0, 3, 7, 5, oflow}, // 2 question - {46, 57, 90, 50, drops_0, 3, 9, 5, oflow_emf}, // 3 exclamation - {46, 57, 78, 50, drops_0, 3, 7, 5, oflow}, // 4 statement, emphatic - {46, 57, 74, 55, drops_0, 4, 7, 5, oflow_less},// 5 statement, less intonation - {46, 57, 74, 55, drops_0, 4, 7, 5, oflow_less},// 6 comma, less intonation - {46, 57, 74, 55, drops_0, 4, 7, 5, oflow_less},// 7 comma, less intonation, less rise - {46, 57, 78, 50, drops_0, 3, 7, 5, oflow}, // 8 pitch raises at end of sentence - {46, 57, 78, 46, drops_0, 3, 7, 5, oflow}, // 9 comma - {46, 57, 78, 50, drops_0, 3, 7, 5, oflow}, // 10 question - {34, 41, 41, 32, drops_0, 3, 7, 5, oflow_less}, // 11 test - {46, 57, 55, 50, drops_0, 3, 7, 5, oflow_less}, // 12 test + { 46, 57, 78, 50, drops_0, 3, 7, 5, oflow }, // 0 statement + { 46, 57, 78, 46, drops_0, 3, 7, 5, oflow }, // 1 comma + { 46, 57, 78, 46, drops_0, 3, 7, 5, oflow }, // 2 question + { 46, 57, 90, 50, drops_0, 3, 9, 5, oflow_emf }, // 3 exclamation + { 46, 57, 78, 50, drops_0, 3, 7, 5, oflow }, // 4 statement, emphatic + { 46, 57, 74, 55, drops_0, 4, 7, 5, oflow_less },// 5 statement, less intonation + { 46, 57, 74, 55, drops_0, 4, 7, 5, oflow_less },// 6 comma, less intonation + { 46, 57, 74, 55, drops_0, 4, 7, 5, oflow_less },// 7 comma, less intonation, less rise + { 46, 57, 78, 50, drops_0, 3, 7, 5, oflow }, // 8 pitch raises at end of sentence + { 46, 57, 78, 46, drops_0, 3, 7, 5, oflow }, // 9 comma + { 46, 57, 78, 50, drops_0, 3, 7, 5, oflow }, // 10 question + { 34, 41, 41, 32, drops_0, 3, 7, 5, oflow_less }, // 11 test + { 46, 57, 55, 50, drops_0, 3, 7, 5, oflow_less }, // 12 test }; static TONE_NUCLEUS tone_nucleus_table[N_TONE_NUCLEUS_TABLE] = { - {PITCHfall, 64, 8, PITCHfall, 70,18, NULL, 24, 12, 0}, // 0 statement - {PITCHfrise, 80,18, PITCHfrise2, 78,22, NULL, 34, 52, 0}, // 1 comma - {PITCHfrise, 88,22, PITCHfrise2, 82,22, NULL, 34, 64, 0}, // 2 question - {PITCHfall, 92, 8, PITCHfall, 92,80, NULL, 76, 8, T_EMPH}, // 3 exclamation + { PITCHfall, 64, 8, PITCHfall, 70, 18, NULL, 24, 12, 0 }, // 0 statement + { PITCHfrise, 80, 18, PITCHfrise2, 78, 22, NULL, 34, 52, 0 }, // 1 comma + { PITCHfrise, 88, 22, PITCHfrise2, 82, 22, NULL, 34, 64, 0 }, // 2 question + { PITCHfall, 92, 8, PITCHfall, 92, 80, NULL, 76, 8, T_EMPH }, // 3 exclamation - {PITCHfall, 86, 4, PITCHfall, 94,66, NULL, 34, 10, 0}, // 4 statement, emphatic - {PITCHfall, 62,10, PITCHfall, 62,20, NULL, 28, 16, 0}, // 5 statement, less intonation - {PITCHfrise, 68,18, PITCHfrise2, 68,22, NULL, 30, 44, 0}, // 6 comma, less intonation - {PITCHfrise2, 64,16, PITCHfall, 66,32, NULL, 32, 18, 0}, // 7 comma, less intonation, less rise - {PITCHrise, 68,46, PITCHfall, 42,32, NULL, 46, 58, 0}, // 8 pitch raises at end of sentence - {PITCHfrise, 78,24, PITCHfrise2, 72,22, NULL, 42, 52, 0}, // 9 comma - {PITCHfrise, 88,34, PITCHfall, 64,32, NULL, 46, 82, 0}, // 10 question - {PITCHfall, 56,12, PITCHfall, 56,20, NULL, 24, 12, 0}, // 11 test - {PITCHfall, 70,18, PITCHfall, 70,24, NULL, 32, 20, 0}, // 12 test + { PITCHfall, 86, 4, PITCHfall, 94, 66, NULL, 34, 10, 0 }, // 4 statement, emphatic + { PITCHfall, 62, 10, PITCHfall, 62, 20, NULL, 28, 16, 0 }, // 5 statement, less intonation + { PITCHfrise, 68, 18, PITCHfrise2, 68, 22, NULL, 30, 44, 0 }, // 6 comma, less intonation + { PITCHfrise2, 64, 16, PITCHfall, 66, 32, NULL, 32, 18, 0 }, // 7 comma, less intonation, less rise + { PITCHrise, 68, 46, PITCHfall, 42, 32, NULL, 46, 58, 0 }, // 8 pitch raises at end of sentence + { PITCHfrise, 78, 24, PITCHfrise2, 72, 22, NULL, 42, 52, 0 }, // 9 comma + { PITCHfrise, 88, 34, PITCHfall, 64, 32, NULL, 46, 82, 0 }, // 10 question + { PITCHfall, 56, 12, PITCHfall, 56, 20, NULL, 24, 12, 0 }, // 11 test + { PITCHfall, 70, 18, PITCHfall, 70, 24, NULL, 32, 20, 0 }, // 12 test }; /* index by 0=. 1=, 2=?, 3=! 4=none, 5=emphasized */ unsigned char punctuation_to_tone[INTONATION_TYPES][PUNCT_INTONATIONS] = { - {0,1,2,3,0,4}, - {0,1,2,3,0,4}, - {5,6,2,3,0,4}, - {5,7,1,3,0,4}, - {8,9,10,3,0,0}, - {8,8,10,3,0,0}, - {11,11,11,11,0,0}, // 6 test - {12,12,12,12,0,0} + { 0, 1, 2, 3, 0, 4 }, + { 0, 1, 2, 3, 0, 4 }, + { 5, 6, 2, 3, 0, 4 }, + { 5, 7, 1, 3, 0, 4 }, + { 8, 9, 10, 3, 0, 0 }, + { 8, 8, 10, 3, 0, 0 }, + { 11, 11, 11, 11, 0, 0 }, // 6 test + { 12, 12, 12, 12, 0, 0 } }; @@ -353,26 +353,20 @@ static void count_pitch_vowels(int start, int end, int clause_end) number_tail = 0; /* number between tonic syllable and next primary */ last_primary = -1; - for(ix=start; ix= max_stress) - { - if(stress > max_stress) - { + if (stress >= max_stress) { + if (stress > max_stress) { max_stress_posn2 = ix; - } - else - { + } else { max_stress_posn2 = max_stress_posn; } max_stress_posn = ix; max_stress = stress; } - if(stress >= PRIMARY) - { - if(number_pre < 0) + if (stress >= PRIMARY) { + if (number_pre < 0) number_pre = ix - start; last_primary = ix; @@ -380,27 +374,20 @@ static void count_pitch_vowels(int start, int end, int clause_end) } - if(number_pre < 0) + if (number_pre < 0) number_pre = end; number_tail = end - max_stress_posn - 1; tone_posn = max_stress_posn; tone_posn2 = max_stress_posn2; - if(no_tonic) - { + if (no_tonic) { tone_posn = tone_posn2 = end; // next position after the end of the truncated clause - } - else - if(last_primary >= 0) - { - if(end == clause_end) - { + } else if (last_primary >= 0) { + if (end == clause_end) { syllable_tab[last_primary].stress = PRIMARY_LAST; } - } - else - { + } else { // no primary stress. Use the highest stress syllable_tab[tone_posn].stress = PRIMARY_LAST; } @@ -415,16 +402,15 @@ static int count_increments(int ix, int end_ix, int min_stress) int count = 0; int stress; - while(ix < end_ix) - { + while (ix < end_ix) { stress = syllable_tab[ix++].stress; - if(stress >= PRIMARY_LAST) + if (stress >= PRIMARY_LAST) break; - if(stress >= min_stress) + if (stress >= min_stress) count++; } - return(count); + return (count); } @@ -436,22 +422,21 @@ static void set_pitch(SYLLABLE *syl, int base, int drop) int pitch1, pitch2; int flags = 0; - if(base < 0) base = 0; + if (base < 0) base = 0; pitch2 = base; - if(drop < 0) - { + if (drop < 0) { flags = SYL_RISE; drop = -drop; } pitch1 = pitch2 + drop; - if(pitch1 < 0) + if (pitch1 < 0) pitch1 = 0; - if(pitch1 > 254) pitch1 = 254; - if(pitch2 > 254) pitch2 = 254; + if (pitch1 > 254) pitch1 = 254; + if (pitch2 > 254) pitch2 = 254; syl->pitch1 = pitch1; syl->pitch2 = pitch2; @@ -463,12 +448,11 @@ static int CountUnstressed(int start, int end, int limit) { int ix; - for(ix=start; ix <= end; ix++) - { - if(syllable_tab[ix].stress >= limit) + for (ix = start; ix <= end; ix++) { + if (syllable_tab[ix].stress >= limit) break; } - return(ix - start); + return (ix - start); } static int SetHeadIntonation(TUNE *tune, int syl_ix, int end_ix, int control) @@ -476,21 +460,21 @@ static int SetHeadIntonation(TUNE *tune, int syl_ix, int end_ix, int control) int stress; SYLLABLE *syl; int ix; - int pitch=0; - int increment=0; - int n_steps=0; + int pitch = 0; + int increment = 0; + int n_steps = 0; int stage; // onset, head, last int initial; - int overflow_ix=0; + int overflow_ix = 0; int pitch_range; int pitch_range_abs; int *drops; - int n_unstressed=0; - int unstressed_ix=0; + int n_unstressed = 0; + int unstressed_ix = 0; int unstressed_inc; int used_onset = 0; int head_final = end_ix; - int secondary=2; // 2 + int secondary = 2; // 2 pitch_range = (tune->head_end - tune->head_start) << 8; pitch_range_abs = abs(pitch_range); @@ -498,84 +482,63 @@ static int SetHeadIntonation(TUNE *tune, int syl_ix, int end_ix, int control) initial = 1; stage = 0; - if(tune->onset == 255) + if (tune->onset == 255) stage = 1; // no onset specified - if(tune->head_last != 255) - { + if (tune->head_last != 255) { // find the last primary stress in the body - for(ix = end_ix-1; ix >= syl_ix; ix--) - { - if(syllable_tab[ix].stress >= 4) - { + for (ix = end_ix-1; ix >= syl_ix; ix--) { + if (syllable_tab[ix].stress >= 4) { head_final = ix; break; } } } - while(syl_ix < end_ix) - { + while (syl_ix < end_ix) { syl = &syllable_tab[syl_ix]; stress = syl->stress; - if(initial || (stress >= 4)) - { + if (initial || (stress >= 4)) { // a primary stress - if((initial) || (stress == 5)) - { + if ((initial) || (stress == 5)) { initial = 0; overflow_ix = 0; - if(tune->onset == 255) - { + if (tune->onset == 255) { n_steps = count_increments(syl_ix, head_final, 4); pitch = tune->head_start << 8; - } - else - { + } else { // a pitch has been specified for the onset syllable, don't include it in the pitch incrementing n_steps = count_increments(syl_ix+1, head_final, 4); pitch = tune->onset << 8; used_onset = 1; } - if(n_steps > tune->head_max_steps) + if (n_steps > tune->head_max_steps) n_steps = tune->head_max_steps; - if(n_steps > 1) - { + if (n_steps > 1) { increment = pitch_range / (n_steps -1); - } - else + } else increment = 0; - } - else - if(syl_ix == head_final) - { + } else if (syl_ix == head_final) { // a pitch has been specified for the last primary stress before the nucleus pitch = tune->head_last << 8; stage = 2; - } - else - { - if(used_onset) - { + } else { + if (used_onset) { stage = 1; used_onset = 0; pitch = tune->head_start << 8; n_steps++; - } - else - if(n_steps > 0) + } else if (n_steps > 0) pitch += increment; - else - { + else { pitch = (tune->head_end << 8) + (pitch_range_abs * tune->head_extend[overflow_ix++])/64; - if(overflow_ix >= tune->n_head_extend) - { + if (overflow_ix >= tune->n_head_extend) { overflow_ix = 0; } } @@ -584,24 +547,18 @@ static int SetHeadIntonation(TUNE *tune, int syl_ix, int end_ix, int control) n_steps--; } - if(stress >= PRIMARY) - { + if (stress >= PRIMARY) { n_unstressed = CountUnstressed(syl_ix+1, end_ix, secondary); unstressed_ix = 0; syl->stress = PRIMARY_STRESSED; syl->env = tune->stressed_env; - set_pitch(syl,(pitch >> 8), tune->stressed_drop); - } - else - if(stress >= secondary) - { + set_pitch(syl, (pitch >> 8), tune->stressed_drop); + } else if (stress >= secondary) { n_unstressed = CountUnstressed(syl_ix+1, end_ix, secondary); unstressed_ix = 0; - set_pitch(syl,(pitch >> 8),drops[stress]); - } - else - { - if(n_unstressed > 1) + set_pitch(syl, (pitch >> 8), drops[stress]); + } else { + if (n_unstressed > 1) unstressed_inc = (tune->unstr_end[stage] - tune->unstr_start[stage]) / (n_unstressed - 1); else unstressed_inc = 0; @@ -612,7 +569,7 @@ static int SetHeadIntonation(TUNE *tune, int syl_ix, int end_ix, int control) syl_ix++; } - return(syl_ix); + return (syl_ix); } @@ -624,12 +581,12 @@ static int SetHeadIntonation(TUNE *tune, int syl_ix, int end_ix, int control) static int calc_pitch_segment(int ix, int end_ix, TONE_HEAD *th, TONE_NUCLEUS *tn, int min_stress, int continuing) { int stress; - int pitch=0; - int increment=0; - int n_primary=0; - int n_steps=0; + int pitch = 0; + int increment = 0; + int n_primary = 0; + int n_steps = 0; int initial; - int overflow=0; + int overflow = 0; int n_overflow; int pitch_range; int pitch_range_abs; @@ -637,63 +594,51 @@ static int calc_pitch_segment(int ix, int end_ix, TONE_HEAD *th, TONE_NUCLEUS *t signed char *overflow_tab; SYLLABLE *syl; - static signed char continue_tab[5] = {-26, 32, 20, 8, 0}; + static signed char continue_tab[5] = { -26, 32, 20, 8, 0 }; drops = th->body_drops; pitch_range = (th->body_end - th->body_start) << 8; pitch_range_abs = abs(pitch_range); - if(continuing) - { - initial =0; + if (continuing) { + initial = 0; overflow = 0; n_overflow = 5; overflow_tab = continue_tab; increment = pitch_range / (th->body_max_steps -1); - } - else - { + } else { n_overflow = th->n_overflow; overflow_tab = th->overflow; initial = 1; } - while(ix < end_ix) - { + while (ix < end_ix) { syl = &syllable_tab[ix]; stress = syl->stress; - if(initial || (stress >= min_stress)) - { + if (initial || (stress >= min_stress)) { // a primary stress - if((initial) || (stress == 5)) - { + if ((initial) || (stress == 5)) { initial = 0; overflow = 0; - n_steps = n_primary = count_increments(ix,end_ix,min_stress); + n_steps = n_primary = count_increments(ix, end_ix, min_stress); - if(n_steps > th->body_max_steps) + if (n_steps > th->body_max_steps) n_steps = th->body_max_steps; - if(n_steps > 1) - { + if (n_steps > 1) { increment = pitch_range / (n_steps -1); - } - else + } else increment = 0; pitch = th->body_start << 8; - } - else - { - if(n_steps > 0) + } else { + if (n_steps > 0) pitch += increment; - else - { + else { pitch = (th->body_end << 8) + (pitch_range_abs * overflow_tab[overflow++])/64; - if(overflow >= n_overflow) - { + if (overflow >= n_overflow) { overflow = 0; overflow_tab = th->overflow; } @@ -703,34 +648,27 @@ static int calc_pitch_segment(int ix, int end_ix, TONE_HEAD *th, TONE_NUCLEUS *t n_steps--; n_primary--; - if((tn->backwards) && (n_primary < 2)) - { + if ((tn->backwards) && (n_primary < 2)) { pitch = tn->backwards[n_primary] << 8; } } - if(stress >= PRIMARY) - { + if (stress >= PRIMARY) { syl->stress = PRIMARY_STRESSED; - set_pitch(syl,(pitch >> 8),drops[stress]); - } - else - if(stress >= SECONDARY) - { - set_pitch(syl,(pitch >> 8),drops[stress]); - } - else - { + set_pitch(syl, (pitch >> 8), drops[stress]); + } else if (stress >= SECONDARY) { + set_pitch(syl, (pitch >> 8), drops[stress]); + } else { /* unstressed, drop pitch if preceded by PRIMARY */ - if((syllable_tab[ix-1].stress & 0x3f) >= SECONDARY) - set_pitch(syl,(pitch >> 8) - th->body_lower_u, drops[stress]); + if ((syllable_tab[ix-1].stress & 0x3f) >= SECONDARY) + set_pitch(syl, (pitch >> 8) - th->body_lower_u, drops[stress]); else - set_pitch(syl,(pitch >> 8),drops[stress]); + set_pitch(syl, (pitch >> 8), drops[stress]); } ix++; } - return(ix); + return (ix); } @@ -751,35 +689,30 @@ static void SetPitchGradient(int start_ix, int end_ix, int start_pitch, int end_ increment = (end_pitch - start_pitch) << 8; n_increments = end_ix - start_ix; - if(n_increments <= 0) + if (n_increments <= 0) return; - if(n_increments > 1) - { + if (n_increments > 1) { increment = increment / n_increments; } pitch = start_pitch << 8; - for(ix=start_ix; ix < end_ix; ix++) - { + for (ix = start_ix; ix < end_ix; ix++) { syl = &syllable_tab[ix]; stress = syl->stress; - if(increment > 0) - { - set_pitch(syl,(pitch >> 8),-(increment >> 8)); + if (increment > 0) { + set_pitch(syl, (pitch >> 8), -(increment >> 8)); pitch += increment; - } - else - { + } else { drop = -(increment >> 8); - if(drop < min_drop[stress]) + if (drop < min_drop[stress]) drop = min_drop[stress]; pitch += increment; - if(drop > 18) + if (drop > 18) drop = 18; set_pitch(syl, (pitch >> 8), drop); } @@ -807,33 +740,29 @@ static int calc_pitches2(int start, int end, int tune_number) /* body of tonic segment */ /*************************/ - if(option_tone_flags & OPTION_EMPHASIZE_PENULTIMATE) - { + if (option_tone_flags & OPTION_EMPHASIZE_PENULTIMATE) { tone_posn = tone_posn2; // put tone on the penultimate stressed word } ix = SetHeadIntonation(tune, ix, tone_posn, 0); - if(no_tonic) - return(0); + if (no_tonic) + return (0); /* tonic syllable */ /******************/ - if(number_tail == 0) - { + if (number_tail == 0) { tone_pitch_env = tune->nucleus0_env; drop = tune->nucleus0_max - tune->nucleus0_min; - set_pitch(&syllable_tab[ix++],tune->nucleus0_min, drop); - } - else - { + set_pitch(&syllable_tab[ix++], tune->nucleus0_min, drop); + } else { tone_pitch_env = tune->nucleus1_env; drop = tune->nucleus1_max - tune->nucleus1_min; - set_pitch(&syllable_tab[ix++],tune->nucleus1_min, drop); + set_pitch(&syllable_tab[ix++], tune->nucleus1_min, drop); } syllable_tab[tone_posn].env = tone_pitch_env; - if(syllable_tab[tone_posn].stress == PRIMARY) + if (syllable_tab[tone_posn].stress == PRIMARY) syllable_tab[tone_posn].stress = PRIMARY_STRESSED; /* tail, after the tonic syllable */ @@ -841,7 +770,7 @@ static int calc_pitches2(int start, int end, int tune_number) SetPitchGradient(ix, end, tune->tail_start, tune->tail_end); - return(tone_pitch_env); + return (tone_pitch_env); } @@ -855,12 +784,11 @@ static int calc_pitches(int control, int start, int end, int tune_number) int drop; int continuing = 0; - if(control == 0) - { - return(calc_pitches2(start, end, tune_number)); + if (control == 0) { + return (calc_pitches2(start, end, tune_number)); } - if(start > 0) + if (start > 0) continuing = 1; th = &tone_head_table[tune_number]; @@ -876,38 +804,33 @@ static int calc_pitches(int control, int start, int end, int tune_number) /* body of tonic segment */ /*************************/ - if(option_tone_flags & OPTION_EMPHASIZE_PENULTIMATE) - { + if (option_tone_flags & OPTION_EMPHASIZE_PENULTIMATE) { tone_posn = tone_posn2; // put tone on the penultimate stressed word } - ix = calc_pitch_segment(ix,tone_posn, th, tn, PRIMARY, continuing); + ix = calc_pitch_segment(ix, tone_posn, th, tn, PRIMARY, continuing); - if(no_tonic) - return(0); + if (no_tonic) + return (0); /* tonic syllable */ /******************/ - if(tn->flags & T_EMPH) - { + if (tn->flags & T_EMPH) { syllable_tab[ix].flags |= SYL_EMPHASIS; } - if(number_tail == 0) - { + if (number_tail == 0) { tone_pitch_env = tn->pitch_env0; drop = tn->tonic_max0 - tn->tonic_min0; - set_pitch(&syllable_tab[ix++],tn->tonic_min0, drop); - } - else - { + set_pitch(&syllable_tab[ix++], tn->tonic_min0, drop); + } else { tone_pitch_env = tn->pitch_env1; drop = tn->tonic_max1 - tn->tonic_min1; - set_pitch(&syllable_tab[ix++],tn->tonic_min1, drop); + set_pitch(&syllable_tab[ix++], tn->tonic_min1, drop); } syllable_tab[tone_posn].env = tone_pitch_env; - if(syllable_tab[tone_posn].stress == PRIMARY) + if (syllable_tab[tone_posn].stress == PRIMARY) syllable_tab[tone_posn].stress = PRIMARY_STRESSED; /* tail, after the tonic syllable */ @@ -915,7 +838,7 @@ static int calc_pitches(int control, int start, int end, int tune_number) SetPitchGradient(ix, end, tn->tail_start, tn->tail_end); - return(tone_pitch_env); + return (tone_pitch_env); } @@ -928,8 +851,8 @@ static void CalcPitches_Tone(Translator *tr, int clause_tone) // clause_tone: 0=. 1=, 2=?, 3=! 4=none PHONEME_LIST *p; int ix; - int count_stressed=0; - int final_stressed=0; + int count_stressed = 0; + int final_stressed = 0; int tone_ph; int pause; @@ -946,15 +869,12 @@ static void CalcPitches_Tone(Translator *tr, int clause_tone) // count number of stressed syllables p = &phoneme_list[0]; - for(ix=0; ixtype == phVOWEL) && (p->stresslevel >= 4)) - { - if(count_stressed == 0) + for (ix = 0; ix < n_phoneme_list; ix++, p++) { + if ((p->type == phVOWEL) && (p->stresslevel >= 4)) { + if (count_stressed == 0) final_stressed = ix; - if(p->stresslevel >= 4) - { + if (p->stresslevel >= 4) { final_stressed = ix; count_stressed++; } @@ -964,11 +884,10 @@ static void CalcPitches_Tone(Translator *tr, int clause_tone) phoneme_list[final_stressed].stresslevel = 7; // language specific, changes to tones - if(tr->translator_name == L('v','i')) - { + if (tr->translator_name == L('v', 'i')) { // LANG=vi p = &phoneme_list[final_stressed]; - if(p->tone_ph == 0) + if (p->tone_ph == 0) p->tone_ph = PhonemeCode('7'); // change default tone (tone 1) to falling tone at end of clause } @@ -980,78 +899,62 @@ static void CalcPitches_Tone(Translator *tr, int clause_tone) prev_tph = prevw_tph = phoneme_tab[phonPAUSE]; // perform tone sandhi - for(ix=0; ixtype == phPAUSE) && (p->ph->std_length > 50)) - { + for (ix = 0; ix < n_phoneme_list; ix++, p++) { + if ((p->type == phPAUSE) && (p->ph->std_length > 50)) { pause = 1; // there is a pause since the previous vowel prevw_tph = phoneme_tab[phonPAUSE]; // forget previous tone } - if(p->newword) - { + if (p->newword) { prev_tph = phoneme_tab[phonPAUSE]; // forget across word boundaries } - if(p->synthflags & SFLAG_SYLLABLE) - { + if (p->synthflags & SFLAG_SYLLABLE) { tone_ph = p->tone_ph; tph = phoneme_tab[tone_ph]; // Mandarin - if(tr->translator_name == L('z','h')) - { - if(tone_ph == 0) - { - if(pause || tone_promoted) - { - tone_ph = PhonemeCode2('5','5'); // no previous vowel, use tone 1 + if (tr->translator_name == L('z', 'h')) { + if (tone_ph == 0) { + if (pause || tone_promoted) { + tone_ph = PhonemeCode2('5', '5'); // no previous vowel, use tone 1 tone_promoted = 1; - } - else - { - tone_ph = PhonemeCode2('1','1'); // default tone 5 + } else { + tone_ph = PhonemeCode2('1', '1'); // default tone 5 } p->tone_ph = tone_ph; tph = phoneme_tab[tone_ph]; - } - else - { + } else { tone_promoted = 0; } - if(ix == final_stressed) - { - if((tph->mnemonic == 0x3535 ) || (tph->mnemonic == 0x3135)) - { + if (ix == final_stressed) { + if ((tph->mnemonic == 0x3535 ) || (tph->mnemonic == 0x3135)) { // change sentence final tone 1 or 4 to stress 6, not 7 phoneme_list[final_stressed].stresslevel = 6; } } - if(prevw_tph->mnemonic == 0x343132) // [214] - { - if(tph->mnemonic == 0x343132) // [214] - prev_p->tone_ph = PhonemeCode2('3','5'); + if (prevw_tph->mnemonic == 0x343132) { // [214] + if (tph->mnemonic == 0x343132) // [214] + prev_p->tone_ph = PhonemeCode2('3', '5'); else - prev_p->tone_ph = PhonemeCode2('2','1'); + prev_p->tone_ph = PhonemeCode2('2', '1'); } - if((prev_tph->mnemonic == 0x3135) && (tph->mnemonic == 0x3135)) // [51] + [51] - { - prev_p->tone_ph = PhonemeCode2('5','3'); + if ((prev_tph->mnemonic == 0x3135) && (tph->mnemonic == 0x3135)) { // [51] + [51] + prev_p->tone_ph = PhonemeCode2('5', '3'); } - if(tph->mnemonic == 0x3131) // [11] Tone 5 - { + if (tph->mnemonic == 0x3131) { // [11] Tone 5 // tone 5, change its level depending on the previous tone (across word boundaries) - if(prevw_tph->mnemonic == 0x3535) - p->tone_ph = PhonemeCode2('2','2'); - if(prevw_tph->mnemonic == 0x3533) - p->tone_ph = PhonemeCode2('3','3'); - if(prevw_tph->mnemonic == 0x343132) - p->tone_ph = PhonemeCode2('4','4'); + if (prevw_tph->mnemonic == 0x3535) + p->tone_ph = PhonemeCode2('2', '2'); + if (prevw_tph->mnemonic == 0x3533) + p->tone_ph = PhonemeCode2('3', '3'); + if (prevw_tph->mnemonic == 0x343132) + p->tone_ph = PhonemeCode2('4', '4'); // tone 5 is unstressed (shorter) p->stresslevel = 0; // diminished stress @@ -1066,29 +969,22 @@ static void CalcPitches_Tone(Translator *tr, int clause_tone) // convert tone numbers to pitch p = &phoneme_list[0]; - for(ix=0; ixsynthflags & SFLAG_SYLLABLE) - { + for (ix = 0; ix < n_phoneme_list; ix++, p++) { + if (p->synthflags & SFLAG_SYLLABLE) { tone_ph = p->tone_ph; - if(p->stresslevel != 0) // TEST, consider all syllables as stressed - { - if(ix == final_stressed) - { + if (p->stresslevel != 0) { // TEST, consider all syllables as stressed + if (ix == final_stressed) { // the last stressed syllable pitch_adjust = pitch_low; - } - else - { + } else { pitch_adjust -= pitch_decrement; - if(pitch_adjust <= pitch_low) + if (pitch_adjust <= pitch_low) pitch_adjust = pitch_high; } } - if(tone_ph ==0) - { + if (tone_ph == 0) { tone_ph = phonDEFAULTTONE; // no tone specified, use default tone 1 p->tone_ph = tone_ph; } @@ -1114,103 +1010,88 @@ void CalcPitches(Translator *tr, int clause_type) int option; int group_tone; int group_tone_comma; - int ph_start=0; + int ph_start = 0; int st_start; int st_clause_end; int count; int n_primary; int count_primary; PHONEME_TAB *ph; - int ph_end=n_phoneme_list; + int ph_end = n_phoneme_list; SYLLABLE syllable_tab2[N_PHONEME_LIST]; syllable_tab = syllable_tab2; // don't use permanent storage. it's only needed during the call of CalcPitches() n_st = 0; n_primary = 0; - for(ix=0; ix<(n_phoneme_list-1); ix++) - { + for (ix = 0; ix < (n_phoneme_list-1); ix++) { p = &phoneme_list[ix]; - if(p->synthflags & SFLAG_SYLLABLE) - { + if (p->synthflags & SFLAG_SYLLABLE) { syllable_tab[n_st].flags = 0; syllable_tab[n_st].env = PITCHfall; syllable_tab[n_st].nextph_type = phoneme_list[ix+1].type; syllable_tab[n_st++].stress = p->stresslevel; - if(p->stresslevel >= 4) + if (p->stresslevel >= 4) n_primary++; - } - else - if((p->ph->code == phonPAUSE_CLAUSE) && (n_st > 0)) - { + } else if ((p->ph->code == phonPAUSE_CLAUSE) && (n_st > 0)) { syllable_tab[n_st-1].flags |= SYL_END_CLAUSE; } } syllable_tab[n_st].stress = 0; // extra 0 entry at the end - if(n_st == 0) + if (n_st == 0) return; // nothing to do - if(tr->langopts.tone_language == 1) - { - CalcPitches_Tone(tr,clause_type); + if (tr->langopts.tone_language == 1) { + CalcPitches_Tone(tr, clause_type); return; } option = tr->langopts.intonation_group; - if(option >= INTONATION_TYPES) + if (option >= INTONATION_TYPES) option = 1; - if(option == 0) - { + if (option == 0) { group_tone = tr->langopts.tunes[clause_type]; group_tone_comma = tr->langopts.tunes[1]; - } - else - { + } else { group_tone = tr->punct_to_tone[option][clause_type]; group_tone_comma = tr->punct_to_tone[option][1]; // emphatic form of statement } - if(clause_type == 4) + if (clause_type == 4) no_tonic = 1; /* incomplete clause, used for abbreviations such as Mr. Dr. Mrs. */ else no_tonic = 0; st_start = 0; - count_primary=0; - for(st_ix=0; st_ixstress >= 4) + if (syl->stress >= 4) count_primary++; - if(syl->stress == 6) - { + if (syl->stress == 6) { // reduce the stress of the previous stressed syllable (review only the previous few syllables) - for(ix=st_ix-1; ix>=st_start && ix>=(st_ix-3); ix--) - { - if(syllable_tab[ix].stress == 6) + for (ix = st_ix-1; ix >= st_start && ix >= (st_ix-3); ix--) { + if (syllable_tab[ix].stress == 6) break; - if(syllable_tab[ix].stress == 4) - { + if (syllable_tab[ix].stress == 4) { syllable_tab[ix].stress = 3; break; } } // are the next primary syllables also emphasized ? - for(ix=st_ix+1; ixstress = 5; @@ -1219,44 +1100,38 @@ void CalcPitches(Translator *tr, int clause_type) } } - if(syl->stress == 6) - { + if (syl->stress == 6) { // an emphasized syllable, end the tone group after the next primary stress syllable_tab[st_ix].flags = SYL_EMPHASIS; count = 0; - if((n_primary - count_primary) > 1) - count =1; + if ((n_primary - count_primary) > 1) + count = 1; - for(ix=st_ix+1; ix 4) + for (ix = st_ix+1; ix < n_st; ix++) { + if (syllable_tab[ix].stress > 4) break; - if(syllable_tab[ix].stress == 4) - { + if (syllable_tab[ix].stress == 4) { count++; - if(count > 1) + if (count > 1) break; } } count_pitch_vowels(st_start, ix, n_st); - if((ix < n_st) || (clause_type == 0)) - { + if ((ix < n_st) || (clause_type == 0)) { calc_pitches(option, st_start, ix, group_tone); // split into > 1 tone groups - if((clause_type==1) || (clause_type==2)) + if ((clause_type == 1) || (clause_type == 2)) group_tone = tr->langopts.tunes[1]; // , or ? remainder has comma-tone else group_tone = tr->langopts.tunes[0]; // . or ! remainder has statement tone - } - else + } else calc_pitches(option, st_start, ix, group_tone); st_start = ix; } - if((st_start < st_ix) && (syl->flags & SYL_END_CLAUSE)) - { + if ((st_start < st_ix) && (syl->flags & SYL_END_CLAUSE)) { // end of clause after this syllable, indicated by a phonPAUSE_CLAUSE phoneme st_clause_end = st_ix+1; count_pitch_vowels(st_start, st_clause_end, st_clause_end); @@ -1265,54 +1140,45 @@ void CalcPitches(Translator *tr, int clause_type) } } - if(st_start < st_ix) - { + if (st_start < st_ix) { count_pitch_vowels(st_start, st_ix, n_st); calc_pitches(option, st_start, st_ix, group_tone); } // unpack pitch data - st_ix=0; - for(ix=ph_start; ix < ph_end; ix++) - { + st_ix = 0; + for (ix = ph_start; ix < ph_end; ix++) { p = &phoneme_list[ix]; p->stresslevel = syllable_tab[st_ix].stress; - if(p->synthflags & SFLAG_SYLLABLE) - { + if (p->synthflags & SFLAG_SYLLABLE) { syl = &syllable_tab[st_ix]; p->pitch1 = syl->pitch1; p->pitch2 = syl->pitch2; p->env = PITCHfall; - if(syl->flags & SYL_RISE) - { + if (syl->flags & SYL_RISE) { p->env = PITCHrise; - } - else - if(p->stresslevel > 5) + } else if (p->stresslevel > 5) p->env = syl->env; - if(p->pitch1 > p->pitch2) - { + if (p->pitch1 > p->pitch2) { // swap so that pitch2 is the higher x = p->pitch1; p->pitch1 = p->pitch2; p->pitch2 = x; } - if(p->tone_ph) - { + if (p->tone_ph) { ph = phoneme_tab[p->tone_ph]; x = (p->pitch1 + p->pitch2)/2; p->pitch2 = x + ph->end_type; p->pitch1 = x + ph->start_type; } - if(syl->flags & SYL_EMPHASIS) - { + if (syl->flags & SYL_EMPHASIS) { p->stresslevel |= 8; // emphasized } diff --git a/src/libespeak-ng/klatt.c b/src/libespeak-ng/klatt.c index 9afa06ba..923e40bb 100644 --- a/src/libespeak-ng/klatt.c +++ b/src/libespeak-ng/klatt.c @@ -49,34 +49,34 @@ static int sample_count; #ifdef _MSC_VER -#define getrandom(min,max) ((rand()%(int)(((max)+1)-(min)))+(min)) +#define getrandom(min, max) ((rand()%(int)(((max)+1)-(min)))+(min)) #else -#define getrandom(min,max) ((rand()%(long)(((max)+1)-(min)))+(min)) +#define getrandom(min, max) ((rand()%(long)(((max)+1)-(min)))+(min)) #endif /* function prototypes for functions private to this file */ static void flutter(klatt_frame_ptr); -static double sampled_source (int); -static double impulsive_source (void); -static double natural_source (void); -static void pitch_synch_par_reset (klatt_frame_ptr); -static double gen_noise (double); -static double DBtoLIN (long); -static void frame_init (klatt_frame_ptr); -static void setabc (long,long,resonator_ptr); -static void setzeroabc (long,long,resonator_ptr); +static double sampled_source(int); +static double impulsive_source(void); +static double natural_source(void); +static void pitch_synch_par_reset(klatt_frame_ptr); +static double gen_noise(double); +static double DBtoLIN(long); +static void frame_init(klatt_frame_ptr); +static void setabc(long, long, resonator_ptr); +static void setzeroabc(long, long, resonator_ptr); static klatt_frame_t kt_frame; static klatt_global_t kt_globals; #define NUMBER_OF_SAMPLES 100 -static int scale_wav_tab[] = {45,38,45,45,55}; // scale output from different voicing sources +static int scale_wav_tab[] = { 45, 38, 45, 45, 55 }; // scale output from different voicing sources // For testing, this can be overwritten in KlattInit() -static short natural_samples2[256]= { +static short natural_samples2[256] = { 2583, 2516, 2450, 2384, 2319, 2254, 2191, 2127, 2067, 2005, 1946, 1890, 1832, 1779, 1726, 1675, 1626, 1579, 1533, 1491, 1449, 1409, 1372, 1336, @@ -110,15 +110,14 @@ static short natural_samples2[256]= { -1680, -1732, -1783, -1839, -1894, -1952, -2010, -2072, -2133, -2196, -2260, -2325, -2390, -2456, -2522, -2589, }; -static short natural_samples[100]= -{ - -310,-400,530,356,224,89,23,-10,-58,-16,461,599,536,701,770, - 605,497,461,560,404,110,224,131,104,-97,155,278,-154,-1165, - -598,737,125,-592,41,11,-247,-10,65,92,80,-304,71,167,-1,122, - 233,161,-43,278,479,485,407,266,650,134,80,236,68,260,269,179, - 53,140,275,293,296,104,257,152,311,182,263,245,125,314,140,44, - 203,230,-235,-286,23,107,92,-91,38,464,443,176,98,-784,-2449, - -1891,-1045,-1600,-1462,-1384,-1261,-949,-730 +static short natural_samples[100] = { + -310, -400, 530, 356, 224, 89, 23, -10, -58, -16, 461, 599, 536, 701, 770, + 605, 497, 461, 560, 404, 110, 224, 131, 104, -97, 155, 278, -154, -1165, + -598, 737, 125, -592, 41, 11, -247, -10, 65, 92, 80, -304, 71, 167, -1, 122, + 233, 161, -43, 278, 479, 485, 407, 266, 650, 134, 80, 236, 68, 260, 269, 179, + 53, 140, 275, 293, 296, 104, 257, 152, 311, 182, 263, 245, 125, 314, 140, 44, + 203, 230, -235, -286, 23, 107, 92, -91, 38, 464, 443, 176, 98, -784, -2449, + -1891, -1045, -1600, -1462, -1384, -1261, -949, -730 }; /* @@ -132,7 +131,7 @@ static double resonator(resonator_ptr r, double input) { double x; - x = (double) ((double)r->a * (double)input + (double)r->b * (double)r->p1 + (double)r->c * (double)r->p2); + x = (double)((double)r->a * (double)input + (double)r->b * (double)r->p1 + (double)r->c * (double)r->p2); r->p2 = (double)r->p1; r->p1 = (double)x; @@ -143,7 +142,7 @@ static double resonator2(resonator_ptr r, double input) { double x; - x = (double) ((double)r->a * (double)input + (double)r->b * (double)r->p1 + (double)r->c * (double)r->p2); + x = (double)((double)r->a * (double)input + (double)r->b * (double)r->p1 + (double)r->c * (double)r->p2); r->p2 = (double)r->p1; r->p1 = (double)x; @@ -185,15 +184,15 @@ static void flutter(klatt_frame_ptr frame) { static int time_count; double delta_f0; - double fla,flb,flc,fld,fle; + double fla, flb, flc, fld, fle; - fla = (double) kt_globals.f0_flutter / 50; - flb = (double) kt_globals.original_f0 / 100; + fla = (double)kt_globals.f0_flutter / 50; + flb = (double)kt_globals.original_f0 / 100; flc = sin(PI*12.7*time_count); // because we are calling flutter() more frequently, every 2.9mS fld = sin(PI*7.1*time_count); fle = sin(PI*4.7*time_count); delta_f0 = fla * flb * (flc + fld + fle) * 10; - frame->F0hz10 = frame->F0hz10 + (long) delta_f0; + frame->F0hz10 = frame->F0hz10 + (long)delta_f0; time_count++; } @@ -217,40 +216,34 @@ static double sampled_source(int source_num) double temp_diff; short *samples; - if(source_num == 0) - { + if (source_num == 0) { samples = natural_samples; kt_globals.num_samples = 100; - } - else - { + } else { samples = natural_samples2; kt_globals.num_samples = 256; } - if(kt_globals.T0!=0) - { - ftemp = (double) kt_globals.nper; + if (kt_globals.T0 != 0) { + ftemp = (double)kt_globals.nper; ftemp = ftemp / kt_globals.T0; ftemp = ftemp * kt_globals.num_samples; - itemp = (int) ftemp; + itemp = (int)ftemp; - temp_diff = ftemp - (double) itemp; + temp_diff = ftemp - (double)itemp; current_value = samples[itemp]; next_value = samples[itemp+1]; - diff_value = (double) next_value - (double) current_value; + diff_value = (double)next_value - (double)current_value; diff_value = diff_value * temp_diff; result = samples[itemp] + diff_value; result = result * kt_globals.sample_factor; - } - else - { + } else { result = 0; } - return(result); + return (result); } @@ -286,8 +279,7 @@ static int parwave(klatt_frame_ptr frame) /* MAIN LOOP, for each output sample of current frame: */ - for (kt_globals.ns=0; kt_globals.ns kt_globals.nmod) - { - noise *= (double) 0.5; + if (kt_globals.nper > kt_globals.nmod) { + noise *= (double)0.5; } /* Compute frication noise */ @@ -310,9 +301,8 @@ static int parwave(klatt_frame_ptr frame) period of female voice. */ - for (n4=0; n4<4; n4++) - { - switch(kt_globals.glsource) + for (n4 = 0; n4 < 4; n4++) { + switch (kt_globals.glsource) { case IMPULSIVE: voice = impulsive_source(); @@ -329,8 +319,7 @@ static int parwave(klatt_frame_ptr frame) } /* Reset period when counter 'nper' reaches T0 */ - if (kt_globals.nper >= kt_globals.T0) - { + if (kt_globals.nper >= kt_globals.T0) { kt_globals.nper = 0; pitch_synch_par_reset(frame); } @@ -340,7 +329,7 @@ static int parwave(klatt_frame_ptr frame) to samrate samples/sec. Resonator f=.09*samrate, bw=.06*samrate */ - voice = resonator(&(kt_globals.rsn[RLP]),voice); + voice = resonator(&(kt_globals.rsn[RLP]), voice); /* Increment counter that keeps track of 4*samrate samples per sec */ kt_globals.nper++; @@ -361,8 +350,7 @@ static int parwave(klatt_frame_ptr frame) */ - if (kt_globals.nper < kt_globals.nopen) - { + if (kt_globals.nper < kt_globals.nopen) { voice += kt_globals.amp_breth * kt_globals.nrand; } @@ -381,19 +369,18 @@ static int parwave(klatt_frame_ptr frame) Nasal antiresonator, then formants FNP, F5, F4, F3, F2, F1 */ - out=0; - if(kt_globals.synthesis_model != ALL_PARALLEL) - { - casc_next_in = antiresonator2(&(kt_globals.rsn[Rnz]),glotout); - casc_next_in = resonator(&(kt_globals.rsn[Rnpc]),casc_next_in); - casc_next_in = resonator(&(kt_globals.rsn[R8c]),casc_next_in); - casc_next_in = resonator(&(kt_globals.rsn[R7c]),casc_next_in); - casc_next_in = resonator(&(kt_globals.rsn[R6c]),casc_next_in); - casc_next_in = resonator2(&(kt_globals.rsn[R5c]),casc_next_in); - casc_next_in = resonator2(&(kt_globals.rsn[R4c]),casc_next_in); - casc_next_in = resonator2(&(kt_globals.rsn[R3c]),casc_next_in); - casc_next_in = resonator2(&(kt_globals.rsn[R2c]),casc_next_in); - out = resonator2(&(kt_globals.rsn[R1c]),casc_next_in); + out = 0; + if (kt_globals.synthesis_model != ALL_PARALLEL) { + casc_next_in = antiresonator2(&(kt_globals.rsn[Rnz]), glotout); + casc_next_in = resonator(&(kt_globals.rsn[Rnpc]), casc_next_in); + casc_next_in = resonator(&(kt_globals.rsn[R8c]), casc_next_in); + casc_next_in = resonator(&(kt_globals.rsn[R7c]), casc_next_in); + casc_next_in = resonator(&(kt_globals.rsn[R6c]), casc_next_in); + casc_next_in = resonator2(&(kt_globals.rsn[R5c]), casc_next_in); + casc_next_in = resonator2(&(kt_globals.rsn[R4c]), casc_next_in); + casc_next_in = resonator2(&(kt_globals.rsn[R3c]), casc_next_in); + casc_next_in = resonator2(&(kt_globals.rsn[R2c]), casc_next_in); + out = resonator2(&(kt_globals.rsn[R1c]), casc_next_in); } /* Excite parallel F1 and FNP by voicing waveform */ @@ -406,22 +393,21 @@ static int parwave(klatt_frame_ptr frame) voicing waveform. */ - out += resonator(&(kt_globals.rsn[R1p]),sourc); - out += resonator(&(kt_globals.rsn[Rnpp]),sourc); + out += resonator(&(kt_globals.rsn[R1p]), sourc); + out += resonator(&(kt_globals.rsn[Rnpp]), sourc); sourc = frics + par_glotout - glotlast; glotlast = par_glotout; - for(ix=R2p; ix<=R6p; ix++) - { - out = resonator(&(kt_globals.rsn[ix]),sourc) - out; + for (ix = R2p; ix <= R6p; ix++) { + out = resonator(&(kt_globals.rsn[ix]), sourc) - out; } outbypas = kt_globals.amp_bypas * sourc; out = outbypas - out; - out = resonator(&(kt_globals.rsn[Rout]),out); + out = resonator(&(kt_globals.rsn[Rout]), out); temp = (int)(out * wdata.amplitude * kt_globals.amp_gain0); /* Convert back to integer */ @@ -432,17 +418,13 @@ static int parwave(klatt_frame_ptr frame) int sample; z2 = 0; - if(wdata.mix_wavefile_ix < wdata.n_mix_wavefile) - { - if(wdata.mix_wave_scale == 0) - { + if (wdata.mix_wavefile_ix < wdata.n_mix_wavefile) { + if (wdata.mix_wave_scale == 0) { // a 16 bit sample c = wdata.mix_wavefile[wdata.mix_wavefile_ix+1]; sample = wdata.mix_wavefile[wdata.mix_wavefile_ix] + (c * 256); wdata.mix_wavefile_ix += 2; - } - else - { + } else { // a 8 bit sample, scaled sample = (signed char)wdata.mix_wavefile[wdata.mix_wavefile_ix++] * wdata.mix_wave_scale; } @@ -453,23 +435,20 @@ static int parwave(klatt_frame_ptr frame) } // if fadeout is set, fade to zero over 64 samples, to avoid clicks at end of synthesis - if(kt_globals.fadeout > 0) - { + if (kt_globals.fadeout > 0) { kt_globals.fadeout--; temp = (temp * kt_globals.fadeout) / 64; } value = (int)temp + ((echo_buf[echo_tail++]*echo_amp) >> 8); - if(echo_tail >= N_ECHO_BUF) - echo_tail=0; + if (echo_tail >= N_ECHO_BUF) + echo_tail = 0; - if (value < -32768) - { + if (value < -32768) { value = -32768; } - if (value > 32767) - { + if (value > 32767) { value = 32767; } @@ -477,16 +456,15 @@ static int parwave(klatt_frame_ptr frame) *out_ptr++ = value >> 8; echo_buf[echo_head++] = value; - if(echo_head >= N_ECHO_BUF) + if (echo_head >= N_ECHO_BUF) echo_head = 0; sample_count++; - if(out_ptr >= out_end) - { - return(1); + if (out_ptr >= out_end) { + return (1); } } - return(0); + return (0); } @@ -497,34 +475,30 @@ void KlattReset(int control) { int r_ix; - if(control == 2) - { - //Full reset + if (control == 2) { + // Full reset kt_globals.FLPhz = (950 * kt_globals.samrate) / 10000; kt_globals.BLPhz = (630 * kt_globals.samrate) / 10000; kt_globals.minus_pi_t = -PI / kt_globals.samrate; kt_globals.two_pi_t = -2.0 * kt_globals.minus_pi_t; - setabc(kt_globals.FLPhz,kt_globals.BLPhz,&(kt_globals.rsn[RLP])); + setabc(kt_globals.FLPhz, kt_globals.BLPhz, &(kt_globals.rsn[RLP])); } - if(control > 0) - { + if (control > 0) { kt_globals.nper = 0; kt_globals.T0 = 0; kt_globals.nopen = 0; kt_globals.nmod = 0; - for(r_ix=RGL; r_ix < N_RSN; r_ix++) - { + for (r_ix = RGL; r_ix < N_RSN; r_ix++) { kt_globals.rsn[r_ix].p1 = 0; kt_globals.rsn[r_ix].p2 = 0; } } - for(r_ix=0; r_ix <= R6p; r_ix++) - { + for (r_ix = 0; r_ix <= R6p; r_ix++) { kt_globals.rsn[r_ix].p1 = 0; kt_globals.rsn[r_ix].p2 = 0; } @@ -540,15 +514,14 @@ void KlattReset(int control) static void frame_init(klatt_frame_ptr frame) { double amp_par[7]; - static double amp_par_factor[7] = {0.6, 0.4, 0.15, 0.06, 0.04, 0.022, 0.03}; + static double amp_par_factor[7] = { 0.6, 0.4, 0.15, 0.06, 0.04, 0.022, 0.03 }; long Gain0_tmp; int ix; kt_globals.original_f0 = frame->F0hz10 / 10; frame->AVdb_tmp = frame->AVdb - 7; - if (frame->AVdb_tmp < 0) - { + if (frame->AVdb_tmp < 0) { frame->AVdb_tmp = 0; } @@ -557,28 +530,24 @@ static void frame_init(klatt_frame_ptr frame) kt_globals.par_amp_voice = DBtoLIN(frame->AVpdb); kt_globals.amp_bypas = DBtoLIN(frame->AB) * 0.05; - for(ix=0; ix <= 6; ix++) - { + for (ix = 0; ix <= 6; ix++) { // parallel amplitudes F1 to F6, and parallel nasal pole amp_par[ix] = DBtoLIN(frame->Ap[ix]) * amp_par_factor[ix]; } Gain0_tmp = frame->Gain0 - 3; - if (Gain0_tmp <= 0) - { + if (Gain0_tmp <= 0) { Gain0_tmp = 57; } kt_globals.amp_gain0 = DBtoLIN(Gain0_tmp) / kt_globals.scale_wav; /* Set coefficients of variable cascade resonators */ - for(ix=1; ix<=9; ix++) - { + for (ix = 1; ix <= 9; ix++) { // formants 1 to 8, plus nasal pole - setabc(frame->Fhz[ix],frame->Bhz[ix],&(kt_globals.rsn[ix])); + setabc(frame->Fhz[ix], frame->Bhz[ix], &(kt_globals.rsn[ix])); - if(ix <= 5) - { - setabc(frame->Fhz_next[ix],frame->Bhz_next[ix],&(kt_globals.rsn_next[ix])); + if (ix <= 5) { + setabc(frame->Fhz_next[ix], frame->Bhz_next[ix], &(kt_globals.rsn_next[ix])); kt_globals.rsn[ix].a_inc = (kt_globals.rsn_next[ix].a - kt_globals.rsn[ix].a) / 64.0; kt_globals.rsn[ix].b_inc = (kt_globals.rsn_next[ix].b - kt_globals.rsn[ix].b) / 64.0; @@ -587,8 +556,8 @@ static void frame_init(klatt_frame_ptr frame) } // nasal zero anti-resonator - setzeroabc(frame->Fhz[F_NZ],frame->Bhz[F_NZ],&(kt_globals.rsn[Rnz])); - setzeroabc(frame->Fhz_next[F_NZ],frame->Bhz_next[F_NZ],&(kt_globals.rsn_next[Rnz])); + setzeroabc(frame->Fhz[F_NZ], frame->Bhz[F_NZ], &(kt_globals.rsn[Rnz])); + setzeroabc(frame->Fhz_next[F_NZ], frame->Bhz_next[F_NZ], &(kt_globals.rsn_next[Rnz])); kt_globals.rsn[F_NZ].a_inc = (kt_globals.rsn_next[F_NZ].a - kt_globals.rsn[F_NZ].a) / 64.0; kt_globals.rsn[F_NZ].b_inc = (kt_globals.rsn_next[F_NZ].b - kt_globals.rsn[F_NZ].b) / 64.0; kt_globals.rsn[F_NZ].c_inc = (kt_globals.rsn_next[F_NZ].c - kt_globals.rsn[F_NZ].c) / 64.0; @@ -596,15 +565,14 @@ static void frame_init(klatt_frame_ptr frame) /* Set coefficients of parallel resonators, and amplitude of outputs */ - for(ix=0; ix<=6; ix++) - { - setabc(frame->Fhz[ix],frame->Bphz[ix],&(kt_globals.rsn[Rparallel+ix])); + for (ix = 0; ix <= 6; ix++) { + setabc(frame->Fhz[ix], frame->Bphz[ix], &(kt_globals.rsn[Rparallel+ix])); kt_globals.rsn[Rparallel+ix].a *= amp_par[ix]; } /* output low-pass filter */ - setabc((long)0.0,(long)(kt_globals.samrate/2),&(kt_globals.rsn[Rout])); + setabc((long)0.0, (long)(kt_globals.samrate/2), &(kt_globals.rsn[Rout])); } @@ -622,19 +590,16 @@ static void frame_init(klatt_frame_ptr frame) static double impulsive_source() { - static double doublet[] = {0.0,13000000.0,-13000000.0}; + static double doublet[] = { 0.0, 13000000.0, -13000000.0 }; static double vwave; - if (kt_globals.nper < 3) - { + if (kt_globals.nper < 3) { vwave = doublet[kt_globals.nper]; - } - else - { + } else { vwave = 0.0; } - return(resonator(&(kt_globals.rsn[RGL]),vwave)); + return (resonator(&(kt_globals.rsn[RGL]), vwave)); } @@ -651,18 +616,15 @@ static double natural_source() double lgtemp; static double vwave; - if (kt_globals.nper < kt_globals.nopen) - { + if (kt_globals.nper < kt_globals.nopen) { kt_globals.pulse_shape_a -= kt_globals.pulse_shape_b; vwave += kt_globals.pulse_shape_a; - lgtemp=vwave * 0.028; + lgtemp = vwave * 0.028; - return(lgtemp); - } - else - { + return (lgtemp); + } else { vwave = 0.0; - return(0.0); + return (0.0); } } @@ -707,26 +669,24 @@ static void pitch_synch_par_reset(klatt_frame_ptr frame) long temp; double temp1; static long skew; - static short B0[224] = - { - 1200,1142,1088,1038, 991, 948, 907, 869, 833, 799, 768, 738, 710, 683, 658, + static short B0[224] = { + 1200, 1142, 1088, 1038, 991, 948, 907, 869, 833, 799, 768, 738, 710, 683, 658, 634, 612, 590, 570, 551, 533, 515, 499, 483, 468, 454, 440, 427, 415, 403, 391, 380, 370, 360, 350, 341, 332, 323, 315, 307, 300, 292, 285, 278, 272, 265, 259, 253, 247, 242, 237, 231, 226, 221, 217, 212, 208, 204, 199, 195, 192, 188, 184, 180, 177, 174, 170, 167, 164, 161, 158, 155, 153, 150, 147, 145, 142, 140, 137, 135, 133, 131, 128, 126, 124, 122, 120, 119, 117, 115, - 113,111, 110, 108, 106, 105, 103, 102, 100, 99, 97, 96, 95, 93, 92, 91, 90, + 113, 111, 110, 108, 106, 105, 103, 102, 100, 99, 97, 96, 95, 93, 92, 91, 90, 88, 87, 86, 85, 84, 83, 82, 80, 79, 78, 77, 76, 75, 75, 74, 73, 72, 71, 70, 69, 68, 68, 67, 66, 65, 64, 64, 63, 62, 61, 61, 60, 59, 59, 58, 57, 57, 56, 56, 55, 55, 54, 54, 53, 53, 52, 52, 51, 51, 50, 50, 49, 49, 48, 48, 47, 47, 46, 46, 45, 45, 44, 44, 43, 43, 42, 42, 41, 41, 41, 41, 40, 40, - 39, 39, 38, 38, 38, 38, 37, 37, 36, 36, 36, 36, 35, 35, 35, 35, 34, 34,33, + 39, 39, 38, 38, 38, 38, 37, 37, 36, 36, 36, 36, 35, 35, 35, 35, 34, 34, 33, 33, 33, 33, 32, 32, 32, 32, 31, 31, 31, 31, 30, 30, 30, 30, 29, 29, 29, 29, 28, 28, 28, 28, 27, 27 }; - if (frame->F0hz10 > 0) - { + if (frame->F0hz10 > 0) { /* T0 is 4* the number of samples in one pitch period */ kt_globals.T0 = (40 * kt_globals.samrate) / frame->F0hz10; @@ -737,8 +697,7 @@ static void pitch_synch_par_reset(klatt_frame_ptr frame) /* Duration of period before amplitude modulation */ kt_globals.nmod = kt_globals.T0; - if (frame->AVdb_tmp > 0) - { + if (frame->AVdb_tmp > 0) { kt_globals.nmod >>= 1; } @@ -750,18 +709,15 @@ static void pitch_synch_par_reset(klatt_frame_ptr frame) kt_globals.nopen = 4 * frame->Kopen; - if ((kt_globals.glsource == IMPULSIVE) && (kt_globals.nopen > 263)) - { + if ((kt_globals.glsource == IMPULSIVE) && (kt_globals.nopen > 263)) { kt_globals.nopen = 263; } - if (kt_globals.nopen >= (kt_globals.T0-1)) - { + if (kt_globals.nopen >= (kt_globals.T0-1)) { kt_globals.nopen = kt_globals.T0 - 2; } - if (kt_globals.nopen < 40) - { + if (kt_globals.nopen < 40) { /* F0 max = 1000 Hz */ kt_globals.nopen = 40; } @@ -776,7 +732,7 @@ static void pitch_synch_par_reset(klatt_frame_ptr frame) temp = kt_globals.samrate / kt_globals.nopen; - setabc((long)0,temp,&(kt_globals.rsn[RGL])); + setabc((long)0, temp, &(kt_globals.rsn[RGL])); /* Make gain at F1 about constant */ @@ -790,25 +746,19 @@ static void pitch_synch_par_reset(klatt_frame_ptr frame) temp = kt_globals.T0 - kt_globals.nopen; - if (frame->Kskew > temp) - { + if (frame->Kskew > temp) { frame->Kskew = temp; } - if (skew >= 0) - { + if (skew >= 0) { skew = frame->Kskew; - } - else - { + } else { skew = -frame->Kskew; } /* Add skewness to closed portion of voicing period */ kt_globals.T0 = kt_globals.T0 + skew; skew = -skew; - } - else - { + } else { kt_globals.T0 = 4; /* Default for f0 undefined */ kt_globals.amp_voice = 0.0; kt_globals.nmod = kt_globals.T0; @@ -819,18 +769,14 @@ static void pitch_synch_par_reset(klatt_frame_ptr frame) /* Reset these pars pitch synchronously or at update rate if f0=0 */ - if ((kt_globals.T0 != 4) || (kt_globals.ns == 0)) - { + if ((kt_globals.T0 != 4) || (kt_globals.ns == 0)) { /* Set one-pole low-pass filter that tilts glottal source */ kt_globals.decay = (0.033 * frame->TLTdb); - if (kt_globals.decay > 0.0) - { + if (kt_globals.decay > 0.0) { kt_globals.onemd = 1.0 - kt_globals.decay; - } - else - { + } else { kt_globals.onemd = 1.0; } } @@ -901,8 +847,7 @@ static void setzeroabc(long int f, long int bw, resonator_ptr rp) * INF, causing an audible sound spike when triggered (e.g. apiration with the * nasal register set to f=0, bw=0). */ - if (rp->a != 0) - { + if (rp->a != 0) { /* Now convert to antiresonator coefficients (a'=1/a, b'=b/a, c'=c/a) */ rp->a = 1.0 / rp->a; rp->c *= -rp->a; @@ -925,13 +870,13 @@ static double gen_noise(double noise) long temp; static double nlast; - temp = (long) getrandom(-8191,8191); - kt_globals.nrand = (long) temp; + temp = (long)getrandom(-8191, 8191); + kt_globals.nrand = (long)temp; noise = kt_globals.nrand + (0.75 * nlast); nlast = noise; - return(noise); + return (noise); } @@ -956,8 +901,7 @@ static double gen_noise(double noise) static double DBtoLIN(long dB) { - static short amptable[88] = - { + static short amptable[88] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 25, 28, 32, 35, 40, 45, 51, 57, 64, 71, 80, 90, 101, 114, 128, @@ -969,12 +913,11 @@ static double DBtoLIN(long dB) 26214, 29491, 32767 }; - if ((dB < 0) || (dB > 87)) - { - return(0); + if ((dB < 0) || (dB > 87)) { + return (0); } - return((double)(amptable[dB]) * 0.001); + return ((double)(amptable[dB]) * 0.001); } @@ -998,28 +941,23 @@ int Wavegen_Klatt(int resume) int ix; int fade; - if(resume==0) - { + if (resume == 0) { sample_count = 0; } - while(sample_count < nsamples) - { + while (sample_count < nsamples) { kt_frame.F0hz10 = (wdata.pitch * 10) / 4096; // formants F6,F7,F8 are fixed values for cascade resonators, set in KlattInit() // but F6 is used for parallel resonator // F0 is used for the nasal zero - for(ix=0; ix < 6; ix++) - { + for (ix = 0; ix < 6; ix++) { kt_frame.Fhz[ix] = peaks[ix].freq; - if(ix < 4) - { + if (ix < 4) { kt_frame.Bhz[ix] = peaks[ix].bw; } } - for(ix=1; ix < 7; ix++) - { + for (ix = 1; ix < 7; ix++) { kt_frame.Ap[ix] = peaks[ix].ap; } @@ -1034,8 +972,7 @@ int Wavegen_Klatt(int resume) kt_frame.Kopen = klattp[KLATT_Kopen]; // advance formants - for(pk=0; pk>8) > 127) ix = 127; + if ((ix = wdata.pitch_ix>>8) > 127) ix = 127; x = wdata.pitch_env[ix] * wdata.pitch_range; wdata.pitch = (x>>8) + wdata.pitch_base; kt_globals.nspfr = (nsamples - sample_count); - if(kt_globals.nspfr > STEPSIZE) + if (kt_globals.nspfr > STEPSIZE) kt_globals.nspfr = STEPSIZE; frame_init(&kt_frame); /* get parameters for next frame of speech */ - if(parwave(&kt_frame) == 1) - { - return(1); // output buffer is full + if (parwave(&kt_frame) == 1) { + return (1); // output buffer is full } } - if(end_wave > 0) - { + if (end_wave > 0) { fade = 64; // not followd by formant synthesis // fade out to avoid a click @@ -1089,13 +1021,12 @@ int Wavegen_Klatt(int resume) end_wave = 0; sample_count -= fade; kt_globals.nspfr = fade; - if(parwave(&kt_frame) == 1) - { - return(1); // output buffer is full + if (parwave(&kt_frame) == 1) { + return (1); // output buffer is full } } - return(0); + return (0); } @@ -1108,10 +1039,8 @@ void SetSynth_Klatt(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t *v frame_t *fr3; static frame_t prev_fr; - if(wvoice != NULL) - { - if((wvoice->klattv[0] > 0) && (wvoice->klattv[0] <=4 )) - { + if (wvoice != NULL) { + if ((wvoice->klattv[0] > 0) && (wvoice->klattv[0] <= 4 )) { kt_globals.glsource = wvoice->klattv[0]; kt_globals.scale_wav = scale_wav_tab[kt_globals.glsource]; } @@ -1119,28 +1048,22 @@ void SetSynth_Klatt(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t *v } end_wave = 0; - if(control & 2) - { + if (control & 2) { end_wave = 1; // fadeout at the end } - if(control & 1) - { + if (control & 1) { end_wave = 1; - for(qix=wcmdq_head+1;; qix++) - { - if(qix >= N_WCMDQ) qix = 0; - if(qix == wcmdq_tail) break; + for (qix = wcmdq_head+1;; qix++) { + if (qix >= N_WCMDQ) qix = 0; + if (qix == wcmdq_tail) break; cmd = wcmdq[qix][0]; - if(cmd==WCMD_KLATT) - { + if (cmd == WCMD_KLATT) { end_wave = 0; // next wave generation is from another spectrum fr3 = (frame_t *)wcmdq[qix][2]; - for(ix=1; ix<6; ix++) - { - if(fr3->ffreq[ix] != fr2->ffreq[ix]) - { + for (ix = 1; ix < 6; ix++) { + if (fr3->ffreq[ix] != fr2->ffreq[ix]) { // there is a discontinuity in formants end_wave = 2; break; @@ -1148,35 +1071,28 @@ void SetSynth_Klatt(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t *v } break; } - if((cmd==WCMD_WAVE) || (cmd==WCMD_PAUSE)) + if ((cmd == WCMD_WAVE) || (cmd == WCMD_PAUSE)) break; // next is not from spectrum, so continue until end of wave cycle } } - if(control & 1) - { - for(ix=1; ix<6; ix++) - { - if(prev_fr.ffreq[ix] != fr1->ffreq[ix]) - { + if (control & 1) { + for (ix = 1; ix < 6; ix++) { + if (prev_fr.ffreq[ix] != fr1->ffreq[ix]) { // Discontinuity in formants. // end_wave was set in SetSynth_Klatt() to fade out the previous frame KlattReset(0); break; } } - memcpy(&prev_fr,fr2,sizeof(prev_fr)); + memcpy(&prev_fr, fr2, sizeof(prev_fr)); } - for(ix=0; ix= 5) && ((fr1->frflags & FRFLAG_KLATT) == 0)) - { + for (ix = 0; ix < N_KLATTP; ix++) { + if ((ix >= 5) && ((fr1->frflags & FRFLAG_KLATT) == 0)) { klattp1[ix] = klattp[ix] = 0; klattp_inc[ix] = 0; - } - else - { + } else { klattp1[ix] = klattp[ix] = fr1->klattp[ix]; klattp_inc[ix] = (double)((fr2->klattp[ix] - klattp[ix]) * STEPSIZE)/length; } @@ -1184,15 +1100,13 @@ void SetSynth_Klatt(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t *v nsamples = length; - for(ix=1; ix < 6; ix++) - { + for (ix = 1; ix < 6; ix++) { peaks[ix].freq1 = (fr1->ffreq[ix] * v->freq[ix] / 256.0) + v->freqadd[ix]; peaks[ix].freq = (int)peaks[ix].freq1; next = (fr2->ffreq[ix] * v->freq[ix] / 256.0) + v->freqadd[ix]; peaks[ix].freq_inc = ((next - peaks[ix].freq1) * STEPSIZE) / length; - if(ix < 4) - { + if (ix < 4) { // klatt bandwidth for f1, f2, f3 (others are fixed) peaks[ix].bw1 = fr1->bw[ix] * 2; peaks[ix].bw = (int)peaks[ix].bw1; @@ -1203,12 +1117,12 @@ void SetSynth_Klatt(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t *v // nasal zero frequency peaks[0].freq1 = fr1->klattp[KLATT_FNZ] * 2; - if(peaks[0].freq1 == 0) + if (peaks[0].freq1 == 0) peaks[0].freq1 = kt_frame.Fhz[F_NP]; // if no nasal zero, set it to same freq as nasal pole peaks[0].freq = (int)peaks[0].freq1; next = fr2->klattp[KLATT_FNZ] * 2; - if(next == 0) + if (next == 0) next = kt_frame.Fhz[F_NP]; peaks[0].freq_inc = ((next - peaks[0].freq1) * STEPSIZE) / length; @@ -1217,11 +1131,9 @@ void SetSynth_Klatt(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t *v peaks[0].bw = 89; peaks[0].bw_inc = 0; - if(fr1->frflags & FRFLAG_KLATT) - { + if (fr1->frflags & FRFLAG_KLATT) { // the frame contains additional parameters for parallel resonators - for(ix=1; ix < 7; ix++) - { + for (ix = 1; ix < 7; ix++) { peaks[ix].bp1 = fr1->klatt_bp[ix] * 4; // parallel bandwidth peaks[ix].bp = (int)peaks[ix].bp1; next = fr2->klatt_bp[ix] * 4; @@ -1238,10 +1150,10 @@ void SetSynth_Klatt(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t *v int Wavegen_Klatt2(int length, int modulation, int resume, frame_t *fr1, frame_t *fr2) { - if(resume==0) + if (resume == 0) SetSynth_Klatt(length, modulation, fr1, fr2, wvoice, 1); - return(Wavegen_Klatt(resume)); + return (Wavegen_Klatt(resume)); } @@ -1249,14 +1161,14 @@ int Wavegen_Klatt2(int length, int modulation, int resume, frame_t *fr1, frame_t void KlattInit() { - static short formant_hz[10] = {280,688,1064,2806,3260,3700,6500,7000,8000,280}; - static short bandwidth[10] = {89,160,70,160,200,200,500,500,500,89}; - static short parallel_amp[10] = { 0,59,59,59,59,59,59,0,0,0}; - static short parallel_bw[10] = {59,59,89,149,200,200,500,0,0,0}; + static short formant_hz[10] = { 280, 688, 1064, 2806, 3260, 3700, 6500, 7000, 8000, 280 }; + static short bandwidth[10] = { 89, 160, 70, 160, 200, 200, 500, 500, 500, 89 }; + static short parallel_amp[10] = { 0, 59, 59, 59, 59, 59, 59, 0, 0, 0 }; + static short parallel_bw[10] = { 59, 59, 89, 149, 200, 200, 500, 0, 0, 0 }; int ix; - sample_count=0; + sample_count = 0; kt_globals.synthesis_model = CASCADE_PARALLEL; kt_globals.samrate = 22050; @@ -1273,8 +1185,7 @@ void KlattInit() KlattReset(2); // set default values for frame parameters - for(ix=0; ix<=9; ix++) - { + for (ix = 0; ix <= 9; ix++) { kt_frame.Fhz[ix] = formant_hz[ix]; kt_frame.Bhz[ix] = bandwidth[ix]; kt_frame.Ap[ix] = parallel_amp[ix]; @@ -1288,7 +1199,7 @@ void KlattInit() kt_frame.Kopen = 40; // 40 kt_frame.Aturb = 0; kt_frame.TLTdb = 0; - kt_frame.AF =50; + kt_frame.AF = 50; kt_frame.Kskew = 0; kt_frame.AB = 0; kt_frame.AVpdb = 0; diff --git a/src/libespeak-ng/klatt.h b/src/libespeak-ng/klatt.h index f4f43145..e8425db1 100644 --- a/src/libespeak-ng/klatt.h +++ b/src/libespeak-ng/klatt.h @@ -43,8 +43,7 @@ typedef long flag; /* Resonator Structure */ -typedef struct -{ +typedef struct { double a; double b; double c; @@ -57,8 +56,7 @@ typedef struct /* Structure for Klatt Globals */ -typedef struct -{ +typedef struct { flag synthesis_model; /* cascade-parallel or all-parallel */ flag outsl; /* Output waveform selector */ long samrate; /* Number of output samples per second */ @@ -136,8 +134,7 @@ typedef struct #define F_NP 9 // nasal pole formant -typedef struct -{ +typedef struct { int F0hz10; /* Voicing fund freq in Hz */ int AVdb; /* Amp of voicing in dB, 0 to 70 */ int Fhz[10]; // formant Hz, F_NZ to F6 to F_NP @@ -156,7 +153,7 @@ typedef struct int AVpdb; /* Amp of voicing, par in dB, 0 to 70 */ int Gain0; /* Overall gain, 60 dB is unity, 0 to 60 */ - int AVdb_tmp; //copy of AVdb, which is changed within parwave() + int AVdb_tmp; // copy of AVdb, which is changed within parwave() int Fhz_next[10]; // Fhz for the next chunk, so we can do interpolation of resonator (a,b,c) parameters int Bhz_next[10]; } klatt_frame_t, *klatt_frame_ptr; diff --git a/src/libespeak-ng/mbrowrap.c b/src/libespeak-ng/mbrowrap.c index 4218fd15..d926c916 100644 --- a/src/libespeak-ng/mbrowrap.c +++ b/src/libespeak-ng/mbrowrap.c @@ -287,7 +287,7 @@ static int mbrola_has_errors(void) char *buf_ptr, *lf; buf_ptr = buffer; - for (;; ) { + for (;;) { result = read(mbr_error_fd, buf_ptr, sizeof(buffer) - (buf_ptr - buffer) - 1); if (result == -1) { @@ -514,7 +514,7 @@ int init_MBR(const char *voice_path) } mbr_samplerate = wavhdr[24] + (wavhdr[25]<<8) + (wavhdr[26]<<16) + (wavhdr[27]<<24); - //log("mbrowrap: voice samplerate = %d", mbr_samplerate); + // log("mbrowrap: voice samplerate = %d", mbr_samplerate); /* remember the voice path for setVolumeRatio_MBR() */ if (mbr_voice_path != voice_path) { diff --git a/src/libespeak-ng/numbers.c b/src/libespeak-ng/numbers.c index fc87837b..d5099830 100644 --- a/src/libespeak-ng/numbers.c +++ b/src/libespeak-ng/numbers.c @@ -82,36 +82,36 @@ typedef struct { // these are tokens to look up in the *_list file. static ACCENTS accents_tab[] = { - {"_lig", 1}, - {"_smc", 0}, // smallcap - {"_tur", 0}, // turned - {"_rev", 0}, // reversed - {"_crl", 0}, // curl + { "_lig", 1 }, + { "_smc", 0 }, // smallcap + { "_tur", 0 }, // turned + { "_rev", 0 }, // reversed + { "_crl", 0 }, // curl - {"_acu", 0}, // acute - {"_brv", 0}, // breve - {"_hac", 0}, // caron/hacek - {"_ced", 0}, // cedilla - {"_cir", 0}, // circumflex - {"_dia", 0}, // diaeresis - {"_ac2", 0}, // double acute - {"_dot", 0}, // dot - {"_grv", 0}, // grave - {"_mcn", 0}, // macron - {"_ogo", 0}, // ogonek - {"_rng", 0}, // ring - {"_stk", 0}, // stroke - {"_tld", 0}, // tilde + { "_acu", 0 }, // acute + { "_brv", 0 }, // breve + { "_hac", 0 }, // caron/hacek + { "_ced", 0 }, // cedilla + { "_cir", 0 }, // circumflex + { "_dia", 0 }, // diaeresis + { "_ac2", 0 }, // double acute + { "_dot", 0 }, // dot + { "_grv", 0 }, // grave + { "_mcn", 0 }, // macron + { "_ogo", 0 }, // ogonek + { "_rng", 0 }, // ring + { "_stk", 0 }, // stroke + { "_tld", 0 }, // tilde - {"_bar", 0}, // bar - {"_rfx", 0}, // retroflex - {"_hok", 0}, // hook + { "_bar", 0 }, // bar + { "_rfx", 0 }, // retroflex + { "_hok", 0 }, // hook }; #define CAPITAL 0 -#define LETTER(ch,mod1,mod2) (ch-59)+(mod1 << 6)+(mod2 << 11) -#define LIGATURE(ch1,ch2,mod1) (ch1-59)+((ch2-59) << 6)+(mod1 << 12)+M_LIGATURE +#define LETTER(ch, mod1, mod2) (ch-59)+(mod1 << 6)+(mod2 << 11) +#define LIGATURE(ch1, ch2, mod1) (ch1-59)+((ch2-59) << 6)+(mod1 << 12)+M_LIGATURE #define L_ALPHA 60 // U+3B1 @@ -139,261 +139,261 @@ static const short non_ascii_tab[] = { // characters U+00e0 to U+017f static const unsigned short letter_accents_0e0[] = { - LETTER('a',M_GRAVE,0), // U+00e0 - LETTER('a',M_ACUTE,0), - LETTER('a',M_CIRCUMFLEX,0), - LETTER('a',M_TILDE,0), - LETTER('a',M_DIAERESIS,0), - LETTER('a',M_RING,0), - LIGATURE('a','e',0), - LETTER('c',M_CEDILLA,0), - LETTER('e',M_GRAVE,0), - LETTER('e',M_ACUTE,0), - LETTER('e',M_CIRCUMFLEX,0), - LETTER('e',M_DIAERESIS,0), - LETTER('i',M_GRAVE,0), - LETTER('i',M_ACUTE,0), - LETTER('i',M_CIRCUMFLEX,0), - LETTER('i',M_DIAERESIS,0), - LETTER('d',M_NAME,0), // eth // U+00f0 - LETTER('n',M_TILDE,0), - LETTER('o',M_GRAVE,0), - LETTER('o',M_ACUTE,0), - LETTER('o',M_CIRCUMFLEX,0), - LETTER('o',M_TILDE,0), - LETTER('o',M_DIAERESIS,0), + LETTER('a', M_GRAVE, 0), // U+00e0 + LETTER('a', M_ACUTE, 0), + LETTER('a', M_CIRCUMFLEX, 0), + LETTER('a', M_TILDE, 0), + LETTER('a', M_DIAERESIS, 0), + LETTER('a', M_RING, 0), + LIGATURE('a', 'e', 0), + LETTER('c', M_CEDILLA, 0), + LETTER('e', M_GRAVE, 0), + LETTER('e', M_ACUTE, 0), + LETTER('e', M_CIRCUMFLEX, 0), + LETTER('e', M_DIAERESIS, 0), + LETTER('i', M_GRAVE, 0), + LETTER('i', M_ACUTE, 0), + LETTER('i', M_CIRCUMFLEX, 0), + LETTER('i', M_DIAERESIS, 0), + LETTER('d', M_NAME, 0), // eth // U+00f0 + LETTER('n', M_TILDE, 0), + LETTER('o', M_GRAVE, 0), + LETTER('o', M_ACUTE, 0), + LETTER('o', M_CIRCUMFLEX, 0), + LETTER('o', M_TILDE, 0), + LETTER('o', M_DIAERESIS, 0), 0, // division sign - LETTER('o',M_STROKE,0), - LETTER('u',M_GRAVE,0), - LETTER('u',M_ACUTE,0), - LETTER('u',M_CIRCUMFLEX,0), - LETTER('u',M_DIAERESIS,0), - LETTER('y',M_ACUTE,0), - LETTER('t',M_NAME,0), // thorn - LETTER('y',M_DIAERESIS,0), + LETTER('o', M_STROKE, 0), + LETTER('u', M_GRAVE, 0), + LETTER('u', M_ACUTE, 0), + LETTER('u', M_CIRCUMFLEX, 0), + LETTER('u', M_DIAERESIS, 0), + LETTER('y', M_ACUTE, 0), + LETTER('t', M_NAME, 0), // thorn + LETTER('y', M_DIAERESIS, 0), CAPITAL, // U+0100 - LETTER('a',M_MACRON,0), + LETTER('a', M_MACRON, 0), CAPITAL, - LETTER('a',M_BREVE,0), + LETTER('a', M_BREVE, 0), CAPITAL, - LETTER('a',M_OGONEK,0), + LETTER('a', M_OGONEK, 0), CAPITAL, - LETTER('c',M_ACUTE,0), + LETTER('c', M_ACUTE, 0), CAPITAL, - LETTER('c',M_CIRCUMFLEX,0), + LETTER('c', M_CIRCUMFLEX, 0), CAPITAL, - LETTER('c',M_DOT_ABOVE,0), + LETTER('c', M_DOT_ABOVE, 0), CAPITAL, - LETTER('c',M_CARON,0), + LETTER('c', M_CARON, 0), CAPITAL, - LETTER('d',M_CARON,0), + LETTER('d', M_CARON, 0), CAPITAL, // U+0110 - LETTER('d',M_STROKE,0), + LETTER('d', M_STROKE, 0), CAPITAL, - LETTER('e',M_MACRON,0), + LETTER('e', M_MACRON, 0), CAPITAL, - LETTER('e',M_BREVE,0), + LETTER('e', M_BREVE, 0), CAPITAL, - LETTER('e',M_DOT_ABOVE,0), + LETTER('e', M_DOT_ABOVE, 0), CAPITAL, - LETTER('e',M_OGONEK,0), + LETTER('e', M_OGONEK, 0), CAPITAL, - LETTER('e',M_CARON,0), + LETTER('e', M_CARON, 0), CAPITAL, - LETTER('g',M_CIRCUMFLEX,0), + LETTER('g', M_CIRCUMFLEX, 0), CAPITAL, - LETTER('g',M_BREVE,0), + LETTER('g', M_BREVE, 0), CAPITAL, // U+0120 - LETTER('g',M_DOT_ABOVE,0), + LETTER('g', M_DOT_ABOVE, 0), CAPITAL, - LETTER('g',M_CEDILLA,0), + LETTER('g', M_CEDILLA, 0), CAPITAL, - LETTER('h',M_CIRCUMFLEX,0), + LETTER('h', M_CIRCUMFLEX, 0), CAPITAL, - LETTER('h',M_STROKE,0), + LETTER('h', M_STROKE, 0), CAPITAL, - LETTER('i',M_TILDE,0), + LETTER('i', M_TILDE, 0), CAPITAL, - LETTER('i',M_MACRON,0), + LETTER('i', M_MACRON, 0), CAPITAL, - LETTER('i',M_BREVE,0), + LETTER('i', M_BREVE, 0), CAPITAL, - LETTER('i',M_OGONEK,0), + LETTER('i', M_OGONEK, 0), CAPITAL, // U+0130 - LETTER('i',M_NAME,0), // dotless i + LETTER('i', M_NAME, 0), // dotless i CAPITAL, - LIGATURE('i','j',0), + LIGATURE('i', 'j', 0), CAPITAL, - LETTER('j',M_CIRCUMFLEX,0), + LETTER('j', M_CIRCUMFLEX, 0), CAPITAL, - LETTER('k',M_CEDILLA,0), - LETTER('k',M_NAME,0), // kra + LETTER('k', M_CEDILLA, 0), + LETTER('k', M_NAME, 0), // kra CAPITAL, - LETTER('l',M_ACUTE,0), + LETTER('l', M_ACUTE, 0), CAPITAL, - LETTER('l',M_CEDILLA,0), + LETTER('l', M_CEDILLA, 0), CAPITAL, - LETTER('l',M_CARON,0), + LETTER('l', M_CARON, 0), CAPITAL, - LETTER('l',M_MIDDLE_DOT,0), // U+0140 + LETTER('l', M_MIDDLE_DOT, 0), // U+0140 CAPITAL, - LETTER('l',M_STROKE,0), + LETTER('l', M_STROKE, 0), CAPITAL, - LETTER('n',M_ACUTE,0), + LETTER('n', M_ACUTE, 0), CAPITAL, - LETTER('n',M_CEDILLA,0), + LETTER('n', M_CEDILLA, 0), CAPITAL, - LETTER('n',M_CARON,0), - LETTER('n',M_NAME,0), // apostrophe n + LETTER('n', M_CARON, 0), + LETTER('n', M_NAME, 0), // apostrophe n CAPITAL, - LETTER('n',M_NAME,0), // eng + LETTER('n', M_NAME, 0), // eng CAPITAL, - LETTER('o',M_MACRON,0), + LETTER('o', M_MACRON, 0), CAPITAL, - LETTER('o',M_BREVE,0), + LETTER('o', M_BREVE, 0), CAPITAL, // U+0150 - LETTER('o',M_DOUBLE_ACUTE,0), + LETTER('o', M_DOUBLE_ACUTE, 0), CAPITAL, - LIGATURE('o','e',0), + LIGATURE('o', 'e', 0), CAPITAL, - LETTER('r',M_ACUTE,0), + LETTER('r', M_ACUTE, 0), CAPITAL, - LETTER('r',M_CEDILLA,0), + LETTER('r', M_CEDILLA, 0), CAPITAL, - LETTER('r',M_CARON,0), + LETTER('r', M_CARON, 0), CAPITAL, - LETTER('s',M_ACUTE,0), + LETTER('s', M_ACUTE, 0), CAPITAL, - LETTER('s',M_CIRCUMFLEX,0), + LETTER('s', M_CIRCUMFLEX, 0), CAPITAL, - LETTER('s',M_CEDILLA,0), + LETTER('s', M_CEDILLA, 0), CAPITAL, // U+0160 - LETTER('s',M_CARON,0), + LETTER('s', M_CARON, 0), CAPITAL, - LETTER('t',M_CEDILLA,0), + LETTER('t', M_CEDILLA, 0), CAPITAL, - LETTER('t',M_CARON,0), + LETTER('t', M_CARON, 0), CAPITAL, - LETTER('t',M_STROKE,0), + LETTER('t', M_STROKE, 0), CAPITAL, - LETTER('u',M_TILDE,0), + LETTER('u', M_TILDE, 0), CAPITAL, - LETTER('u',M_MACRON,0), + LETTER('u', M_MACRON, 0), CAPITAL, - LETTER('u',M_BREVE,0), + LETTER('u', M_BREVE, 0), CAPITAL, - LETTER('u',M_RING,0), + LETTER('u', M_RING, 0), CAPITAL, // U+0170 - LETTER('u',M_DOUBLE_ACUTE,0), + LETTER('u', M_DOUBLE_ACUTE, 0), CAPITAL, - LETTER('u',M_OGONEK,0), + LETTER('u', M_OGONEK, 0), CAPITAL, - LETTER('w',M_CIRCUMFLEX,0), + LETTER('w', M_CIRCUMFLEX, 0), CAPITAL, - LETTER('y',M_CIRCUMFLEX,0), + LETTER('y', M_CIRCUMFLEX, 0), CAPITAL, // Y-DIAERESIS CAPITAL, - LETTER('z',M_ACUTE,0), + LETTER('z', M_ACUTE, 0), CAPITAL, - LETTER('z',M_DOT_ABOVE,0), + LETTER('z', M_DOT_ABOVE, 0), CAPITAL, - LETTER('z',M_CARON,0), - LETTER('s',M_NAME,0), // long-s // U+17f + LETTER('z', M_CARON, 0), + LETTER('s', M_NAME, 0), // long-s // U+17f }; // characters U+0250 to U+029F static const unsigned short letter_accents_250[] = { - LETTER('a',M_TURNED,0), // U+250 - LETTER(L_ALPHA,0,0), - LETTER(L_ALPHA,M_TURNED,0), - LETTER('b',M_IMPLOSIVE,0), + LETTER('a', M_TURNED, 0), // U+250 + LETTER(L_ALPHA, 0, 0), + LETTER(L_ALPHA, M_TURNED, 0), + LETTER('b', M_IMPLOSIVE, 0), 0, // open-o - LETTER('c',M_CURL,0), - LETTER('d',M_RETROFLEX,0), - LETTER('d',M_IMPLOSIVE,0), - LETTER('e',M_REVERSED,0), // U+258 + LETTER('c', M_CURL, 0), + LETTER('d', M_RETROFLEX, 0), + LETTER('d', M_IMPLOSIVE, 0), + LETTER('e', M_REVERSED, 0), // U+258 0, // schwa - LETTER(L_SCHWA,M_HOOK,0), + LETTER(L_SCHWA, M_HOOK, 0), 0, // open-e - LETTER(L_OPEN_E,M_REVERSED,0), - LETTER(L_OPEN_E,M_HOOK,M_REVERSED), + LETTER(L_OPEN_E, M_REVERSED, 0), + LETTER(L_OPEN_E, M_HOOK, M_REVERSED), 0, - LETTER('j',M_BAR,0), - LETTER('g',M_IMPLOSIVE,0), // U+260 - LETTER('g',0,0), - LETTER('g',M_SMALLCAP,0), - LETTER(L_GAMMA,0,0), + LETTER('j', M_BAR, 0), + LETTER('g', M_IMPLOSIVE, 0), // U+260 + LETTER('g', 0, 0), + LETTER('g', M_SMALLCAP, 0), + LETTER(L_GAMMA, 0, 0), 0, // ramshorn - LETTER('h',M_TURNED,0), - LETTER('h',M_HOOK,0), + LETTER('h', M_TURNED, 0), + LETTER('h', M_HOOK, 0), 0, - LETTER('i',M_BAR,0), // U+268 - LETTER(L_IOTA,0,0), - LETTER('i',M_SMALLCAP,0), - LETTER('l',M_TILDE,0), - LETTER('l',M_BAR,0), - LETTER('l',M_RETROFLEX,0), - LIGATURE('l','z',0), - LETTER('m',M_TURNED,0), + LETTER('i', M_BAR, 0), // U+268 + LETTER(L_IOTA, 0, 0), + LETTER('i', M_SMALLCAP, 0), + LETTER('l', M_TILDE, 0), + LETTER('l', M_BAR, 0), + LETTER('l', M_RETROFLEX, 0), + LIGATURE('l', 'z', 0), + LETTER('m', M_TURNED, 0), 0, - LETTER('m',M_HOOK,0), + LETTER('m', M_HOOK, 0), 0, - LETTER('n',M_RETROFLEX,0), - LETTER('n',M_SMALLCAP,0), - LETTER('o',M_BAR,0), - LIGATURE('o','e',M_SMALLCAP), + LETTER('n', M_RETROFLEX, 0), + LETTER('n', M_SMALLCAP, 0), + LETTER('o', M_BAR, 0), + LIGATURE('o', 'e', M_SMALLCAP), 0, - LETTER(L_PHI,0,0), // U+278 - LETTER('r',M_TURNED,0), - LETTER(L_RLONG,M_TURNED,0), - LETTER('r',M_RETROFLEX,M_TURNED), + LETTER(L_PHI, 0, 0), // U+278 + LETTER('r', M_TURNED, 0), + LETTER(L_RLONG, M_TURNED, 0), + LETTER('r', M_RETROFLEX, M_TURNED), 0, - LETTER('r',M_RETROFLEX,0), + LETTER('r', M_RETROFLEX, 0), 0, // r-tap - LETTER(L_RTAP,M_REVERSED,0), - LETTER('r',M_SMALLCAP,0), // U+280 - LETTER('r',M_TURNED,M_SMALLCAP), - LETTER('s',M_RETROFLEX,0), + LETTER(L_RTAP, M_REVERSED, 0), + LETTER('r', M_SMALLCAP, 0), // U+280 + LETTER('r', M_TURNED, M_SMALLCAP), + LETTER('s', M_RETROFLEX, 0), 0, // esh - LETTER('j',M_HOOK,0), - LETTER(L_ESH,M_REVERSED,0), - LETTER(L_ESH,M_CURL,0), - LETTER('t',M_TURNED,0), - LETTER('t',M_RETROFLEX,0), // U+288 - LETTER('u',M_BAR,0), - LETTER(L_UPSILON,0,0), - LETTER('v',M_HOOK,0), - LETTER('v',M_TURNED,0), - LETTER('w',M_TURNED,0), - LETTER('y',M_TURNED,0), - LETTER('y',M_SMALLCAP,0), - LETTER('z',M_RETROFLEX,0), // U+290 - LETTER('z',M_CURL,0), + LETTER('j', M_HOOK, 0), + LETTER(L_ESH, M_REVERSED, 0), + LETTER(L_ESH, M_CURL, 0), + LETTER('t', M_TURNED, 0), + LETTER('t', M_RETROFLEX, 0), // U+288 + LETTER('u', M_BAR, 0), + LETTER(L_UPSILON, 0, 0), + LETTER('v', M_HOOK, 0), + LETTER('v', M_TURNED, 0), + LETTER('w', M_TURNED, 0), + LETTER('y', M_TURNED, 0), + LETTER('y', M_SMALLCAP, 0), + LETTER('z', M_RETROFLEX, 0), // U+290 + LETTER('z', M_CURL, 0), 0, // ezh - LETTER(L_EZH,M_CURL,0), + LETTER(L_EZH, M_CURL, 0), 0, // glottal stop - LETTER(L_GLOTTAL,M_REVERSED,0), - LETTER(L_GLOTTAL,M_TURNED,0), + LETTER(L_GLOTTAL, M_REVERSED, 0), + LETTER(L_GLOTTAL, M_TURNED, 0), 0, 0, // bilabial click // U+298 - LETTER('b',M_SMALLCAP,0), + LETTER('b', M_SMALLCAP, 0), 0, - LETTER('g',M_IMPLOSIVE,M_SMALLCAP), - LETTER('h',M_SMALLCAP,0), - LETTER('j',M_CURL,0), - LETTER('k',M_TURNED,0), - LETTER('l',M_SMALLCAP,0), - LETTER('q',M_HOOK,0), // U+2a0 - LETTER(L_GLOTTAL,M_STROKE,0), - LETTER(L_GLOTTAL,M_STROKE,M_REVERSED), - LIGATURE('d','z',0), + LETTER('g', M_IMPLOSIVE, M_SMALLCAP), + LETTER('h', M_SMALLCAP, 0), + LETTER('j', M_CURL, 0), + LETTER('k', M_TURNED, 0), + LETTER('l', M_SMALLCAP, 0), + LETTER('q', M_HOOK, 0), // U+2a0 + LETTER(L_GLOTTAL, M_STROKE, 0), + LETTER(L_GLOTTAL, M_STROKE, M_REVERSED), + LIGATURE('d', 'z', 0), 0, // dezh - LIGATURE('d','z',M_CURL), - LIGATURE('t','s',0), + LIGATURE('d', 'z', M_CURL), + LIGATURE('t', 's', 0), 0, // tesh - LIGATURE('t','s',M_CURL), + LIGATURE('t', 's', M_CURL), }; static int LookupLetter2(Translator *tr, unsigned int letter, char *ph_buf) @@ -407,15 +407,13 @@ static int LookupLetter2(Translator *tr, unsigned int letter, char *ph_buf) single_letter[len+2] = ' '; single_letter[len+3] = 0; - if(Lookup(tr, &single_letter[1], ph_buf) == 0) - { + if (Lookup(tr, &single_letter[1], ph_buf) == 0) { single_letter[1] = ' '; - if(Lookup(tr, &single_letter[2], ph_buf) == 0) - { - TranslateRules(tr, &single_letter[2], ph_buf, 20, NULL,0,NULL); + if (Lookup(tr, &single_letter[2], ph_buf) == 0) { + TranslateRules(tr, &single_letter[2], ph_buf, 20, NULL, 0, NULL); } } - return(ph_buf[0]); + return (ph_buf[0]); } @@ -427,7 +425,7 @@ void LookupAccentedLetter(Translator *tr, unsigned int letter, char *ph_buf) int accent2 = 0; int flags1, flags2; int basic_letter; - int letter2=0; + int letter2 = 0; char ph_letter1[30]; char ph_letter2[30]; char ph_accent1[30]; @@ -435,69 +433,54 @@ void LookupAccentedLetter(Translator *tr, unsigned int letter, char *ph_buf) ph_accent2[0] = 0; - if((letter >= 0xe0) && (letter < 0x17f)) - { + if ((letter >= 0xe0) && (letter < 0x17f)) { accent_data = letter_accents_0e0[letter - 0xe0]; - } - else if((letter >= 0x250) && (letter <= 0x2a8)) - { + } else if ((letter >= 0x250) && (letter <= 0x2a8)) { accent_data = letter_accents_250[letter - 0x250]; } - if(accent_data != 0) - { + if (accent_data != 0) { basic_letter = (accent_data & 0x3f) + 59; - if(basic_letter < 'a') + if (basic_letter < 'a') basic_letter = non_ascii_tab[basic_letter-59]; - if(accent_data & M_LIGATURE) - { + if (accent_data & M_LIGATURE) { letter2 = (accent_data >> 6) & 0x3f; letter2 += 59; accent2 = (accent_data >> 12) & 0x7; - } - else - { + } else { accent1 = (accent_data >> 6) & 0x1f; accent2 = (accent_data >> 11) & 0xf; } - if((accent1==0) && !(accent_data & M_LIGATURE)) - { + if ((accent1 == 0) && !(accent_data & M_LIGATURE)) { // just a letter name, not an accented character or ligature return; } - if((flags1 = Lookup(tr, accents_tab[accent1].name, ph_accent1)) != 0) - { + if ((flags1 = Lookup(tr, accents_tab[accent1].name, ph_accent1)) != 0) { - if(LookupLetter2(tr, basic_letter, ph_letter1) != 0) - { - if(accent2 != 0) - { + if (LookupLetter2(tr, basic_letter, ph_letter1) != 0) { + if (accent2 != 0) { flags2 = Lookup(tr, accents_tab[accent2].name, ph_accent2); - if(flags2 & FLAG_ACCENT_BEFORE) - { - strcpy(ph_buf,ph_accent2); + if (flags2 & FLAG_ACCENT_BEFORE) { + strcpy(ph_buf, ph_accent2); ph_buf += strlen(ph_buf); ph_accent2[0] = 0; } } - if(letter2 != 0) - { - //ligature + if (letter2 != 0) { + // ligature LookupLetter2(tr, letter2, ph_letter2); - sprintf(ph_buf,"%s%c%s%c%s%s",ph_accent1, phonPAUSE_VSHORT, ph_letter1, phonSTRESS_P, ph_letter2, ph_accent2); - } - else - { - if(accent1 == 0) + sprintf(ph_buf, "%s%c%s%c%s%s", ph_accent1, phonPAUSE_VSHORT, ph_letter1, phonSTRESS_P, ph_letter2, ph_accent2); + } else { + if (accent1 == 0) strcpy(ph_buf, ph_letter1); - else if((tr->langopts.accents & 1) || (flags1 & FLAG_ACCENT_BEFORE) || (accents_tab[accent1].accent_flags & 1)) - sprintf(ph_buf,"%s%c%c%s", ph_accent1, phonPAUSE_VSHORT, phonSTRESS_P, ph_letter1); + else if ((tr->langopts.accents & 1) || (flags1 & FLAG_ACCENT_BEFORE) || (accents_tab[accent1].accent_flags & 1)) + sprintf(ph_buf, "%s%c%c%s", ph_accent1, phonPAUSE_VSHORT, phonSTRESS_P, ph_letter1); else - sprintf(ph_buf,"%c%s%c%s%c", phonSTRESS_2, ph_letter1, phonPAUSE_VSHORT, ph_accent1, phonPAUSE_VSHORT); + sprintf(ph_buf, "%c%s%c%s%c", phonSTRESS_2, ph_letter1, phonPAUSE_VSHORT, ph_accent1, phonPAUSE_VSHORT); } } } @@ -511,47 +494,44 @@ void LookupLetter(Translator *tr, unsigned int letter, int next_byte, char *ph_b // control, bit 0: not the first letter of a word int len; - static char single_letter[10] = {0,0}; + static char single_letter[10] = { 0, 0 }; unsigned int dict_flags[2]; char ph_buf3[40]; ph_buf1[0] = 0; - len = utf8_out(letter,&single_letter[2]); + len = utf8_out(letter, &single_letter[2]); single_letter[len+2] = ' '; - if(next_byte == -1) - { + if (next_byte == -1) { // speaking normal text, not individual characters - if(Lookup(tr, &single_letter[2], ph_buf1) != 0) + if (Lookup(tr, &single_letter[2], ph_buf1) != 0) return; single_letter[1] = '_'; - if(Lookup(tr, &single_letter[1], ph_buf3) != 0) + if (Lookup(tr, &single_letter[1], ph_buf3) != 0) return; // the character is specified as _* so ignore it when speaking normal text // check whether this character is specified for English - if(tr->translator_name == L('e','n')) + if (tr->translator_name == L('e', 'n')) return; // we are already using English SetTranslator2("en"); - if(Lookup(translator2, &single_letter[2], ph_buf3) != 0) - { + if (Lookup(translator2, &single_letter[2], ph_buf3) != 0) { // yes, switch to English and re-translate the word - sprintf(ph_buf1,"%c",phonSWITCH); + sprintf(ph_buf1, "%c", phonSWITCH); } SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table return; } - if((letter <= 32) || iswspace(letter)) - { + if ((letter <= 32) || iswspace(letter)) { // lookup space as _&32 etc. - sprintf(&single_letter[1],"_#%d ",letter); + sprintf(&single_letter[1], "_#%d ", letter); Lookup(tr, &single_letter[1], ph_buf1); return; } - if(next_byte != ' ') + if (next_byte != ' ') next_byte = RULE_SPELLING; single_letter[3+len] = next_byte; // follow by space-space if the end of the word, or space-31 @@ -560,23 +540,19 @@ void LookupLetter(Translator *tr, unsigned int letter, int next_byte, char *ph_b // if the $accent flag is set for this letter, use the accents table (below) dict_flags[1] = 0; - if(Lookup(tr, &single_letter[1], ph_buf3) == 0) - { + if (Lookup(tr, &single_letter[1], ph_buf3) == 0) { single_letter[1] = ' '; - if(Lookup(tr, &single_letter[2], ph_buf3) == 0) - { - TranslateRules(tr, &single_letter[2], ph_buf3, sizeof(ph_buf3), NULL,FLAG_NO_TRACE,NULL); + if (Lookup(tr, &single_letter[2], ph_buf3) == 0) { + TranslateRules(tr, &single_letter[2], ph_buf3, sizeof(ph_buf3), NULL, FLAG_NO_TRACE, NULL); } } - if(ph_buf3[0] == 0) - { + if (ph_buf3[0] == 0) { LookupAccentedLetter(tr, letter, ph_buf3); } strcpy(ph_buf1, ph_buf3); - if((ph_buf1[0] == 0) || (ph_buf1[0] == phonSWITCH)) - { + if ((ph_buf1[0] == 0) || (ph_buf1[0] == phonSWITCH)) { return; } @@ -602,20 +578,19 @@ int NonAsciiNumber(int letter) const int *p; int base; - for(p=number_ranges; (base = *p) != 0; p++) - { - if(letter < base) + for (p = number_ranges; (base = *p) != 0; p++) { + if (letter < base) break; // not found - if(letter < (base+10)) - return(letter-base+'0'); + if (letter < (base+10)) + return (letter-base+'0'); } - return(-1); + return (-1); } #define L_SUB 0x4000 // subscript #define L_SUP 0x8000 // superscript -static const char *modifiers[] = {NULL, "_sub", "_sup", NULL}; +static const char *modifiers[] = { NULL, "_sub", "_sup", NULL }; // this list must be in ascending order static unsigned short derived_letters[] = { @@ -681,11 +656,11 @@ static unsigned short derived_letters[] = { 0x209a, 'p'+L_SUB, 0x209b, 's'+L_SUB, 0x209c, 't'+L_SUB, - 0,0 + 0, 0 }; -static const char *hex_letters[] = {"'e:j","b'i:","s'i:","d'i:","'i:","'ef"}; // names, using phonemes available to all languages +static const char *hex_letters[] = { "'e:j", "b'i:", "s'i:", "d'i:", "'i:", "'ef" }; // names, using phonemes available to all languages int IsSuperscript(int letter) @@ -694,14 +669,13 @@ int IsSuperscript(int letter) int ix; int c; - for(ix=0; (c = derived_letters[ix]) != 0; ix+=2) - { - if(c > letter) + for (ix = 0; (c = derived_letters[ix]) != 0; ix += 2) { + if (c > letter) break; - if(c == letter) - return(derived_letters[ix+1]); + if (c == letter) + return (derived_letters[ix+1]); } - return(0); + return (0); } @@ -734,47 +708,39 @@ int TranslateLetter(Translator *tr, char *word, char *phonemes, int control) char ph_buf2[80]; char ph_alphabet[80]; char hexbuf[12]; - static char pause_string[] = {phonPAUSE, 0}; + static char pause_string[] = { phonPAUSE, 0 }; ph_buf[0] = 0; ph_alphabet[0] = 0; capital[0] = 0; phontab_1 = translator->phoneme_tab_ix; - n_bytes = utf8_in(&letter,word); + n_bytes = utf8_in(&letter, word); - if((letter & 0xfff00) == 0x0e000) - { + if ((letter & 0xfff00) == 0x0e000) { letter &= 0xff; // uncode private usage area } - if(control & 2) - { + if (control & 2) { // include CAPITAL information - if(iswupper2(letter)) - { + if (iswupper2(letter)) { Lookup(tr, "_cap", capital); } } letter = towlower2(letter); LookupLetter(tr, letter, word[n_bytes], ph_buf, control & 1); - if(ph_buf[0] == 0) - { + if (ph_buf[0] == 0) { // is this a subscript or superscript letter ? - if((c = IsSuperscript(letter)) != 0) - { + if ((c = IsSuperscript(letter)) != 0) { letter = c & 0x3fff; - if((control & 4 ) && ((modifier = modifiers[c >> 14]) != NULL)) - { + if ((control & 4 ) && ((modifier = modifiers[c >> 14]) != NULL)) { // don't say "superscript" during normal text reading Lookup(tr, modifier, capital); - if(capital[0] == 0) - { + if (capital[0] == 0) { capital[2] = SetTranslator2("en"); // overwrites previous contents of translator2 Lookup(translator2, modifier, &capital[3]); - if(capital[3] != 0) - { + if (capital[3] != 0) { capital[0] = phonPAUSE; capital[1] = phonSWITCH; len = strlen(&capital[3]); @@ -788,55 +754,43 @@ int TranslateLetter(Translator *tr, char *word, char *phonemes, int control) LookupLetter(tr, letter, word[n_bytes], ph_buf, control & 1); } - if(ph_buf[0] == phonSWITCH) - { - strcpy(phonemes,ph_buf); - return(0); + if (ph_buf[0] == phonSWITCH) { + strcpy(phonemes, ph_buf); + return (0); } - if((ph_buf[0] == 0) && ((number = NonAsciiNumber(letter)) > 0)) - { + if ((ph_buf[0] == 0) && ((number = NonAsciiNumber(letter)) > 0)) { // convert a non-ascii number to 0-9 LookupLetter(tr, number, 0, ph_buf, control & 1); } al_offset = 0; al_flags = 0; - if((alphabet = AlphabetFromChar(letter)) != NULL) - { + if ((alphabet = AlphabetFromChar(letter)) != NULL) { al_offset = alphabet->offset; al_flags = alphabet->flags; } - if(alphabet != current_alphabet) - { + if (alphabet != current_alphabet) { // speak the name of the alphabet current_alphabet = alphabet; - if((alphabet != NULL) && !(al_flags & AL_DONT_NAME) && (al_offset != translator->letter_bits_offset)) - { - if((al_flags & AL_DONT_NAME) || (al_offset == translator->langopts.alt_alphabet) || (al_offset == translator->langopts.our_alphabet)) - { + if ((alphabet != NULL) && !(al_flags & AL_DONT_NAME) && (al_offset != translator->letter_bits_offset)) { + if ((al_flags & AL_DONT_NAME) || (al_offset == translator->langopts.alt_alphabet) || (al_offset == translator->langopts.our_alphabet)) { // don't say the alphabet name - } - else - { + } else { ph_buf2[0] = 0; - if(Lookup(translator, alphabet->name, ph_alphabet) == 0) // the original language for the current voice - { + if (Lookup(translator, alphabet->name, ph_alphabet) == 0) { // the original language for the current voice // Can't find the local name for this alphabet, use the English name ph_alphabet[2] = SetTranslator2("en"); // overwrites previous contents of translator2 Lookup(translator2, alphabet->name, ph_buf2); - } - else if(translator != tr) - { + } else if (translator != tr) { phontab_1 = tr->phoneme_tab_ix; strcpy(ph_buf2, ph_alphabet); ph_alphabet[2] = translator->phoneme_tab_ix; } - if(ph_buf2[0] != 0) - { + if (ph_buf2[0] != 0) { // we used a different language for the alphabet name (now in ph_buf2) ph_alphabet[0] = phonPAUSE; ph_alphabet[1] = phonSWITCH; @@ -853,18 +807,15 @@ int TranslateLetter(Translator *tr, char *word, char *phonemes, int control) // caution: SetWordStress() etc don't expect phonSWITCH + phoneme table number - if(ph_buf[0] == 0) - { - if((al_offset != 0) && (al_offset == translator->langopts.alt_alphabet)) + if (ph_buf[0] == 0) { + if ((al_offset != 0) && (al_offset == translator->langopts.alt_alphabet)) language = translator->langopts.alt_alphabet_lang; - else - if((alphabet != NULL) && (alphabet->language != 0) && !(al_flags & AL_NOT_LETTERS)) + else if ((alphabet != NULL) && (alphabet->language != 0) && !(al_flags & AL_NOT_LETTERS)) language = alphabet->language; else - language = L('e','n'); + language = L('e', 'n'); - if((language != tr->translator_name) || (language == L('k','o'))) - { + if ((language != tr->translator_name) || (language == L('k', 'o'))) { char *p3; int initial, code; char hangul_buf[12]; @@ -872,17 +823,14 @@ int TranslateLetter(Translator *tr, char *word, char *phonemes, int control) // speak in the language for this alphabet (or English) ph_buf[2] = SetTranslator2(WordToString2(language)); - if(translator2 != NULL) - { - if(((code = letter - 0xac00) >= 0) && (letter <= 0xd7af)) - { + if (translator2 != NULL) { + if (((code = letter - 0xac00) >= 0) && (letter <= 0xd7af)) { // Special case for Korean letters. // break a syllable hangul into 2 or 3 individual jamo hangul_buf[0] = ' '; p3 = &hangul_buf[1]; - if((initial = (code/28)/21) != 11) - { + if ((initial = (code/28)/21) != 11) { p3 += utf8_out(initial + 0x1100, p3); } utf8_out(((code/28) % 21) + 0x1161, p3); // medial @@ -892,14 +840,11 @@ int TranslateLetter(Translator *tr, char *word, char *phonemes, int control) ph_buf[3] = 0; TranslateRules(translator2, &hangul_buf[1], &ph_buf[3], sizeof(ph_buf)-3, NULL, 0, NULL); SetWordStress(translator2, &ph_buf[3], NULL, -1, 0); - } - else - { + } else { LookupLetter(translator2, letter, word[n_bytes], &ph_buf[3], control & 1); } - if(ph_buf[3] == phonSWITCH) - { + if (ph_buf[3] == phonSWITCH) { // another level of language change ph_buf[2] = SetTranslator2(&ph_buf[4]); LookupLetter(translator2, letter, word[n_bytes], &ph_buf[3], control & 1); @@ -907,8 +852,7 @@ int TranslateLetter(Translator *tr, char *word, char *phonemes, int control) SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table - if(ph_buf[3] != 0) - { + if (ph_buf[3] != 0) { ph_buf[0] = phonPAUSE; ph_buf[1] = phonSWITCH; len = strlen(&ph_buf[3]) + 3; @@ -920,62 +864,49 @@ int TranslateLetter(Translator *tr, char *word, char *phonemes, int control) } } - if(ph_buf[0] == 0) - { + if (ph_buf[0] == 0) { // character name not found - if(ph_buf[0]== 0) - { + if (ph_buf[0] == 0) { speak_letter_number = 1; - if(!(al_flags & AL_NO_SYMBOL)) - { - if(iswalpha2(letter)) + if (!(al_flags & AL_NO_SYMBOL)) { + if (iswalpha2(letter)) Lookup(translator, "_?A", ph_buf); - if((ph_buf[0]==0) && !iswspace(letter)) + if ((ph_buf[0] == 0) && !iswspace(letter)) Lookup(translator, "_??", ph_buf); - if(ph_buf[0] == 0) - { + if (ph_buf[0] == 0) { EncodePhonemes("l'et@", ph_buf, NULL); } } - if(!(control & 4) && (al_flags & AL_NOT_CODE)) - { + if (!(control & 4) && (al_flags & AL_NOT_CODE)) { // don't speak the character code number, unless we want full details of this character speak_letter_number = 0; } - if(speak_letter_number) - { - if(al_offset == 0x2800) - { + if (speak_letter_number) { + if (al_offset == 0x2800) { // braille dots symbol, list the numbered dots p2 = hexbuf; - for(ix=0; ix<8; ix++) - { - if(letter & (1 << ix)) - { + for (ix = 0; ix < 8; ix++) { + if (letter & (1 << ix)) { *p2++ = '1'+ix; } } *p2 = 0; - } - else - { + } else { // speak the hexadecimal number of the character code - sprintf(hexbuf,"%x",letter); + sprintf(hexbuf, "%x", letter); } pbuf = ph_buf; - for(p2 = hexbuf; *p2 != 0; p2++) - { + for (p2 = hexbuf; *p2 != 0; p2++) { pbuf += strlen(pbuf); *pbuf++ = phonPAUSE_VSHORT; LookupLetter(translator, *p2, 0, pbuf, 1); - if(((pbuf[0] == 0) || (pbuf[0]==phonSWITCH)) && (*p2 >= 'a')) - { + if (((pbuf[0] == 0) || (pbuf[0] == phonSWITCH)) && (*p2 >= 'a')) { // This language has no translation for 'a' to 'f', speak English names using base phonemes EncodePhonemes(hex_letters[*p2 - 'a'], pbuf, NULL); } @@ -987,15 +918,14 @@ int TranslateLetter(Translator *tr, char *word, char *phonemes, int control) len = strlen(phonemes); - if(tr->langopts.accents & 2) // 'capital' before or after the word ? - sprintf(ph_buf2,"%c%s%s%s",0xff,ph_alphabet,ph_buf,capital); + if (tr->langopts.accents & 2) // 'capital' before or after the word ? + sprintf(ph_buf2, "%c%s%s%s", 0xff, ph_alphabet, ph_buf, capital); else - sprintf(ph_buf2,"%c%s%s%s",0xff,ph_alphabet,capital,ph_buf); // the 0xff marker will be removed or replaced in SetSpellingStress() - if((len + strlen(ph_buf2)) < N_WORD_PHONEMES) - { - strcpy(&phonemes[len],ph_buf2); + sprintf(ph_buf2, "%c%s%s%s", 0xff, ph_alphabet, capital, ph_buf); // the 0xff marker will be removed or replaced in SetSpellingStress() + if ((len + strlen(ph_buf2)) < N_WORD_PHONEMES) { + strcpy(&phonemes[len], ph_buf2); } - return(n_bytes); + return (n_bytes); } @@ -1005,15 +935,13 @@ void SetSpellingStress(Translator *tr, char *phonemes, int control, int n_chars) // Individual letter names, reduce the stress of some. int ix; unsigned int c; - int n_stress=0; + int n_stress = 0; int prev = 0; int count; unsigned char buf[N_WORD_PHONEMES]; - for(ix=0; (c = phonemes[ix]) != 0; ix++) - { - if((c == phonSTRESS_P) && (prev != phonSWITCH)) - { + for (ix = 0; (c = phonemes[ix]) != 0; ix++) { + if ((c == phonSTRESS_P) && (prev != phonSWITCH)) { n_stress++; } buf[ix] = prev = c; @@ -1022,42 +950,34 @@ void SetSpellingStress(Translator *tr, char *phonemes, int control, int n_chars) count = 0; prev = 0; - for(ix=0; (c = buf[ix]) != 0; ix++) - { - if((c == phonSTRESS_P) && (n_chars > 1) && (prev != phonSWITCH)) - { + for (ix = 0; (c = buf[ix]) != 0; ix++) { + if ((c == phonSTRESS_P) && (n_chars > 1) && (prev != phonSWITCH)) { count++; - if(tr->langopts.spelling_stress == 1) - { + if (tr->langopts.spelling_stress == 1) { // stress on initial letter when spelling - if(count > 1) + if (count > 1) c = phonSTRESS_3; - } - else - { - if(count != n_stress) - { - if(((count % 3) != 0) || (count == n_stress-1)) + } else { + if (count != n_stress) { + if (((count % 3) != 0) || (count == n_stress-1)) c = phonSTRESS_3; // reduce to secondary stress } } - } - else if(c == 0xff) - { - if((control < 2) || (ix==0)) + } else if (c == 0xff) { + if ((control < 2) || (ix == 0)) continue; // don't insert pauses - if(control == 4) + if (control == 4) c = phonPAUSE; // pause after each character - if(((count % 3) == 0) || (control > 2)) + if (((count % 3) == 0) || (control > 2)) c = phonPAUSE_NOLINK; // pause following a primary stress else c = phonPAUSE_VSHORT; } *phonemes++ = prev = c; } - if(control >= 2) + if (control >= 2) *phonemes++ = phonPAUSE_NOLINK; *phonemes = 0; } @@ -1077,52 +997,46 @@ static int CheckDotOrdinal(Translator *tr, char *word, char *word_end, WORD_TAB int c2; int nextflags; - if((tr->langopts.numbers & NUM_ORDINAL_DOT) && ((word_end[0] == '.') || (wtab[0].flags & FLAG_HAS_DOT)) && !(wtab[1].flags & FLAG_NOSPACE)) - { - if(roman || !(wtab[1].flags & FLAG_FIRST_UPPER)) - { - if(word_end[0] == '.') + if ((tr->langopts.numbers & NUM_ORDINAL_DOT) && ((word_end[0] == '.') || (wtab[0].flags & FLAG_HAS_DOT)) && !(wtab[1].flags & FLAG_NOSPACE)) { + if (roman || !(wtab[1].flags & FLAG_FIRST_UPPER)) { + if (word_end[0] == '.') utf8_in(&c2, &word_end[2]); else utf8_in(&c2, &word_end[0]); - if((word_end[0] != 0) && (word_end[1] != 0) && ((c2 == 0) || (wtab[0].flags & FLAG_COMMA_AFTER) || IsAlpha(c2))) - { + if ((word_end[0] != 0) && (word_end[1] != 0) && ((c2 == 0) || (wtab[0].flags & FLAG_COMMA_AFTER) || IsAlpha(c2))) { // ordinal number is indicated by dot after the number // but not if the next word starts with an upper-case letter // (c2 == 0) is for cases such as, "2.," ordinal = 2; - if(word_end[0] == '.') + if (word_end[0] == '.') word_end[0] = ' '; - if((roman==0) && (tr->translator_name == L('h','u'))) - { + if ((roman == 0) && (tr->translator_name == L('h', 'u'))) { // lang=hu don't treat dot as ordinal indicator if the next word is a month name ($alt). It may have a suffix. nextflags = 0; - if(IsAlpha(c2)) - { + if (IsAlpha(c2)) { nextflags = TranslateWord(tr, &word_end[2], 0, NULL, NULL); } - if((tr->prev_dict_flags[0] & FLAG_ALT_TRANS) && ((c2 == 0) || (wtab[0].flags & FLAG_COMMA_AFTER) || iswdigit(c2))) + if ((tr->prev_dict_flags[0] & FLAG_ALT_TRANS) && ((c2 == 0) || (wtab[0].flags & FLAG_COMMA_AFTER) || iswdigit(c2))) ordinal = 0; // TEST 09.02.10 - if(nextflags & FLAG_ALT_TRANS) + if (nextflags & FLAG_ALT_TRANS) ordinal = 0; - if(nextflags & FLAG_ALT3_TRANS) - { - if(word[-2] == '-') + if (nextflags & FLAG_ALT3_TRANS) { + if (word[-2] == '-') ordinal = 0; // eg. december 2-5. között - if(tr->prev_dict_flags[0] & (FLAG_ALT_TRANS | FLAG_ALT3_TRANS)) + if (tr->prev_dict_flags[0] & (FLAG_ALT_TRANS | FLAG_ALT3_TRANS)) ordinal = 0x22; } } } } } - return(ordinal); + return (ordinal); } @@ -1130,17 +1044,16 @@ static int hu_number_e(const char *word, int thousandplex, int value) { // lang-hu: variant form of numbers when followed by hyphen and a suffix starting with 'a' or 'e' (but not a, e, az, ez, azt, ezt, att. ett - if((word[0] == 'a') || (word[0] == 'e')) - { - if((word[1] == ' ') || (word[1] == 'z') || ((word[1] == 't') && (word[2] == 't'))) - return(0); + if ((word[0] == 'a') || (word[0] == 'e')) { + if ((word[1] == ' ') || (word[1] == 'z') || ((word[1] == 't') && (word[2] == 't'))) + return (0); - if(((thousandplex==1) || ((value % 1000) == 0)) && (word[1] == 'l')) - return(0); // 1000-el + if (((thousandplex == 1) || ((value % 1000) == 0)) && (word[1] == 'l')) + return (0); // 1000-el - return(1); + return (1); } - return(0); + return (0); } @@ -1163,7 +1076,7 @@ int TranslateRoman(Translator *tr, char *word, char *ph_out, WORD_TAB *wtab) char number_chars[N_WORD_BYTES]; static const char *roman_numbers = "ixcmvld"; - static int roman_values[] = {1,10,100,1000,5,50,500}; + static int roman_values[] = { 1, 10, 100, 1000, 5, 50, 500 }; acc = 0; prev = 0; @@ -1172,103 +1085,85 @@ int TranslateRoman(Translator *tr, char *word, char *ph_out, WORD_TAB *wtab) flags[0] = 0; flags[1] = 0; - if(((tr->langopts.numbers & NUM_ROMAN_CAPITALS) && !(wtab[0].flags & FLAG_ALL_UPPER)) || IsDigit09(word[-2])) - return(0); // not '2xx' + if (((tr->langopts.numbers & NUM_ROMAN_CAPITALS) && !(wtab[0].flags & FLAG_ALL_UPPER)) || IsDigit09(word[-2])) + return (0); // not '2xx' - if(word[1] == ' ') - { - if((tr->langopts.numbers & (NUM_ROMAN_CAPITALS | NUM_ROMAN_ORDINAL | NUM_ORDINAL_DOT)) && (wtab[0].flags & FLAG_HAS_DOT)) - { + if (word[1] == ' ') { + if ((tr->langopts.numbers & (NUM_ROMAN_CAPITALS | NUM_ROMAN_ORDINAL | NUM_ORDINAL_DOT)) && (wtab[0].flags & FLAG_HAS_DOT)) { // allow single letter Roman ordinal followed by dot. - } - else - return(0); // only one letter, don't speak as a Roman Number + } else + return (0); // only one letter, don't speak as a Roman Number } word_start = word; - while((c = *word++) != ' ') - { - if((p2 = strchr(roman_numbers,c)) == NULL) - return(0); + while ((c = *word++) != ' ') { + if ((p2 = strchr(roman_numbers, c)) == NULL) + return (0); value = roman_values[p2 - roman_numbers]; - if(value == prev) - { + if (value == prev) { repeat++; - if(repeat >= 3) - return(0); - } - else + if (repeat >= 3) + return (0); + } else repeat = 0; - if((prev > 1) && (prev != 10) && (prev != 100)) - { - if(value >= prev) - return(0); + if ((prev > 1) && (prev != 10) && (prev != 100)) { + if (value >= prev) + return (0); } - if((prev != 0) && (prev < value)) - { - if(((acc % 10) != 0) || ((prev*10) < value)) - return(0); + if ((prev != 0) && (prev < value)) { + if (((acc % 10) != 0) || ((prev*10) < value)) + return (0); subtract = prev; value -= subtract; - } - else if(value >= subtract) - return(0); + } else if (value >= subtract) + return (0); else acc += prev; prev = value; n_digits++; } - if(IsDigit09(word[0])) - return(0); // eg. 'xx2' + if (IsDigit09(word[0])) + return (0); // eg. 'xx2' acc += prev; - if(acc < tr->langopts.min_roman) - return(0); + if (acc < tr->langopts.min_roman) + return (0); - if(acc > tr->langopts.max_roman) - return(0); + if (acc > tr->langopts.max_roman) + return (0); - Lookup(tr, "_roman",ph_roman); // precede by "roman" if _rom is defined in *_list + Lookup(tr, "_roman", ph_roman); // precede by "roman" if _rom is defined in *_list p = &ph_out[0]; - if((tr->langopts.numbers & NUM_ROMAN_AFTER) == 0) - { - strcpy(ph_out,ph_roman); + if ((tr->langopts.numbers & NUM_ROMAN_AFTER) == 0) { + strcpy(ph_out, ph_roman); p = &ph_out[strlen(ph_roman)]; } - sprintf(number_chars," %d %s ",acc, tr->langopts.roman_suffix); + sprintf(number_chars, " %d %s ", acc, tr->langopts.roman_suffix); - if(word[0] == '.') - { + if (word[0] == '.') { // dot has not been removed. This implies that there was no space after it - return(0); + return (0); } - if(CheckDotOrdinal(tr, word_start, word, wtab, 1)) + if (CheckDotOrdinal(tr, word_start, word, wtab, 1)) wtab[0].flags |= FLAG_ORDINAL; - if(tr->langopts.numbers & NUM_ROMAN_ORDINAL) - { - if(tr->translator_name == L('h','u')) - { - if(!(wtab[0].flags & FLAG_ORDINAL)) - { - if((wtab[0].flags & FLAG_HYPHEN_AFTER) && hu_number_e(word, 0, acc)) - { + if (tr->langopts.numbers & NUM_ROMAN_ORDINAL) { + if (tr->translator_name == L('h', 'u')) { + if (!(wtab[0].flags & FLAG_ORDINAL)) { + if ((wtab[0].flags & FLAG_HYPHEN_AFTER) && hu_number_e(word, 0, acc)) { // should use the 'e' form of the number num_control |= 1; - } - else - return(0); + } else + return (0); } - } - else - { + } else { wtab[0].flags |= FLAG_ORDINAL; } } @@ -1277,10 +1172,10 @@ int TranslateRoman(Translator *tr, char *word, char *ph_out, WORD_TAB *wtab) tr->prev_dict_flags[1] = 0; TranslateNumber(tr, &number_chars[2], p, flags, wtab, num_control); - if(tr->langopts.numbers & NUM_ROMAN_AFTER) - strcat(ph_out,ph_roman); + if (tr->langopts.numbers & NUM_ROMAN_AFTER) + strcat(ph_out, ph_roman); - return(1); + return (1); } @@ -1290,44 +1185,43 @@ static const char *M_Variant(int value) int teens = 0; - if(((value % 100) > 10) && ((value % 100) < 20)) + if (((value % 100) > 10) && ((value % 100) < 20)) teens = 1; - switch((translator->langopts.numbers2 >> 6) & 0x7) + switch ((translator->langopts.numbers2 >> 6) & 0x7) { case 1: // lang=ru use singular for xx1 except for x11 - if((teens == 0) && ((value % 10) == 1)) - return("1M"); + if ((teens == 0) && ((value % 10) == 1)) + return ("1M"); break; case 2: // lang=cs,sk - if((value >= 2) && (value <= 4)) - return("0MA"); + if ((value >= 2) && (value <= 4)) + return ("0MA"); break; case 3: // lang=pl - if((teens == 0) && (((value % 10) >= 2) && ((value % 10) <= 4))) - return("0MA"); + if ((teens == 0) && (((value % 10) >= 2) && ((value % 10) <= 4))) + return ("0MA"); break; case 4: // lang=lt - if((teens == 1) || ((value % 10) == 0)) - return("0MB"); - if((value % 10) == 1) - return("0MA"); + if ((teens == 1) || ((value % 10) == 0)) + return ("0MB"); + if ((value % 10) == 1) + return ("0MA"); break; case 5: // lang=bs,hr,sr - if(teens == 0) - { - if((value % 10) == 1) - return("1M"); - if(((value % 10) >= 2) && ((value % 10) <= 4)) - return("0MA"); + if (teens == 0) { + if ((value % 10) == 1) + return ("1M"); + if (((value % 10) >= 2) && ((value % 10) <= 4)) + return ("0MA"); } break; } - return("0M"); + return ("0M"); } @@ -1335,7 +1229,7 @@ static int LookupThousands(Translator *tr, int value, int thousandplex, int thou { // thousands_exact: bit 0 no hundreds,tens,or units, bit 1 ordinal numberr int found; - int found_value=0; + int found_value = 0; char string[12]; char ph_of[12]; char ph_thousands[40]; @@ -1344,98 +1238,81 @@ static int LookupThousands(Translator *tr, int value, int thousandplex, int thou ph_of[0] = 0; // first look for a match with the exact value of thousands - if(value > 0) - { - if(thousands_exact & 1) - { - if(thousands_exact & 2) - { + if (value > 0) { + if (thousands_exact & 1) { + if (thousands_exact & 2) { // ordinal number - sprintf(string,"_%dM%do",value,thousandplex); + sprintf(string, "_%dM%do", value, thousandplex); found_value = Lookup(tr, string, ph_thousands); } - if(!found_value && (number_control & 1)) - { + if (!found_value && (number_control & 1)) { // look for the 'e' variant - sprintf(string,"_%dM%de",value,thousandplex); + sprintf(string, "_%dM%de", value, thousandplex); found_value = Lookup(tr, string, ph_thousands); } - if(!found_value) - { + if (!found_value) { // is there a different pronunciation if there are no hundreds,tens,or units ? (LANG=ta) - sprintf(string,"_%dM%dx",value,thousandplex); + sprintf(string, "_%dM%dx", value, thousandplex); found_value = Lookup(tr, string, ph_thousands); } } - if(found_value == 0) - { - sprintf(string,"_%dM%d",value,thousandplex); + if (found_value == 0) { + sprintf(string, "_%dM%d", value, thousandplex); found_value = Lookup(tr, string, ph_thousands); } } - if(found_value == 0) - { - if((value % 100) >= 20) - { + if (found_value == 0) { + if ((value % 100) >= 20) { Lookup(tr, "_0of", ph_of); } found = 0; - if(thousands_exact & 1) - { - if(thousands_exact & 2) - { + if (thousands_exact & 1) { + if (thousands_exact & 2) { // ordinal number - sprintf(string,"_%s%do",M_Variant(value), thousandplex); + sprintf(string, "_%s%do", M_Variant(value), thousandplex); found = Lookup(tr, string, ph_thousands); } - if(!found && (number_control & 1)) - { + if (!found && (number_control & 1)) { // look for the 'e' variant - sprintf(string,"_%s%de",M_Variant(value), thousandplex); + sprintf(string, "_%s%de", M_Variant(value), thousandplex); found = Lookup(tr, string, ph_thousands); } - if(!found) - { + if (!found) { // is there a different pronunciation if there are no hundreds,tens,or units ? - sprintf(string,"_%s%dx",M_Variant(value), thousandplex); + sprintf(string, "_%s%dx", M_Variant(value), thousandplex); found = Lookup(tr, string, ph_thousands); } } - if(found == 0) - { - sprintf(string,"_%s%d",M_Variant(value), thousandplex); + if (found == 0) { + sprintf(string, "_%s%d", M_Variant(value), thousandplex); - if(Lookup(tr, string, ph_thousands) == 0) - { - if(thousandplex > 3) - { - sprintf(string,"_0M%d", thousandplex-1); - if(Lookup(tr, string, ph_buf) == 0) - { + if (Lookup(tr, string, ph_thousands) == 0) { + if (thousandplex > 3) { + sprintf(string, "_0M%d", thousandplex-1); + if (Lookup(tr, string, ph_buf) == 0) { // say "millions" if this name is not available and neither is the next lower Lookup(tr, "_0M2", ph_thousands); speak_missing_thousands = 3; } } - if(ph_thousands[0] == 0) - { + if (ph_thousands[0] == 0) { // repeat "thousand" if higher order names are not available - sprintf(string,"_%dM1",value); - if((found_value = Lookup(tr, string, ph_thousands)) == 0) + sprintf(string, "_%dM1", value); + if ((found_value = Lookup(tr, string, ph_thousands)) == 0) Lookup(tr, "_0M1", ph_thousands); speak_missing_thousands = 2; } } } } - sprintf(ph_out,"%s%s",ph_of,ph_thousands); + sprintf(ph_out, "%s%s", ph_of, ph_thousands); - if((value == 1) && (thousandplex == 1) && (tr->langopts.numbers & NUM_OMIT_1_THOUSAND)) - return(1); + if ((value == 1) && (thousandplex == 1) && (tr->langopts.numbers & NUM_OMIT_1_THOUSAND)) + return (1); - return(found_value); + return (found_value); } @@ -1456,7 +1333,7 @@ static int LookupNum2(Translator *tr, int value, int thousandplex, const int con int units; int tens; int is_ordinal; - int used_and=0; + int used_and = 0; int found_ordinal = 0; int next_phtype; int ord_type = 'o'; @@ -1475,85 +1352,64 @@ static int LookupNum2(Translator *tr, int value, int thousandplex, const int con ph_digits[0] = 0; ph_and[0] = 0; - if(control & 0x20) - { + if (control & 0x20) { ord_type = 'q'; } is_ordinal = control & 1; - if((control & 2) && (n_digit_lookup == 2)) - { + if ((control & 2) && (n_digit_lookup == 2)) { // pronunciation of the final 2 digits has already been found strcpy(ph_out, digit_lookup); - } - else - { - if(digit_lookup[0] == 0) - { + } else { + if (digit_lookup[0] == 0) { // is there a special pronunciation for this 2-digit number - if(control & 8) - { + if (control & 8) { // is there a feminine or thousands-variant form? - sprintf(string,"_%dfx",value); - if((found = Lookup(tr, string, ph_digits)) == 0) - { - sprintf(string,"_%df",value); + sprintf(string, "_%dfx", value); + if ((found = Lookup(tr, string, ph_digits)) == 0) { + sprintf(string, "_%df", value); found = Lookup(tr, string, ph_digits); } - } - else if(is_ordinal) - { + } else if (is_ordinal) { strcpy(ph_ordinal, ph_ordinal2); - if(control & 4) - { - sprintf(string,"_%d%cx",value,ord_type); // LANG=hu, special word for 1. 2. when there are no higher digits - if((found = Lookup(tr, string, ph_digits)) != 0) - { - if(ph_ordinal2x[0] != 0) + if (control & 4) { + sprintf(string, "_%d%cx", value, ord_type); // LANG=hu, special word for 1. 2. when there are no higher digits + if ((found = Lookup(tr, string, ph_digits)) != 0) { + if (ph_ordinal2x[0] != 0) strcpy(ph_ordinal, ph_ordinal2x); // alternate pronunciation (lang=an) } } - if(found == 0) - { - sprintf(string,"_%d%c",value,ord_type); + if (found == 0) { + sprintf(string, "_%d%c", value, ord_type); found = Lookup(tr, string, ph_digits); } found_ordinal = found; } - if(found == 0) - { - if(control & 2) - { + if (found == 0) { + if (control & 2) { // the final tens and units of a number - if(number_control & 1) - { + if (number_control & 1) { // look for 'e' variant - sprintf(string,"_%de",value); + sprintf(string, "_%de", value); found = Lookup(tr, string, ph_digits); } - } - else - { + } else { // followed by hundreds or thousands etc - if((tr->langopts.numbers2 & NUM2_ORDINAL_AND_THOUSANDS) && (thousandplex <= 1)) + if ((tr->langopts.numbers2 & NUM2_ORDINAL_AND_THOUSANDS) && (thousandplex <= 1)) sprintf(string, "_%do", value); // LANG=TA else sprintf(string, "_%da", value); found = Lookup(tr, string, ph_digits); } - if(!found) - { - if((is_ordinal) && (tr->langopts.numbers2 & NUM2_NO_TEEN_ORDINALS)) - { + if (!found) { + if ((is_ordinal) && (tr->langopts.numbers2 & NUM2_NO_TEEN_ORDINALS)) { // don't use numbers 10-99 to make ordinals, always use _1Xo etc (lang=pt) - } - else - { - sprintf(string,"_%d",value); + } else { + sprintf(string, "_%d", value); found = Lookup(tr, string, ph_digits); } } @@ -1562,101 +1418,78 @@ static int LookupNum2(Translator *tr, int value, int thousandplex, const int con // no, speak as tens+units - if((value < 10) && (control & 0x10)) - { + if ((value < 10) && (control & 0x10)) { // speak leading zero Lookup(tr, "_0", ph_tens); - } - else - { - if(found) - { + } else { + if (found) { ph_tens[0] = 0; - } - else - { + } else { - if(is_ordinal) - { - sprintf(string,"_%dX%c", tens, ord_type); - if(Lookup(tr, string, ph_tens) != 0) - { + if (is_ordinal) { + sprintf(string, "_%dX%c", tens, ord_type); + if (Lookup(tr, string, ph_tens) != 0) { found_ordinal = 1; - if((units != 0) && (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL)) - { + if ((units != 0) && (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL)) { // Use the ordinal form of tens as well as units. Add the ordinal ending strcat(ph_tens, ph_ordinal2); } } } - if(found_ordinal == 0) - { - if(control & 0x200) + if (found_ordinal == 0) { + if (control & 0x200) sprintf(string, "_%dXf", tens); else - sprintf(string,"_%dX", tens); + sprintf(string, "_%dX", tens); Lookup(tr, string, ph_tens); } - if((ph_tens[0] == 0) && (tr->langopts.numbers & NUM_VIGESIMAL)) - { + if ((ph_tens[0] == 0) && (tr->langopts.numbers & NUM_VIGESIMAL)) { // tens not found, (for example) 73 is 60+13 units = (value % 20); - sprintf(string,"_%dX", tens & 0xfe); + sprintf(string, "_%dX", tens & 0xfe); Lookup(tr, string, ph_tens); } ph_digits[0] = 0; - if(units > 0) - { + if (units > 0) { found = 0; - if((control & 2) && (digit_lookup[0] != 0)) - { + if ((control & 2) && (digit_lookup[0] != 0)) { // we have an entry for this digit (possibly together with the next word) strcpy(ph_digits, digit_lookup); found_ordinal = 1; ph_ordinal[0] = 0; - } - else - { - if(control & 8) - { + } else { + if (control & 8) { // is there a variant form of this number? - sprintf(string,"_%df",units); + sprintf(string, "_%df", units); found = Lookup(tr, string, ph_digits); } - if((is_ordinal) && ((tr->langopts.numbers & NUM_SWAP_TENS) == 0)) - { + if ((is_ordinal) && ((tr->langopts.numbers & NUM_SWAP_TENS) == 0)) { // ordinal - sprintf(string,"_%d%c",units,ord_type); - if((found = Lookup(tr, string, ph_digits)) != 0) - { + sprintf(string, "_%d%c", units, ord_type); + if ((found = Lookup(tr, string, ph_digits)) != 0) { found_ordinal = 1; } } - if(found == 0) - { - if((number_control & 1) && (control & 2)) - { + if (found == 0) { + if ((number_control & 1) && (control & 2)) { // look for 'e' variant - sprintf(string,"_%de",units); + sprintf(string, "_%de", units); found = Lookup(tr, string, ph_digits); - } - else if(((control & 2) == 0) || ((tr->langopts.numbers & NUM_SWAP_TENS) != 0)) - { + } else if (((control & 2) == 0) || ((tr->langopts.numbers & NUM_SWAP_TENS) != 0)) { // followed by hundreds or thousands (or tens) - if((tr->langopts.numbers2 & NUM2_ORDINAL_AND_THOUSANDS) && (thousandplex <= 1)) + if ((tr->langopts.numbers2 & NUM2_ORDINAL_AND_THOUSANDS) && (thousandplex <= 1)) sprintf(string, "_%do", units); // LANG=TA, only for 100s, 1000s else sprintf(string, "_%da", units); found = Lookup(tr, string, ph_digits); } } - if(found == 0) - { - sprintf(string,"_%d",units); + if (found == 0) { + sprintf(string, "_%d", units); Lookup(tr, string, ph_digits); } } @@ -1664,87 +1497,71 @@ static int LookupNum2(Translator *tr, int value, int thousandplex, const int con } } - if((is_ordinal) && (found_ordinal == 0) && (ph_ordinal[0] == 0)) - { - if((value >= 20) && (((value % 10) == 0) || (tr->langopts.numbers & NUM_SWAP_TENS))) + if ((is_ordinal) && (found_ordinal == 0) && (ph_ordinal[0] == 0)) { + if ((value >= 20) && (((value % 10) == 0) || (tr->langopts.numbers & NUM_SWAP_TENS))) Lookup(tr, "_ord20", ph_ordinal); - if(ph_ordinal[0] == 0) + if (ph_ordinal[0] == 0) Lookup(tr, "_ord", ph_ordinal); } - if((tr->langopts.numbers & (NUM_SWAP_TENS | NUM_AND_UNITS)) && (ph_tens[0] != 0) && (ph_digits[0] != 0)) - { + if ((tr->langopts.numbers & (NUM_SWAP_TENS | NUM_AND_UNITS)) && (ph_tens[0] != 0) && (ph_digits[0] != 0)) { Lookup(tr, "_0and", ph_and); - if((is_ordinal) && (tr->langopts.numbers2 & NUM2_ORDINAL_NO_AND)) + if ((is_ordinal) && (tr->langopts.numbers2 & NUM2_ORDINAL_NO_AND)) ph_and[0] = 0; - if(tr->langopts.numbers & NUM_SWAP_TENS) - sprintf(ph_out,"%s%s%s%s",ph_digits, ph_and, ph_tens, ph_ordinal); + if (tr->langopts.numbers & NUM_SWAP_TENS) + sprintf(ph_out, "%s%s%s%s", ph_digits, ph_and, ph_tens, ph_ordinal); else - sprintf(ph_out,"%s%s%s%s",ph_tens, ph_and, ph_digits, ph_ordinal); + sprintf(ph_out, "%s%s%s%s", ph_tens, ph_and, ph_digits, ph_ordinal); used_and = 1; - } - else - { - if(tr->langopts.numbers & NUM_SINGLE_VOWEL) - { + } else { + if (tr->langopts.numbers & NUM_SINGLE_VOWEL) { // remove vowel from the end of tens if units starts with a vowel (LANG=Italian) - if(((ix = strlen(ph_tens)-1) >= 0) && (ph_digits[0] != 0)) - { - if((next_phtype = phoneme_tab[(unsigned int)(ph_digits[0])]->type) == phSTRESS) + if (((ix = strlen(ph_tens)-1) >= 0) && (ph_digits[0] != 0)) { + if ((next_phtype = phoneme_tab[(unsigned int)(ph_digits[0])]->type) == phSTRESS) next_phtype = phoneme_tab[(unsigned int)(ph_digits[1])]->type; - if((phoneme_tab[(unsigned int)(ph_tens[ix])]->type == phVOWEL) && (next_phtype == phVOWEL)) + if ((phoneme_tab[(unsigned int)(ph_tens[ix])]->type == phVOWEL) && (next_phtype == phVOWEL)) ph_tens[ix] = 0; } } - if((tr->langopts.numbers2 & NUM2_ORDINAL_DROP_VOWEL) && (ph_ordinal[0] != 0)) - { - ix = sprintf(ph_out,"%s%s", ph_tens, ph_digits); - if((ix > 0) && (phoneme_tab[(unsigned char)(ph_out[ix-1])]->type == phVOWEL)) + if ((tr->langopts.numbers2 & NUM2_ORDINAL_DROP_VOWEL) && (ph_ordinal[0] != 0)) { + ix = sprintf(ph_out, "%s%s", ph_tens, ph_digits); + if ((ix > 0) && (phoneme_tab[(unsigned char)(ph_out[ix-1])]->type == phVOWEL)) ix--; sprintf(&ph_out[ix], "%s", ph_ordinal); - } - else - { - sprintf(ph_out,"%s%s%s",ph_tens, ph_digits, ph_ordinal); + } else { + sprintf(ph_out, "%s%s%s", ph_tens, ph_digits, ph_ordinal); } } } - if(tr->langopts.numbers & NUM_SINGLE_STRESS_L) - { + if (tr->langopts.numbers & NUM_SINGLE_STRESS_L) { // only one primary stress, on the first part (tens) found = 0; - for(ix=0; ix < (signed)strlen(ph_out); ix++) - { - if(ph_out[ix] == phonSTRESS_P) - { - if(found) + for (ix = 0; ix < (signed)strlen(ph_out); ix++) { + if (ph_out[ix] == phonSTRESS_P) { + if (found) ph_out[ix] = phonSTRESS_3; else found = 1; } } - } - else if(tr->langopts.numbers & NUM_SINGLE_STRESS) - { + } else if (tr->langopts.numbers & NUM_SINGLE_STRESS) { // only one primary stress found = 0; - for(ix=strlen(ph_out)-1; ix>=0; ix--) - { - if(ph_out[ix] == phonSTRESS_P) - { - if(found) + for (ix = strlen(ph_out)-1; ix >= 0; ix--) { + if (ph_out[ix] == phonSTRESS_P) { + if (found) ph_out[ix] = phonSTRESS_3; else found = 1; } } } - return(used_and); + return (used_and); } @@ -1763,7 +1580,7 @@ static int LookupNum3(Translator *tr, int value, char *ph_out, int suppress_null int exact; int ordinal; int tplex; - int say_zero_hundred=0; + int say_zero_hundred = 0; int say_one_hundred; char string[12]; // for looking up entries in **_list char buf1[100]; @@ -1783,38 +1600,29 @@ static int LookupNum3(Translator *tr, int value, char *ph_out, int suppress_null ph_thousands[0] = 0; ph_thousand_and[0] = 0; - if((tr->langopts.numbers & NUM_ZERO_HUNDRED) && ((control & 1) || (hundreds >= 10))) - { + if ((tr->langopts.numbers & NUM_ZERO_HUNDRED) && ((control & 1) || (hundreds >= 10))) { say_zero_hundred = 1; // lang=vi } - if((hundreds > 0) || say_zero_hundred) - { + if ((hundreds > 0) || say_zero_hundred) { found = 0; - if(ordinal && (tensunits == 0)) - { + if (ordinal && (tensunits == 0)) { // ordinal number, with no tens or units found = Lookup(tr, "_0Co", ph_100); } - if(found == 0) - { - if(tensunits==0) - { + if (found == 0) { + if (tensunits == 0) { // special form for exact hundreds? found = Lookup(tr, "_0C0", ph_100); } - if(!found) - { + if (!found) { Lookup(tr, "_0C", ph_100); } } - if(((tr->langopts.numbers & NUM_1900) != 0) && (hundreds == 19)) - { + if (((tr->langopts.numbers & NUM_1900) != 0) && (hundreds == 19)) { // speak numbers such as 1984 as years: nineteen-eighty-four - } - else if(hundreds >= 10) - { + } else if (hundreds >= 10) { ph_digits[0] = 0; exact = 0; @@ -1822,28 +1630,26 @@ static int LookupNum3(Translator *tr, int value, char *ph_out, int suppress_null exact = 1; tplex = thousandplex+1; - if(tr->langopts.numbers2 & NUM2_MYRIADS) - { + if (tr->langopts.numbers2 & NUM2_MYRIADS) { tplex = 0; } - if(LookupThousands(tr, hundreds / 10, tplex, exact | ordinal, ph_10T) == 0) - { + if (LookupThousands(tr, hundreds / 10, tplex, exact | ordinal, ph_10T) == 0) { x = 0; - if(tr->langopts.numbers2 & (1 << tplex)) + if (tr->langopts.numbers2 & (1 << tplex)) x = 8; // use variant (feminine) for before thousands and millions - if(tr->translator_name == L('m','l')) + if (tr->translator_name == L('m', 'l')) x = 0x208; LookupNum2(tr, hundreds/10, thousandplex, x, ph_digits); } - if(tr->langopts.numbers2 & 0x200) - sprintf(ph_thousands,"%s%c%s%c",ph_10T,phonEND_WORD,ph_digits,phonEND_WORD); // say "thousands" before its number, not after + if (tr->langopts.numbers2 & 0x200) + sprintf(ph_thousands, "%s%c%s%c", ph_10T, phonEND_WORD, ph_digits, phonEND_WORD); // say "thousands" before its number, not after else - sprintf(ph_thousands,"%s%c%s%c",ph_digits,phonEND_WORD,ph_10T,phonEND_WORD); + sprintf(ph_thousands, "%s%c%s%c", ph_digits, phonEND_WORD, ph_10T, phonEND_WORD); hundreds %= 10; - if((hundreds == 0) && (say_zero_hundred == 0)) + if ((hundreds == 0) && (say_zero_hundred == 0)) ph_100[0] = 0; suppress_null = 1; control |= 1; @@ -1851,99 +1657,75 @@ static int LookupNum3(Translator *tr, int value, char *ph_out, int suppress_null ph_digits[0] = 0; - if((hundreds > 0) || say_zero_hundred) - { - if((tr->langopts.numbers & NUM_AND_HUNDRED) && ((control & 1) || (ph_thousands[0] != 0))) - { + if ((hundreds > 0) || say_zero_hundred) { + if ((tr->langopts.numbers & NUM_AND_HUNDRED) && ((control & 1) || (ph_thousands[0] != 0))) { Lookup(tr, "_0and", ph_thousand_and); } suppress_null = 1; found = 0; - if((ordinal) - && ((tensunits == 0) || (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL))) - { + if ((ordinal) + && ((tensunits == 0) || (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL))) { // ordinal number sprintf(string, "_%dCo", hundreds); found = Lookup(tr, string, ph_digits); - if((tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL) && (tensunits > 0)) - { + if ((tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL) && (tensunits > 0)) { // Use ordinal form of hundreds, as well as for tens and units // Add ordinal suffix to the hundreds strcat(ph_digits, ph_ordinal2); } } - if((hundreds == 0) && say_zero_hundred) - { + if ((hundreds == 0) && say_zero_hundred) { Lookup(tr, "_0", ph_digits); - } - else - { - if((hundreds==1) && (tr->langopts.numbers2 & NUM2_OMIT_1_HUNDRED_ONLY) && ((control & 1)==0)) - { + } else { + if ((hundreds == 1) && (tr->langopts.numbers2 & NUM2_OMIT_1_HUNDRED_ONLY) && ((control & 1) == 0)) { // only look for special 100 if there are previous thousands - } - else - { - if((!found) && (tensunits == 0)) - { + } else { + if ((!found) && (tensunits == 0)) { // is there a special pronunciation for exactly n00 ? - sprintf(string,"_%dC0",hundreds); + sprintf(string, "_%dC0", hundreds); found = Lookup(tr, string, ph_digits); } - if(!found) - { - sprintf(string,"_%dC",hundreds); + if (!found) { + sprintf(string, "_%dC", hundreds); found = Lookup(tr, string, ph_digits); // is there a specific pronunciation for n-hundred ? } } - if(found) - { + if (found) { ph_100[0] = 0; - } - else - { + } else { say_one_hundred = 1; - if(hundreds == 1) - { - if((tr->langopts.numbers & NUM_OMIT_1_HUNDRED) != 0) + if (hundreds == 1) { + if ((tr->langopts.numbers & NUM_OMIT_1_HUNDRED) != 0) say_one_hundred = 0; } - if(say_one_hundred != 0) - { + if (say_one_hundred != 0) { LookupNum2(tr, hundreds, thousandplex, 0, ph_digits); } } } } - sprintf(buf1,"%s%s%s%s",ph_thousands,ph_thousand_and,ph_digits,ph_100); + sprintf(buf1, "%s%s%s%s", ph_thousands, ph_thousand_and, ph_digits, ph_100); } ph_hundred_and[0] = 0; - if(tensunits > 0) - { - if((control & 2) && (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL)) - { + if (tensunits > 0) { + if ((control & 2) && (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL)) { // Don't use "and" if we apply ordinal to both hundreds and units - } - else - { - if((value > 100) || ((control & 1) && (thousandplex==0))) - { - if((tr->langopts.numbers & NUM_HUNDRED_AND) || ((tr->langopts.numbers & NUM_HUNDRED_AND_DIGIT) && (tensunits < 10))) - { + } else { + if ((value > 100) || ((control & 1) && (thousandplex == 0))) { + if ((tr->langopts.numbers & NUM_HUNDRED_AND) || ((tr->langopts.numbers & NUM_HUNDRED_AND_DIGIT) && (tensunits < 10))) { Lookup(tr, "_0and", ph_hundred_and); } } - if((tr->langopts.numbers & NUM_THOUSAND_AND) && (hundreds == 0) && ((control & 1) || (ph_thousands[0] != 0))) - { + if ((tr->langopts.numbers & NUM_THOUSAND_AND) && (hundreds == 0) && ((control & 1) || (ph_thousands[0] != 0))) { Lookup(tr, "_0and", ph_hundred_and); } } @@ -1952,56 +1734,46 @@ static int LookupNum3(Translator *tr, int value, char *ph_out, int suppress_null buf2[0] = 0; - if((tensunits != 0) || (suppress_null == 0)) - { + if ((tensunits != 0) || (suppress_null == 0)) { x = 0; - if(thousandplex==0) - { + if (thousandplex == 0) { x = 2; // allow "eins" for 1 rather than "ein" - if(ordinal) + if (ordinal) x = 3; // ordinal number - if((value < 100) && !(control & 1)) + if ((value < 100) && !(control & 1)) x |= 4; // tens and units only, no higher digits - if(ordinal & 0x20) + if (ordinal & 0x20) x |= 0x20; // variant form of ordinal number - } - else - { - if(tr->langopts.numbers2 & (1 << thousandplex)) + } else { + if (tr->langopts.numbers2 & (1 << thousandplex)) x = 8; // use variant (feminine) for before thousands and millions } - if((tr->translator_name == L('m','l')) && (thousandplex == 1)) - { + if ((tr->translator_name == L('m', 'l')) && (thousandplex == 1)) { x |= 0x208; // use #f form for both tens and units } - if((tr->langopts.numbers2 & NUM2_ZERO_TENS) && ((control & 1) || (hundreds > 0))) - { + if ((tr->langopts.numbers2 & NUM2_ZERO_TENS) && ((control & 1) || (hundreds > 0))) { // LANG=zh, x |= 0x10; } - if(LookupNum2(tr, tensunits, thousandplex, x | (control & 0x100), buf2) != 0) - { - if(tr->langopts.numbers & NUM_SINGLE_AND) + if (LookupNum2(tr, tensunits, thousandplex, x | (control & 0x100), buf2) != 0) { + if (tr->langopts.numbers & NUM_SINGLE_AND) ph_hundred_and[0] = 0; // don't put 'and' after 'hundred' if there's 'and' between tens and units } - } - else - { - if(ph_ordinal2[0] != 0) - { + } else { + if (ph_ordinal2[0] != 0) { ix = strlen(buf1); - if((ix > 0) && (buf1[ix-1] == phonPAUSE_SHORT)) + if ((ix > 0) && (buf1[ix-1] == phonPAUSE_SHORT)) buf1[ix-1] = 0; // remove pause before addding ordinal suffix strcpy(buf2, ph_ordinal2); } } - sprintf(ph_out,"%s%s%c%s",buf1,ph_hundred_and,phonEND_WORD,buf2); + sprintf(ph_out, "%s%s%c%s", buf1, ph_hundred_and, phonEND_WORD, buf2); - return(0); + return (0); } @@ -2010,15 +1782,14 @@ bool CheckThousandsGroup(char *word, int group_len) // Is this a group of 3 digits which looks like a thousands group? int ix; - if(IsDigit09(word[group_len]) || IsDigit09(-1)) - return(false); + if (IsDigit09(word[group_len]) || IsDigit09(-1)) + return (false); - for(ix=0; ix < group_len; ix++) - { - if(!IsDigit09(word[ix])) - return(false); + for (ix = 0; ix < group_len; ix++) { + if (!IsDigit09(word[ix])) + return (false); } - return(true); + return (true); } @@ -2058,7 +1829,7 @@ static int TranslateNumber_1(Translator *tr, char *word, char *ph_out, unsigned char suffix[30]; // string[] must be long enough for sizeof(suffix)+2 char buf_digit_lookup[50]; - static const char str_pause[2] = {phonPAUSE_NOLINK,0}; + static const char str_pause[2] = { phonPAUSE_NOLINK, 0 }; *flags = 0; n_digit_lookup = 0; @@ -2066,133 +1837,108 @@ static int TranslateNumber_1(Translator *tr, char *word, char *ph_out, unsigned digit_lookup = buf_digit_lookup; number_control = control; - for(ix=0; IsDigit09(word[ix]); ix++); + for (ix = 0; IsDigit09(word[ix]); ix++) ; n_digits = ix; value = this_value = atoi(word); group_len = 3; - if(tr->langopts.numbers2 & NUM2_MYRIADS) + if (tr->langopts.numbers2 & NUM2_MYRIADS) group_len = 4; // is there a previous thousands part (as a previous "word") ? - if((n_digits == group_len) && (word[-2] == tr->langopts.thousands_sep) && IsDigit09(word[-3])) - { + if ((n_digits == group_len) && (word[-2] == tr->langopts.thousands_sep) && IsDigit09(word[-3])) { prev_thousands = 1; - } - else if((tr->langopts.thousands_sep == ' ') || (tr->langopts.numbers & NUM_ALLOW_SPACE)) - { + } else if ((tr->langopts.thousands_sep == ' ') || (tr->langopts.numbers & NUM_ALLOW_SPACE)) { // thousands groups can be separated by spaces - if((n_digits == 3) && !(wtab->flags & FLAG_MULTIPLE_SPACES) && IsDigit09(word[-2])) - { + if ((n_digits == 3) && !(wtab->flags & FLAG_MULTIPLE_SPACES) && IsDigit09(word[-2])) { prev_thousands = 1; } } - if(prev_thousands == 0) - { + if (prev_thousands == 0) { speak_missing_thousands = 0; } ph_ordinal2[0] = 0; ph_zeros[0] = 0; - if(prev_thousands || (word[0] != '0')) - { + if (prev_thousands || (word[0] != '0')) { // don't check for ordinal if the number has a leading zero ordinal = CheckDotOrdinal(tr, word, &word[ix], wtab, 0); } - if((word[ix] == '.') && !IsDigit09(word[ix+1]) && !IsDigit09(word[ix+2]) && !(wtab[1].flags & FLAG_NOSPACE)) - { + if ((word[ix] == '.') && !IsDigit09(word[ix+1]) && !IsDigit09(word[ix+2]) && !(wtab[1].flags & FLAG_NOSPACE)) { // remove dot unless followed by another number word[ix] = 0; } - if((ordinal == 0) || (tr->translator_name == L('h','u'))) - { + if ((ordinal == 0) || (tr->translator_name == L('h', 'u'))) { // NOTE lang=hu, allow both dot and ordinal suffix, eg. "december 21.-én" // look for an ordinal number suffix after the number ix++; p = suffix; - if(wtab[0].flags & FLAG_HYPHEN_AFTER) - { + if (wtab[0].flags & FLAG_HYPHEN_AFTER) { *p++ = '-'; ix++; } - while((word[ix] != 0) && (word[ix] != ' ') && (ix < (int)(sizeof(suffix)-1))) - { + while ((word[ix] != 0) && (word[ix] != ' ') && (ix < (int)(sizeof(suffix)-1))) { *p++ = word[ix++]; } *p = 0; - if(suffix[0] != 0) - { - if((tr->langopts.ordinal_indicator != NULL) && (strcmp(suffix, tr->langopts.ordinal_indicator) == 0)) - { + if (suffix[0] != 0) { + if ((tr->langopts.ordinal_indicator != NULL) && (strcmp(suffix, tr->langopts.ordinal_indicator) == 0)) { ordinal = 2; - } - else if(!IsDigit09(suffix[0])) // not _#9 (tab) - { - sprintf(string,"_#%s",suffix); - if(Lookup(tr, string, ph_ordinal2)) - { + } else if (!IsDigit09(suffix[0])) { // not _#9 (tab) + sprintf(string, "_#%s", suffix); + if (Lookup(tr, string, ph_ordinal2)) { // this is an ordinal suffix ordinal = 2; flags[0] |= FLAG_SKIPWORDS; skipwords = 1; - sprintf(string,"_x#%s",suffix); + sprintf(string, "_x#%s", suffix); Lookup(tr, string, ph_ordinal2x); // is there an alternate pronunciation? } } } } - if(wtab[0].flags & FLAG_ORDINAL) + if (wtab[0].flags & FLAG_ORDINAL) ordinal = 2; ph_append[0] = 0; ph_buf2[0] = 0; - if((word[0] == '0') && (prev_thousands == 0) && (word[1] != ' ') && (word[1] != tr->langopts.decimal_sep)) - { - if((n_digits == 2) && (word[3] == ':') && IsDigit09(word[5]) && isspace(word[7])) - { + if ((word[0] == '0') && (prev_thousands == 0) && (word[1] != ' ') && (word[1] != tr->langopts.decimal_sep)) { + if ((n_digits == 2) && (word[3] == ':') && IsDigit09(word[5]) && isspace(word[7])) { // looks like a time 02:30, omit the leading zero - } - else - { - if(n_digits > 3) - { + } else { + if (n_digits > 3) { flags[0] &= ~FLAG_SKIPWORDS; - return(0); // long number string with leading zero, speak as individual digits + return (0); // long number string with leading zero, speak as individual digits } // speak leading zeros - for(ix=0; (word[ix] == '0') && (ix < (n_digits-1)); ix++) - { + for (ix = 0; (word[ix] == '0') && (ix < (n_digits-1)); ix++) { Lookup(tr, "_0", &ph_zeros[strlen(ph_zeros)]); } } } - if((tr->langopts.numbers & NUM_ALLOW_SPACE) && (word[n_digits] == ' ')) + if ((tr->langopts.numbers & NUM_ALLOW_SPACE) && (word[n_digits] == ' ')) thousands_inc = 1; - else if(word[n_digits] == tr->langopts.thousands_sep) + else if (word[n_digits] == tr->langopts.thousands_sep) thousands_inc = 2; suffix_ix = n_digits+2; - if(thousands_inc > 0) - { + if (thousands_inc > 0) { // if the following "words" are three-digit groups, count them and add // a "thousand"/"million" suffix to this one digix = n_digits + thousands_inc; - while(((wtab[thousandplex+1].flags & FLAG_MULTIPLE_SPACES) == 0) && CheckThousandsGroup(&word[digix], group_len)) - { - for(ix=0; ixlangopts.thousands_sep) || ((tr->langopts.numbers & NUM_ALLOW_SPACE) && (word[digix] == ' '))) - { + if ((word[digix] == tr->langopts.thousands_sep) || ((tr->langopts.numbers & NUM_ALLOW_SPACE) && (word[digix] == ' '))) { suffix_ix = digix+2; digix += thousands_inc; - } - else + } else break; } } - if((value == 0) && prev_thousands) - { + if ((value == 0) && prev_thousands) { suppress_null = 1; } - if(tr->translator_name == L('h','u')) - { + if (tr->translator_name == L('h', 'u')) { // variant form of numbers when followed by hyphen and a suffix starting with 'a' or 'e' (but not a, e, az, ez, azt, ezt - if((wtab[thousandplex].flags & FLAG_HYPHEN_AFTER) && (thousands_exact==1) && hu_number_e(&word[suffix_ix], thousandplex, value)) - { + if ((wtab[thousandplex].flags & FLAG_HYPHEN_AFTER) && (thousands_exact == 1) && hu_number_e(&word[suffix_ix], thousandplex, value)) { number_control |= 1; // use _1e variant of number } } - if((word[n_digits] == tr->langopts.decimal_sep) && IsDigit09(word[n_digits+1])) - { + if ((word[n_digits] == tr->langopts.decimal_sep) && IsDigit09(word[n_digits+1])) { // this "word" ends with a decimal point Lookup(tr, "_dpt", ph_append); decimal_point = 0x100; - } - else if(suppress_null == 0) - { - if(thousands_inc > 0) - { - if(thousandplex > 0) - { - if((suppress_null == 0) && (LookupThousands(tr,value,thousandplex, thousands_exact, ph_append))) - { + } else if (suppress_null == 0) { + if (thousands_inc > 0) { + if (thousandplex > 0) { + if ((suppress_null == 0) && (LookupThousands(tr, value, thousandplex, thousands_exact, ph_append))) { // found an exact match for N thousand value = 0; suppress_null = 1; } } } - } - else - - if(speak_missing_thousands == 1) - { + } else if (speak_missing_thousands == 1) { // speak this thousandplex if there was no word for the previous thousandplex - sprintf(string,"_0M%d",thousandplex+1); - if(Lookup(tr, string, buf1)==0) - { - sprintf(string,"_0M%d",thousandplex); + sprintf(string, "_0M%d", thousandplex+1); + if (Lookup(tr, string, buf1) == 0) { + sprintf(string, "_0M%d", thousandplex); Lookup(tr, string, ph_append); } } - if((ph_append[0] == 0) && (word[n_digits] == '.') && (thousandplex == 0)) - { + if ((ph_append[0] == 0) && (word[n_digits] == '.') && (thousandplex == 0)) { Lookup(tr, "_.", ph_append); } - if(thousandplex == 0) - { + if (thousandplex == 0) { char *p2; // look for combinations of the number with the next word p = word; - while(IsDigit09(p[1])) p++; // just use the last digit - if(IsDigit09(p[-1])) - { + while (IsDigit09(p[1])) p++; // just use the last digit + if (IsDigit09(p[-1])) { p2 = p - 1; - if(LookupDictList(tr, &p2, buf_digit_lookup, flags, FLAG_SUFX, wtab)) // lookup 2 digits - { + if (LookupDictList(tr, &p2, buf_digit_lookup, flags, FLAG_SUFX, wtab)) { // lookup 2 digits n_digit_lookup = 2; } } - if((buf_digit_lookup[0] == 0) && (*p != '0')) - { + if ((buf_digit_lookup[0] == 0) && (*p != '0')) { // LANG=hu ? // not found, lookup only the last digit (?? but not if dot-ordinal has been found) - if(LookupDictList(tr, &p, buf_digit_lookup, flags, FLAG_SUFX, wtab)) // don't match '0', or entries with $only - { + if (LookupDictList(tr, &p, buf_digit_lookup, flags, FLAG_SUFX, wtab)) { // don't match '0', or entries with $only n_digit_lookup = 1; } } - if(prev_thousands == 0) - { - if((decimal_point == 0) && (ordinal == 0)) - { + if (prev_thousands == 0) { + if ((decimal_point == 0) && (ordinal == 0)) { // Look for special pronunciation for this number in isolation (LANG=kl) sprintf(string, "_%dn", value); - if(Lookup(tr, string, ph_out)) - { - return(1); + if (Lookup(tr, string, ph_out)) { + return (1); } } - if(tr->langopts.numbers2 & NUM2_PERCENT_BEFORE) - { + if (tr->langopts.numbers2 & NUM2_PERCENT_BEFORE) { // LANG=si, say "percent" before the number p2 = word; - while((*p2 != ' ') && (*p2 != 0)) - { + while ((*p2 != ' ') && (*p2 != 0)) { p2++; } - if(p2[1] == '%') - { + if (p2[1] == '%') { Lookup(tr, "%", ph_out); ph_out += strlen(ph_out); p2[1] = ' '; @@ -2320,38 +2038,35 @@ static int TranslateNumber_1(Translator *tr, char *word, char *ph_out, unsigned } LookupNum3(tr, value, ph_buf, suppress_null, thousandplex, prev_thousands | ordinal | decimal_point); - if((thousandplex > 0) && (tr->langopts.numbers2 & 0x200)) - sprintf(ph_out,"%s%s%c%s%s",ph_zeros,ph_append,phonEND_WORD,ph_buf2,ph_buf); // say "thousands" before its number + if ((thousandplex > 0) && (tr->langopts.numbers2 & 0x200)) + sprintf(ph_out, "%s%s%c%s%s", ph_zeros, ph_append, phonEND_WORD, ph_buf2, ph_buf); // say "thousands" before its number else - sprintf(ph_out,"%s%s%s%c%s",ph_zeros,ph_buf2,ph_buf,phonEND_WORD,ph_append); + sprintf(ph_out, "%s%s%s%c%s", ph_zeros, ph_buf2, ph_buf, phonEND_WORD, ph_append); - while(decimal_point) - { + while (decimal_point) { n_digits++; decimal_count = 0; - while(IsDigit09(word[n_digits+decimal_count])) + while (IsDigit09(word[n_digits+decimal_count])) decimal_count++; max_decimal_count = 2; - switch(decimal_mode = (tr->langopts.numbers & 0xe000)) + switch (decimal_mode = (tr->langopts.numbers & 0xe000)) { case NUM_DFRACTION_4: max_decimal_count = 5; case NUM_DFRACTION_2: // French/Polish decimal fraction - while(word[n_digits] == '0') - { + while (word[n_digits] == '0') { Lookup(tr, "_0", buf1); - strcat(ph_out,buf1); + strcat(ph_out, buf1); decimal_count--; n_digits++; } - if((decimal_count <= max_decimal_count) && IsDigit09(word[n_digits])) - { - LookupNum3(tr, atoi(&word[n_digits]), buf1, 0,0,0); - strcat(ph_out,buf1); + if ((decimal_count <= max_decimal_count) && IsDigit09(word[n_digits])) { + LookupNum3(tr, atoi(&word[n_digits]), buf1, 0, 0, 0); + strcat(ph_out, buf1); n_digits += decimal_count; } break; @@ -2359,100 +2074,91 @@ static int TranslateNumber_1(Translator *tr, char *word, char *ph_out, unsigned case NUM_DFRACTION_1: // italian, say "hundredths" if leading zero case NUM_DFRACTION_5: // hungarian, always say "tenths" etc. case NUM_DFRACTION_6: // kazakh, always say "tenths" etc, before the decimal fraction - LookupNum3(tr, atoi(&word[n_digits]), ph_buf, 0,0,0); - if((word[n_digits]=='0') || (decimal_mode != NUM_DFRACTION_1)) - { + LookupNum3(tr, atoi(&word[n_digits]), ph_buf, 0, 0, 0); + if ((word[n_digits] == '0') || (decimal_mode != NUM_DFRACTION_1)) { // decimal part has leading zeros, so add a "hundredths" or "thousandths" suffix - sprintf(string,"_0Z%d",decimal_count); - if(Lookup(tr, string, buf1) == 0) + sprintf(string, "_0Z%d", decimal_count); + if (Lookup(tr, string, buf1) == 0) break; // revert to speaking single digits - if(decimal_mode == NUM_DFRACTION_6) + if (decimal_mode == NUM_DFRACTION_6) strcat(ph_out, buf1); else strcat(ph_buf, buf1); } - strcat(ph_out,ph_buf); + strcat(ph_out, ph_buf); n_digits += decimal_count; break; case NUM_DFRACTION_3: // Romanian decimal fractions - if((decimal_count <= 4) && (word[n_digits] != '0')) - { - LookupNum3(tr, atoi(&word[n_digits]), buf1, 0,0,0); - strcat(ph_out,buf1); + if ((decimal_count <= 4) && (word[n_digits] != '0')) { + LookupNum3(tr, atoi(&word[n_digits]), buf1, 0, 0, 0); + strcat(ph_out, buf1); n_digits += decimal_count; } break; case NUM_DFRACTION_7: // alternative form of decimal fraction digits, except the final digit - while(decimal_count-- > 1) - { - sprintf(string,"_%cd", word[n_digits]); - if(Lookup(tr, string, buf1) == 0) + while (decimal_count-- > 1) { + sprintf(string, "_%cd", word[n_digits]); + if (Lookup(tr, string, buf1) == 0) break; n_digits++; strcat(ph_out, buf1); } } - while(IsDigit09(c = word[n_digits]) && (strlen(ph_out) < (N_WORD_PHONEMES - 10))) - { + while (IsDigit09(c = word[n_digits]) && (strlen(ph_out) < (N_WORD_PHONEMES - 10))) { // speak any remaining decimal fraction digits individually value = word[n_digits++] - '0'; LookupNum2(tr, value, 0, 2, buf1); len = strlen(ph_out); - sprintf(&ph_out[len],"%c%s", phonEND_WORD, buf1); + sprintf(&ph_out[len], "%c%s", phonEND_WORD, buf1); } // something after the decimal part ? - if(Lookup(tr, "_dpt2", buf1)) - strcat(ph_out,buf1); + if (Lookup(tr, "_dpt2", buf1)) + strcat(ph_out, buf1); - if((c == tr->langopts.decimal_sep) && IsDigit09(word[n_digits+1])) - { + if ((c == tr->langopts.decimal_sep) && IsDigit09(word[n_digits+1])) { Lookup(tr, "_dpt", buf1); - strcat(ph_out,buf1); - } - else - { + strcat(ph_out, buf1); + } else { decimal_point = 0; } } - if((ph_out[0] != 0) && (ph_out[0] != phonSWITCH)) - { + if ((ph_out[0] != 0) && (ph_out[0] != phonSWITCH)) { int next_char; char *p; p = &word[n_digits+1]; - p += utf8_in(&next_char,p); - if((tr->langopts.numbers & NUM_NOPAUSE) && (next_char == ' ')) - utf8_in(&next_char,p); + p += utf8_in(&next_char, p); + if ((tr->langopts.numbers & NUM_NOPAUSE) && (next_char == ' ')) + utf8_in(&next_char, p); - if(!iswalpha2(next_char) && (thousands_exact==0)) - strcat(ph_out,str_pause); // don't add pause for 100s, 6th, etc. + if (!iswalpha2(next_char) && (thousands_exact == 0)) + strcat(ph_out, str_pause); // don't add pause for 100s, 6th, etc. } *flags |= FLAG_FOUND; speak_missing_thousands--; - if(skipwords) + if (skipwords) dictionary_skipwords = skipwords; - return(1); + return (1); } int TranslateNumber(Translator *tr, char *word1, char *ph_out, unsigned int *flags, WORD_TAB *wtab, int control) { - if((option_sayas == SAYAS_DIGITS1) || (wtab[0].flags & FLAG_INDIVIDUAL_DIGITS)) - return(0); // speak digits individually + if ((option_sayas == SAYAS_DIGITS1) || (wtab[0].flags & FLAG_INDIVIDUAL_DIGITS)) + return (0); // speak digits individually - if(tr->langopts.numbers != 0) - { - return(TranslateNumber_1(tr, word1, ph_out, flags, wtab, control)); + if (tr->langopts.numbers != 0) { + return (TranslateNumber_1(tr, word1, ph_out, flags, wtab, control)); } - return(0); + return (0); } diff --git a/src/libespeak-ng/phoneme.h b/src/libespeak-ng/phoneme.h index 55a293ad..129aebfe 100644 --- a/src/libespeak-ng/phoneme.h +++ b/src/libespeak-ng/phoneme.h @@ -160,9 +160,9 @@ typedef struct { -#define PH(c1,c2) (c2<<8)+c1 // combine two characters into an integer for phoneme name -#define PH3(c1,c2,c3) (c3<<16)+(c2<<8)+c1 -#define PhonemeCode2(c1,c2) PhonemeCode((c2<<8)+c1) +#define PH(c1, c2) (c2<<8)+c1 // combine two characters into an integer for phoneme name +#define PH3(c1, c2, c3) (c3<<16)+(c2<<8)+c1 +#define PhonemeCode2(c1, c2) PhonemeCode((c2<<8)+c1) int LookupPhonemeString(const char *string); int PhonemeCode(unsigned int mnem); diff --git a/src/libespeak-ng/phonemelist.c b/src/libespeak-ng/phonemelist.c index e47b4133..f26ecf96 100644 --- a/src/libespeak-ng/phonemelist.c +++ b/src/libespeak-ng/phonemelist.c @@ -33,7 +33,7 @@ #include "translate.h" -const unsigned char pause_phonemes[8] = {0, phonPAUSE_VSHORT, phonPAUSE_SHORT, phonPAUSE, phonPAUSE_LONG, phonGLOTTALSTOP, phonPAUSE_LONG, phonPAUSE_LONG}; +const unsigned char pause_phonemes[8] = { 0, phonPAUSE_VSHORT, phonPAUSE_SHORT, phonPAUSE, phonPAUSE_LONG, phonGLOTTALSTOP, phonPAUSE_LONG, phonPAUSE_LONG }; extern int n_ph_list2; @@ -51,59 +51,54 @@ static int SubstitutePhonemes(Translator *tr, PHONEME_LIST *plist_out) int n_plist_out = 0; int word_end; PHONEME_LIST2 *plist2; - PHONEME_TAB *next=NULL; + PHONEME_TAB *next = NULL; - for(ix=0; (ix < n_ph_list2) && (n_plist_out < N_PHONEME_LIST); ix++) - { + for (ix = 0; (ix < n_ph_list2) && (n_plist_out < N_PHONEME_LIST); ix++) { plist2 = &ph_list2[ix]; // don't do any substitution if the language has been temporarily changed - if(!(plist2->synthflags & SFLAG_SWITCHED_LANG)) - { - if(ix < (n_ph_list2 -1)) + if (!(plist2->synthflags & SFLAG_SWITCHED_LANG)) { + if (ix < (n_ph_list2 -1)) next = phoneme_tab[ph_list2[ix+1].phcode]; word_end = 0; - if((plist2+1)->sourceix || ((next != 0) && (next->type == phPAUSE))) + if ((plist2+1)->sourceix || ((next != 0) && (next->type == phPAUSE))) word_end = 1; // this phoneme is the end of a word // check whether a Voice has specified that we should replace this phoneme - for(k=0; kphcode == replace_phonemes[k].old_ph) - { + for (k = 0; k < n_replace_phonemes; k++) { + if (plist2->phcode == replace_phonemes[k].old_ph) { replace_flags = replace_phonemes[k].type; - if((replace_flags & 1) && (word_end == 0)) + if ((replace_flags & 1) && (word_end == 0)) continue; // this replacement only occurs at the end of a word - if((replace_flags & 2) && ((plist2->stresslevel & 0x7) > 3)) + if ((replace_flags & 2) && ((plist2->stresslevel & 0x7) > 3)) continue; // this replacement doesn't occur in stressed syllables - if((replace_flags & 4) && (plist2->sourceix == 0)) + if ((replace_flags & 4) && (plist2->sourceix == 0)) continue; // this replacement only occurs at the start of a word // substitute the replacement phoneme plist2->phcode = replace_phonemes[k].new_ph; - if((plist2->stresslevel > 1) && (phoneme_tab[plist2->phcode]->phflags & phUNSTRESSED)) + if ((plist2->stresslevel > 1) && (phoneme_tab[plist2->phcode]->phflags & phUNSTRESSED)) plist2->stresslevel = 0; // the replacement must be unstressed break; } } - if(plist2->phcode == 0) - { + if (plist2->phcode == 0) { continue; // phoneme has been replaced by NULL, so don't copy it } } // copy phoneme into the output list - memcpy(&plist_out[n_plist_out],plist2,sizeof(PHONEME_LIST2)); + memcpy(&plist_out[n_plist_out], plist2, sizeof(PHONEME_LIST2)); plist_out[n_plist_out].ph = phoneme_tab[plist2->phcode]; plist_out[n_plist_out].type = plist_out[n_plist_out].ph->type; n_plist_out++; } - return(n_plist_out); + return (n_plist_out); } @@ -111,7 +106,7 @@ static int SubstitutePhonemes(Translator *tr, PHONEME_LIST *plist_out) void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) { - int ix=0; + int ix = 0; int j; int insert_ph = 0; PHONEME_LIST *phlist; @@ -146,26 +141,21 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) // is the last word of the clause unstressed ? max_stress = 0; - for(j = n_ph_list2-3; j>=0; j--) - { + for (j = n_ph_list2-3; j >= 0; j--) { // start with the last phoneme (before the terminating pauses) and move backwards - if((plist2[j].stresslevel & 0x7f) > max_stress) + if ((plist2[j].stresslevel & 0x7f) > max_stress) max_stress = plist2[j].stresslevel & 0x7f; - if(plist2[j].sourceix != 0) + if (plist2[j].sourceix != 0) break; } - if(max_stress < 4) - { + if (max_stress < 4) { // the last word is unstressed, look for a previous word that can be stressed - while(--j >= 0) - { - if(plist2[j].synthflags & SFLAG_PROMOTE_STRESS) // dictionary flags indicated that this stress can be promoted - { + while (--j >= 0) { + if (plist2[j].synthflags & SFLAG_PROMOTE_STRESS) { // dictionary flags indicated that this stress can be promoted plist2[j].stresslevel = 4; // promote to stressed break; } - if(plist2[j].stresslevel >= 4) - { + if (plist2[j].stresslevel >= 4) { // found a stressed syllable, so stop looking break; } @@ -175,32 +165,25 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) // look for switch of phoneme tables delete_count = 0; current_phoneme_tab = tr->phoneme_tab_ix; - for(j = 0; j < n_ph_list2; j++) - { - if(current_phoneme_tab != tr->phoneme_tab_ix) - { + for (j = 0; j < n_ph_list2; j++) { + if (current_phoneme_tab != tr->phoneme_tab_ix) { plist2[j].synthflags |= SFLAG_SWITCHED_LANG; } - if(delete_count > 0) - { + if (delete_count > 0) { memcpy(&plist2[j-delete_count], &plist2[j], sizeof(plist2[0])); } - if(plist2[j].phcode == phonSWITCH) - { - if((!(plist2[j].synthflags & SFLAG_EMBEDDED)) && ( - (plist2[j].tone_ph == current_phoneme_tab) || - (plist2[j+1].phcode == phonSWITCH) || - ((plist2[j+1].phcode == phonPAUSE) && (plist2[j+2].phcode == phonSWITCH)) - )) - { + if (plist2[j].phcode == phonSWITCH) { + if ((!(plist2[j].synthflags & SFLAG_EMBEDDED)) && ( + (plist2[j].tone_ph == current_phoneme_tab) || + (plist2[j+1].phcode == phonSWITCH) || + ((plist2[j+1].phcode == phonPAUSE) && (plist2[j+2].phcode == phonSWITCH)) + )) { // delete this phonSWITCH if it's switching to the current phoneme table, or // delete this phonSWITCH if its followed by another phonSWITCH delete_count++; - } - else - { + } else { current_phoneme_tab = plist2[j].tone_ph; } } @@ -208,95 +191,71 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) } n_ph_list2 -= delete_count; - if((regression = tr->langopts.param[LOPT_REGRESSIVE_VOICING]) != 0) - { + if ((regression = tr->langopts.param[LOPT_REGRESSIVE_VOICING]) != 0) { // set consonant clusters to all voiced or all unvoiced // Regressive int type; int stop_propagation = 0; voicing = 0; - for(j=n_ph_list2-1; j>=0; j--) - { + for (j = n_ph_list2-1; j >= 0; j--) { ph = phoneme_tab[plist2[j].phcode]; - if(ph == NULL) + if (ph == NULL) continue; - if(plist2[j].synthflags & SFLAG_SWITCHED_LANG) - { + if (plist2[j].synthflags & SFLAG_SWITCHED_LANG) { stop_propagation = 0; voicing = 0; - if(regression & 0x100) + if (regression & 0x100) voicing = 1; // word-end devoicing continue; } type = ph->type; - if(regression & 0x2) - { + if (regression & 0x2) { // [v] amd [v;] don't cause regression, or [R^] - if(((ph->mnemonic & 0xff) == 'v') || ((ph->mnemonic & 0xff)== 'R')) - { + if (((ph->mnemonic & 0xff) == 'v') || ((ph->mnemonic & 0xff) == 'R')) { stop_propagation = 1; - if(regression & 0x10) + if (regression & 0x10) voicing = 0; } } - if((type==phSTOP) || type==(phFRICATIVE)) - { - if((voicing==0) && (regression & 0xf)) - { + if ((type == phSTOP) || type == (phFRICATIVE)) { + if ((voicing == 0) && (regression & 0xf)) { voicing = 1; - } - else if((voicing==2) && (ph->end_type != 0)) // use end_type field for voicing_switch for consonants - { + } else if ((voicing == 2) && (ph->end_type != 0)) { // use end_type field for voicing_switch for consonants plist2[j].phcode = ph->end_type; // change to voiced equivalent } - } - else if((type==phVSTOP) || type==(phVFRICATIVE)) - { - if((voicing==0) && (regression & 0xf)) - { + } else if ((type == phVSTOP) || type == (phVFRICATIVE)) { + if ((voicing == 0) && (regression & 0xf)) { voicing = 2; - } - else if((voicing==1) && (ph->end_type != 0)) - { + } else if ((voicing == 1) && (ph->end_type != 0)) { plist2[j].phcode = ph->end_type; // change to unvoiced equivalent } - } - else - { - if(regression & 0x8) - { + } else { + if (regression & 0x8) { // LANG=Polish, propagate through liquids and nasals - if((type == phPAUSE) || (type == phVOWEL)) + if ((type == phPAUSE) || (type == phVOWEL)) voicing = 0; - } - else - { + } else { voicing = 0; } } - if(stop_propagation) - { + if (stop_propagation) { voicing = 0; stop_propagation = 0; } - if(plist2[j].sourceix) - { - if(regression & 0x04) - { + if (plist2[j].sourceix) { + if (regression & 0x04) { // stop propagation at a word boundary voicing = 0; } - if(regression & 0x100) - { + if (regression & 0x100) { // devoice word-final consonants, unless propagating voiced - if(voicing == 0) - { + if (voicing == 0) { voicing = 1; } } @@ -304,35 +263,29 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) } } - n_ph_list3 = SubstitutePhonemes(tr,ph_list3) - 2; + n_ph_list3 = SubstitutePhonemes(tr, ph_list3) - 2; - for(j=0; (j < n_ph_list3) && (ix < N_PHONEME_LIST-3); ) - { - if(ph_list3[j].sourceix) - { + for (j = 0; (j < n_ph_list3) && (ix < N_PHONEME_LIST-3);) { + if (ph_list3[j].sourceix) { // start of a word int k; int nextw; word_stress = 0; // find the highest stress level in this word - for(nextw=j; nextw < n_ph_list3; ) - { - if(ph_list3[nextw].stresslevel > word_stress) + for (nextw = j; nextw < n_ph_list3;) { + if (ph_list3[nextw].stresslevel > word_stress) word_stress = ph_list3[nextw].stresslevel; nextw++; - if(ph_list3[nextw].sourceix) + if (ph_list3[nextw].sourceix) break; // start of the next word } - for(k=j; kphcode]; // this phoneme, i.e. after the insert @@ -357,20 +308,16 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) // That's OK because we don't look backwards from plist3 *** but CountVowelPosition() and isAfterStress does !!! j--; plist3 = plist3_inserted = &ph_list3[j]; - if(j > 0) - { + if (j > 0) { // move all previous phonemes in the word back one place int k; - if(word_start > 0) - { + if (word_start > 0) { k = word_start; word_start--; - } - else - { + } else { k = 2; // No more space, don't loose the start of word mark at ph_list2[word_start] } - for(; k<=j; k++) + for (; k <= j; k++) memcpy(&ph_list3[k-1], &ph_list3[k], sizeof(*plist3)); } memset(&plist3[0], 0, sizeof(*plist3)); @@ -379,18 +326,15 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) plist3->ph = ph; insert_ph = 0; inserted = 1; // don't insert the same phoneme repeatedly - } - else - { + } else { // otherwise get the next phoneme from the list - if(plist3->sourceix != 0) + if (plist3->sourceix != 0) word_start = j; ph = phoneme_tab[plist3->phcode]; plist3[0].ph = ph; - if(plist3->phcode == phonSWITCH) - { + if (plist3->phcode == phonSWITCH) { // change phoneme table SelectPhonemeTable(plist3->tone_ph); } @@ -398,20 +342,18 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) plist3[1].ph = next; } - if(ph == NULL) continue; + if (ph == NULL) continue; InterpretPhoneme(tr, 0x100, plist3, &phdata, &worddata); - if((alternative = phdata.pd_param[pd_CHANGE_NEXTPHONEME]) > 0) - { + if ((alternative = phdata.pd_param[pd_CHANGE_NEXTPHONEME]) > 0) { ph_list3[j+1].ph = phoneme_tab[alternative]; ph_list3[j+1].phcode = alternative; ph_list3[j+1].type = phoneme_tab[alternative]->type; next = phoneme_tab[alternative]; } - if(((alternative = phdata.pd_param[pd_INSERTPHONEME]) > 0) && (inserted == 0)) - { + if (((alternative = phdata.pd_param[pd_INSERTPHONEME]) > 0) && (inserted == 0)) { // PROBLEM: if we insert a phoneme before a vowel then we loose the stress. PHONEME_TAB *ph2; ph2 = ph; @@ -421,13 +363,11 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) plist3->ph = ph; plist3->phcode = alternative; - if(ph->type == phVOWEL) - { + if (ph->type == phVOWEL) { plist3->synthflags |= SFLAG_SYLLABLE; - if(ph2->type != phVOWEL) + if (ph2->type != phVOWEL) plist3->stresslevel = 0; // change from non-vowel to vowel, make sure it's unstressed - } - else + } else plist3->synthflags &= ~SFLAG_SYLLABLE; // re-interpret the changed phoneme @@ -435,27 +375,21 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) InterpretPhoneme(tr, 0x100, plist3, &phdata, &worddata); } - if((alternative = phdata.pd_param[pd_CHANGEPHONEME]) > 0) - { + if ((alternative = phdata.pd_param[pd_CHANGEPHONEME]) > 0) { PHONEME_TAB *ph2; ph2 = ph; ph = phoneme_tab[alternative]; plist3->ph = ph; plist3->phcode = alternative; - if(alternative == 1) - { + if (alternative == 1) { deleted = 1; // NULL phoneme, discard - } - else - { - if(ph->type == phVOWEL) - { + } else { + if (ph->type == phVOWEL) { plist3->synthflags |= SFLAG_SYLLABLE; - if(ph2->type != phVOWEL) + if (ph2->type != phVOWEL) plist3->stresslevel = 0; // change from non-vowel to vowel, make sure it's unstressed - } - else + } else plist3->synthflags &= ~SFLAG_SYLLABLE; // re-interpret the changed phoneme @@ -464,64 +398,48 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) } } - if((ph->type == phVOWEL) && (deleted == 0)) - { + if ((ph->type == phVOWEL) && (deleted == 0)) { PHONEME_LIST *p; // Check for consecutive unstressed syllables, even across word boundaries. // Do this after changing phonemes according to stress level. - if(plist3->stresslevel <= 1) - { + if (plist3->stresslevel <= 1) { // an unstressed vowel unstress_count++; - if(tr->langopts.stress_flags & 0x08) - { + if (tr->langopts.stress_flags & 0x08) { // change sequences of consecutive unstressed vowels in unstressed words to diminished stress (TEST) - for(p=plist3+1; p->type != phPAUSE; p++) - { - if(p->type == phVOWEL) - { - if(p->stresslevel <= 1) - { - if(plist3->wordstress < 4) + for (p = plist3+1; p->type != phPAUSE; p++) { + if (p->type == phVOWEL) { + if (p->stresslevel <= 1) { + if (plist3->wordstress < 4) plist3->stresslevel = 0; - if(p->wordstress < 4) + if (p->wordstress < 4) p->stresslevel = 0; } break; } } - } - else - { - if((unstress_count > 1) && ((unstress_count & 1)==0)) - { + } else { + if ((unstress_count > 1) && ((unstress_count & 1) == 0)) { // in a sequence of unstressed syllables, reduce alternate syllables to 'diminished' // stress. But not for the last phoneme of a stressed word - if((tr->langopts.stress_flags & S_NO_DIM) || ((word_stress > 3) && ((plist3+1)->sourceix!=0))) - { + if ((tr->langopts.stress_flags & S_NO_DIM) || ((word_stress > 3) && ((plist3+1)->sourceix != 0))) { // An unstressed final vowel of a stressed word - unstress_count=1; // try again for next syllable - } - else - { + unstress_count = 1; // try again for next syllable + } else { plist3->stresslevel = 0; // change stress to 'diminished' } } } - } - else - { + } else { unstress_count = 0; } } - if((plist3+1)->synthflags & SFLAG_LENGTHEN) - { - static char types_double[] = {phFRICATIVE,phVFRICATIVE,phNASAL,phLIQUID,0}; - if((j > 0) && (strchr(types_double,next->type))) - { + if ((plist3+1)->synthflags & SFLAG_LENGTHEN) { + static char types_double[] = { phFRICATIVE, phVFRICATIVE, phNASAL, phLIQUID, 0 }; + if ((j > 0) && (strchr(types_double, next->type))) { // lengthen this consonant by doubling it // BUT, can't insert a phoneme at position plist3[0] because it crashes PrevPh() insert_ph = next->code; @@ -529,59 +447,48 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) } } - if((plist3+1)->sourceix != 0) - { + if ((plist3+1)->sourceix != 0) { int x; - if(tr->langopts.vowel_pause && (ph->type != phPAUSE)) - { + if (tr->langopts.vowel_pause && (ph->type != phPAUSE)) { - if((ph->type != phVOWEL) && (tr->langopts.vowel_pause & 0x200)) - { + if ((ph->type != phVOWEL) && (tr->langopts.vowel_pause & 0x200)) { // add a pause after a word which ends in a consonant insert_ph = phonPAUSE_NOLINK; } - if(next->type == phVOWEL) - { - if((x = tr->langopts.vowel_pause & 0x0c) != 0) - { + if (next->type == phVOWEL) { + if ((x = tr->langopts.vowel_pause & 0x0c) != 0) { // break before a word which starts with a vowel - if(x == 0xc) + if (x == 0xc) insert_ph = phonPAUSE_NOLINK; else insert_ph = phonPAUSE_VSHORT; } - if((ph->type == phVOWEL) && ((x = tr->langopts.vowel_pause & 0x03) != 0)) - { + if ((ph->type == phVOWEL) && ((x = tr->langopts.vowel_pause & 0x03) != 0)) { // adjacent vowels over a word boundary - if(x == 2) + if (x == 2) insert_ph = phonPAUSE_SHORT; else insert_ph = phonPAUSE_VSHORT; } - if(((plist3+1)->stresslevel >= 4) && (tr->langopts.vowel_pause & 0x100)) - { + if (((plist3+1)->stresslevel >= 4) && (tr->langopts.vowel_pause & 0x100)) { // pause before a words which starts with a stressed vowel insert_ph = phonPAUSE_SHORT; } } } - if((plist3 != plist3_inserted) && (ix > 0)) - { - if((x = (tr->langopts.word_gap & 0x7)) != 0) - { - if((x > 1) || ((insert_ph != phonPAUSE_SHORT) && (insert_ph != phonPAUSE_NOLINK))) - { + if ((plist3 != plist3_inserted) && (ix > 0)) { + if ((x = (tr->langopts.word_gap & 0x7)) != 0) { + if ((x > 1) || ((insert_ph != phonPAUSE_SHORT) && (insert_ph != phonPAUSE_NOLINK))) { // don't reduce the pause insert_ph = pause_phonemes[x]; } } - if(option_wordgap > 0) - { + if (option_wordgap > 0) { insert_ph = phonPAUSE_LONG; } } @@ -590,13 +497,11 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) next2 = phoneme_tab[plist3[2].phcode]; plist3[2].ph = next2; - if((insert_ph == 0) && (phdata.pd_param[pd_APPENDPHONEME] != 0)) - { + if ((insert_ph == 0) && (phdata.pd_param[pd_APPENDPHONEME] != 0)) { insert_ph = phdata.pd_param[pd_APPENDPHONEME]; } - if(deleted == 0) - { + if (deleted == 0) { phlist[ix].ph = ph; phlist[ix].type = ph->type; phlist[ix].env = PITCHfall; // default, can be changed in the "intonation" module @@ -607,31 +512,25 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) phlist[ix].sourceix = 0; phlist[ix].phcode = ph->code; - if(plist3->sourceix != 0) - { + if (plist3->sourceix != 0) { phlist[ix].sourceix = plist3->sourceix; phlist[ix].newword = 1; // this phoneme is the start of a word - if(start_sentence) - { + if (start_sentence) { phlist[ix].newword = 5; // start of sentence + start of word start_sentence = 0; } - } - else - { + } else { phlist[ix].newword = 0; } phlist[ix].length = phdata.pd_param[i_SET_LENGTH]*2; - if((ph->code == phonPAUSE_LONG) && (option_wordgap > 0) && (plist3[1].sourceix != 0)) - { + if ((ph->code == phonPAUSE_LONG) && (option_wordgap > 0) && (plist3[1].sourceix != 0)) { phlist[ix].ph = phoneme_tab[phonPAUSE_SHORT]; phlist[ix].length = option_wordgap*14; // 10mS per unit at the default speed } - if(ph->type==phVOWEL || ph->type==phLIQUID || ph->type==phNASAL || ph->type==phVSTOP || ph->type==phVFRICATIVE || (ph->phflags & phPREVOICE)) - { + if (ph->type == phVOWEL || ph->type == phLIQUID || ph->type == phNASAL || ph->type == phVSTOP || ph->type == phVFRICATIVE || (ph->phflags & phPREVOICE)) { phlist[ix].length = 128; // length_mod phlist[ix].env = PITCHfall; } @@ -655,7 +554,7 @@ void MakePhonemeList(Translator *tr, int post_pause, int start_sentence) phlist[ix].phcode = phonPAUSE; phlist[ix].type = phPAUSE; phlist[ix].length = 0; - phlist[ix].sourceix=0; + phlist[ix].sourceix = 0; phlist[ix].synthflags = 0; phlist[ix++].ph = phoneme_tab[phonPAUSE_SHORT]; diff --git a/src/libespeak-ng/readclause.c b/src/libespeak-ng/readclause.c index c05f5ee1..5e05467e 100644 --- a/src/libespeak-ng/readclause.c +++ b/src/libespeak-ng/readclause.c @@ -47,7 +47,7 @@ static const char *xmlbase = ""; // base URL from -static int namedata_ix=0; +static int namedata_ix = 0; static int n_namedata = 0; char *namedata = NULL; @@ -60,8 +60,8 @@ static int ungot_char; static const char *ungot_word = NULL; static int end_of_input; -static int ignore_text=0; // set during ... to ignore text which has been replaced by an alias -static int audio_text=0; // set during +static int ignore_text = 0; // set during ... to ignore text which has been replaced by an alias +static int audio_text = 0; // set during static int clear_skipping_text = 0; // next clause should clear the skipping_text flag int count_characters = 0; static int sayas_mode; @@ -69,104 +69,104 @@ static int sayas_start; static int ssml_ignore_l_angle = 0; // punctuations symbols that can end a clause -static const unsigned short punct_chars[] = {',','.','?','!',':',';', - 0x00a1, // inverted exclamation - 0x00bf, // inverted question - 0x2013, // en-dash - 0x2014, // em-dash - 0x2026, // elipsis +static const unsigned short punct_chars[] = { ',', '.', '?', '!', ':', ';', + 0x00a1, // inverted exclamation + 0x00bf, // inverted question + 0x2013, // en-dash + 0x2014, // em-dash + 0x2026, // elipsis - 0x037e, // Greek question mark (looks like semicolon) - 0x0387, // Greek semicolon, ano teleia - 0x0964, // Devanagari Danda (fullstop) + 0x037e, // Greek question mark (looks like semicolon) + 0x0387, // Greek semicolon, ano teleia + 0x0964, // Devanagari Danda (fullstop) - 0x0589, // Armenian period - 0x055d, // Armenian comma - 0x055c, // Armenian exclamation - 0x055e, // Armenian question - 0x055b, // Armenian emphasis mark + 0x0589, // Armenian period + 0x055d, // Armenian comma + 0x055c, // Armenian exclamation + 0x055e, // Armenian question + 0x055b, // Armenian emphasis mark - 0x060c, // Arabic , - 0x061b, // Arabic ; - 0x061f, // Arabic ? - 0x06d4, // Arabic . + 0x060c, // Arabic , + 0x061b, // Arabic ; + 0x061f, // Arabic ? + 0x06d4, // Arabic . - 0x0df4, // Singhalese Kunddaliya - 0x0f0d, // Tibet Shad - 0x0f0e, + 0x0df4, // Singhalese Kunddaliya + 0x0f0d, // Tibet Shad + 0x0f0e, - 0x1362, // Ethiopic period - 0x1363, - 0x1364, - 0x1365, - 0x1366, - 0x1367, - 0x1368, - 0x10fb, // Georgian paragraph + 0x1362, // Ethiopic period + 0x1363, + 0x1364, + 0x1365, + 0x1366, + 0x1367, + 0x1368, + 0x10fb, // Georgian paragraph - 0x3001, // ideograph comma - 0x3002, // ideograph period + 0x3001, // ideograph comma + 0x3002, // ideograph period - 0xff01, // fullwidth exclamation - 0xff0c, // fullwidth comma - 0xff0e, // fullwidth period - 0xff1a, // fullwidth colon - 0xff1b, // fullwidth semicolon - 0xff1f, // fullwidth question mark + 0xff01, // fullwidth exclamation + 0xff0c, // fullwidth comma + 0xff0e, // fullwidth period + 0xff1a, // fullwidth colon + 0xff1b, // fullwidth semicolon + 0xff1f, // fullwidth question mark - 0}; + 0 }; // indexed by (entry num. in punct_chars) + 1 // bits 0-7 pause x 10mS, bits 12-14 intonation type, bit 15 don't need following space or bracket -static const unsigned int punct_attributes [] = { 0, - CLAUSE_COMMA, CLAUSE_PERIOD, CLAUSE_QUESTION, CLAUSE_EXCLAMATION, CLAUSE_COLON, CLAUSE_SEMICOLON, - CLAUSE_SEMICOLON | 0x8000, // inverted exclamation - CLAUSE_SEMICOLON | 0x8000, // inverted question - CLAUSE_SEMICOLON, // en-dash - CLAUSE_SEMICOLON, // em-dash - CLAUSE_SEMICOLON | PUNCT_SAY_NAME | 0x8000, // elipsis +static const unsigned int punct_attributes[] = { 0, + CLAUSE_COMMA, CLAUSE_PERIOD, CLAUSE_QUESTION, CLAUSE_EXCLAMATION, CLAUSE_COLON, CLAUSE_SEMICOLON, + CLAUSE_SEMICOLON | 0x8000, // inverted exclamation + CLAUSE_SEMICOLON | 0x8000, // inverted question + CLAUSE_SEMICOLON, // en-dash + CLAUSE_SEMICOLON, // em-dash + CLAUSE_SEMICOLON | PUNCT_SAY_NAME | 0x8000, // elipsis - CLAUSE_QUESTION, // Greek question mark - CLAUSE_SEMICOLON, // Greek semicolon - CLAUSE_PERIOD | 0x8000, // Devanagari Danda (fullstop) + CLAUSE_QUESTION, // Greek question mark + CLAUSE_SEMICOLON, // Greek semicolon + CLAUSE_PERIOD | 0x8000, // Devanagari Danda (fullstop) - CLAUSE_PERIOD | 0x8000, // Armenian period - CLAUSE_COMMA, // Armenian comma - CLAUSE_EXCLAMATION | PUNCT_IN_WORD, // Armenian exclamation - CLAUSE_QUESTION | PUNCT_IN_WORD, // Armenian question - CLAUSE_PERIOD | PUNCT_IN_WORD, // Armenian emphasis mark + CLAUSE_PERIOD | 0x8000, // Armenian period + CLAUSE_COMMA, // Armenian comma + CLAUSE_EXCLAMATION | PUNCT_IN_WORD, // Armenian exclamation + CLAUSE_QUESTION | PUNCT_IN_WORD, // Armenian question + CLAUSE_PERIOD | PUNCT_IN_WORD, // Armenian emphasis mark - CLAUSE_COMMA, // Arabic , - CLAUSE_SEMICOLON, // Arabic ; - CLAUSE_QUESTION, // Arabic question mark - CLAUSE_PERIOD, // Arabic full stop + CLAUSE_COMMA, // Arabic , + CLAUSE_SEMICOLON, // Arabic ; + CLAUSE_QUESTION, // Arabic question mark + CLAUSE_PERIOD, // Arabic full stop - CLAUSE_PERIOD+0x8000, // Singhalese period - CLAUSE_PERIOD+0x8000, // Tibet period - CLAUSE_PARAGRAPH, + CLAUSE_PERIOD+0x8000, // Singhalese period + CLAUSE_PERIOD+0x8000, // Tibet period + CLAUSE_PARAGRAPH, - CLAUSE_PERIOD, // Ethiopic period - CLAUSE_COMMA, // Ethiopic comma - CLAUSE_SEMICOLON, // Ethiopic semicolon - CLAUSE_COLON, // Ethiopic colon - CLAUSE_COLON, // Ethiopic preface colon - CLAUSE_QUESTION, // Ethiopic question mark - CLAUSE_PARAGRAPH, // Ethiopic paragraph - CLAUSE_PARAGRAPH, // Georgian paragraph + CLAUSE_PERIOD, // Ethiopic period + CLAUSE_COMMA, // Ethiopic comma + CLAUSE_SEMICOLON, // Ethiopic semicolon + CLAUSE_COLON, // Ethiopic colon + CLAUSE_COLON, // Ethiopic preface colon + CLAUSE_QUESTION, // Ethiopic question mark + CLAUSE_PARAGRAPH, // Ethiopic paragraph + CLAUSE_PARAGRAPH, // Georgian paragraph - CLAUSE_COMMA+0x8000, // ideograph comma - CLAUSE_PERIOD+0x8000, // ideograph period + CLAUSE_COMMA+0x8000, // ideograph comma + CLAUSE_PERIOD+0x8000, // ideograph period - CLAUSE_EXCLAMATION+0x8000, // fullwidth - CLAUSE_COMMA+0x8000, - CLAUSE_PERIOD+0x8000, - CLAUSE_COLON+0x8000, - CLAUSE_SEMICOLON+0x8000, - CLAUSE_QUESTION+0x8000, + CLAUSE_EXCLAMATION+0x8000, // fullwidth + CLAUSE_COMMA+0x8000, + CLAUSE_PERIOD+0x8000, + CLAUSE_COLON+0x8000, + CLAUSE_SEMICOLON+0x8000, + CLAUSE_QUESTION+0x8000, - CLAUSE_SEMICOLON, // spare - 0 }; + CLAUSE_SEMICOLON, // spare + 0 }; // stack for language and voice properties @@ -185,8 +185,8 @@ static int n_ssml_stack; static SSML_STACK ssml_stack[N_SSML_STACK]; static espeak_VOICE base_voice; -static char base_voice_variant_name[40] = {0}; -static char current_voice_id[40] = {0}; +static char base_voice_variant_name[40] = { 0 }; +static char current_voice_id[40] = { 0 }; #define N_PARAM_STACK 20 @@ -194,7 +194,7 @@ static int n_param_stack; PARAM_STACK param_stack[N_PARAM_STACK]; static int speech_parameters[N_SPEECH_PARAM]; // current values, from param_stack -int saved_parameters[N_SPEECH_PARAM]; //Parameters saved on synthesis start +int saved_parameters[N_SPEECH_PARAM]; // Parameters saved on synthesis start const int param_defaults[N_SPEECH_PARAM] = { 0, // silence (internal use) @@ -262,7 +262,7 @@ static const short wchar_tolower[] = { 0x23d, 0x19a, 0x23e, 0x2c66, 0x243, 0x180, - 0,0 + 0, 0 }; static const short wchar_toupper[] = { @@ -281,7 +281,7 @@ static const short wchar_toupper[] = { 0x1cc, 0x1ca, 0x1dd, 0x18e, 0x1f3, 0x1f1, - 0,0 + 0, 0 }; @@ -290,27 +290,27 @@ static const short wchar_toupper[] = { // use ctype.h functions for Latin1 (character < 0x100) int iswalpha(int c) { - if(c < 0x80) - return(isalpha(c)); - if((c > 0x3040) && (c <= 0xa700)) - return(1); // japanese, chinese characters - if(c > MAX_WALPHA) - return(0); - return(walpha_tab[c-0x80]); + if (c < 0x80) + return (isalpha(c)); + if ((c > 0x3040) && (c <= 0xa700)) + return (1); // japanese, chinese characters + if (c > MAX_WALPHA) + return (0); + return (walpha_tab[c-0x80]); } int iswdigit(int c) { - if(c < 0x80) - return(isdigit(c)); - return(0); + if (c < 0x80) + return (isdigit(c)); + return (0); } int iswalnum(int c) { - if(iswdigit(c)) - return(1); - return(iswalpha(c)); + if (iswdigit(c)) + return (1); + return (iswalpha(c)); } int towlower(int c) @@ -318,97 +318,92 @@ int towlower(int c) int x; int ix; - if(c < 0x80) - return(tolower(c)); + if (c < 0x80) + return (tolower(c)); - if((c > MAX_WALPHA) || ((x = walpha_tab[c-0x80]) >= 0xfe)) - return(c); + if ((c > MAX_WALPHA) || ((x = walpha_tab[c-0x80]) >= 0xfe)) + return (c); - if(x == 0xfd) - { + if (x == 0xfd) { // special cases, lookup translation table - for(ix=0; wchar_tolower[ix] != 0; ix+=2) - { - if(wchar_tolower[ix] == c) - return(wchar_tolower[ix+1]); + for (ix = 0; wchar_tolower[ix] != 0; ix += 2) { + if (wchar_tolower[ix] == c) + return (wchar_tolower[ix+1]); } } - return(c + x); // convert to lower case + return (c + x); // convert to lower case } int towupper(int c) { int ix; // check whether a previous character code is the upper-case equivalent of this character - if(towlower(c-32) == c) - return(c-32); // yes, use it - if(towlower(c-1) == c) - return(c-1); - for(ix=0; wchar_toupper[ix] != 0; ix+=2) - { - if(wchar_toupper[ix] == c) - return(wchar_toupper[ix+1]); + if (towlower(c-32) == c) + return (c-32); // yes, use it + if (towlower(c-1) == c) + return (c-1); + for (ix = 0; wchar_toupper[ix] != 0; ix += 2) { + if (wchar_toupper[ix] == c) + return (wchar_toupper[ix+1]); } - return(c); // no + return (c); // no } int iswupper(int c) { int x; - if(c < 0x80) - return(isupper(c)); - if(((c > MAX_WALPHA) || (x = walpha_tab[c-0x80])==0) || (x == 0xff)) - return(0); - return(1); + if (c < 0x80) + return (isupper(c)); + if (((c > MAX_WALPHA) || (x = walpha_tab[c-0x80]) == 0) || (x == 0xff)) + return (0); + return (1); } int iswlower(int c) { - if(c < 0x80) - return(islower(c)); - if((c > MAX_WALPHA) || (walpha_tab[c-0x80] != 0xff)) - return(0); - return(1); + if (c < 0x80) + return (islower(c)); + if ((c > MAX_WALPHA) || (walpha_tab[c-0x80] != 0xff)) + return (0); + return (1); } int iswspace(int c) { - if(c < 0x80) - return(isspace(c)); - if(c == 0xa0) - return(1); - return(0); + if (c < 0x80) + return (isspace(c)); + if (c == 0xa0) + return (1); + return (0); } int iswpunct(int c) { - if(c < 0x100) - return(ispunct(c)); - return(0); + if (c < 0x100) + return (ispunct(c)); + return (0); } const wchar_t *wcschr(const wchar_t *str, int c) { - while(*str != 0) - { - if(*str == c) - return(str); + while (*str != 0) { + if (*str == c) + return (str); str++; } - return(NULL); + return (NULL); } #ifndef WINCE // wcslen() is provided by WINCE, but not the other wchar functions const int wcslen(const wchar_t *str) { - int ix=0; + int ix = 0; - while(*str != 0) - { + while (*str != 0) { ix++; } - return(ix); + return (ix); } #endif @@ -416,15 +411,14 @@ float wcstod(const wchar_t *str, wchar_t **tailptr) { int ix; char buf[80]; - while(isspace(*str)) str++; - for(ix=0; ix<80; ix++) - { + while (isspace(*str)) str++; + for (ix = 0; ix < 80; ix++) { buf[ix] = str[ix]; - if(isspace(buf[ix])) + if (isspace(buf[ix])) break; } *tailptr = (wchar_t *)&str[ix]; - return(atof(buf)); + return (atof(buf)); } #endif @@ -433,36 +427,36 @@ float wcstod(const wchar_t *str, wchar_t **tailptr) // iswalpha() on Windows is unreliable (U+AA, U+BA). int iswalpha2(int c) { - if(c < 0x80) - return(isalpha(c)); - if((c > 0x3040) && (c <= 0xa700)) - return(1); // japanese, chinese characters - if(c > MAX_WALPHA) - return(iswalpha(c)); - return(walpha_tab[c-0x80]); + if (c < 0x80) + return (isalpha(c)); + if ((c > 0x3040) && (c <= 0xa700)) + return (1); // japanese, chinese characters + if (c > MAX_WALPHA) + return (iswalpha(c)); + return (walpha_tab[c-0x80]); } int iswlower2(int c) { - if(c < 0x80) - return(islower(c)); - if(c > MAX_WALPHA) - return(iswlower(c)); - if(walpha_tab[c-0x80] == 0xff) - return(1); - return(0); + if (c < 0x80) + return (islower(c)); + if (c > MAX_WALPHA) + return (iswlower(c)); + if (walpha_tab[c-0x80] == 0xff) + return (1); + return (0); } int iswupper2(int c) { int x; - if(c < 0x80) - return(isupper(c)); - if(c > MAX_WALPHA) - return(iswupper(c)); - if(((x = walpha_tab[c-0x80]) > 0) && (x < 0xfe)) - return(1); - return(0); + if (c < 0x80) + return (isupper(c)); + if (c > MAX_WALPHA) + return (iswupper(c)); + if (((x = walpha_tab[c-0x80]) > 0) && (x < 0xfe)) + return (1); + return (0); } int towlower2(unsigned int c) @@ -471,69 +465,63 @@ int towlower2(unsigned int c) int ix; // check for non-standard upper to lower case conversions - if(c == 'I') - { - if(translator->langopts.dotless_i) - { + if (c == 'I') { + if (translator->langopts.dotless_i) { c = 0x131; // I -> ı } } - if(c < 0x80) - return(tolower(c)); + if (c < 0x80) + return (tolower(c)); - if(c > MAX_WALPHA) - return(towlower(c)); + if (c > MAX_WALPHA) + return (towlower(c)); - if((x = walpha_tab[c-0x80]) >= 0xfe) - return(c); // this is not an upper case letter + if ((x = walpha_tab[c-0x80]) >= 0xfe) + return (c); // this is not an upper case letter - if(x == 0xfd) - { + if (x == 0xfd) { // special cases, lookup translation table - for(ix=0; wchar_tolower[ix] != 0; ix+=2) - { - if(wchar_tolower[ix] == (int)c) - return(wchar_tolower[ix+1]); + for (ix = 0; wchar_tolower[ix] != 0; ix += 2) { + if (wchar_tolower[ix] == (int)c) + return (wchar_tolower[ix+1]); } } - return(c + x); // convert to lower case + return (c + x); // convert to lower case } int towupper2(unsigned int c) { int ix; - if(c > MAX_WALPHA) - return(towupper(c)); + if (c > MAX_WALPHA) + return (towupper(c)); // check whether a previous character code is the upper-case equivalent of this character - if(towlower2(c-32) == (int)c) - return(c-32); // yes, use it - if(towlower2(c-1) == (int)c) - return(c-1); - for(ix=0; wchar_toupper[ix] != 0; ix+=2) - { - if(wchar_toupper[ix] == (int)c) - return(wchar_toupper[ix+1]); + if (towlower2(c-32) == (int)c) + return (c-32); // yes, use it + if (towlower2(c-1) == (int)c) + return (c-1); + for (ix = 0; wchar_toupper[ix] != 0; ix += 2) { + if (wchar_toupper[ix] == (int)c) + return (wchar_toupper[ix+1]); } - return(c); // no + return (c); // no } static int IsRomanU(unsigned int c) { - if((c=='I') || (c=='V') || (c=='X') || (c=='L')) - return(1); - return(0); + if ((c == 'I') || (c == 'V') || (c == 'X') || (c == 'L')) + return (1); + return (0); } static void GetC_unget(int c) { // This is only called with UTF8 input, not wchar input - if(f_input != NULL) - ungetc(c,f_input); - else - { + if (f_input != NULL) + ungetc(c, f_input); + else { p_textinput--; *p_textinput = c; end_of_input = 0; @@ -542,13 +530,13 @@ static void GetC_unget(int c) int Eof(void) { - if(ungot_char != 0) - return(0); + if (ungot_char != 0) + return (0); - if(f_input != 0) - return(feof(f_input)); + if (f_input != 0) + return (feof(f_input)); - return(end_of_input); + return (end_of_input); } @@ -557,51 +545,42 @@ static int GetC_get(void) unsigned int c; unsigned int c2; - if(f_input != NULL) - { + if (f_input != NULL) { c = fgetc(f_input); - if(feof(f_input)) c = ' '; + if (feof(f_input)) c = ' '; - if(option_multibyte == espeakCHARS_16BIT) - { + if (option_multibyte == espeakCHARS_16BIT) { c2 = fgetc(f_input); - if(feof(f_input)) c2 = 0; + if (feof(f_input)) c2 = 0; c = c + (c2 << 8); } - return(c); + return (c); } - if(option_multibyte == espeakCHARS_WCHAR) - { - if(*p_wchar_input == 0) - { + if (option_multibyte == espeakCHARS_WCHAR) { + if (*p_wchar_input == 0) { end_of_input = 1; - return(0); + return (0); } - if(!end_of_input) - return(*p_wchar_input++); - } - else - { - if(*p_textinput == 0) - { + if (!end_of_input) + return (*p_wchar_input++); + } else { + if (*p_textinput == 0) { end_of_input = 1; - return(0); + return (0); } - if(!end_of_input) - { - if(option_multibyte == espeakCHARS_16BIT) - { + if (!end_of_input) { + if (option_multibyte == espeakCHARS_16BIT) { c = p_textinput[0] + (p_textinput[1] << 8); p_textinput += 2; - return(c); + return (c); } - return(*p_textinput++ & 0xff); + return (*p_textinput++ & 0xff); } } - return(0); + return (0); } @@ -617,61 +596,49 @@ static int GetC(void) int ix; int n_bytes; static int ungot2 = 0; - static const unsigned char mask[4] = {0xff,0x1f,0x0f,0x07}; + static const unsigned char mask[4] = { 0xff, 0x1f, 0x0f, 0x07 }; - if((c1 = ungot_char) != 0) - { + if ((c1 = ungot_char) != 0) { ungot_char = 0; - return(c1); + return (c1); } - if(ungot2 != 0) - { + if (ungot2 != 0) { c1 = ungot2; ungot2 = 0; - } - else - { + } else { c1 = GetC_get(); } - if((option_multibyte == espeakCHARS_WCHAR) || (option_multibyte == espeakCHARS_16BIT)) - { + if ((option_multibyte == espeakCHARS_WCHAR) || (option_multibyte == espeakCHARS_16BIT)) { count_characters++; - return(c1); // wchar_t text + return (c1); // wchar_t text } - if((option_multibyte < 2) && (c1 & 0x80)) - { + if ((option_multibyte < 2) && (c1 & 0x80)) { // multi-byte utf8 encoding, convert to unicode n_bytes = 0; - if(((c1 & 0xe0) == 0xc0) && ((c1 & 0x1e) != 0)) + if (((c1 & 0xe0) == 0xc0) && ((c1 & 0x1e) != 0)) n_bytes = 1; - else - if((c1 & 0xf0) == 0xe0) + else if ((c1 & 0xf0) == 0xe0) n_bytes = 2; - else - if(((c1 & 0xf8) == 0xf0) && ((c1 & 0x0f) <= 4)) + else if (((c1 & 0xf8) == 0xf0) && ((c1 & 0x0f) <= 4)) n_bytes = 3; - if((ix = n_bytes) > 0) - { + if ((ix = n_bytes) > 0) { c = c1 & mask[ix]; - while(ix > 0) - { - if((c2 = cbuf[ix] = GetC_get()) == 0) - { - if(option_multibyte==espeakCHARS_AUTO) - option_multibyte=espeakCHARS_8BIT; // change "auto" option to "no" + while (ix > 0) { + if ((c2 = cbuf[ix] = GetC_get()) == 0) { + if (option_multibyte == espeakCHARS_AUTO) + option_multibyte = espeakCHARS_8BIT; // change "auto" option to "no" GetC_unget(' '); break; } - if((c2 & 0xc0) != 0x80) - { + if ((c2 & 0xc0) != 0x80) { // This is not UTF8. Change to 8-bit characterset. - if((n_bytes == 2) && (ix == 1)) + if ((n_bytes == 2) && (ix == 1)) ungot2 = cbuf[2]; GetC_unget(c2); break; @@ -679,22 +646,21 @@ static int GetC(void) c = (c << 6) + (c2 & 0x3f); ix--; } - if(ix == 0) - { + if (ix == 0) { count_characters++; - return(c); + return (c); } } // top-bit-set character is not utf8, drop through to 8bit charset case - if((option_multibyte==espeakCHARS_AUTO) && !Eof()) - option_multibyte=espeakCHARS_8BIT; // change "auto" option to "no" + if ((option_multibyte == espeakCHARS_AUTO) && !Eof()) + option_multibyte = espeakCHARS_8BIT; // change "auto" option to "no" } // 8 bit character set, convert to unicode if count_characters++; - if(c1 >= 0xa0) - return(translator->charset_a0[c1-0xa0]); - return(c1); + if (c1 >= 0xa0) + return (translator->charset_a0[c1-0xa0]); + return (c1); } @@ -712,17 +678,16 @@ const char *WordToString2(unsigned int word) char *p; p = buf; - for(ix=3; ix>=0; ix--) - { - if((*p = word >> (ix*8)) != 0) + for (ix = 3; ix >= 0; ix--) { + if ((*p = word >> (ix*8)) != 0) p++; } *p = 0; - return(buf); + return (buf); } -static const char *LookupSpecial(Translator *tr, const char *string, char* text_out) +static const char *LookupSpecial(Translator *tr, const char *string, char *text_out) { unsigned int flags[2]; char phonemes[55]; @@ -730,14 +695,13 @@ static const char *LookupSpecial(Translator *tr, const char *string, char* text_ char *string1 = (char *)string; flags[0] = flags[1] = 0; - if(LookupDictList(tr,&string1,phonemes,flags,0,NULL)) - { + if (LookupDictList(tr, &string1, phonemes, flags, 0, NULL)) { SetWordStress(tr, phonemes, flags, -1, 0); - DecodePhonemes(phonemes,phonemes2); - sprintf(text_out,"[\002%s]]",phonemes2); - return(text_out); + DecodePhonemes(phonemes, phonemes2); + sprintf(text_out, "[\002%s]]", phonemes2); + return (text_out); } - return(NULL); + return (NULL); } @@ -760,74 +724,57 @@ static const char *LookupCharName(Translator *tr, int c, int only) flags[1] = 0; single_letter[0] = 0; single_letter[1] = '_'; - ix = utf8_out(c,&single_letter[2]); - single_letter[2+ix]=0; + ix = utf8_out(c, &single_letter[2]); + single_letter[2+ix] = 0; - if(only) - { + if (only) { string = &single_letter[2]; LookupDictList(tr, &string, phonemes, flags, 0, NULL); - } - else - { + } else { string = &single_letter[1]; - if(LookupDictList(tr, &string, phonemes, flags, 0, NULL) == 0) - { + if (LookupDictList(tr, &string, phonemes, flags, 0, NULL) == 0) { // try _* then * string = &single_letter[2]; - if(LookupDictList(tr, &string, phonemes, flags, 0, NULL) == 0) - { + if (LookupDictList(tr, &string, phonemes, flags, 0, NULL) == 0) { // now try the rules single_letter[1] = ' '; - TranslateRules(tr, &single_letter[2], phonemes, sizeof(phonemes), NULL,0,NULL); + TranslateRules(tr, &single_letter[2], phonemes, sizeof(phonemes), NULL, 0, NULL); } } } - if((only==0) && ((phonemes[0] == 0) || (phonemes[0] == phonSWITCH)) && (tr->translator_name != L('e','n'))) - { + if ((only == 0) && ((phonemes[0] == 0) || (phonemes[0] == phonSWITCH)) && (tr->translator_name != L('e', 'n'))) { // not found, try English SetTranslator2("en"); string = &single_letter[1]; single_letter[1] = '_'; - if(LookupDictList(translator2, &string, phonemes, flags, 0, NULL) == 0) - { + if (LookupDictList(translator2, &string, phonemes, flags, 0, NULL) == 0) { string = &single_letter[2]; LookupDictList(translator2, &string, phonemes, flags, 0, NULL); } - if(phonemes[0]) - { + if (phonemes[0]) { lang_name = "en"; - } - else - { + } else { SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table } } - if(phonemes[0]) - { - if(lang_name) - { + if (phonemes[0]) { + if (lang_name) { SetWordStress(translator2, phonemes, flags, -1, 0); - DecodePhonemes(phonemes,phonemes2); - sprintf(buf,"[\002_^_%s %s _^_%s]]","en",phonemes2,WordToString2(tr->translator_name)); + DecodePhonemes(phonemes, phonemes2); + sprintf(buf, "[\002_^_%s %s _^_%s]]", "en", phonemes2, WordToString2(tr->translator_name)); SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table - } - else - { + } else { SetWordStress(tr, phonemes, flags, -1, 0); - DecodePhonemes(phonemes,phonemes2); - sprintf(buf,"[\002%s]] ",phonemes2); + DecodePhonemes(phonemes, phonemes2); + sprintf(buf, "[\002%s]] ", phonemes2); } - } - else - if(only == 0) - { - strcpy(buf,"[\002(X1)(X1)(X1)]]"); + } else if (only == 0) { + strcpy(buf, "[\002(X1)(X1)(X1)]]"); } - return(buf); + return (buf); } int Read4Bytes(FILE *f) @@ -835,14 +782,13 @@ int Read4Bytes(FILE *f) // Read 4 bytes (least significant first) into a word int ix; unsigned char c; - int acc=0; + int acc = 0; - for(ix=0; ix<4; ix++) - { + for (ix = 0; ix < 4; ix++) { c = fgetc(f) & 0xff; acc += (c << (ix*8)); } - return(acc); + return (acc); } @@ -855,48 +801,42 @@ static int LoadSoundFile(const char *fname, int index) char fname_temp[100]; char fname2[sizeof(path_home)+13+40]; - if(fname == NULL) - { + if (fname == NULL) { // filename is already in the table fname = soundicon_tab[index].filename; } - if(fname==NULL) - return(1); + if (fname == NULL) + return (1); - if(fname[0] != '/') - { + if (fname[0] != '/') { // a relative path, look in espeak-data/soundicons - sprintf(fname2,"%s%csoundicons%c%s",path_home,PATHSEP,PATHSEP,fname); + sprintf(fname2, "%s%csoundicons%c%s", path_home, PATHSEP, PATHSEP, fname); fname = fname2; } f = NULL; #ifdef PLATFORM_POSIX - if((f = fopen(fname,"rb")) != NULL) - { + if ((f = fopen(fname, "rb")) != NULL) { int ix; int fd_temp; int header[3]; char command[sizeof(fname2)+sizeof(fname2)+40]; - fseek(f,20,SEEK_SET); - for(ix=0; ix<3; ix++) + fseek(f, 20, SEEK_SET); + for (ix = 0; ix < 3; ix++) header[ix] = Read4Bytes(f); // if the sound file is not mono, 16 bit signed, at the correct sample rate, then convert it - if((header[0] != 0x10001) || (header[1] != samplerate) || (header[2] != samplerate*2)) - { + if ((header[0] != 0x10001) || (header[1] != samplerate) || (header[2] != samplerate*2)) { fclose(f); f = NULL; - strcpy(fname_temp,"/tmp/espeakXXXXXX"); - if((fd_temp = mkstemp(fname_temp)) >= 0) - { + strcpy(fname_temp, "/tmp/espeakXXXXXX"); + if ((fd_temp = mkstemp(fname_temp)) >= 0) { close(fd_temp); - sprintf(command,"sox \"%s\" -r %d -c1 -t wav %s\n", fname, samplerate, fname_temp); - if(system(command) == 0) - { + sprintf(command, "sox \"%s\" -r %d -c1 -t wav %s\n", fname, samplerate, fname_temp); + if (system(command) == 0) { fname = fname_temp; } } @@ -904,31 +844,28 @@ static int LoadSoundFile(const char *fname, int index) } #endif - if(f == NULL) - { - f = fopen(fname,"rb"); - if(f == NULL) - { - fprintf(stderr,"Can't read temp file: %s\n",fname); - return(3); + if (f == NULL) { + f = fopen(fname, "rb"); + if (f == NULL) { + fprintf(stderr, "Can't read temp file: %s\n", fname); + return (3); } } length = GetFileLength(fname); - fseek(f,0,SEEK_SET); - if((p = (char *)realloc(soundicon_tab[index].data, length)) == NULL) - { + fseek(f, 0, SEEK_SET); + if ((p = (char *)realloc(soundicon_tab[index].data, length)) == NULL) { fclose(f); - return(4); + return (4); } - length = fread(p,1,length,f); + length = fread(p, 1, length, f); fclose(f); remove(fname_temp); ip = (int *)(&p[40]); soundicon_tab[index].length = (*ip) / 2; // length in samples soundicon_tab[index].data = p; - return(0); + return (0); } @@ -937,19 +874,16 @@ static int LookupSoundicon(int c) // Find the sound icon number for a punctuation chatacter int ix; - for(ix=N_SOUNDICON_SLOTS; ix= N_SOUNDICON_SLOTS) + if (slot >= N_SOUNDICON_SLOTS) slot = 0; - if(LoadSoundFile(fname, slot) != 0) - return(-1); + if (LoadSoundFile(fname, slot) != 0) + return (-1); soundicon_tab[slot].filename = (char *)realloc(soundicon_tab[ix].filename, strlen(fname)+1); strcpy(soundicon_tab[slot].filename, fname); - return(slot); + return (slot); } @@ -1003,79 +936,59 @@ static int AnnouncePunctuation(Translator *tr, int c1, int *c2_ptr, char *output c2 = *c2_ptr; buf[0] = 0; - if((soundicon = LookupSoundicon(c1)) >= 0) - { + if ((soundicon = LookupSoundicon(c1)) >= 0) { // add an embedded command to play the soundicon - sprintf(buf,"\001%dI ",soundicon); + sprintf(buf, "\001%dI ", soundicon); UngetC(c2); - } - else - { - if((c1 == '.') && (end_clause) && (c2 != '.')) - { - if(LookupSpecial(tr, "_.p", ph_buf)) - { + } else { + if ((c1 == '.') && (end_clause) && (c2 != '.')) { + if (LookupSpecial(tr, "_.p", ph_buf)) { punctname = ph_buf; // use word for 'period' instead of 'dot' } } - if(punctname == NULL) - { + if (punctname == NULL) { punctname = LookupCharName(tr, c1, 0); } - if(punctname == NULL) - return(-1); + if (punctname == NULL) + return (-1); - if((*bufix==0) || (end_clause ==0) || (tr->langopts.param[LOPT_ANNOUNCE_PUNCT] & 2)) - { - punct_count=1; - while((c2 == c1) && (c1 != '<')) // don't eat extra '<', it can miss XML tags - { + if ((*bufix == 0) || (end_clause == 0) || (tr->langopts.param[LOPT_ANNOUNCE_PUNCT] & 2)) { + punct_count = 1; + while ((c2 == c1) && (c1 != '<')) { // don't eat extra '<', it can miss XML tags punct_count++; c2 = GetC(); } *c2_ptr = c2; - if(end_clause) - { + if (end_clause) { UngetC(c2); } - if(punct_count==1) - { - sprintf(buf," %s",punctname); // we need the space before punctname, to ensure it doesn't merge with the previous word (eg. "2.-a") - } - else - if(punct_count < 4) - { + if (punct_count == 1) { + sprintf(buf, " %s", punctname); // we need the space before punctname, to ensure it doesn't merge with the previous word (eg. "2.-a") + } else if (punct_count < 4) { buf[0] = 0; - if(embedded_value[EMBED_S] < 300) - sprintf(buf,"\001+10S"); // Speak punctuation name faster, unless we are already speaking fast. It would upset Sonic SpeedUp + if (embedded_value[EMBED_S] < 300) + sprintf(buf, "\001+10S"); // Speak punctuation name faster, unless we are already speaking fast. It would upset Sonic SpeedUp - while(punct_count-- > 0) - { - sprintf(buf2," %s",punctname); + while (punct_count-- > 0) { + sprintf(buf2, " %s", punctname); strcat(buf, buf2); } - if(embedded_value[EMBED_S] < 300) - { - sprintf(buf2," \001-10S"); + if (embedded_value[EMBED_S] < 300) { + sprintf(buf2, " \001-10S"); strcat(buf, buf2); } + } else { + sprintf(buf, " %s %d %s", + punctname, punct_count, punctname); } - else - { - sprintf(buf," %s %d %s", - punctname,punct_count,punctname); - } - } - else - { + } else { // end the clause now and pick up the punctuation next time UngetC(c2); - if(option_ssml) - { - if((c1 == '<') || (c1 == '&')) + if (option_ssml) { + if ((c1 == '<') || (c1 == '&')) ssml_ignore_l_angle = c1; // this was < which was converted to <, don't pick it up again as < } ungot_char2 = c1; @@ -1086,32 +999,31 @@ static int AnnouncePunctuation(Translator *tr, int c1, int *c2_ptr, char *output bufix1 = *bufix; len = strlen(buf); - strcpy(&output[*bufix],buf); + strcpy(&output[*bufix], buf); *bufix += len; - if(end_clause==0) - return(-1); + if (end_clause == 0) + return (-1); - if(c1 == '-') - return(CLAUSE_NONE); // no pause + if (c1 == '-') + return (CLAUSE_NONE); // no pause - attributes = punct_attributes[lookupwchar(punct_chars,c1)]; + attributes = punct_attributes[lookupwchar(punct_chars, c1)]; short_pause = CLAUSE_SHORTFALL; - if((attributes & CLAUSE_BITS_INTONATION) == 0x1000) + if ((attributes & CLAUSE_BITS_INTONATION) == 0x1000) short_pause = CLAUSE_SHORTCOMMA; - if((bufix1 > 0) && !(tr->langopts.param[LOPT_ANNOUNCE_PUNCT] & 2)) - { - if((attributes & ~0x8000) == CLAUSE_SEMICOLON) - return(CLAUSE_SHORTFALL); - return(short_pause); + if ((bufix1 > 0) && !(tr->langopts.param[LOPT_ANNOUNCE_PUNCT] & 2)) { + if ((attributes & ~0x8000) == CLAUSE_SEMICOLON) + return (CLAUSE_SHORTFALL); + return (short_pause); } - if(attributes & CLAUSE_BIT_SENTENCE) - return(attributes); + if (attributes & CLAUSE_BIT_SENTENCE) + return (attributes); - return(short_pause); + return (short_pause); } #define SSML_SPEAK 1 @@ -1133,44 +1045,44 @@ static int AnnouncePunctuation(Translator *tr, int c1, int *c2_ptr, char *output #define SSML_CLOSE 0x20 // for a closing tag, OR this with the tag type // these tags have no effect if they are self-closing, eg. -static char ignore_if_self_closing[] = {0,1,1,1,1,0,0,0,0,1,1,0,1,0,1,0,0,0,0}; +static char ignore_if_self_closing[] = { 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0 }; static MNEM_TAB ssmltags[] = { - {"speak", SSML_SPEAK}, - {"voice", SSML_VOICE}, - {"prosody", SSML_PROSODY}, - {"say-as", SSML_SAYAS}, - {"mark", SSML_MARK}, - {"s", SSML_SENTENCE}, - {"p", SSML_PARAGRAPH}, - {"phoneme", SSML_PHONEME}, - {"sub", SSML_SUB}, - {"tts:style", SSML_STYLE}, - {"audio", SSML_AUDIO}, - {"emphasis", SSML_EMPHASIS}, - {"break", SSML_BREAK}, - {"metadata", SSML_IGNORE_TEXT}, + { "speak", SSML_SPEAK }, + { "voice", SSML_VOICE }, + { "prosody", SSML_PROSODY }, + { "say-as", SSML_SAYAS }, + { "mark", SSML_MARK }, + { "s", SSML_SENTENCE }, + { "p", SSML_PARAGRAPH }, + { "phoneme", SSML_PHONEME }, + { "sub", SSML_SUB }, + { "tts:style", SSML_STYLE }, + { "audio", SSML_AUDIO }, + { "emphasis", SSML_EMPHASIS }, + { "break", SSML_BREAK }, + { "metadata", SSML_IGNORE_TEXT }, - {"br", HTML_BREAK}, - {"li", HTML_BREAK}, - {"dd", HTML_BREAK}, - {"img", HTML_BREAK}, - {"td", HTML_BREAK}, - {"h1", SSML_PARAGRAPH}, - {"h2", SSML_PARAGRAPH}, - {"h3", SSML_PARAGRAPH}, - {"h4", SSML_PARAGRAPH}, - {"hr", SSML_PARAGRAPH}, - {"script", SSML_IGNORE_TEXT}, - {"style", SSML_IGNORE_TEXT}, - {"font", HTML_NOSPACE}, - {"b", HTML_NOSPACE}, - {"i", HTML_NOSPACE}, - {"strong", HTML_NOSPACE}, - {"em", HTML_NOSPACE}, - {"code", HTML_NOSPACE}, - {NULL,0} + { "br", HTML_BREAK }, + { "li", HTML_BREAK }, + { "dd", HTML_BREAK }, + { "img", HTML_BREAK }, + { "td", HTML_BREAK }, + { "h1", SSML_PARAGRAPH }, + { "h2", SSML_PARAGRAPH }, + { "h3", SSML_PARAGRAPH }, + { "h4", SSML_PARAGRAPH }, + { "hr", SSML_PARAGRAPH }, + { "script", SSML_IGNORE_TEXT }, + { "style", SSML_IGNORE_TEXT }, + { "font", HTML_NOSPACE }, + { "b", HTML_NOSPACE }, + { "i", HTML_NOSPACE }, + { "strong", HTML_NOSPACE }, + { "em", HTML_NOSPACE }, + { "code", HTML_NOSPACE }, + { NULL, 0 } }; @@ -1191,20 +1103,18 @@ static const char *VoiceFromStack() char language[40]; char buf[80]; - strcpy(voice_name,ssml_stack[0].voice_name); - strcpy(language,ssml_stack[0].language); + strcpy(voice_name, ssml_stack[0].voice_name); + strcpy(language, ssml_stack[0].language); voice_select.age = ssml_stack[0].voice_age; voice_select.gender = ssml_stack[0].voice_gender; voice_select.variant = ssml_stack[0].voice_variant_number; voice_select.identifier = NULL; - for(ix=0; ixvoice_name[0] != 0) && (SelectVoiceByName(NULL,sp->voice_name) != NULL)) - { + if ((sp->voice_name[0] != 0) && (SelectVoiceByName(NULL, sp->voice_name) != NULL)) { voice_name_specified = 1; strcpy(voice_name, sp->voice_name); language[0] = 0; @@ -1212,16 +1122,13 @@ static const char *VoiceFromStack() voice_select.age = 0; voice_select.variant = 0; } - if(sp->language[0] != 0) - { + if (sp->language[0] != 0) { strcpy(language, sp->language); // is this language provided by the base voice? p = base_voice.languages; - while(*p++ != 0) - { - if(strcmp(p, language) == 0) - { + while (*p++ != 0) { + if (strcmp(p, language) == 0) { // yes, change the language to the main language of the base voice strcpy(language, &base_voice.languages[1]); break; @@ -1229,34 +1136,32 @@ static const char *VoiceFromStack() p += (strlen(p) + 1); } - if(voice_name_specified == 0) + if (voice_name_specified == 0) voice_name[0] = 0; // forget a previous voice name if a language is specified } - if(sp->voice_gender != 0) - { + if (sp->voice_gender != 0) { voice_select.gender = sp->voice_gender; } - if(sp->voice_age != 0) + if (sp->voice_age != 0) voice_select.age = sp->voice_age; - if(sp->voice_variant_number != 0) + if (sp->voice_variant_number != 0) voice_select.variant = sp->voice_variant_number; } voice_select.name = voice_name; voice_select.languages = language; v_id = SelectVoice(&voice_select, &voice_found); - if(v_id == NULL) - return("default"); + if (v_id == NULL) + return ("default"); - if((strchr(v_id, '+') == NULL) && ((voice_select.gender == 0) || (voice_select.gender == base_voice.gender)) && (base_voice_variant_name[0] != 0)) - { + if ((strchr(v_id, '+') == NULL) && ((voice_select.gender == 0) || (voice_select.gender == base_voice.gender)) && (base_voice_variant_name[0] != 0)) { // a voice variant has not been selected, use the original voice variant sprintf(buf, "%s+%s", v_id, base_voice_variant_name); strncpy0(voice_name, buf, sizeof(voice_name)); - return(voice_name); + return (voice_name); } - return(v_id); + return (v_id); } @@ -1269,28 +1174,24 @@ static void ProcessParamStack(char *outbuf, int *outix) int value; char buf[20]; int new_parameters[N_SPEECH_PARAM]; - static char cmd_letter[N_SPEECH_PARAM] = {0, 'S','A','P','R', 0, 'C', 0, 0, 0, 0, 0, 'F'}; // embedded command letters + static char cmd_letter[N_SPEECH_PARAM] = { 0, 'S', 'A', 'P', 'R', 0, 'C', 0, 0, 0, 0, 0, 'F' }; // embedded command letters - for(param=0; param= 0) + for (ix = 0; ix < n_param_stack; ix++) { + for (param = 0; param < N_SPEECH_PARAM; param++) { + if (param_stack[ix].parameter[param] >= 0) new_parameters[param] = param_stack[ix].parameter[param]; } } - for(param=0; paramtype = tag_type; - for(ix=0; ixparameter[ix] = -1; } - return(sp); + return (sp); } @@ -1341,18 +1241,15 @@ static void PopParamStack(int tag_type, char *outbuf, int *outix) int ix; int top = 0; - if(tag_type >= SSML_CLOSE) + if (tag_type >= SSML_CLOSE) tag_type -= SSML_CLOSE; - for(ix=0; ix 0) - { + if (top > 0) { n_param_stack = top; } ProcessParamStack(outbuf, outix); @@ -1365,33 +1262,29 @@ static wchar_t *GetSsmlAttribute(wchar_t *pw, const char *name) // Gets the value string for an attribute. // Returns NULL if the attribute is not present int ix; - static wchar_t empty[1] = {0}; + static wchar_t empty[1] = { 0 }; - while(*pw != 0) - { - if(iswspace(pw[-1])) - { + while (*pw != 0) { + if (iswspace(pw[-1])) { ix = 0; - while(*pw == name[ix]) - { + while (*pw == name[ix]) { pw++; ix++; } - if(name[ix]==0) - { + if (name[ix] == 0) { // found the attribute, now get the value - while(iswspace(*pw)) pw++; - if(*pw == '=') pw++; - while(iswspace(*pw)) pw++; - if((*pw == '"') || (*pw == '\'')) // allow single-quotes ? - return(pw+1); + while (iswspace(*pw)) pw++; + if (*pw == '=') pw++; + while (iswspace(*pw)) pw++; + if ((*pw == '"') || (*pw == '\'')) // allow single-quotes ? + return (pw+1); else - return(empty); + return (empty); } } pw++; } - return(NULL); + return (NULL); } @@ -1399,15 +1292,14 @@ static int attrcmp(const wchar_t *string1, const char *string2) { int ix; - if(string1 == NULL) - return(1); + if (string1 == NULL) + return (1); - for(ix=0; (string1[ix] == string2[ix]) && (string1[ix] != 0); ix++) - { + for (ix = 0; (string1[ix] == string2[ix]) && (string1[ix] != 0); ix++) { } - if(((string1[ix]=='"') || (string1[ix]=='\'')) && (string2[ix]==0)) - return(0); - return(1); + if (((string1[ix] == '"') || (string1[ix] == '\'')) && (string2[ix] == 0)) + return (0); + return (1); } @@ -1415,12 +1307,11 @@ static int attrlookup(const wchar_t *string1, const MNEM_TAB *mtab) { int ix; - for(ix=0; mtab[ix].mnem != NULL; ix++) - { - if(attrcmp(string1,mtab[ix].mnem) == 0) - return(mtab[ix].value); + for (ix = 0; mtab[ix].mnem != NULL; ix++) { + if (attrcmp(string1, mtab[ix].mnem) == 0) + return (mtab[ix].value); } - return(mtab[ix].value); + return (mtab[ix].value); } @@ -1428,19 +1319,17 @@ static int attrnumber(const wchar_t *pw, int default_value, int type) { int value = 0; - if((pw == NULL) || !IsDigit09(*pw)) - return(default_value); + if ((pw == NULL) || !IsDigit09(*pw)) + return (default_value); - while(IsDigit09(*pw)) - { + while (IsDigit09(*pw)) { value = value*10 + *pw++ - '0'; } - if((type==1) && (towlower(*pw)=='s')) - { + if ((type == 1) && (towlower(*pw) == 's')) { // time: seconds rather than ms value *= 1000; } - return(value); + return (value); } @@ -1453,19 +1342,17 @@ static int attrcopy_utf8(char *buf, const wchar_t *pw, int len) int n; int prev_c = 0; - if(pw != NULL) - { - while((ix < (len-4)) && ((c = *pw++) != 0)) - { - if((c=='"') && (prev_c != '\\')) + if (pw != NULL) { + while ((ix < (len-4)) && ((c = *pw++) != 0)) { + if ((c == '"') && (prev_c != '\\')) break; // " indicates end of attribute, unless preceded by backstroke - n = utf8_out(c,&buf[ix]); + n = utf8_out(c, &buf[ix]); ix += n; prev_c = c; } } buf[ix] = 0; - return(ix); + return (ix); } @@ -1476,57 +1363,51 @@ static int attr_prosody_value(int param_type, const wchar_t *pw, int *value_out) wchar_t *tail; double value; - while(iswspace(*pw)) pw++; - if(*pw == '+') - { + while (iswspace(*pw)) pw++; + if (*pw == '+') { pw++; sign = 1; } - if(*pw == '-') - { + if (*pw == '-') { pw++; sign = -1; } - value = (double)wcstod(pw,&tail); - if(tail == pw) - { + value = (double)wcstod(pw, &tail); + if (tail == pw) { // failed to find a number, return 100% *value_out = 100; - return(2); + return (2); } - if(*tail == '%') - { - if(sign != 0) + if (*tail == '%') { + if (sign != 0) value = 100 + (sign * value); *value_out = (int)value; - return(2); // percentage + return (2); // percentage } - if((tail[0]=='s') && (tail[1]=='t')) - { + if ((tail[0] == 's') && (tail[1] == 't')) { #ifdef PLATFORM_RISCOS *value_out = 100; #else double x; // convert from semitones to a frequency percentage - x = pow((double)2.0,(double)((value*sign)/12)) * 100; + x = pow((double)2.0, (double)((value*sign)/12)) * 100; *value_out = (int)x; #endif - return(2); // percentage + return (2); // percentage } - if(param_type == espeakRATE) - { - if(sign == 0) + if (param_type == espeakRATE) { + if (sign == 0) *value_out = (int)(value * 100); else *value_out = 100 + (int)(sign * value * 100); - return(2); // percentage + return (2); // percentage } *value_out = (int)value; - return(sign); // -1, 0, or 1 + return (sign); // -1, 0, or 1 } @@ -1538,29 +1419,25 @@ int AddNameData(const char *name, int wide) int len; void *vp; - if(wide) - { + if (wide) { len = (wcslen((const wchar_t *)name)+1)*sizeof(wchar_t); n_namedata = (n_namedata + sizeof(wchar_t) - 1) % sizeof(wchar_t); // round to wchar_t boundary - } - else - { + } else { len = strlen(name)+1; } - if(namedata_ix+len >= n_namedata) - { + if (namedata_ix+len >= n_namedata) { // allocate more space for marker names - if((vp = realloc(namedata, namedata_ix+len + 1000)) == NULL) - return(-1); // failed to allocate, original data is unchanged but ignore this new name + if ((vp = realloc(namedata, namedata_ix+len + 1000)) == NULL) + return (-1); // failed to allocate, original data is unchanged but ignore this new name // !!! Bug?? If the allocated data shifts position, then pointers given to user application will be invalid namedata = (char *)vp; n_namedata = namedata_ix+len + 1000; } - memcpy(&namedata[ix = namedata_ix],name,len); + memcpy(&namedata[ix = namedata_ix], name, len); namedata_ix += len; - return(ix); + return (ix); } @@ -1569,20 +1446,19 @@ void SetVoiceStack(espeak_VOICE *v, const char *variant_name) SSML_STACK *sp; sp = &ssml_stack[0]; - if(v == NULL) - { - memset(sp,0,sizeof(ssml_stack[0])); + if (v == NULL) { + memset(sp, 0, sizeof(ssml_stack[0])); return; } - if(v->languages != NULL) - strcpy(sp->language,v->languages); - if(v->name != NULL) + if (v->languages != NULL) + strcpy(sp->language, v->languages); + if (v->name != NULL) strncpy0(sp->voice_name, v->name, sizeof(sp->voice_name)); sp->voice_variant_number = v->variant; sp->voice_age = v->age; sp->voice_gender = v->gender; - if(memcmp(variant_name, "!v", 2) == 0) + if (memcmp(variant_name, "!v", 2) == 0) variant_name += 3;// strip variant directory name, !v plus PATHSEP strncpy0(base_voice_variant_name, variant_name, sizeof(base_voice_variant_name)); memcpy(&base_voice, ¤t_voice_selected, sizeof(base_voice)); @@ -1607,65 +1483,57 @@ static int GetVoiceAttributes(wchar_t *pw, int tag_type) SSML_STACK *ssml_sp; static const MNEM_TAB mnem_gender[] = { - {"male", 1}, - {"female", 2}, - {"neutral", 3}, - {NULL, 0} + { "male", 1 }, + { "female", 2 }, + { "neutral", 3 }, + { NULL, 0 } }; - if(tag_type & SSML_CLOSE) - { + if (tag_type & SSML_CLOSE) { // delete a stack frame - if(n_ssml_stack > 1) - { + if (n_ssml_stack > 1) { n_ssml_stack--; } - } - else - { + } else { // add a stack frame if any voice details are specified - lang = GetSsmlAttribute(pw,"xml:lang"); + lang = GetSsmlAttribute(pw, "xml:lang"); - if(tag_type != SSML_VOICE) - { + if (tag_type != SSML_VOICE) { // only expect an xml:lang attribute name = NULL; variant = NULL; age = NULL; gender = NULL; - } - else - { - name = GetSsmlAttribute(pw,"name"); - variant = GetSsmlAttribute(pw,"variant"); - age = GetSsmlAttribute(pw,"age"); - gender = GetSsmlAttribute(pw,"gender"); + } else { + name = GetSsmlAttribute(pw, "name"); + variant = GetSsmlAttribute(pw, "variant"); + age = GetSsmlAttribute(pw, "age"); + gender = GetSsmlAttribute(pw, "gender"); } - if((tag_type != SSML_VOICE) && (lang==NULL)) - return(0); // or

without language spec, nothing to do + if ((tag_type != SSML_VOICE) && (lang == NULL)) + return (0); // or

without language spec, nothing to do ssml_sp = &ssml_stack[n_ssml_stack++]; - attrcopy_utf8(ssml_sp->language,lang,sizeof(ssml_sp->language)); - attrcopy_utf8(ssml_sp->voice_name,name,sizeof(ssml_sp->voice_name)); - if((value = attrnumber(variant,1,0)) > 0) + attrcopy_utf8(ssml_sp->language, lang, sizeof(ssml_sp->language)); + attrcopy_utf8(ssml_sp->voice_name, name, sizeof(ssml_sp->voice_name)); + if ((value = attrnumber(variant, 1, 0)) > 0) value--; // variant='0' and variant='1' the same ssml_sp->voice_variant_number = value; - ssml_sp->voice_age = attrnumber(age,0,0); - ssml_sp->voice_gender = attrlookup(gender,mnem_gender); + ssml_sp->voice_age = attrnumber(age, 0, 0); + ssml_sp->voice_gender = attrlookup(gender, mnem_gender); ssml_sp->tag_type = tag_type; } new_voice_id = VoiceFromStack(); - if(strcmp(new_voice_id,current_voice_id) != 0) - { + if (strcmp(new_voice_id, current_voice_id) != 0) { // add an embedded command to change the voice - strcpy(current_voice_id,new_voice_id); - return(CLAUSE_BIT_VOICE); // change of voice + strcpy(current_voice_id, new_voice_id); + return (CLAUSE_BIT_VOICE); // change of voice } - return(0); + return (0); } @@ -1675,44 +1543,44 @@ static void SetProsodyParameter(int param_type, wchar_t *attr1, PARAM_STACK *sp) int sign; static const MNEM_TAB mnem_volume[] = { - {"default",100}, - {"silent",0}, - {"x-soft",30}, - {"soft",65}, - {"medium",100}, - {"loud",150}, - {"x-loud",230}, - {NULL, -1} + { "default", 100 }, + { "silent", 0 }, + { "x-soft", 30 }, + { "soft", 65 }, + { "medium", 100 }, + { "loud", 150 }, + { "x-loud", 230 }, + { NULL, -1 } }; static const MNEM_TAB mnem_rate[] = { - {"default",100}, - {"x-slow",60}, - {"slow",80}, - {"medium",100}, - {"fast",125}, - {"x-fast",160}, - {NULL, -1} + { "default", 100 }, + { "x-slow", 60 }, + { "slow", 80 }, + { "medium", 100 }, + { "fast", 125 }, + { "x-fast", 160 }, + { NULL, -1 } }; static const MNEM_TAB mnem_pitch[] = { - {"default",100}, - {"x-low",70}, - {"low",85}, - {"medium",100}, - {"high",110}, - {"x-high",120}, - {NULL, -1} + { "default", 100 }, + { "x-low", 70 }, + { "low", 85 }, + { "medium", 100 }, + { "high", 110 }, + { "x-high", 120 }, + { NULL, -1 } }; static const MNEM_TAB mnem_range[] = { - {"default",100}, - {"x-low",20}, - {"low",50}, - {"medium",100}, - {"high",140}, - {"x-high",180}, - {NULL, -1} + { "default", 100 }, + { "x-low", 20 }, + { "low", 50 }, + { "medium", 100 }, + { "high", 140 }, + { "x-high", 180 }, + { NULL, -1 } }; static const MNEM_TAB *mnem_tabs[5] = { @@ -1720,25 +1588,18 @@ static void SetProsodyParameter(int param_type, wchar_t *attr1, PARAM_STACK *sp) }; - if((value = attrlookup(attr1,mnem_tabs[param_type])) >= 0) - { + if ((value = attrlookup(attr1, mnem_tabs[param_type])) >= 0) { // mnemonic specifies a value as a percentage of the base pitch/range/rate/volume sp->parameter[param_type] = (param_stack[0].parameter[param_type] * value)/100; - } - else - { - sign = attr_prosody_value(param_type,attr1,&value); + } else { + sign = attr_prosody_value(param_type, attr1, &value); - if(sign == 0) + if (sign == 0) sp->parameter[param_type] = value; // absolute value in Hz - else - if(sign == 2) - { + else if (sign == 2) { // change specified as percentage or in semitones sp->parameter[param_type] = (speech_parameters[param_type] * value)/100; - } - else - { + } else { // change specified as plus or minus Hz sp->parameter[param_type] = speech_parameters[param_type] + (value*sign); } @@ -1750,11 +1611,11 @@ static int ReplaceKeyName(char *outbuf, int index, int *outix) { // Replace some key-names by single characters, so they can be pronounced in different languages static MNEM_TAB keynames[] = { - {"space ",0xe020}, - {"tab ", 0xe009}, - {"underscore ", 0xe05f}, - {"double-quote ", '"'}, - {NULL, 0} + { "space ", 0xe020 }, + { "tab ", 0xe009 }, + { "underscore ", 0xe05f }, + { "double-quote ", '"' }, + { NULL, 0 } }; int ix; @@ -1763,13 +1624,12 @@ static int ReplaceKeyName(char *outbuf, int index, int *outix) p = &outbuf[index]; - if((letter = LookupMnem(keynames, p)) != 0) - { + if ((letter = LookupMnem(keynames, p)) != 0) { ix = utf8_out(letter, p); *outix = index + ix; - return(letter); + return (letter); } - return(0); + return (0); } @@ -1799,65 +1659,64 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb SSML_STACK *ssml_sp; static const MNEM_TAB mnem_phoneme_alphabet[] = { - {"espeak",1}, - {NULL, -1} + { "espeak", 1 }, + { NULL, -1 } }; static const MNEM_TAB mnem_punct[] = { - {"none", 1}, - {"all", 2}, - {"some", 3}, - {NULL, -1} + { "none", 1 }, + { "all", 2 }, + { "some", 3 }, + { NULL, -1 } }; static const MNEM_TAB mnem_capitals[] = { - {"no", 0}, - {"spelling", 2}, - {"icon", 1}, - {"pitch", 20}, // this is the amount by which to raise the pitch - {NULL, -1} + { "no", 0 }, + { "spelling", 2 }, + { "icon", 1 }, + { "pitch", 20 }, // this is the amount by which to raise the pitch + { NULL, -1 } }; static const MNEM_TAB mnem_interpret_as[] = { - {"characters",SAYAS_CHARS}, - {"tts:char",SAYAS_SINGLE_CHARS}, - {"tts:key",SAYAS_KEY}, - {"tts:digits",SAYAS_DIGITS}, - {"telephone",SAYAS_DIGITS1}, - {NULL, -1} + { "characters", SAYAS_CHARS }, + { "tts:char", SAYAS_SINGLE_CHARS }, + { "tts:key", SAYAS_KEY }, + { "tts:digits", SAYAS_DIGITS }, + { "telephone", SAYAS_DIGITS1 }, + { NULL, -1 } }; static const MNEM_TAB mnem_sayas_format[] = { - {"glyphs",1}, - {NULL, -1} + { "glyphs", 1 }, + { NULL, -1 } }; static const MNEM_TAB mnem_break[] = { - {"none",0}, - {"x-weak",1}, - {"weak",2}, - {"medium",3}, - {"strong",4}, - {"x-strong",5}, - {NULL,-1} + { "none", 0 }, + { "x-weak", 1 }, + { "weak", 2 }, + { "medium", 3 }, + { "strong", 4 }, + { "x-strong", 5 }, + { NULL, -1 } }; static const MNEM_TAB mnem_emphasis[] = { - {"none",1}, - {"reduced",2}, - {"moderate",3}, - {"strong",4}, - {"x-strong",5}, - {NULL,-1} + { "none", 1 }, + { "reduced", 2 }, + { "moderate", 3 }, + { "strong", 4 }, + { "x-strong", 5 }, + { NULL, -1 } }; static const char *prosody_attr[5] = { NULL, "rate", "volume", "pitch", "range" }; - for(ix=0; ix<(sizeof(tag_name)-1); ix++) - { - if(((c = xml_buf[ix]) == 0) || iswspace(c)) + for (ix = 0; ix < (sizeof(tag_name)-1); ix++) { + if (((c = xml_buf[ix]) == 0) || iswspace(c)) break; tag_name[ix] = tolower((char)c); } @@ -1865,25 +1724,20 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb px = &xml_buf[ix]; // the tag's attributes - if(tag_name[0] == '/') - { + if (tag_name[0] == '/') { // closing tag - if((tag_type = LookupMnem(ssmltags,&tag_name[1])) != HTML_NOSPACE) - { + if ((tag_type = LookupMnem(ssmltags, &tag_name[1])) != HTML_NOSPACE) { outbuf[(*outix)++] = ' '; } tag_type += SSML_CLOSE; - } - else - { - if((tag_type = LookupMnem(ssmltags,tag_name)) != HTML_NOSPACE) - { + } else { + if ((tag_type = LookupMnem(ssmltags, tag_name)) != HTML_NOSPACE) { // separate SSML tags from the previous word (but not HMTL tags such as which can occur inside a word) outbuf[(*outix)++] = ' '; } - if(self_closing && ignore_if_self_closing[tag_type]) - return(0); + if (self_closing && ignore_if_self_closing[tag_type]) + return (0); } @@ -1891,23 +1745,19 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb terminator = CLAUSE_NONE; ssml_sp = &ssml_stack[n_ssml_stack-1]; - switch(tag_type) + switch (tag_type) { case SSML_STYLE: sp = PushParamStack(tag_type); - attr1 = GetSsmlAttribute(px,"field"); - attr2 = GetSsmlAttribute(px,"mode"); + attr1 = GetSsmlAttribute(px, "field"); + attr2 = GetSsmlAttribute(px, "mode"); - if(attrcmp(attr1,"punctuation")==0) - { - value = attrlookup(attr2,mnem_punct); + if (attrcmp(attr1, "punctuation") == 0) { + value = attrlookup(attr2, mnem_punct); sp->parameter[espeakPUNCTUATION] = value; - } - else - if(attrcmp(attr1,"capital_letters")==0) - { - value = attrlookup(attr2,mnem_capitals); + } else if (attrcmp(attr1, "capital_letters") == 0) { + value = attrlookup(attr2, mnem_capitals); sp->parameter[espeakCAPITALS] = value; } ProcessParamStack(outbuf, outix); @@ -1917,10 +1767,8 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb sp = PushParamStack(tag_type); // look for attributes: rate, volume, pitch, range - for(param_type=espeakRATE; param_type <= espeakRANGE; param_type++) - { - if((attr1 = GetSsmlAttribute(px,prosody_attr[param_type])) != NULL) - { + for (param_type = espeakRATE; param_type <= espeakRANGE; param_type++) { + if ((attr1 = GetSsmlAttribute(px, prosody_attr[param_type])) != NULL) { SetProsodyParameter(param_type, attr1, sp); } } @@ -1931,22 +1779,18 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb case SSML_EMPHASIS: sp = PushParamStack(tag_type); value = 3; // default is "moderate" - if((attr1 = GetSsmlAttribute(px,"level")) != NULL) - { - value = attrlookup(attr1,mnem_emphasis); + if ((attr1 = GetSsmlAttribute(px, "level")) != NULL) { + value = attrlookup(attr1, mnem_emphasis); } - if(translator->langopts.tone_language == 1) - { - static unsigned char emphasis_to_pitch_range[] = {50,50,40,70,90,100}; - static unsigned char emphasis_to_volume[] = {100,100,70,110,135,150}; + if (translator->langopts.tone_language == 1) { + static unsigned char emphasis_to_pitch_range[] = { 50, 50, 40, 70, 90, 100 }; + static unsigned char emphasis_to_volume[] = { 100, 100, 70, 110, 135, 150 }; // tone language (eg.Chinese) do emphasis by increasing the pitch range. sp->parameter[espeakRANGE] = emphasis_to_pitch_range[value]; sp->parameter[espeakVOLUME] = emphasis_to_volume[value]; - } - else - { - static unsigned char emphasis_to_volume2[] = {100,100,75,100,120,150}; + } else { + static unsigned char emphasis_to_volume2[] = { 100, 100, 75, 100, 120, 150 }; sp->parameter[espeakVOLUME] = emphasis_to_volume2[value]; sp->parameter[espeakEMPHASIS] = value; } @@ -1960,40 +1804,38 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb break; case SSML_PHONEME: - attr1 = GetSsmlAttribute(px,"alphabet"); - attr2 = GetSsmlAttribute(px,"ph"); - value = attrlookup(attr1,mnem_phoneme_alphabet); - if (value == 1) // alphabet="espeak" - { + attr1 = GetSsmlAttribute(px, "alphabet"); + attr2 = GetSsmlAttribute(px, "ph"); + value = attrlookup(attr1, mnem_phoneme_alphabet); + if (value == 1) { // alphabet="espeak" outbuf[(*outix)++] = '['; outbuf[(*outix)++] = '['; - *outix += attrcopy_utf8(&outbuf[*outix],attr2,n_outbuf-*outix); + *outix += attrcopy_utf8(&outbuf[*outix], attr2, n_outbuf-*outix); outbuf[(*outix)++] = ']'; outbuf[(*outix)++] = ']'; } break; case SSML_SAYAS: - attr1 = GetSsmlAttribute(px,"interpret-as"); - attr2 = GetSsmlAttribute(px,"format"); - attr3 = GetSsmlAttribute(px,"detail"); - value = attrlookup(attr1,mnem_interpret_as); - value2 = attrlookup(attr2,mnem_sayas_format); - if(value2 == 1) + attr1 = GetSsmlAttribute(px, "interpret-as"); + attr2 = GetSsmlAttribute(px, "format"); + attr3 = GetSsmlAttribute(px, "detail"); + value = attrlookup(attr1, mnem_interpret_as); + value2 = attrlookup(attr2, mnem_sayas_format); + if (value2 == 1) value = SAYAS_GLYPHS; - value3 = attrnumber(attr3,0,0); + value3 = attrnumber(attr3, 0, 0); - if(value == SAYAS_DIGITS) - { - if(value3 <= 1) + if (value == SAYAS_DIGITS) { + if (value3 <= 1) value = SAYAS_DIGITS1; else value = SAYAS_DIGITS + value3; } - sprintf(buf,"%c%dY",CTRL_EMBEDDED,value); - strcpy(&outbuf[*outix],buf); + sprintf(buf, "%c%dY", CTRL_EMBEDDED, value); + strcpy(&outbuf[*outix], buf); *outix += strlen(buf); sayas_start = *outix; @@ -2001,8 +1843,7 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb break; case SSML_SAYAS + SSML_CLOSE: - if(sayas_mode == SAYAS_KEY) - { + if (sayas_mode == SAYAS_KEY) { outbuf[*outix] = 0; ReplaceKeyName(outbuf, sayas_start, outix); } @@ -2013,11 +1854,10 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb break; case SSML_SUB: - if((attr1 = GetSsmlAttribute(px,"alias")) != NULL) - { + if ((attr1 = GetSsmlAttribute(px, "alias")) != NULL) { // use the alias rather than the text ignore_text = 1; - *outix += attrcopy_utf8(&outbuf[*outix],attr1,n_outbuf-*outix); + *outix += attrcopy_utf8(&outbuf[*outix], attr1, n_outbuf-*outix); } break; @@ -2031,23 +1871,20 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb break; case SSML_MARK: - if((attr1 = GetSsmlAttribute(px,"name")) != NULL) - { + if ((attr1 = GetSsmlAttribute(px, "name")) != NULL) { // add name to circular buffer of marker names - attrcopy_utf8(buf,attr1,sizeof(buf)); + attrcopy_utf8(buf, attr1, sizeof(buf)); - if(strcmp(skip_marker,buf)==0) - { + if (strcmp(skip_marker, buf) == 0) { // This is the marker we are waiting for before starting to speak clear_skipping_text = 1; skip_marker[0] = 0; - return(CLAUSE_NONE); + return (CLAUSE_NONE); } - if((index = AddNameData(buf,0)) >= 0) - { - sprintf(buf,"%c%dM",CTRL_EMBEDDED,index); - strcpy(&outbuf[*outix],buf); + if ((index = AddNameData(buf, 0)) >= 0) { + sprintf(buf, "%c%dM", CTRL_EMBEDDED, index); + strcpy(&outbuf[*outix], buf); *outix += strlen(buf); } } @@ -2056,39 +1893,29 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb case SSML_AUDIO: sp = PushParamStack(tag_type); - if((attr1 = GetSsmlAttribute(px,"src")) != NULL) - { + if ((attr1 = GetSsmlAttribute(px, "src")) != NULL) { char fname[256]; - attrcopy_utf8(buf,attr1,sizeof(buf)); + attrcopy_utf8(buf, attr1, sizeof(buf)); - if(uri_callback == NULL) - { - if((xmlbase != NULL) && (buf[0] != '/')) - { - sprintf(fname,"%s/%s",xmlbase,buf); + if (uri_callback == NULL) { + if ((xmlbase != NULL) && (buf[0] != '/')) { + sprintf(fname, "%s/%s", xmlbase, buf); index = LoadSoundFile2(fname); - } - else - { + } else { index = LoadSoundFile2(buf); } - if(index >= 0) - { - sprintf(buf,"%c%dI",CTRL_EMBEDDED,index); - strcpy(&outbuf[*outix],buf); + if (index >= 0) { + sprintf(buf, "%c%dI", CTRL_EMBEDDED, index); + strcpy(&outbuf[*outix], buf); *outix += strlen(buf); sp->parameter[espeakSILENCE] = 1; } - } - else - { - if((index = AddNameData(buf,0)) >= 0) - { + } else { + if ((index = AddNameData(buf, 0)) >= 0) { uri = &namedata[index]; - if(uri_callback(1,uri,xmlbase) == 0) - { - sprintf(buf,"%c%dU",CTRL_EMBEDDED,index); - strcpy(&outbuf[*outix],buf); + if (uri_callback(1, uri, xmlbase) == 0) { + sprintf(buf, "%c%dU", CTRL_EMBEDDED, index); + strcpy(&outbuf[*outix], buf); *outix += strlen(buf); sp->parameter[espeakSILENCE] = 1; } @@ -2097,145 +1924,131 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb } ProcessParamStack(outbuf, outix); - if(self_closing) + if (self_closing) PopParamStack(tag_type, outbuf, outix); else audio_text = 1; - return(CLAUSE_NONE); + return (CLAUSE_NONE); case SSML_AUDIO + SSML_CLOSE: PopParamStack(tag_type, outbuf, outix); audio_text = 0; - return(CLAUSE_NONE); + return (CLAUSE_NONE); case SSML_BREAK: value = 21; terminator = CLAUSE_NONE; - if((attr1 = GetSsmlAttribute(px,"strength")) != NULL) - { - static int break_value[6] = {0,7,14,21,40,80}; // *10mS - value = attrlookup(attr1,mnem_break); - if(value < 3) - { + if ((attr1 = GetSsmlAttribute(px, "strength")) != NULL) { + static int break_value[6] = { 0, 7, 14, 21, 40, 80 }; // *10mS + value = attrlookup(attr1, mnem_break); + if (value < 3) { // adjust prepause on the following word - sprintf(&outbuf[*outix],"%c%dB",CTRL_EMBEDDED,value); + sprintf(&outbuf[*outix], "%c%dB", CTRL_EMBEDDED, value); *outix += 3; terminator = 0; } value = break_value[value]; } - if((attr2 = GetSsmlAttribute(px,"time")) != NULL) - { - value2 = attrnumber(attr2,0,1); // pause in mS + if ((attr2 = GetSsmlAttribute(px, "time")) != NULL) { + value2 = attrnumber(attr2, 0, 1); // pause in mS // compensate for speaking speed to keep constant pause length, see function PauseLength() // 'value' here is x 10mS value = (value2 * 256) / (speed.clause_pause_factor * 10); - if(value < 200) + if (value < 200) value = (value2 * 256) / (speed.pause_factor * 10); - if(terminator == 0) + if (terminator == 0) terminator = CLAUSE_NONE; } - if(terminator) - { - if(value > 0xfff) - { + if (terminator) { + if (value > 0xfff) { // scale down the value and set a scaling indicator bit value = value / 32; - if(value > 0xfff) + if (value > 0xfff) value = 0xfff; terminator |= CLAUSE_PAUSE_LONG; } - return(terminator + value); + return (terminator + value); } break; case SSML_SPEAK: - if((attr1 = GetSsmlAttribute(px,"xml:base")) != NULL) - { - attrcopy_utf8(buf,attr1,sizeof(buf)); - if((index = AddNameData(buf,0)) >= 0) - { + if ((attr1 = GetSsmlAttribute(px, "xml:base")) != NULL) { + attrcopy_utf8(buf, attr1, sizeof(buf)); + if ((index = AddNameData(buf, 0)) >= 0) { xmlbase = &namedata[index]; } } - if(GetVoiceAttributes(px, tag_type) == 0) - return(0); // no voice change - return(CLAUSE_VOICE); + if (GetVoiceAttributes(px, tag_type) == 0) + return (0); // no voice change + return (CLAUSE_VOICE); case SSML_VOICE: - if(GetVoiceAttributes(px, tag_type) == 0) - return(0); // no voice change - return(CLAUSE_VOICE); + if (GetVoiceAttributes(px, tag_type) == 0) + return (0); // no voice change + return (CLAUSE_VOICE); case SSML_SPEAK + SSML_CLOSE: // unwind stack until the previous or tag - while((n_ssml_stack > 1) && (ssml_stack[n_ssml_stack-1].tag_type != SSML_SPEAK)) - { + while ((n_ssml_stack > 1) && (ssml_stack[n_ssml_stack-1].tag_type != SSML_SPEAK)) { n_ssml_stack--; } - return(CLAUSE_PERIOD + GetVoiceAttributes(px, tag_type)); + return (CLAUSE_PERIOD + GetVoiceAttributes(px, tag_type)); case SSML_VOICE + SSML_CLOSE: // unwind stack until the previous or tag - while((n_ssml_stack > 1) && (ssml_stack[n_ssml_stack-1].tag_type != SSML_VOICE)) - { + while ((n_ssml_stack > 1) && (ssml_stack[n_ssml_stack-1].tag_type != SSML_VOICE)) { n_ssml_stack--; } - terminator=0; // ?? Sentence intonation, but no pause ?? - return(terminator + GetVoiceAttributes(px, tag_type)); + terminator = 0; // ?? Sentence intonation, but no pause ?? + return (terminator + GetVoiceAttributes(px, tag_type)); case HTML_BREAK: case HTML_BREAK + SSML_CLOSE: - return(CLAUSE_COLON); + return (CLAUSE_COLON); case SSML_SENTENCE: - if(ssml_sp->tag_type == SSML_SENTENCE) - { + if (ssml_sp->tag_type == SSML_SENTENCE) { // new sentence implies end-of-sentence voice_change_flag = GetVoiceAttributes(px, SSML_SENTENCE+SSML_CLOSE); } voice_change_flag |= GetVoiceAttributes(px, tag_type); - return(CLAUSE_PARAGRAPH + voice_change_flag); + return (CLAUSE_PARAGRAPH + voice_change_flag); case SSML_PARAGRAPH: - if(ssml_sp->tag_type == SSML_SENTENCE) - { + if (ssml_sp->tag_type == SSML_SENTENCE) { // new paragraph implies end-of-sentence or end-of-paragraph voice_change_flag = GetVoiceAttributes(px, SSML_SENTENCE+SSML_CLOSE); } - if(ssml_sp->tag_type == SSML_PARAGRAPH) - { + if (ssml_sp->tag_type == SSML_PARAGRAPH) { // new paragraph implies end-of-sentence or end-of-paragraph voice_change_flag |= GetVoiceAttributes(px, SSML_PARAGRAPH+SSML_CLOSE); } voice_change_flag |= GetVoiceAttributes(px, tag_type); - return(CLAUSE_PARAGRAPH + voice_change_flag); + return (CLAUSE_PARAGRAPH + voice_change_flag); case SSML_SENTENCE + SSML_CLOSE: - if(ssml_sp->tag_type == SSML_SENTENCE) - { + if (ssml_sp->tag_type == SSML_SENTENCE) { // end of a sentence which specified a language voice_change_flag = GetVoiceAttributes(px, tag_type); } - return(CLAUSE_PERIOD + voice_change_flag); + return (CLAUSE_PERIOD + voice_change_flag); case SSML_PARAGRAPH + SSML_CLOSE: - if((ssml_sp->tag_type == SSML_SENTENCE) || (ssml_sp->tag_type == SSML_PARAGRAPH)) - { + if ((ssml_sp->tag_type == SSML_SENTENCE) || (ssml_sp->tag_type == SSML_PARAGRAPH)) { // End of a paragraph which specified a language. // (End-of-paragraph also implies end-of-sentence) - return(GetVoiceAttributes(px, tag_type) + CLAUSE_PARAGRAPH); + return (GetVoiceAttributes(px, tag_type) + CLAUSE_PARAGRAPH); } - return(CLAUSE_PARAGRAPH); + return (CLAUSE_PARAGRAPH); } - return(0); + return (0); } @@ -2249,13 +2062,13 @@ static void RemoveChar(char *p) static MNEM_TAB xml_char_mnemonics[] = { - {"gt",'>'}, - {"lt", 0xe000 + '<'}, // private usage area, to avoid confusion with XML tag - {"amp", '&'}, - {"quot", '"'}, - {"nbsp", ' '}, - {"apos", '\''}, - {NULL,-1} + { "gt", '>' }, + { "lt", 0xe000 + '<' }, // private usage area, to avoid confusion with XML tag + { "amp", '&' }, + { "quot", '"' }, + { "nbsp", ' ' }, + { "apos", '\'' }, + { NULL, -1 } }; @@ -2272,10 +2085,10 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix punctuation immediately followed by alphanumeric eg. 1.23 !Speak :path repeated punctuation, eg. ... !!! */ - int c1=' '; // current character + int c1 = ' '; // current character int c2; // next character - int cprev=' '; // previous character - int cprev2=' '; + int cprev = ' '; // previous character + int cprev2 = ' '; int c_next; int parag; int ix = 0; @@ -2302,8 +2115,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix static char ungot_string[N_XML_BUF2+4]; static int ungot_string_ix = -1; - if(clear_skipping_text) - { + if (clear_skipping_text) { skipping_text = 0; clear_skipping_text = 0; } @@ -2317,40 +2129,32 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix f_input = f_in; // for GetC etc - if(ungot_word != NULL) - { - strcpy(buf,ungot_word); + if (ungot_word != NULL) { + strcpy(buf, ungot_word); ix += strlen(ungot_word); ungot_word = NULL; } - if(ungot_char2 != 0) - { + if (ungot_char2 != 0) { c2 = ungot_char2; - } - else - { + } else { c2 = GetC(); } - while(!Eof() || (ungot_char != 0) || (ungot_char2 != 0) || (ungot_string_ix >= 0)) - { - if(!iswalnum(c1)) - { - if((end_character_position > 0) && (count_characters > end_character_position)) - { + while (!Eof() || (ungot_char != 0) || (ungot_char2 != 0) || (ungot_string_ix >= 0)) { + if (!iswalnum(c1)) { + if ((end_character_position > 0) && (count_characters > end_character_position)) { end_of_input = 1; - return(CLAUSE_EOF); + return (CLAUSE_EOF); } - if((skip_characters > 0) && (count_characters >= skip_characters)) - { + if ((skip_characters > 0) && (count_characters >= skip_characters)) { // reached the specified start position // don't break a word clear_skipping_text = 1; skip_characters = 0; UngetC(c2); - return(CLAUSE_NONE); + return (CLAUSE_NONE); } } @@ -2358,114 +2162,86 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix cprev = c1; c1 = c2; - if(ungot_string_ix >= 0) - { - if(ungot_string[ungot_string_ix] == 0) + if (ungot_string_ix >= 0) { + if (ungot_string[ungot_string_ix] == 0) ungot_string_ix = -1; } - if((ungot_string_ix == 0) && (ungot_char2 == 0)) - { + if ((ungot_string_ix == 0) && (ungot_char2 == 0)) { c1 = ungot_string[ungot_string_ix++]; } - if(ungot_string_ix >= 0) - { + if (ungot_string_ix >= 0) { c2 = ungot_string[ungot_string_ix++]; - } - else - { + } else { c2 = GetC(); - if(Eof()) - { + if (Eof()) { c2 = ' '; } } ungot_char2 = 0; - if((option_ssml) && (phoneme_mode==0)) - { - if((ssml_ignore_l_angle != '&') && (c1 == '&') && ((c2=='#') || ((c2 >= 'a') && (c2 <= 'z')))) - { + if ((option_ssml) && (phoneme_mode == 0)) { + if ((ssml_ignore_l_angle != '&') && (c1 == '&') && ((c2 == '#') || ((c2 >= 'a') && (c2 <= 'z')))) { n_xml_buf = 0; c1 = c2; - while(!Eof() && (iswalnum(c1) || (c1=='#')) && (n_xml_buf < N_XML_BUF2)) - { + while (!Eof() && (iswalnum(c1) || (c1 == '#')) && (n_xml_buf < N_XML_BUF2)) { xml_buf2[n_xml_buf++] = c1; c1 = GetC(); } xml_buf2[n_xml_buf] = 0; c2 = GetC(); - sprintf(ungot_string,"%s%c%c",&xml_buf2[0],c1,c2); + sprintf(ungot_string, "%s%c%c", &xml_buf2[0], c1, c2); - if(c1 == ';') - { - if(xml_buf2[0] == '#') - { + if (c1 == ';') { + if (xml_buf2[0] == '#') { // character code number - if(xml_buf2[1] == 'x') - found = sscanf(&xml_buf2[2],"%x",(unsigned int *)(&c1)); + if (xml_buf2[1] == 'x') + found = sscanf(&xml_buf2[2], "%x", (unsigned int *)(&c1)); else - found = sscanf(&xml_buf2[1],"%d",&c1); - } - else - { - if((found = LookupMnem(xml_char_mnemonics,xml_buf2)) != -1) - { + found = sscanf(&xml_buf2[1], "%d", &c1); + } else { + if ((found = LookupMnem(xml_char_mnemonics, xml_buf2)) != -1) { c1 = found; - if(c2 == 0) + if (c2 == 0) c2 = ' '; } } - } - else - { + } else { found = -1; } - if(found <= 0) - { + if (found <= 0) { ungot_string_ix = 0; c1 = '&'; c2 = ' '; } - if((c1 <= 0x20) && ((sayas_mode == SAYAS_SINGLE_CHARS) || (sayas_mode == SAYAS_KEY))) - { + if ((c1 <= 0x20) && ((sayas_mode == SAYAS_SINGLE_CHARS) || (sayas_mode == SAYAS_KEY))) { c1 += 0xe000; // move into unicode private usage area } - } - else - if((c1 == '<') && (ssml_ignore_l_angle != '<')) - { - if((c2 == '!') || (c2 == '?')) - { + } else if ((c1 == '<') && (ssml_ignore_l_angle != '<')) { + if ((c2 == '!') || (c2 == '?')) { // a comment, ignore until closing '<' (or ')) - { + while (!Eof() && (c1 != '>')) { c1 = GetC(); } c2 = ' '; - } - else - if((c2 == '/') || iswalpha2(c2)) - { + } else if ((c2 == '/') || iswalpha2(c2)) { // check for space in the output buffer for embedded commands produced by the SSML tag - if(ix > (n_buf - 20)) - { + if (ix > (n_buf - 20)) { // Perhaps not enough room, end the clause before the SSML tag UngetC(c2); ungot_char2 = c1; buf[ix] = ' '; buf[ix+1] = 0; - return(CLAUSE_NONE); + return (CLAUSE_NONE); } // SSML Tag n_xml_buf = 0; c1 = c2; - while(!Eof() && (c1 != '>') && (n_xml_buf < N_XML_BUF)) - { + while (!Eof() && (c1 != '>') && (n_xml_buf < N_XML_BUF)) { xml_buf[n_xml_buf++] = c1; c1 = GetC(); } @@ -2473,28 +2249,25 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix c2 = ' '; self_closing = 0; - if(xml_buf[n_xml_buf-1] == '/') - { + if (xml_buf[n_xml_buf-1] == '/') { // a self-closing tag xml_buf[n_xml_buf-1] = ' '; self_closing = 1; } - terminator = ProcessSsmlTag(xml_buf,buf,&ix,n_buf,self_closing); + terminator = ProcessSsmlTag(xml_buf, buf, &ix, n_buf, self_closing); - if(terminator != 0) - { - if(end_clause_after_tag) + if (terminator != 0) { + if (end_clause_after_tag) ix = end_clause_index; buf[ix] = ' '; buf[ix++] = 0; - if(terminator & CLAUSE_BIT_VOICE) - { + if (terminator & CLAUSE_BIT_VOICE) { strcpy(voice_change, current_voice_id); } - return(terminator); + return (terminator); } c1 = ' '; c2 = GetC(); @@ -2502,61 +2275,49 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix } } } - ssml_ignore_l_angle=0; + ssml_ignore_l_angle = 0; - if(ignore_text) + if (ignore_text) continue; - if((c2=='\n') && (option_linelength == -1)) - { + if ((c2 == '\n') && (option_linelength == -1)) { // single-line mode, return immediately on NL - if((punct = lookupwchar(punct_chars,c1)) == 0) - { + if ((punct = lookupwchar(punct_chars, c1)) == 0) { charix[ix] = count_characters - clause_start_char; *charix_top = ix; - ix += utf8_out(c1,&buf[ix]); + ix += utf8_out(c1, &buf[ix]); terminator = CLAUSE_PERIOD; // line doesn't end in punctuation, assume period - } - else - { + } else { terminator = punct_attributes[punct]; } buf[ix] = ' '; buf[ix+1] = 0; - return(terminator); + return (terminator); } - if((c1 == CTRL_EMBEDDED) || (c1 == ctrl_embedded)) - { + if ((c1 == CTRL_EMBEDDED) || (c1 == ctrl_embedded)) { // an embedded command. If it's a voice change, end the clause - if(c2 == 'V') - { + if (c2 == 'V') { buf[ix++] = 0; // end the clause at this point - while(!iswspace(c1 = GetC()) && !Eof() && (ix < (n_buf-1))) + while (!iswspace(c1 = GetC()) && !Eof() && (ix < (n_buf-1))) buf[ix++] = c1; // add voice name to end of buffer, after the text buf[ix++] = 0; - return(CLAUSE_VOICE); - } - else - if(c2 == 'B') - { + return (CLAUSE_VOICE); + } else if (c2 == 'B') { // set the punctuation option from an embedded command // B0 B1 B - strcpy(&buf[ix]," "); + strcpy(&buf[ix], " "); ix += 3; - if((c2 = GetC()) == '0') + if ((c2 = GetC()) == '0') option_punctuation = 0; - else - { + else { option_punctuation = 1; option_punctlist[0] = 0; - if(c2 != '1') - { + if (c2 != '1') { // a list of punctuation characters to be spoken, terminated by space j = 0; - while(!iswspace(c2) && !Eof()) - { + while (!iswspace(c2) && !Eof()) { option_punctlist[j++] = c2; c2 = GetC(); buf[ix++] = ' '; @@ -2572,135 +2333,111 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix linelength++; - if((j = lookupwchar2(tr->chars_ignore,c1)) != 0) - { - if(j == 1) - { + if ((j = lookupwchar2(tr->chars_ignore, c1)) != 0) { + if (j == 1) { // ignore this character (eg. zero-width-non-joiner U+200C) continue; } c1 = j; // replace the character } - if(iswalnum(c1)) + if (iswalnum(c1)) any_alnum = 1; - else - { - if(stressed_word) - { + else { + if (stressed_word) { stressed_word = 0; c1 = CHAR_EMPHASIS; // indicate this word is stressed UngetC(c2); c2 = ' '; } - if(c1 == 0xf0b) + if (c1 == 0xf0b) c1 = ' '; // Tibet inter-syllabic mark, ?? replace by space ?? - if(iswspace(c1)) - { + if (iswspace(c1)) { char *p_word; - if(tr->translator_name == 0x6a626f) - { + if (tr->translator_name == 0x6a626f) { // language jbo : lojban // treat "i" or ".i" as end-of-sentence p_word = &buf[ix-1]; - if(p_word[0] == 'i') - { - if(p_word[-1] == '.') + if (p_word[0] == 'i') { + if (p_word[-1] == '.') p_word--; - if(p_word[-1] == ' ') - { + if (p_word[-1] == ' ') { ungot_word = "i "; UngetC(c2); p_word[0] = 0; - return(CLAUSE_PERIOD); + return (CLAUSE_PERIOD); } } } } - if(c1 == 0xd4d) - { + if (c1 == 0xd4d) { // Malayalam virama, check if next character is Zero-width-joiner - if(c2 == 0x200d) - { + if (c2 == 0x200d) { c1 = 0xd4e; // use this unofficial code for chillu-virama } } } - if(iswupper2(c1)) - { + if (iswupper2(c1)) { tr->clause_upper_count++; - if((option_capitals == 2) && (sayas_mode == 0) && !iswupper2(cprev)) - { + if ((option_capitals == 2) && (sayas_mode == 0) && !iswupper2(cprev)) { char text_buf[40]; char text_buf2[30]; - if(LookupSpecial(tr, "_cap", text_buf2) != NULL) - { - sprintf(text_buf,"%s",text_buf2); + if (LookupSpecial(tr, "_cap", text_buf2) != NULL) { + sprintf(text_buf, "%s", text_buf2); j = strlen(text_buf); - if((ix + j) < n_buf) - { - strcpy(&buf[ix],text_buf); + if ((ix + j) < n_buf) { + strcpy(&buf[ix], text_buf); ix += j; } } } - } - else - if(iswalpha2(c1)) + } else if (iswalpha2(c1)) tr->clause_lower_count++; - if(option_phoneme_input) - { - if(phoneme_mode > 0) + if (option_phoneme_input) { + if (phoneme_mode > 0) phoneme_mode--; - else - if((c1 == '[') && (c2 == '[')) + else if ((c1 == '[') && (c2 == '[')) phoneme_mode = -1; // input is phoneme mnemonics, so don't look for punctuation - else - if((c1 == ']') && (c2 == ']')) + else if ((c1 == ']') && (c2 == ']')) phoneme_mode = 2; // set phoneme_mode to zero after the next two characters } - if(c1 == '\n') - { + if (c1 == '\n') { parag = 0; // count consecutive newlines, ignoring other spaces - while(!Eof() && iswspace(c2)) - { - if(c2 == '\n') + while (!Eof() && iswspace(c2)) { + if (c2 == '\n') parag++; c2 = GetC(); } - if(parag > 0) - { + if (parag > 0) { // 2nd newline, assume paragraph UngetC(c2); - if(end_clause_after_tag) - { + if (end_clause_after_tag) { RemoveChar(&buf[end_clause_index]); // delete clause-end punctiation } buf[ix] = ' '; buf[ix+1] = 0; - if(parag > 3) + if (parag > 3) parag = 3; - if(option_ssml) parag=1; - return((CLAUSE_PARAGRAPH-30) + 30*parag); // several blank lines, longer pause + if (option_ssml) parag = 1; + return ((CLAUSE_PARAGRAPH-30) + 30*parag); // several blank lines, longer pause } - if(linelength <= option_linelength) - { + if (linelength <= option_linelength) { // treat lines shorter than a specified length as end-of-clause UngetC(c2); buf[ix] = ' '; buf[ix+1] = 0; - return(CLAUSE_COLON); + return (CLAUSE_COLON); } linelength = 0; @@ -2708,168 +2445,135 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix announced_punctuation = 0; - if((phoneme_mode==0) && (sayas_mode==0)) - { + if ((phoneme_mode == 0) && (sayas_mode == 0)) { is_end_clause = 0; - if(end_clause_after_tag) - { + if (end_clause_after_tag) { // Because of an xml tag, we are waiting for the // next non-blank character to decide whether to end the clause // i.e. is dot followed by an upper-case letter? - if(!iswspace(c1)) - { - if(!IsAlpha(c1) || !iswlower2(c1)) - { + if (!iswspace(c1)) { + if (!IsAlpha(c1) || !iswlower2(c1)) { UngetC(c2); ungot_char2 = c1; buf[end_clause_index] = ' '; // delete the end-clause punctuation buf[end_clause_index+1] = 0; - return(end_clause_after_tag); + return (end_clause_after_tag); } end_clause_after_tag = 0; } } - if((c1 == '.') && (c2 == '.')) - { - while((c_next = GetC()) == '.') - { + if ((c1 == '.') && (c2 == '.')) { + while ((c_next = GetC()) == '.') { // 3 or more dots, replace by elipsis c1 = 0x2026; c2 = ' '; } - if(c1 == 0x2026) + if (c1 == 0x2026) c2 = c_next; else UngetC(c_next); } punct_data = 0; - if((punct = lookupwchar(punct_chars,c1)) != 0) - { + if ((punct = lookupwchar(punct_chars, c1)) != 0) { punct_data = punct_attributes[punct]; - if(punct_data & PUNCT_IN_WORD) - { + if (punct_data & PUNCT_IN_WORD) { // Armenian punctuation inside a word stressed_word = 1; *tone_type = punct_data >> 12 & 0xf; // override the end-of-sentence type continue; } - if((iswspace(c2) || (punct_data & 0x8000) || IsBracket(c2) || (c2=='?') || Eof() || (c2 == ctrl_embedded))) // don't check for '-' because it prevents recognizing ':-)' - { + if ((iswspace(c2) || (punct_data & 0x8000) || IsBracket(c2) || (c2 == '?') || Eof() || (c2 == ctrl_embedded))) { // don't check for '-' because it prevents recognizing ':-)' // note: (c2='?') is for when a smart-quote has been replaced by '?' is_end_clause = 1; } } // don't announce punctuation for the alternative text inside inside - if(c1 == 0xe000+'<') c1 = '<'; - if(option_punctuation && iswpunct(c1) && (audio_text == 0)) - { + if (c1 == 0xe000+'<') c1 = '<'; + if (option_punctuation && iswpunct(c1) && (audio_text == 0)) { // option is set to explicitly speak punctuation characters // if a list of allowed punctuation has been set up, check whether the character is in it - if((option_punctuation == 1) || (wcschr(option_punctlist,c1) != NULL)) - { + if ((option_punctuation == 1) || (wcschr(option_punctlist, c1) != NULL)) { tr->phonemes_repeat_count = 0; - if((terminator = AnnouncePunctuation(tr, c1, &c2, buf, &ix, is_end_clause)) >= 0) - return(terminator); + if ((terminator = AnnouncePunctuation(tr, c1, &c2, buf, &ix, is_end_clause)) >= 0) + return (terminator); announced_punctuation = c1; } } - if((punct_data & PUNCT_SAY_NAME) && (announced_punctuation == 0)) - { + if ((punct_data & PUNCT_SAY_NAME) && (announced_punctuation == 0)) { // used for elipsis (and 3 dots) if a pronunciation for elipsis is given in *_list char *p2; p2 = &buf[ix]; - sprintf(p2,"%s",LookupCharName(tr, c1, 1)); - if(p2[0] != 0) - { + sprintf(p2, "%s", LookupCharName(tr, c1, 1)); + if (p2[0] != 0) { ix += strlen(p2); announced_punctuation = c1; punct_data = punct_data & ~CLAUSE_BITS_INTONATION; // change intonation type to 0 (full-stop) } } - if(is_end_clause) - { + if (is_end_clause) { nl_count = 0; c_next = c2; - if(iswspace(c_next)) - { - while(!Eof() && iswspace(c_next)) - { - if(c_next == '\n') + if (iswspace(c_next)) { + while (!Eof() && iswspace(c_next)) { + if (c_next == '\n') nl_count++; c_next = GetC(); // skip past space(s) } } - if((c1 == '.') && (nl_count < 2)) - { + if ((c1 == '.') && (nl_count < 2)) { punct_data |= CLAUSE_DOT; } - if(nl_count==0) - { - if((c1 == ',') && (cprev == '.') && (tr->translator_name == L('h','u')) && iswdigit(cprev2) && (iswdigit(c_next) || (iswlower2(c_next)))) - { + if (nl_count == 0) { + if ((c1 == ',') && (cprev == '.') && (tr->translator_name == L('h', 'u')) && iswdigit(cprev2) && (iswdigit(c_next) || (iswlower2(c_next)))) { // lang=hu, fix for ordinal numbers, eg: "december 2., szerda", ignore ',' after ordinal number c1 = CHAR_COMMA_BREAK; is_end_clause = 0; } - if(c1 == '.') - { - if((tr->langopts.numbers & NUM_ORDINAL_DOT) && - (iswdigit(cprev) || (IsRomanU(cprev) && (IsRomanU(cprev2) || iswspace(cprev2))))) // lang=hu - { + if (c1 == '.') { + if ((tr->langopts.numbers & NUM_ORDINAL_DOT) && + (iswdigit(cprev) || (IsRomanU(cprev) && (IsRomanU(cprev2) || iswspace(cprev2))))) { // lang=hu // dot after a number indicates an ordinal number - if(!iswdigit(cprev)) - { + if (!iswdigit(cprev)) { is_end_clause = 0; // Roman number followed by dot - } - else - { - if (iswlower2(c_next) || (c_next=='-')) // hyphen is needed for lang-hu (eg. 2.-kal) + } else { + if (iswlower2(c_next) || (c_next == '-')) // hyphen is needed for lang-hu (eg. 2.-kal) is_end_clause = 0; // only if followed by lower-case, (or if there is a XML tag) } - } - else - if(c_next == '\'') - { + } else if (c_next == '\'') { is_end_clause = 0; // eg. u.s.a.'s } - if(iswlower2(c_next)) - { + if (iswlower2(c_next)) { // next word has no capital letter, this dot is probably from an abbreviation is_end_clause = 0; } - if(any_alnum==0) - { + if (any_alnum == 0) { // no letters or digits yet, so probably not a sentence terminator // Here, dot is followed by space or bracket c1 = ' '; is_end_clause = 0; } - } - else - { - if(any_alnum==0) - { + } else { + if (any_alnum == 0) { // no letters or digits yet, so probably not a sentence terminator is_end_clause = 0; } } - if(is_end_clause && (c1 == '.') && (c_next == '<') && option_ssml) - { + if (is_end_clause && (c1 == '.') && (c_next == '<') && option_ssml) { // wait until after the end of the xml tag, then look for upper-case letter is_end_clause = 0; end_clause_index = ix; @@ -2877,97 +2581,81 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix } } - if(is_end_clause) - { + if (is_end_clause) { UngetC(c_next); buf[ix] = ' '; buf[ix+1] = 0; - if(iswdigit(cprev) && !IsAlpha(c_next)) // ???? - { + if (iswdigit(cprev) && !IsAlpha(c_next)) { // ???? punct_data &= ~CLAUSE_DOT; } - if(nl_count > 1) - { - if((punct_data == CLAUSE_QUESTION) || (punct_data == CLAUSE_EXCLAMATION)) - return(punct_data + 35); // with a longer pause - return(CLAUSE_PARAGRAPH); + if (nl_count > 1) { + if ((punct_data == CLAUSE_QUESTION) || (punct_data == CLAUSE_EXCLAMATION)) + return (punct_data + 35); // with a longer pause + return (CLAUSE_PARAGRAPH); } - return(punct_data); // only recognise punctuation if followed by a blank or bracket/quote - } - else - { - if(!Eof()) - { - if(iswspace(c2)) + return (punct_data); // only recognise punctuation if followed by a blank or bracket/quote + } else { + if (!Eof()) { + if (iswspace(c2)) UngetC(c_next); } } } } - if(speech_parameters[espeakSILENCE]==1) + if (speech_parameters[espeakSILENCE] == 1) continue; - if(c1 == announced_punctuation) - { + if (c1 == announced_punctuation) { // This character has already been announced, so delete it so that it isn't spoken a second time. // Unless it's a hyphen or apostrophe (which is used by TranslateClause() ) - if(IsBracket(c1)) - { + if (IsBracket(c1)) { c1 = 0xe000 + '('; // Unicode private useage area. So TranslateRules() knows the bracket name has been spoken - } - else - if(c1 != '-') - { + } else if (c1 != '-') { c1 = ' '; } } j = ix+1; - if(c1 == 0xe000 + '<') c1 = '<'; + if (c1 == 0xe000 + '<') c1 = '<'; - ix += utf8_out(c1,&buf[ix]); - if(!iswspace(c1) && !IsBracket(c1)) - { + ix += utf8_out(c1, &buf[ix]); + if (!iswspace(c1) && !IsBracket(c1)) { charix[ix] = count_characters - clause_start_char; - while(j < ix) + while (j < ix) charix[j++] = -1; // subsequent bytes of a multibyte character } *charix_top = ix; - if(((ix > (n_buf-75)) && !IsAlpha(c1) && !iswdigit(c1)) || (ix >= (n_buf-4))) - { + if (((ix > (n_buf-75)) && !IsAlpha(c1) && !iswdigit(c1)) || (ix >= (n_buf-4))) { // clause too long, getting near end of buffer, so break here // try to break at a word boundary (unless we actually reach the end of buffer). // (n_buf-4) is to allow for 3 bytes of multibyte character plus terminator. buf[ix] = ' '; buf[ix+1] = 0; UngetC(c2); - return(CLAUSE_NONE); + return (CLAUSE_NONE); } } - if(stressed_word) - { + if (stressed_word) { ix += utf8_out(CHAR_EMPHASIS, &buf[ix]); } - if(end_clause_after_tag) - { + if (end_clause_after_tag) { RemoveChar(&buf[end_clause_index]); // delete clause-end punctiation } buf[ix] = ' '; buf[ix+1] = 0; - return(CLAUSE_EOF); // end of file + return (CLAUSE_EOF); // end of file } void InitNamedata(void) { namedata_ix = 0; - if(namedata != NULL) - { + if (namedata != NULL) { free(namedata); namedata = NULL; n_namedata = 0; @@ -2982,11 +2670,11 @@ void InitText2(void) ungot_char = 0; ungot_char2 = 0; - n_ssml_stack =1; + n_ssml_stack = 1; n_param_stack = 1; ssml_stack[0].tag_type = 0; - for(param=0; paramspeed_percent > 0) - { + if (voice->speed_percent > 0) { wpm = (wpm * voice->speed_percent)/100; } - if(control & 2) - { + if (control & 2) { DoSonicSpeed(1 * 1024); } - if((wpm_value >= 450) || ((wpm_value > speed.fast_settings[0]) && (wpm > 350))) - { + if ((wpm_value >= 450) || ((wpm_value > speed.fast_settings[0]) && (wpm > 350))) { wpm2 = wpm; wpm = 175; // set special eSpeak speed parameters for Sonic use // The eSpeak output will be speeded up by at least x2 x = 73; - if(control & 1) - { + if (control & 1) { speed1 = (x * voice->speedf1)/256; speed2 = (x * voice->speedf2)/256; speed3 = (x * voice->speedf3)/256; } - if(control & 2) - { + if (control & 2) { sonic = ((double)wpm2)/wpm; DoSonicSpeed((int)(sonic * 1024)); speed.pause_factor = 85; @@ -200,71 +195,61 @@ void SetSpeed(int control) return; } - if(wpm > 450) + if (wpm > 450) wpm = 450; - if(wpm > 360) - { + if (wpm > 360) { speed.loud_consonants = (wpm - 360) / 8; } wpm2 = wpm; - if(wpm > 359) wpm2 = 359; - if(wpm < 80) wpm2 = 80; + if (wpm > 359) wpm2 = 359; + if (wpm < 80) wpm2 = 80; x = speed_lookup[wpm2-80]; - if(wpm >= 380) + if (wpm >= 380) x = 7; - if(wpm >= 400) + if (wpm >= 400) x = 6; - if(control & 1) - { + if (control & 1) { // set speed factors for different syllable positions within a word // these are used in CalcLengths() speed1 = (x * voice->speedf1)/256; speed2 = (x * voice->speedf2)/256; speed3 = (x * voice->speedf3)/256; - if(x <= 7) - { + if (x <= 7) { speed1 = x; speed2 = speed3 = x - 1; } } - if(control & 2) - { + if (control & 2) { // these are used in synthesis file - if(wpm > 350) - { + if (wpm > 350) { speed.lenmod_factor = 85 - (wpm - 350) / 3; speed.lenmod2_factor = 60 - (wpm - 350) / 8; - } - else - if(wpm > 250) - { + } else if (wpm > 250) { speed.lenmod_factor = 110 - (wpm - 250)/4; speed.lenmod2_factor = 110 - (wpm - 250)/2; } s1 = (x * voice->speedf1)/256; - if(wpm >= 170) + if (wpm >= 170) speed.wav_factor = 110 + (150*s1)/128; // reduced speed adjustment, used for playing recorded sounds else speed.wav_factor = 128 + (128*s1)/130; // = 215 at 170 wpm - if(wpm >= 350) - { + if (wpm >= 350) { speed.wav_factor = wav_factor_350[wpm-350]; } - if(wpm >= 390) - { + if (wpm >= 390) { speed.min_sample_len = 450 - (wpm - 400)/2; - if(wpm > 440) + if (wpm > 440) speed.min_sample_len = 420 - (wpm - 440); } @@ -274,30 +259,19 @@ void SetSpeed(int control) speed.pause_factor = (256 * s1)/115; // full speed adjustment, used for pause length speed.clause_pause_factor = 0; - if(wpm > 430) - { + if (wpm > 430) { speed.pause_factor = 12; - } - else - if(wpm > 400) - { + } else if (wpm > 400) { speed.pause_factor = 13; - } - else - if(wpm > 374) - { + } else if (wpm > 374) { speed.pause_factor = 14; - } - else - if(wpm > 350) - { + } else if (wpm > 350) { speed.pause_factor = pause_factor_350[wpm - 350]; } - if(speed.clause_pause_factor == 0) - { + if (speed.clause_pause_factor == 0) { // restrict the reduction of pauses between clauses - if((speed.clause_pause_factor = speed.pause_factor) < 16) + if ((speed.clause_pause_factor = speed.pause_factor) < 16) speed.clause_pause_factor = 16; } } @@ -319,108 +293,86 @@ void SetSpeed(int control) speed.lenmod2_factor = 100; wpm = embedded_value[EMBED_S]; - if(control == 2) + if (control == 2) wpm = embedded_value[EMBED_S2]; - if(voice->speed_percent > 0) - { + if (voice->speed_percent > 0) { wpm = (wpm * voice->speed_percent)/100; } - if(wpm > 450) + if (wpm > 450) wpm = 450; - if(wpm > 360) - { + if (wpm > 360) { speed.loud_consonants = (wpm - 360) / 8; } wpm2 = wpm; - if(wpm > 359) wpm2 = 359; - if(wpm < 80) wpm2 = 80; + if (wpm > 359) wpm2 = 359; + if (wpm < 80) wpm2 = 80; x = speed_lookup[wpm2-80]; - if(wpm >= 380) + if (wpm >= 380) x = 7; - if(wpm >= 400) + if (wpm >= 400) x = 6; - if(control & 1) - { + if (control & 1) { // set speed factors for different syllable positions within a word // these are used in CalcLengths() speed1 = (x * voice->speedf1)/256; speed2 = (x * voice->speedf2)/256; speed3 = (x * voice->speedf3)/256; - if(x <= 7) - { + if (x <= 7) { speed1 = x; speed2 = speed3 = x - 1; } } - if(control & 2) - { + if (control & 2) { // these are used in synthesis file - if(wpm > 350) - { + if (wpm > 350) { speed.lenmod_factor = 85 - (wpm - 350) / 3; speed.lenmod2_factor = 60 - (wpm - 350) / 8; - } - else - if(wpm > 250) - { + } else if (wpm > 250) { speed.lenmod_factor = 110 - (wpm - 250)/4; speed.lenmod2_factor = 110 - (wpm - 250)/2; } s1 = (x * voice->speedf1)/256; - if(wpm >= 170) + if (wpm >= 170) speed.wav_factor = 110 + (150*s1)/128; // reduced speed adjustment, used for playing recorded sounds else speed.wav_factor = 128 + (128*s1)/130; // = 215 at 170 wpm - if(wpm >= 350) - { + if (wpm >= 350) { speed.wav_factor = wav_factor_350[wpm-350]; } - if(wpm >= 390) - { + if (wpm >= 390) { speed.min_sample_len = 450 - (wpm - 400)/2; - if(wpm > 440) + if (wpm > 440) speed.min_sample_len = 420 - (wpm - 440); } speed.pause_factor = (256 * s1)/115; // full speed adjustment, used for pause length speed.clause_pause_factor = 0; - if(wpm > 430) - { + if (wpm > 430) { speed.pause_factor = 12; - } - else - if(wpm > 400) - { + } else if (wpm > 400) { speed.pause_factor = 13; - } - else - if(wpm > 374) - { + } else if (wpm > 374) { speed.pause_factor = 14; - } - else - if(wpm > 350) - { + } else if (wpm > 350) { speed.pause_factor = pause_factor_350[wpm - 350]; } - if(speed.clause_pause_factor == 0) - { + if (speed.clause_pause_factor == 0) { // restrict the reduction of pauses between clauses - if((speed.clause_pause_factor = speed.pause_factor) < 16) + if ((speed.clause_pause_factor = speed.pause_factor) < 16) speed.clause_pause_factor = 16; } } @@ -437,10 +389,8 @@ void SetParameter(int parameter, int value, int relative) int new_value = value; int default_value; - if(relative) - { - if(parameter < 5) - { + if (relative) { + if (parameter < 5) { default_value = param_defaults[parameter]; new_value = default_value + (default_value * value)/100; } @@ -448,7 +398,7 @@ void SetParameter(int parameter, int value, int relative) param_stack[0].parameter[parameter] = new_value; saved_parameters[parameter] = new_value; - switch(parameter) + switch (parameter) { case espeakRATE: embedded_value[EMBED_S] = new_value; @@ -462,13 +412,13 @@ void SetParameter(int parameter, int value, int relative) break; case espeakPITCH: - if(new_value > 99) new_value = 99; - if(new_value < 0) new_value = 0; + if (new_value > 99) new_value = 99; + if (new_value < 0) new_value = 0; embedded_value[EMBED_P] = new_value; break; case espeakRANGE: - if(new_value > 99) new_value = 99; + if (new_value > 99) new_value = 99; embedded_value[EMBED_R] = new_value; break; @@ -481,7 +431,7 @@ void SetParameter(int parameter, int value, int relative) break; case espeakINTONATION: - if((new_value & 0xff) != 0) + if ((new_value & 0xff) != 0) translator->langopts.intonation_group = new_value & 0xff; option_tone_flags = new_value; break; @@ -502,13 +452,12 @@ static void DoEmbedded2(int *embix) do { word = embedded_list[(*embix)++]; - if((word & 0x1f) == EMBED_S) - { + if ((word & 0x1f) == EMBED_S) { // speed SetEmbedded(word & 0x7f, word >> 8); // adjusts embedded_value[EMBED_S] SetSpeed(1); } - } while((word & 0x80) == 0); + } while ((word & 0x80) == 0); } @@ -525,9 +474,9 @@ void CalcLengths(Translator *tr) int stress; int type; - static int more_syllables=0; - int pre_sonorant=0; - int pre_voiced=0; + static int more_syllables = 0; + int pre_sonorant = 0; + int pre_voiced = 0; int last_pitch = 0; int pitch_start; int length_mod; @@ -540,11 +489,10 @@ void CalcLengths(Translator *tr) int pitch1; int emphasized; int tone_mod; - unsigned char *pitch_env=NULL; + unsigned char *pitch_env = NULL; PHONEME_DATA phdata_tone; - for(ix=1; ixstresslevel & 0x7; @@ -552,16 +500,15 @@ void CalcLengths(Translator *tr) next = &phoneme_list[ix+1]; - if(p->synthflags & SFLAG_EMBEDDED) - { + if (p->synthflags & SFLAG_EMBEDDED) { DoEmbedded2(&embedded_ix); } type = p->type; - if(p->synthflags & SFLAG_SYLLABLE) + if (p->synthflags & SFLAG_SYLLABLE) type = phVOWEL; - switch(type) + switch (type) { case phPAUSE: last_pitch = 0; @@ -569,109 +516,91 @@ void CalcLengths(Translator *tr) case phSTOP: last_pitch = 0; - if(prev->type == phFRICATIVE) + if (prev->type == phFRICATIVE) p->prepause = 25; - else - if((more_syllables > 0) || (stress < 4)) + else if ((more_syllables > 0) || (stress < 4)) p->prepause = 48; else p->prepause = 60; - if(prev->type == phSTOP) + if (prev->type == phSTOP) p->prepause = 60; - if((tr->langopts.word_gap & 0x10) && (p->newword)) + if ((tr->langopts.word_gap & 0x10) && (p->newword)) p->prepause = 60; - if(p->ph->phflags & phLENGTHENSTOP) + if (p->ph->phflags & phLENGTHENSTOP) p->prepause += 30; - if(p->synthflags & SFLAG_LENGTHEN) + if (p->synthflags & SFLAG_LENGTHEN) p->prepause += tr->langopts.long_stop; break; case phVFRICATIVE: case phFRICATIVE: - if(p->newword) - { - if((prev->type == phVOWEL) && (p->ph->phflags & phNOPAUSE)) - { - } - else - { + if (p->newword) { + if ((prev->type == phVOWEL) && (p->ph->phflags & phNOPAUSE)) { + } else { p->prepause = 15; } } - if(next->type==phPAUSE && prev->type==phNASAL && !(p->ph->phflags&phFORTIS)) + if (next->type == phPAUSE && prev->type == phNASAL && !(p->ph->phflags&phFORTIS)) p->prepause = 25; - if(prev->ph->phflags & phBRKAFTER) + if (prev->ph->phflags & phBRKAFTER) p->prepause = 30; - if((tr->langopts.word_gap & 0x10) && (p->newword)) + if ((tr->langopts.word_gap & 0x10) && (p->newword)) p->prepause = 30; - if((p->ph->phflags & phSIBILANT) && next->type==phSTOP && !next->newword) - { - if(prev->type == phVOWEL) + if ((p->ph->phflags & phSIBILANT) && next->type == phSTOP && !next->newword) { + if (prev->type == phVOWEL) p->length = 200; // ?? should do this if it's from a prefix else p->length = 150; - } - else + } else p->length = 256; - if(type == phVFRICATIVE) - { - if(next->type==phVOWEL) - { + if (type == phVFRICATIVE) { + if (next->type == phVOWEL) { pre_voiced = 1; } - if((prev->type==phVOWEL) || (prev->type == phLIQUID)) - { + if ((prev->type == phVOWEL) || (prev->type == phLIQUID)) { p->length = (255 + prev->length)/2; } } break; case phVSTOP: - if(prev->type==phVFRICATIVE || prev->type==phFRICATIVE || (prev->ph->phflags & phSIBILANT) || (prev->type == phLIQUID)) + if (prev->type == phVFRICATIVE || prev->type == phFRICATIVE || (prev->ph->phflags & phSIBILANT) || (prev->type == phLIQUID)) p->prepause = 30; - if(next->type==phVOWEL || next->type==phLIQUID) - { - if((next->type==phVOWEL) || !next->newword) + if (next->type == phVOWEL || next->type == phLIQUID) { + if ((next->type == phVOWEL) || !next->newword) pre_voiced = 1; p->prepause = 40; - if(prev->type == phVOWEL) - { + if (prev->type == phVOWEL) { p->prepause = 0; // use murmur instead to link from the preceding vowel - } - else - if(prev->type == phPAUSE) - { + } else if (prev->type == phPAUSE) { // reduce by the length of the preceding pause - if(prev->length < p->prepause) + if (prev->length < p->prepause) p->prepause -= prev->length; else p->prepause = 0; - } - else - if(p->newword==0) - { - if(prev->type==phLIQUID) + } else if (p->newword == 0) { + if (prev->type == phLIQUID) p->prepause = 20; - if(prev->type==phNASAL) + if (prev->type == phNASAL) p->prepause = 12; - if(prev->type==phSTOP && !(prev->ph->phflags & phFORTIS)) + if (prev->type == phSTOP && !(prev->ph->phflags & phFORTIS)) p->prepause = 0; } } - if((tr->langopts.word_gap & 0x10) && (p->newword) && (p->prepause < 20)) + if ((tr->langopts.word_gap & 0x10) && (p->newword) && (p->prepause < 20)) p->prepause = 20; break; @@ -682,49 +611,36 @@ void CalcLengths(Translator *tr) p->length = 256; // TEMPORARY min_drop = 0; - if(p->newword) - { - if(prev->type==phLIQUID) + if (p->newword) { + if (prev->type == phLIQUID) p->prepause = 25; - if(prev->type==phVOWEL) - { - if(!(p->ph->phflags & phNOPAUSE)) + if (prev->type == phVOWEL) { + if (!(p->ph->phflags & phNOPAUSE)) p->prepause = 12; } } - if(next->type==phVOWEL) - { + if (next->type == phVOWEL) { pre_sonorant = 1; - } - else - { + } else { p->pitch2 = last_pitch; - if((prev->type==phVOWEL) || (prev->type == phLIQUID)) - { + if ((prev->type == phVOWEL) || (prev->type == phLIQUID)) { p->length = prev->length; - if(p->type == phLIQUID) - { + if (p->type == phLIQUID) { p->length = speed1; } - if(next->type == phVSTOP) - { + if (next->type == phVSTOP) { p->length = (p->length * 160)/100; } - if(next->type == phVFRICATIVE) - { + if (next->type == phVFRICATIVE) { p->length = (p->length * 120)/100; } - } - else - { - for(ix2=ix; ix2pitch2 = phoneme_list[ix2].pitch2; break; } @@ -732,8 +648,7 @@ void CalcLengths(Translator *tr) } p->pitch1 = p->pitch2-16; - if(p->pitch2 < 16) - { + if (p->pitch2 < 16) { p->pitch1 = 0; } p->env = PITCHfall; @@ -746,49 +661,44 @@ void CalcLengths(Translator *tr) next2 = &phoneme_list[ix+2]; next3 = &phoneme_list[ix+3]; - if(stress > 7) stress = 7; + if (stress > 7) stress = 7; - if(stress <= 1) - { + if (stress <= 1) { stress = stress ^ 1; // swap diminished and unstressed (until we swap stress_amps,stress_lengths in tr_languages) } - if(pre_sonorant) + if (pre_sonorant) p->amp = tr->stress_amps[stress]-1; else p->amp = tr->stress_amps[stress]; - if(emphasized) + if (emphasized) p->amp = 25; - if(ix >= (n_phoneme_list-3)) - { + if (ix >= (n_phoneme_list-3)) { // last phoneme of a clause, limit its amplitude - if(p->amp > tr->langopts.param[LOPT_MAXAMP_EOC]) + if (p->amp > tr->langopts.param[LOPT_MAXAMP_EOC]) p->amp = tr->langopts.param[LOPT_MAXAMP_EOC]; } // is the last syllable of a word ? - more_syllables=0; + more_syllables = 0; end_of_clause = 0; - for(p2 = p+1; p2->newword== 0; p2++) - { - if((p2->type == phVOWEL) && !(p2->ph->phflags & phNONSYLLABIC)) + for (p2 = p+1; p2->newword == 0; p2++) { + if ((p2->type == phVOWEL) && !(p2->ph->phflags & phNONSYLLABIC)) more_syllables++; - if(p2->ph->code == phonPAUSE_CLAUSE) + if (p2->ph->code == phonPAUSE_CLAUSE) end_of_clause = 2; } - if(p2->ph->code == phonPAUSE_CLAUSE) + if (p2->ph->code == phonPAUSE_CLAUSE) end_of_clause = 2; - if((p2->newword & 2) && (more_syllables==0)) - { + if ((p2->newword & 2) && (more_syllables == 0)) { end_of_clause = 2; } // calc length modifier - if((next->ph->code == phonPAUSE_VSHORT) && (next2->type == phPAUSE)) - { + if ((next->ph->code == phonPAUSE_VSHORT) && (next2->type == phPAUSE)) { // if PAUSE_VSHORT is followed by a pause, then use that next = next2; next2 = next3; @@ -796,101 +706,84 @@ void CalcLengths(Translator *tr) } next2type = next2->ph->length_mod; - if(more_syllables==0) - { - if(next->newword || next2->newword) - { + if (more_syllables == 0) { + if (next->newword || next2->newword) { // don't use 2nd phoneme over a word boundary, unless it's a pause - if(next2type != 1) + if (next2type != 1) next2type = 0; } len = tr->langopts.length_mods0[next2type *10+ next->ph->length_mod]; - if((next->newword) && (tr->langopts.word_gap & 0x20)) - { + if ((next->newword) && (tr->langopts.word_gap & 0x20)) { // consider as a pause + first phoneme of the next word length_mod = (len + tr->langopts.length_mods0[next->ph->length_mod *10+ 1])/2; - } - else + } else length_mod = len; - } - else - { + } else { length_mod = tr->langopts.length_mods[next2type *10+ next->ph->length_mod]; - if((next->type == phNASAL) && (next2->type == phSTOP || next2->type == phVSTOP) && (next3->ph->phflags & phFORTIS)) + if ((next->type == phNASAL) && (next2->type == phSTOP || next2->type == phVSTOP) && (next3->ph->phflags & phFORTIS)) length_mod -= 15; } - if(more_syllables==0) + if (more_syllables == 0) length_mod *= speed1; - else - if(more_syllables==1) + else if (more_syllables == 1) length_mod *= speed2; else length_mod *= speed3; length_mod = length_mod / 128; - if(length_mod < 8) + if (length_mod < 8) length_mod = 8; // restrict how much lengths can be reduced - if(stress >= 7) - { + if (stress >= 7) { // tonic syllable, include a constant component so it doesn't decrease directly with speed length_mod += tr->langopts.lengthen_tonic; - if(emphasized) + if (emphasized) length_mod += (tr->langopts.lengthen_tonic/2); - } - else - if(emphasized) - { + } else if (emphasized) { length_mod += tr->langopts.lengthen_tonic; } - if((len = tr->stress_lengths[stress]) == 0) + if ((len = tr->stress_lengths[stress]) == 0) len = tr->stress_lengths[6]; length_mod = length_mod * len; - if(p->tone_ph != 0) - { - if((tone_mod = phoneme_tab[p->tone_ph]->std_length) > 0) - { + if (p->tone_ph != 0) { + if ((tone_mod = phoneme_tab[p->tone_ph]->std_length) > 0) { // a tone phoneme specifies a percentage change to the length length_mod = (length_mod * tone_mod) / 100; } } - if((end_of_clause == 2) && !(tr->langopts.stress_flags & S_NO_EOC_LENGTHEN)) - { + if ((end_of_clause == 2) && !(tr->langopts.stress_flags & S_NO_EOC_LENGTHEN)) { // this is the last syllable in the clause, lengthen it - more for short vowels len = (p->ph->std_length * 2); - if(tr->langopts.stress_flags & S_EO_CLAUSE1) - len=200; // don't lengthen short vowels more than long vowels at end-of-clause + if (tr->langopts.stress_flags & S_EO_CLAUSE1) + len = 200; // don't lengthen short vowels more than long vowels at end-of-clause length_mod = length_mod * (256 + (280 - len)/3)/256; } - if(length_mod > tr->langopts.max_lengthmod*speed1) - { - //limit the vowel length adjustment for some languages + if (length_mod > tr->langopts.max_lengthmod*speed1) { + // limit the vowel length adjustment for some languages length_mod = (tr->langopts.max_lengthmod*speed1); } length_mod = length_mod / 128; - if(p->type != phVOWEL) - { + if (p->type != phVOWEL) { length_mod = 256; // syllabic consonant min_drop = 16; } p->length = length_mod; - if(p->env >= (N_ENVELOPE_DATA-1)) - { - fprintf(stderr,"espeak: Bad intonation data\n"); + if (p->env >= (N_ENVELOPE_DATA-1)) { + fprintf(stderr, "espeak: Bad intonation data\n"); p->env = 0; } @@ -898,73 +791,61 @@ void CalcLengths(Translator *tr) // set last-pitch env2 = p->env + 1; // version for use with preceding semi-vowel - if(p->tone_ph != 0) - { + if (p->tone_ph != 0) { InterpretPhoneme2(p->tone_ph, &phdata_tone); pitch_env = GetEnvelope(phdata_tone.pitch_env); - } - else - { + } else { pitch_env = envelope_data[env2]; } pitch_start = p->pitch1 + ((p->pitch2-p->pitch1)*pitch_env[0])/256; - if(pre_sonorant || pre_voiced) - { + if (pre_sonorant || pre_voiced) { // set pitch for pre-vocalic part - if(pitch_start == 255) + if (pitch_start == 255) last_pitch = pitch_start; // pitch is not set - if(pitch_start - last_pitch > 16) + if (pitch_start - last_pitch > 16) last_pitch = pitch_start - 16; prev->pitch1 = last_pitch; prev->pitch2 = pitch_start; - if(last_pitch < pitch_start) - { + if (last_pitch < pitch_start) { prev->env = PITCHrise; p->env = env2; - } - else - { + } else { prev->env = PITCHfall; } prev->length = length_mod; prev->amp = p->amp; - if((prev->type != phLIQUID) && (prev->amp > 18)) + if ((prev->type != phLIQUID) && (prev->amp > 18)) prev->amp = 18; } // vowel & post-vocalic part next->synthflags &= ~SFLAG_SEQCONTINUE; - if(next->type == phNASAL && next2->type != phVOWEL) + if (next->type == phNASAL && next2->type != phVOWEL) next->synthflags |= SFLAG_SEQCONTINUE; - if(next->type == phLIQUID) - { + if (next->type == phLIQUID) { next->synthflags |= SFLAG_SEQCONTINUE; - if(next2->type == phVOWEL) - { + if (next2->type == phVOWEL) { next->synthflags &= ~SFLAG_SEQCONTINUE; } - if(next2->type != phVOWEL) - { - if(next->ph->mnemonic == ('/'*256+'r')) - { + if (next2->type != phVOWEL) { + if (next->ph->mnemonic == ('/'*256+'r')) { next->synthflags &= ~SFLAG_SEQCONTINUE; } } } - if((min_drop > 0) && ((p->pitch2 - p->pitch1) < min_drop)) - { + if ((min_drop > 0) && ((p->pitch2 - p->pitch1) < min_drop)) { pitch1 = p->pitch2 - min_drop; - if(pitch1 < 0) + if (pitch1 < 0) pitch1 = 0; p->pitch1 = pitch1; } diff --git a/src/libespeak-ng/speak_lib.c b/src/libespeak-ng/speak_lib.c index 2fd88e45..dd946ad8 100644 --- a/src/libespeak-ng/speak_lib.c +++ b/src/libespeak-ng/speak_lib.c @@ -56,28 +56,28 @@ #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) #endif -unsigned char *outbuf=NULL; +unsigned char *outbuf = NULL; -espeak_EVENT *event_list=NULL; -int event_list_ix=0; +espeak_EVENT *event_list = NULL; +int event_list_ix = 0; int n_event_list; long count_samples; -void* my_audio=NULL; +void *my_audio = NULL; -static unsigned int my_unique_identifier=0; -static void* my_user_data=NULL; -static espeak_AUDIO_OUTPUT my_mode=AUDIO_OUTPUT_SYNCHRONOUS; +static unsigned int my_unique_identifier = 0; +static void *my_user_data = NULL; +static espeak_AUDIO_OUTPUT my_mode = AUDIO_OUTPUT_SYNCHRONOUS; static int synchronous_mode = 1; static int out_samplerate = 0; static int voice_samplerate = 22050; static espeak_ERROR err = EE_OK; -t_espeak_callback* synth_callback = NULL; -int (* uri_callback)(int, const char *, const char *) = NULL; -int (* phoneme_callback)(const char *) = NULL; +t_espeak_callback *synth_callback = NULL; +int (*uri_callback)(int, const char *, const char *) = NULL; +int (*phoneme_callback)(const char *) = NULL; char path_home[N_PATH_HOME]; // this is the espeak-data directory -extern int saved_parameters[N_SPEECH_PARAM]; //Parameters saved on synthesis start +extern int saved_parameters[N_SPEECH_PARAM]; // Parameters saved on synthesis start void WVoiceChanged(voice_t *wvoice) @@ -89,7 +89,7 @@ void WVoiceChanged(voice_t *wvoice) #ifdef USE_ASYNC -static int dispatch_audio(short* outbuf, int length, espeak_EVENT* event) +static int dispatch_audio(short *outbuf, int length, espeak_EVENT *event) { ENTER("dispatch_audio"); @@ -102,58 +102,50 @@ static int dispatch_audio(short* outbuf, int length, espeak_EVENT* event) a_wave_can_be_played); #endif - switch(my_mode) + switch (my_mode) { case AUDIO_OUTPUT_PLAYBACK: { - int event_type=0; - if(event) - { + int event_type = 0; + if (event) { event_type = event->type; } - if(event_type == espeakEVENT_SAMPLERATE) - { + if (event_type == espeakEVENT_SAMPLERATE) { voice_samplerate = event->id.number; - if(out_samplerate != voice_samplerate) - { - if(out_samplerate != 0) - { + if (out_samplerate != voice_samplerate) { + if (out_samplerate != 0) { // sound was previously open with a different sample rate wave_close(my_audio); sleep(1); } out_samplerate = voice_samplerate; - if(!wave_init(voice_samplerate)) - { + if (!wave_init(voice_samplerate)) { err = EE_INTERNAL_ERROR; - return(-1); + return (-1); } - wave_set_callback_is_output_enabled( fifo_is_command_enabled); + wave_set_callback_is_output_enabled(fifo_is_command_enabled); my_audio = wave_open("alsa"); event_init(); } } - if (outbuf && length && a_wave_can_be_played) - { - wave_write (my_audio, (char*)outbuf, 2*length); + if (outbuf && length && a_wave_can_be_played) { + wave_write(my_audio, (char *)outbuf, 2*length); } - while(a_wave_can_be_played) { + while (a_wave_can_be_played) { // TBD: some event are filtered here but some insight might be given // TBD: in synthesise.cpp for avoiding to create WORDs with size=0. // TBD: For example sentence "or ALT)." returns three words // "or", "ALT" and "". // TBD: the last one has its size=0. - if (event && (event->type == espeakEVENT_WORD) && (event->length==0)) - { + if (event && (event->type == espeakEVENT_WORD) && (event->length == 0)) { break; } espeak_ERROR a_error = event_declare(event); - if (a_error != EE_BUFFER_FULL) - { + if (a_error != EE_BUFFER_FULL) { break; } SHOW_TIME("dispatch_audio > EE_BUFFER_FULL\n"); @@ -164,8 +156,7 @@ static int dispatch_audio(short* outbuf, int length, espeak_EVENT* event) break; case AUDIO_OUTPUT_RETRIEVAL: - if (synth_callback) - { + if (synth_callback) { synth_callback(outbuf, length, event); } break; @@ -175,22 +166,21 @@ static int dispatch_audio(short* outbuf, int length, espeak_EVENT* event) break; } - if (!a_wave_can_be_played) - { + if (!a_wave_can_be_played) { SHOW_TIME("dispatch_audio > synth must be stopped!\n"); } SHOW_TIME("LEAVE dispatch_audio\n"); - return (a_wave_can_be_played==0); // 1 = stop synthesis, -1 = error + return (a_wave_can_be_played == 0); // 1 = stop synthesis, -1 = error } -static int create_events(short* outbuf, int length, espeak_EVENT* event, uint32_t the_write_pos) +static int create_events(short *outbuf, int length, espeak_EVENT *event, uint32_t the_write_pos) { int finished; - int i=0; + int i = 0; // The audio data are written to the output device. // The list of events in event_list (index: event_list_ix) is read: @@ -198,15 +188,11 @@ static int create_events(short* outbuf, int length, espeak_EVENT* event, uint32_ // The event object is responsible of calling the external callback // as soon as the relevant audio sample is played. - do - { // for each event - espeak_EVENT* event; - if (event_list_ix == 0) - { + do { // for each event + espeak_EVENT *event; + if (event_list_ix == 0) { event = NULL; - } - else - { + } else { event = event_list + i; #ifdef DEBUG_ENABLED SHOW("Synthesize: event->sample(%d) + %d = %d\n", event->sample, the_write_pos, event->sample + the_write_pos); @@ -214,21 +200,21 @@ static int create_events(short* outbuf, int length, espeak_EVENT* event, uint32_ event->sample += the_write_pos; } #ifdef DEBUG_ENABLED - SHOW("*** Synthesize: i=%d (event_list_ix=%d), length=%d\n",i,event_list_ix,length); + SHOW("*** Synthesize: i=%d (event_list_ix=%d), length=%d\n", i, event_list_ix, length); #endif finished = dispatch_audio((short *)outbuf, length, event); length = 0; // the wave data are played once. i++; - } while((i < event_list_ix) && !finished); + } while ((i < event_list_ix) && !finished); return finished; } -int sync_espeak_terminated_msg( uint32_t unique_identifier, void* user_data) +int sync_espeak_terminated_msg(uint32_t unique_identifier, void *user_data) { ENTER("sync_espeak_terminated_msg"); - int finished=0; + int finished = 0; memset(event_list, 0, 2*sizeof(espeak_EVENT)); @@ -239,24 +225,18 @@ int sync_espeak_terminated_msg( uint32_t unique_identifier, void* user_data) event_list[1].unique_identifier = unique_identifier; event_list[1].user_data = user_data; - if (my_mode==AUDIO_OUTPUT_PLAYBACK) - { - while(1) - { + if (my_mode == AUDIO_OUTPUT_PLAYBACK) { + while (1) { espeak_ERROR a_error = event_declare(event_list); - if (a_error != EE_BUFFER_FULL) - { + if (a_error != EE_BUFFER_FULL) { break; } SHOW_TIME("sync_espeak_terminated_msg > EE_BUFFER_FULL\n"); usleep(10000); } - } - else - { - if (synth_callback) - { - finished=synth_callback(NULL,0,event_list); + } else { + if (synth_callback) { + finished = synth_callback(NULL, 0, event_list); } } return finished; @@ -273,7 +253,7 @@ static void select_output(espeak_AUDIO_OUTPUT output_type) option_waveout = 1; // inhibit portaudio callback from wavegen.cpp out_samplerate = 0; - switch(my_mode) + switch (my_mode) { case AUDIO_OUTPUT_PLAYBACK: // wave_init() is now called just before the first wave_write() @@ -302,13 +282,13 @@ int GetFileLength(const char *filename) { struct stat statbuf; - if(stat(filename,&statbuf) != 0) - return(0); + if (stat(filename, &statbuf) != 0) + return (0); - if(S_ISDIR(statbuf.st_mode)) - return(-2); // a directory + if (S_ISDIR(statbuf.st_mode)) + return (-2); // a directory - return(statbuf.st_size); + return (statbuf.st_size); } #pragma GCC visibility pop @@ -316,14 +296,14 @@ int GetFileLength(const char *filename) char *Alloc(int size) { char *p; - if((p = (char *)malloc(size)) == NULL) - fprintf(stderr,"Can't allocate memory\n"); // I was told that size+1 fixes a crash on 64-bit systems - return(p); + if ((p = (char *)malloc(size)) == NULL) + fprintf(stderr, "Can't allocate memory\n"); // I was told that size+1 fixes a crash on 64-bit systems + return (p); } void Free(void *ptr) { - if(ptr != NULL) + if (ptr != NULL) free(ptr); } @@ -338,16 +318,14 @@ static void init_path(const char *path) char *env; unsigned char buf[sizeof(path_home)-13]; - if(path != NULL) - { - sprintf(path_home,"%s/espeak-data",path); + if (path != NULL) { + sprintf(path_home, "%s/espeak-data", path); return; } - if((env = getenv("ESPEAK_DATA_PATH")) != NULL) - { - sprintf(path_home,"%s/espeak-data",env); - if(GetFileLength(path_home) == -2) + if ((env = getenv("ESPEAK_DATA_PATH")) != NULL) { + sprintf(path_home, "%s/espeak-data", env); + if (GetFileLength(path_home) == -2) return; // an espeak-data directory exists } @@ -357,29 +335,26 @@ static void init_path(const char *path) var_type = REG_SZ; RegQueryValueExA(RegKey, "path", 0, &var_type, buf, &size); - sprintf(path_home,"%s\\espeak-data",buf); + sprintf(path_home, "%s\\espeak-data", buf); #else char *env; - if(path != NULL) - { - snprintf(path_home,sizeof(path_home),"%s/espeak-data",path); + if (path != NULL) { + snprintf(path_home, sizeof(path_home), "%s/espeak-data", path); return; } // check for environment variable - if((env = getenv("ESPEAK_DATA_PATH")) != NULL) - { - snprintf(path_home,sizeof(path_home),"%s/espeak-data",env); - if(GetFileLength(path_home) == -2) + if ((env = getenv("ESPEAK_DATA_PATH")) != NULL) { + snprintf(path_home, sizeof(path_home), "%s/espeak-data", env); + if (GetFileLength(path_home) == -2) return; // an espeak-data directory exists } - snprintf(path_home,sizeof(path_home),"%s/espeak-data",getenv("HOME")); - if(access(path_home,R_OK) != 0) - { - strcpy(path_home,PATH_ESPEAK_DATA); + snprintf(path_home, sizeof(path_home), "%s/espeak-data", getenv("HOME")); + if (access(path_home, R_OK) != 0) { + strcpy(path_home, PATH_ESPEAK_DATA); } #endif } @@ -393,30 +368,26 @@ static int initialise(int control) err = EE_OK; LoadConfig(); - if((result = LoadPhData(&srate)) != 1) // reads sample rate from espeak-data/phontab - { - if(result == -1) - { - fprintf(stderr,"Failed to load espeak-data\n"); - if((control & espeakINITIALIZE_DONT_EXIT) == 0) - { + if ((result = LoadPhData(&srate)) != 1) { // reads sample rate from espeak-data/phontab + if (result == -1) { + fprintf(stderr, "Failed to load espeak-data\n"); + if ((control & espeakINITIALIZE_DONT_EXIT) == 0) { exit(1); } - } - else - fprintf(stderr,"Wrong version of espeak-data 0x%x (expects 0x%x) at %s\n",result,version_phdata,path_home); + } else + fprintf(stderr, "Wrong version of espeak-data 0x%x (expects 0x%x) at %s\n", result, version_phdata, path_home); } - WavegenInit(srate,0); + WavegenInit(srate, 0); - memset(¤t_voice_selected,0,sizeof(current_voice_selected)); + memset(¤t_voice_selected, 0, sizeof(current_voice_selected)); SetVoiceStack(NULL, ""); SynthesizeInit(); InitNamedata(); - for(param=0; param uid=%d, flags=%d, >>>text=%s<<<\n", unique_identifier, flags, text); } #endif - if((outbuf==NULL) || (event_list==NULL)) - return(EE_INTERNAL_ERROR); // espeak_Initialize() has not been called + if ((outbuf == NULL) || (event_list == NULL)) + return (EE_INTERNAL_ERROR); // espeak_Initialize() has not been called option_multibyte = flags & 7; option_ssml = flags & espeakSSML; @@ -449,23 +419,19 @@ static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text, count_samples = 0; #ifdef USE_ASYNC - if(my_mode == AUDIO_OUTPUT_PLAYBACK) - { + if (my_mode == AUDIO_OUTPUT_PLAYBACK) { a_write_pos = wave_get_write_position(my_audio); } #endif - if(translator == NULL) - { + if (translator == NULL) { SetVoiceByName("default"); } - SpeakNextClause(NULL,text,0); + SpeakNextClause(NULL, text, 0); - if(my_mode == AUDIO_OUTPUT_SYNCH_PLAYBACK) - { - for(;; ) - { + if (my_mode == AUDIO_OUTPUT_SYNCH_PLAYBACK) { + for (;;) { #ifdef PLATFORM_WINDOWS Sleep(300); // 0.3s #else @@ -474,21 +440,20 @@ static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text, struct timespec remaining; period.tv_sec = 0; period.tv_nsec = 300000000; // 0.3 sec - nanosleep(&period,&remaining); + nanosleep(&period, &remaining); #else sleep(1); #endif #endif - if(SynthOnTimer() != 0) + if (SynthOnTimer() != 0) break; } - return(EE_OK); + return (EE_OK); } - for(;; ) - { + for (;;) { #ifdef DEBUG_ENABLED - SHOW("Synthesize > %s\n","for (next)"); + SHOW("Synthesize > %s\n", "for (next)"); #endif out_ptr = outbuf; out_end = &outbuf[outbuf_size]; @@ -502,29 +467,23 @@ static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text, event_list[event_list_ix].user_data = my_user_data; count_buffers++; - if (my_mode==AUDIO_OUTPUT_PLAYBACK) - { + if (my_mode == AUDIO_OUTPUT_PLAYBACK) { #ifdef USE_ASYNC finished = create_events((short *)outbuf, length, event_list, a_write_pos); - if(finished < 0) + if (finished < 0) return EE_INTERNAL_ERROR; length = 0; // the wave data are played once. #endif - } - else - { + } else { finished = synth_callback((short *)outbuf, length, event_list); } - if(finished) - { - SpeakNextClause(NULL,0,2); // stop + if (finished) { + SpeakNextClause(NULL, 0, 2); // stop break; } - if(Generate(phoneme_list,&n_phoneme_list,1)==0) - { - if(WcmdqUsed() == 0) - { + if (Generate(phoneme_list, &n_phoneme_list, 1) == 0) { + if (WcmdqUsed() == 0) { // don't process the next clause until the previous clause has finished generating speech. // This ensures that

without language spec, nothing to do + return 0; // or

without language spec, nothing to do ssml_sp = &ssml_stack[n_ssml_stack++]; @@ -1530,10 +1530,10 @@ static int GetVoiceAttributes(wchar_t *pw, int tag_type) if (strcmp(new_voice_id, current_voice_id) != 0) { // add an embedded command to change the voice strcpy(current_voice_id, new_voice_id); - return (CLAUSE_BIT_VOICE); // change of voice + return CLAUSE_BIT_VOICE; // change of voice } - return (0); + return 0; } @@ -1627,9 +1627,9 @@ static int ReplaceKeyName(char *outbuf, int index, int *outix) if ((letter = LookupMnem(keynames, p)) != 0) { ix = utf8_out(letter, p); *outix = index + ix; - return (letter); + return letter; } - return (0); + return 0; } @@ -1737,7 +1737,7 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb } if (self_closing && ignore_if_self_closing[tag_type]) - return (0); + return 0; } @@ -1879,7 +1879,7 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb // This is the marker we are waiting for before starting to speak clear_skipping_text = 1; skip_marker[0] = 0; - return (CLAUSE_NONE); + return CLAUSE_NONE; } if ((index = AddNameData(buf, 0)) >= 0) { @@ -1928,12 +1928,12 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb PopParamStack(tag_type, outbuf, outix); else audio_text = 1; - return (CLAUSE_NONE); + return CLAUSE_NONE; case SSML_AUDIO + SSML_CLOSE: PopParamStack(tag_type, outbuf, outix); audio_text = 0; - return (CLAUSE_NONE); + return CLAUSE_NONE; case SSML_BREAK: value = 21; @@ -1970,7 +1970,7 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb value = 0xfff; terminator |= CLAUSE_PAUSE_LONG; } - return (terminator + value); + return terminator + value; } break; @@ -1982,20 +1982,20 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb } } if (GetVoiceAttributes(px, tag_type) == 0) - return (0); // no voice change - return (CLAUSE_VOICE); + return 0; // no voice change + return CLAUSE_VOICE; case SSML_VOICE: if (GetVoiceAttributes(px, tag_type) == 0) - return (0); // no voice change - return (CLAUSE_VOICE); + return 0; // no voice change + return CLAUSE_VOICE; case SSML_SPEAK + SSML_CLOSE: // unwind stack until the previous or tag while ((n_ssml_stack > 1) && (ssml_stack[n_ssml_stack-1].tag_type != SSML_SPEAK)) { n_ssml_stack--; } - return (CLAUSE_PERIOD + GetVoiceAttributes(px, tag_type)); + return CLAUSE_PERIOD + GetVoiceAttributes(px, tag_type); case SSML_VOICE + SSML_CLOSE: // unwind stack until the previous or tag @@ -2004,11 +2004,11 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb } terminator = 0; // ?? Sentence intonation, but no pause ?? - return (terminator + GetVoiceAttributes(px, tag_type)); + return terminator + GetVoiceAttributes(px, tag_type); case HTML_BREAK: case HTML_BREAK + SSML_CLOSE: - return (CLAUSE_COLON); + return CLAUSE_COLON; case SSML_SENTENCE: if (ssml_sp->tag_type == SSML_SENTENCE) { @@ -2016,7 +2016,7 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb voice_change_flag = GetVoiceAttributes(px, SSML_SENTENCE+SSML_CLOSE); } voice_change_flag |= GetVoiceAttributes(px, tag_type); - return (CLAUSE_PARAGRAPH + voice_change_flag); + return CLAUSE_PARAGRAPH + voice_change_flag; case SSML_PARAGRAPH: @@ -2029,7 +2029,7 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb voice_change_flag |= GetVoiceAttributes(px, SSML_PARAGRAPH+SSML_CLOSE); } voice_change_flag |= GetVoiceAttributes(px, tag_type); - return (CLAUSE_PARAGRAPH + voice_change_flag); + return CLAUSE_PARAGRAPH + voice_change_flag; case SSML_SENTENCE + SSML_CLOSE: @@ -2037,18 +2037,18 @@ static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outb // end of a sentence which specified a language voice_change_flag = GetVoiceAttributes(px, tag_type); } - return (CLAUSE_PERIOD + voice_change_flag); + return CLAUSE_PERIOD + voice_change_flag; case SSML_PARAGRAPH + SSML_CLOSE: if ((ssml_sp->tag_type == SSML_SENTENCE) || (ssml_sp->tag_type == SSML_PARAGRAPH)) { // End of a paragraph which specified a language. // (End-of-paragraph also implies end-of-sentence) - return (GetVoiceAttributes(px, tag_type) + CLAUSE_PARAGRAPH); + return GetVoiceAttributes(px, tag_type) + CLAUSE_PARAGRAPH; } - return (CLAUSE_PARAGRAPH); + return CLAUSE_PARAGRAPH; } - return (0); + return 0; } @@ -2145,7 +2145,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix if (!iswalnum(c1)) { if ((end_character_position > 0) && (count_characters > end_character_position)) { end_of_input = 1; - return (CLAUSE_EOF); + return CLAUSE_EOF; } if ((skip_characters > 0) && (count_characters >= skip_characters)) { @@ -2154,7 +2154,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix clear_skipping_text = 1; skip_characters = 0; UngetC(c2); - return (CLAUSE_NONE); + return CLAUSE_NONE; } } @@ -2235,7 +2235,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix ungot_char2 = c1; buf[ix] = ' '; buf[ix+1] = 0; - return (CLAUSE_NONE); + return CLAUSE_NONE; } // SSML Tag @@ -2267,7 +2267,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix if (terminator & CLAUSE_BIT_VOICE) { strcpy(voice_change, current_voice_id); } - return (terminator); + return terminator; } c1 = ' '; c2 = GetC(); @@ -2292,7 +2292,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix } buf[ix] = ' '; buf[ix+1] = 0; - return (terminator); + return terminator; } if ((c1 == CTRL_EMBEDDED) || (c1 == ctrl_embedded)) { @@ -2302,7 +2302,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix while (!iswspace(c1 = GetC()) && !Eof() && (ix < (n_buf-1))) buf[ix++] = c1; // add voice name to end of buffer, after the text buf[ix++] = 0; - return (CLAUSE_VOICE); + return CLAUSE_VOICE; } else if (c2 == 'B') { // set the punctuation option from an embedded command // B0 B1 B @@ -2368,7 +2368,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix ungot_word = "i "; UngetC(c2); p_word[0] = 0; - return (CLAUSE_PERIOD); + return CLAUSE_PERIOD; } } } @@ -2429,7 +2429,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix if (parag > 3) parag = 3; if (option_ssml) parag = 1; - return ((CLAUSE_PARAGRAPH-30) + 30*parag); // several blank lines, longer pause + return (CLAUSE_PARAGRAPH-30) + 30*parag; // several blank lines, longer pause } if (linelength <= option_linelength) { @@ -2437,7 +2437,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix UngetC(c2); buf[ix] = ' '; buf[ix+1] = 0; - return (CLAUSE_COLON); + return CLAUSE_COLON; } linelength = 0; @@ -2459,7 +2459,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix ungot_char2 = c1; buf[end_clause_index] = ' '; // delete the end-clause punctuation buf[end_clause_index+1] = 0; - return (end_clause_after_tag); + return end_clause_after_tag; } end_clause_after_tag = 0; } @@ -2502,7 +2502,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix if ((option_punctuation == 1) || (wcschr(option_punctlist, c1) != NULL)) { tr->phonemes_repeat_count = 0; if ((terminator = AnnouncePunctuation(tr, c1, &c2, buf, &ix, is_end_clause)) >= 0) - return (terminator); + return terminator; announced_punctuation = c1; } } @@ -2591,10 +2591,10 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix } if (nl_count > 1) { if ((punct_data == CLAUSE_QUESTION) || (punct_data == CLAUSE_EXCLAMATION)) - return (punct_data + 35); // with a longer pause - return (CLAUSE_PARAGRAPH); + return punct_data + 35; // with a longer pause + return CLAUSE_PARAGRAPH; } - return (punct_data); // only recognise punctuation if followed by a blank or bracket/quote + return punct_data; // only recognise punctuation if followed by a blank or bracket/quote } else { if (!Eof()) { if (iswspace(c2)) @@ -2636,7 +2636,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix buf[ix] = ' '; buf[ix+1] = 0; UngetC(c2); - return (CLAUSE_NONE); + return CLAUSE_NONE; } } @@ -2648,7 +2648,7 @@ int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix } buf[ix] = ' '; buf[ix+1] = 0; - return (CLAUSE_EOF); // end of file + return CLAUSE_EOF; // end of file } diff --git a/src/libespeak-ng/speak_lib.c b/src/libespeak-ng/speak_lib.c index dd946ad8..7a1641ed 100644 --- a/src/libespeak-ng/speak_lib.c +++ b/src/libespeak-ng/speak_lib.c @@ -123,7 +123,7 @@ static int dispatch_audio(short *outbuf, int length, espeak_EVENT *event) out_samplerate = voice_samplerate; if (!wave_init(voice_samplerate)) { err = EE_INTERNAL_ERROR; - return (-1); + return -1; } wave_set_callback_is_output_enabled(fifo_is_command_enabled); my_audio = wave_open("alsa"); @@ -172,7 +172,7 @@ static int dispatch_audio(short *outbuf, int length, espeak_EVENT *event) SHOW_TIME("LEAVE dispatch_audio\n"); - return (a_wave_can_be_played == 0); // 1 = stop synthesis, -1 = error + return a_wave_can_be_played == 0; // 1 = stop synthesis, -1 = error } @@ -283,12 +283,12 @@ int GetFileLength(const char *filename) struct stat statbuf; if (stat(filename, &statbuf) != 0) - return (0); + return 0; if (S_ISDIR(statbuf.st_mode)) - return (-2); // a directory + return -2; // a directory - return (statbuf.st_size); + return statbuf.st_size; } #pragma GCC visibility pop @@ -298,7 +298,7 @@ char *Alloc(int size) char *p; if ((p = (char *)malloc(size)) == NULL) fprintf(stderr, "Can't allocate memory\n"); // I was told that size+1 fixes a crash on 64-bit systems - return (p); + return p; } void Free(void *ptr) @@ -387,7 +387,7 @@ static int initialise(int control) for (param = 0; param < N_SPEECH_PARAM; param++) param_stack[0].parameter[param] = param_defaults[param]; - return (0); + return 0; } @@ -409,7 +409,7 @@ static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text, #endif if ((outbuf == NULL) || (event_list == NULL)) - return (EE_INTERNAL_ERROR); // espeak_Initialize() has not been called + return EE_INTERNAL_ERROR; // espeak_Initialize() has not been called option_multibyte = flags & 7; option_ssml = flags & espeakSSML; @@ -448,7 +448,7 @@ static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text, if (SynthOnTimer() != 0) break; } - return (EE_OK); + return EE_OK; } for (;;) { @@ -507,7 +507,7 @@ static espeak_ERROR Synthesize(unsigned int unique_identifier, const void *text, } } } - return (EE_OK); + return EE_OK; } #ifdef DEBUG_ENABLED @@ -642,7 +642,7 @@ espeak_ERROR sync_espeak_Synth_Mark(unsigned int unique_identifier, const void * aStatus = Synthesize(unique_identifier, text, flags | espeakSSML); SHOW_TIME("LEAVE sync_espeak_Synth_Mark"); - return (aStatus); + return aStatus; } @@ -755,13 +755,13 @@ ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output_type, int buf_length outbuf_size = (buf_length * samplerate)/500; outbuf = (unsigned char *)realloc(outbuf, outbuf_size); if ((out_start = outbuf) == NULL) - return (EE_INTERNAL_ERROR); + return EE_INTERNAL_ERROR; // allocate space for event list. Allow 200 events per second. // Add a constant to allow for very small buf_length n_event_list = (buf_length*200)/1000 + 20; if ((event_list = (espeak_EVENT *)realloc(event_list, sizeof(espeak_EVENT) * n_event_list)) == NULL) - return (EE_INTERNAL_ERROR); + return EE_INTERNAL_ERROR; option_phonemes = 0; option_phoneme_events = (options & (espeakINITIALIZE_PHONEME_EVENTS | espeakINITIALIZE_PHONEME_IPA)); @@ -781,7 +781,7 @@ ESPEAK_API int espeak_Initialize(espeak_AUDIO_OUTPUT output_type, int buf_length fifo_init(); #endif - return (samplerate); + return samplerate; } @@ -811,7 +811,7 @@ ESPEAK_API espeak_ERROR espeak_Synth(const void *text, size_t size, *unique_identifier = 0; if (synchronous_mode) { - return (sync_espeak_Synth(0, text, size, position, position_type, end_position, flags, user_data)); + return sync_espeak_Synth(0, text, size, position, position_type, end_position, flags, user_data); } #ifdef USE_ASYNC @@ -869,7 +869,7 @@ ESPEAK_API espeak_ERROR espeak_Synth_Mark(const void *text, size_t size, *unique_identifier = 0; if (synchronous_mode) { - return (sync_espeak_Synth_Mark(0, text, size, index_mark, end_position, flags, user_data)); + return sync_espeak_Synth_Mark(0, text, size, index_mark, end_position, flags, user_data); } #ifdef USE_ASYNC @@ -915,7 +915,7 @@ ESPEAK_API espeak_ERROR espeak_Key(const char *key) if (synchronous_mode) { sync_espeak_Key(key); - return (EE_OK); + return EE_OK; } #ifdef USE_ASYNC @@ -944,7 +944,7 @@ ESPEAK_API espeak_ERROR espeak_Char(wchar_t character) if (synchronous_mode) { sync_espeak_Char(character); - return (EE_OK); + return EE_OK; } t_espeak_command *c = create_espeak_char(character, NULL); @@ -955,7 +955,7 @@ ESPEAK_API espeak_ERROR espeak_Char(wchar_t character) return a_error; #else sync_espeak_Char(character); - return (EE_OK); + return EE_OK; #endif } @@ -964,7 +964,7 @@ ESPEAK_API espeak_ERROR espeak_SetVoiceByName(const char *name) { ENTER("espeak_SetVoiceByName"); - return (SetVoiceByName(name)); + return SetVoiceByName(name); } @@ -973,7 +973,7 @@ ESPEAK_API espeak_ERROR espeak_SetVoiceByProperties(espeak_VOICE *voice_selector { ENTER("espeak_SetVoiceByProperties"); - return (SetVoiceByProperties(voice_selector)); + return SetVoiceByProperties(voice_selector); } @@ -982,9 +982,9 @@ ESPEAK_API int espeak_GetParameter(espeak_PARAMETER parameter, int current) ENTER("espeak_GetParameter"); // current: 0=default value, 1=current value if (current) { - return (param_stack[0].parameter[parameter]); + return param_stack[0].parameter[parameter]; } else { - return (param_defaults[parameter]); + return param_defaults[parameter]; } } @@ -1001,7 +1001,7 @@ ESPEAK_API espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int valu if (synchronous_mode) { SetParameter(parameter, value, relative); - return (EE_OK); + return EE_OK; } t_espeak_command *c = create_espeak_parameter(parameter, value, relative); @@ -1013,7 +1013,7 @@ ESPEAK_API espeak_ERROR espeak_SetParameter(espeak_PARAMETER parameter, int valu return a_error; #else SetParameter(parameter, value, relative); - return (EE_OK); + return EE_OK; #endif } @@ -1028,7 +1028,7 @@ ESPEAK_API espeak_ERROR espeak_SetPunctuationList(const wchar_t *punctlist) if (synchronous_mode) { sync_espeak_SetPunctuationList(punctlist); - return (EE_OK); + return EE_OK; } t_espeak_command *c = create_espeak_punctuation_list(punctlist); @@ -1039,7 +1039,7 @@ ESPEAK_API espeak_ERROR espeak_SetPunctuationList(const wchar_t *punctlist) return a_error; #else sync_espeak_SetPunctuationList(punctlist); - return (EE_OK); + return EE_OK; #endif } @@ -1077,7 +1077,7 @@ ESPEAK_API const char *espeak_TextToPhonemes(const void **textptr, int textmode, option_multibyte = textmode & 7; *textptr = TranslateClause(translator, NULL, *textptr, NULL, NULL); - return (GetTranslatedPhonemeString(phonememode)); + return GetTranslatedPhonemeString(phonememode); } @@ -1113,11 +1113,11 @@ ESPEAK_API int espeak_IsPlaying(void) { #ifdef USE_ASYNC if ((my_mode == AUDIO_OUTPUT_PLAYBACK) && wave_is_busy(my_audio)) - return (1); + return 1; - return (fifo_is_busy()); + return fifo_is_busy(); #else - return (0); + return 0; #endif } @@ -1175,7 +1175,7 @@ ESPEAK_API const char *espeak_Info(const char **ptr) if (ptr != NULL) { *ptr = path_home; } - return (version_string); + return version_string; } #pragma GCC visibility pop diff --git a/src/libespeak-ng/spect.c b/src/libespeak-ng/spect.c index 7da3b491..d0badfd0 100644 --- a/src/libespeak-ng/spect.c +++ b/src/libespeak-ng/spect.c @@ -86,7 +86,7 @@ float polint(float xa[], float ya[], int n, float x) hp = xa[i+m]-x; w = c[i+1]-d[i]; if ((den = ho-hp) == 0.0) { - return (ya[2]); // two input xa are identical + return ya[2]; // two input xa are identical } den = w/den; d[i] = hp*den; @@ -94,7 +94,7 @@ float polint(float xa[], float ya[], int n, float x) } y += ((2*ns < (n-m) ? c[ns+1] : d[ns--])); } - return (y); + return y; } @@ -187,7 +187,7 @@ int LoadFrame(SpectFrame *frame, FILE *stream, int file_format_type) if (spect_data == NULL) { fprintf(stderr, "Failed to allocate memory\n"); - return (1); + return 1; } frame->max_y = 0; @@ -198,7 +198,7 @@ int LoadFrame(SpectFrame *frame, FILE *stream, int file_format_type) } frame->spect = spect_data; - return (0); + return 0; } @@ -226,7 +226,7 @@ double GetFrameRms(SpectFrame *frame, int seq_amplitude) total += ((htab[h] * htab[h]) >> 10); } frame->rms = sqrt(total) / 7.25; - return (frame->rms); + return frame->rms; } @@ -272,13 +272,13 @@ static float GetFrameLength(SpectSeq *spect, int frame) int ix; float adjust = 0; - if (frame >= spect->numframes-1) return (0); + if (frame >= spect->numframes-1) return 0; for (ix = frame+1; ix < spect->numframes-1; ix++) { if (spect->frames[ix]->keyframe) break; // reached next keyframe adjust += spect->frames[ix]->length_adjust; } - return ((spect->frames[ix]->time - spect->frames[frame]->time) * 1000.0 + adjust); + return (spect->frames[ix]->time - spect->frames[frame]->time) * 1000.0 + adjust; } @@ -294,7 +294,7 @@ int LoadSpectSeq(SpectSeq *spect, const char *filename) FILE *stream = fopen(filename, "rb"); if (stream == NULL) { fprintf(stderr, "Failed to open: '%s'", filename); - return (0); + return 0; } fread(&id1, sizeof(uint32_t), 1, stream); @@ -309,7 +309,7 @@ int LoadSpectSeq(SpectSeq *spect, const char *filename) } else { fprintf(stderr, "Unsupported spectral file format.\n"); fclose(stream); - return (1); + return 1; } fread(&name_len, sizeof(uint32_t), 1, stream); @@ -326,7 +326,7 @@ int LoadSpectSeq(SpectSeq *spect, const char *filename) if (n == 0) { fclose(stream); - return (0); + return 0; } if (spect->frames != NULL) { @@ -383,5 +383,5 @@ int LoadSpectSeq(SpectSeq *spect, const char *filename) spect->frames[ix]->length_adjust = spect->frames[ix]->length - GetFrameLength(spect, ix); } fclose(stream); - return (0); + return 0; } diff --git a/src/libespeak-ng/synth_mbrola.c b/src/libespeak-ng/synth_mbrola.c index aa1658c9..644c21be 100644 --- a/src/libespeak-ng/synth_mbrola.c +++ b/src/libespeak-ng/synth_mbrola.c @@ -127,7 +127,7 @@ espeak_ERROR LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, int if (mbrola_voice == NULL) { samplerate = samplerate_native; SetParameter(espeakVOICETYPE, 0, 0); - return (EE_OK); + return EE_OK; } sprintf(path, "%s/mbrola/%s", path_home, mbrola_voice); @@ -150,12 +150,12 @@ espeak_ERROR LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, int #ifdef PLATFORM_WINDOWS if (load_MBR() == FALSE) { // load mbrola.dll fprintf(stderr, "Can't load mbrola.dll\n"); - return (EE_INTERNAL_ERROR); + return EE_INTERNAL_ERROR; } #endif if (init_MBR(path) != 0) // initialise the required mbrola voice - return (EE_NOT_FOUND); + return EE_NOT_FOUND; setNoError_MBR(1); // don't stop on phoneme errors @@ -164,13 +164,13 @@ espeak_ERROR LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, int size = GetFileLength(path); if ((f_in = fopen(path, "rb")) == NULL) { close_MBR(); - return (EE_NOT_FOUND); + return EE_NOT_FOUND; } if ((mbrola_tab = (MBROLA_TAB *)realloc(mbrola_tab, size)) == NULL) { fclose(f_in); close_MBR(); - return (EE_INTERNAL_ERROR); + return EE_INTERNAL_ERROR; } mbrola_control = Read4Bytes(f_in); @@ -189,7 +189,7 @@ espeak_ERROR LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, int SetParameter(espeakVOICETYPE, 1, 0); strcpy(mbrola_name, mbrola_voice); mbrola_delay = 1000; // improve synchronization of events - return (EE_OK); + return EE_OK; } @@ -254,7 +254,7 @@ static int GetMbrName(PHONEME_LIST *plist, PHONEME_TAB *ph, PHONEME_TAB *ph_prev if (pr->control & 0x10) { mbr_name_prefix = pr->mbr_name; - return (0); + return 0; } mnem = pr->mbr_name; break; @@ -268,7 +268,7 @@ static int GetMbrName(PHONEME_LIST *plist, PHONEME_TAB *ph, PHONEME_TAB *ph_prev mnem = (mnem << 8) | (mbr_name_prefix & 0xff); } mbr_name_prefix = 0; - return (mnem); + return mnem; } @@ -368,7 +368,7 @@ static char *WritePitch(int env, int pitch1, int pitch2, int split, int final) if (final) sprintf(output, "\t100 %d\n", p_end); - return (output); + return output; } @@ -586,7 +586,7 @@ int MbrolaGenerate(PHONEME_LIST *phoneme_list, int *n_ph, int resume) FILE *f_mbrola = NULL; if (*n_ph == 0) - return (0); + return 0; if (option_phonemes & espeakPHONEMES_MBROLA) { // send mbrola data to a file, not to the mbrola library @@ -650,17 +650,17 @@ void MbrolaReset(void) espeak_ERROR LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, int *srate) { - return (EE_INTERNAL_ERROR); + return EE_INTERNAL_ERROR; } int MbrolaGenerate(PHONEME_LIST *phoneme_list, int *n_ph, int resume) { - return (0); + return 0; } int MbrolaFill(int length, int resume, int amplitude) { - return (0); + return 0; } void MbrolaReset(void) diff --git a/src/libespeak-ng/synthdata.c b/src/libespeak-ng/synthdata.c index 48b9261f..0b585243 100644 --- a/src/libespeak-ng/synthdata.c +++ b/src/libespeak-ng/synthdata.c @@ -86,7 +86,7 @@ static char *ReadPhFile(void *ptr, const char *fname, int *size) if ((f_in = fopen(buf, "rb")) == NULL) { fprintf(stderr, "Can't read data file: '%s'\n", buf); - return (NULL); + return NULL; } if (ptr != NULL) @@ -94,18 +94,18 @@ static char *ReadPhFile(void *ptr, const char *fname, int *size) if ((p = Alloc(length)) == NULL) { fclose(f_in); - return (NULL); + return NULL; } if (fread(p, 1, length, f_in) != length) { fclose(f_in); Free(p); - return (NULL); + return NULL; } fclose(f_in); if (size != NULL) *size = length; - return (p); + return p; } @@ -121,13 +121,13 @@ int LoadPhData(int *srate) int *pw; if ((phoneme_tab_data = (unsigned char *)ReadPhFile((void *)(phoneme_tab_data), "phontab", NULL)) == NULL) - return (-1); + return -1; if ((phoneme_index = (USHORT *)ReadPhFile((void *)(phoneme_index), "phonindex", NULL)) == NULL) - return (-1); + return -1; if ((phondata_ptr = ReadPhFile((void *)(phondata_ptr), "phondata", NULL)) == NULL) - return (-1); + return -1; if ((tunes = (TUNE *)ReadPhFile((void *)(tunes), "intonations", &length)) == NULL) - return (-1); + return -1; wavefile_data = (unsigned char *)phondata_ptr; n_tunes = length / sizeof(TUNE); @@ -166,7 +166,7 @@ int LoadPhData(int *srate) if (srate != NULL) *srate = rate; - return (result); + return result; } @@ -191,9 +191,9 @@ int PhonemeCode(unsigned int mnem) if (phoneme_tab[ix] == NULL) continue; if (phoneme_tab[ix]->mnemonic == mnem) - return (phoneme_tab[ix]->code); + return phoneme_tab[ix]->code; } - return (0); + return 0; } @@ -211,7 +211,7 @@ int LookupPhonemeString(const char *string) mnem |= (c << (ix*8)); } - return (PhonemeCode(mnem)); + return PhonemeCode(mnem); } @@ -344,7 +344,7 @@ frameref_t *LookupSpect(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params, } *n_frames = nf; - return (frames); + return frames; } @@ -353,9 +353,9 @@ unsigned char *GetEnvelope(int index) { if (index == 0) { fprintf(stderr, "espeak: No envelope\n"); - return (envelope_data[0]); // not found, use a default envelope + return envelope_data[0]; // not found, use a default envelope } - return ((unsigned char *)&phondata_ptr[index]); + return (unsigned char *)&phondata_ptr[index]; } @@ -409,9 +409,9 @@ int LookupPhonemeTable(const char *name) } } if (ix == n_phoneme_tables) - return (-1); + return -1; - return (ix); + return ix; } @@ -422,10 +422,10 @@ int SelectPhonemeTableName(const char *name) int ix; if ((ix = LookupPhonemeTable(name)) == -1) - return (-1); + return -1; SelectPhonemeTable(ix); - return (ix); + return ix; } @@ -508,7 +508,7 @@ static bool StressCondition(Translator *tr, PHONEME_LIST *plist, int condition, if (phoneme_tab[plist[1].phcode]->type == phVOWEL) { pl = &plist[1]; } else - return (false); // no stress elevel for this consonant + return false; // no stress elevel for this consonant } stress_level = pl->stresslevel & 0xf; @@ -516,7 +516,7 @@ static bool StressCondition(Translator *tr, PHONEME_LIST *plist, int condition, if (tr != NULL) { if ((control & 1) && (plist->synthflags & SFLAG_DICTIONARY) && ((tr->langopts.param[LOPT_REDUCE] & 1) == 0)) { // change phoneme. Don't change phonemes which are given for the word in the dictionary. - return (false); + return false; } if ((tr->langopts.param[LOPT_REDUCE] & 0x2) && (stress_level >= pl->wordstress)) { @@ -526,18 +526,18 @@ static bool StressCondition(Translator *tr, PHONEME_LIST *plist, int condition, } if (condition == 4) { - return (stress_level >= pl->wordstress); + return stress_level >= pl->wordstress; } if (condition == 3) { // if stressed if (stress_level > 3) - return (true); + return true; } else { if (stress_level < condition_level[condition]) - return (true); + return true; } - return (false); + return false; } @@ -553,7 +553,7 @@ static int CountVowelPosition(PHONEME_LIST *plist) break; plist--; } - return (count); + return count; } @@ -594,17 +594,17 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, if (which == 4) { // nextPhW not word boundary if (plist[1].sourceix) - return (false); + return false; } if (which == 5) { // prevPhW, not word boundary if (plist[0].sourceix) - return (false); + return false; } if (which == 6) { // next2PhW, not word boundary if (plist[1].sourceix || plist[2].sourceix) - return (false); + return false; } @@ -633,7 +633,7 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, // nextVowel, not word boundary for (which = 1;; which++) { if (plist[which].sourceix) - return (false); + return false; if (phoneme_tab[plist[which].phcode]->type == phVOWEL) { plist = &plist[which]; break; @@ -643,7 +643,7 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, case 8: // prevVowel in this word if ((worddata == NULL) || (worddata->prev_vowel.ph == NULL)) - return (false); // no previous vowel + return false; // no previous vowel plist = &(worddata->prev_vowel); check_endtype = 1; break; @@ -651,14 +651,14 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, case 9: // next3PhW for (ix = 1; ix <= 3; ix++) { if (plist[ix].sourceix) - return (false); + return false; } plist = &plist[3]; break; case 10: // prev2PhW if ((plist[0].sourceix) || (plist[-1].sourceix)) - return (false); + return false; plist -= 2; check_endtype = 1; break; @@ -680,12 +680,12 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, if (instn2 < 7) { // 'data' is a phoneme number if ((phoneme_tab[data]->mnemonic == ph->mnemonic) == true) - return (true); + return true; // not an exact match, check for a vowel type (eg. #i ) if ((check_endtype) && (ph->type == phVOWEL)) - return (data == ph->end_type); // prevPh() match on end_type - return (data == ph->start_type); // thisPh() or nextPh(), match on start_type + return data == ph->end_type; // prevPh() match on end_type + return data == ph->start_type; // thisPh() or nextPh(), match on start_type } data = instn & 0x1f; @@ -694,17 +694,17 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, { case 0x00: // phoneme type, vowel, nasal, fricative, etc - return (ph->type == data); + return ph->type == data; break; case 0x20: // place of articulation - return (((ph->phflags >> 16) & 0xf) == data); + return ((ph->phflags >> 16) & 0xf) == data; break; case 0x40: // is a bit set in phoneme flags - return ((ph->phflags & (1 << data)) != 0); + return (ph->phflags & (1 << data)) != 0; break; case 0x80: @@ -715,59 +715,59 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, case 2: case 3: case 4: - return (StressCondition(tr, plist, data, 0)); + return StressCondition(tr, plist, data, 0); case 5: // isBreak, Either pause phoneme, or (stop/vstop/vfric not followed by vowel or (liquid in same word)) - return ((ph->type == phPAUSE) || (plist_this->synthflags & SFLAG_NEXT_PAUSE)); + return (ph->type == phPAUSE) || (plist_this->synthflags & SFLAG_NEXT_PAUSE); case 6: // isWordStart - return (plist->sourceix != 0); + return plist->sourceix != 0; case 7: // notWordStart - return (plist->sourceix == 0); + return plist->sourceix == 0; case 8: // isWordEnd - return (plist[1].sourceix || (plist[1].ph->type == phPAUSE)); + return plist[1].sourceix || (plist[1].ph->type == phPAUSE); break; case 9: // isAfterStress if (plist->sourceix != 0) - return (false); + return false; do { plist--; if ((plist->stresslevel & 0xf) >= 4) - return (true); + return true; } while (plist->sourceix == 0); break; case 10: // isNotVowel - return (ph->type != phVOWEL); + return ph->type != phVOWEL; case 11: // isFinalVowel for (;;) { plist++; // plist->ph = phoneme_tab[plist->phcode]; // Why was this line here?? It corrupts plist if we have language switching if phoneme_tab is wrong language if (plist->sourceix != 0) - return (true); // start of next word, without finding another vowel + return true; // start of next word, without finding another vowel if (plist->ph->type == phVOWEL) - return (false); + return false; } break; case 12: // isVoiced - return ((ph->type == phVOWEL) || (ph->type == phLIQUID) || (ph->phflags & phVOICED)); + return (ph->type == phVOWEL) || (ph->type == phLIQUID) || (ph->phflags & phVOICED); case 13: // isFirstVowel - return (CountVowelPosition(plist) == 1); + return CountVowelPosition(plist) == 1; case 14: // isSecondVowel - return (CountVowelPosition(plist) == 2); + return CountVowelPosition(plist) == 2; case 15: // isSeqFlag1 // is this preceded by a sequence if 1 or more vowels which have 'flag1' ? (lang=hi) if (plist->sourceix != 0) - return (false); // this is the first phoneme in the word, so no. + return false; // this is the first phoneme in the word, so no. count = 0; for (;;) { @@ -781,28 +781,28 @@ static bool InterpretCondition(Translator *tr, int control, PHONEME_LIST *plist, if (plist->sourceix != 0) break; } - return (count > 0); + return count > 0; case 0x10: // isTranslationGiven - return ((plist->synthflags & SFLAG_DICTIONARY) != 0); + return (plist->synthflags & SFLAG_DICTIONARY) != 0; } break; } - return (false); + return false; } else if (instn2 == 0xf) { // Other conditions switch (data) { case 1: // PreVoicing - return (control & 1); + return control & 1; case 2: // KlattSynth - return (voice->klattv[0] != 0); + return voice->klattv[0] != 0; case 3: // MbrolaSynth - return (mbrola_name[0] != 0); + return mbrola_name[0] != 0; } } - return (false); + return false; } @@ -843,41 +843,41 @@ int NumInstnWords(USHORT *prog) instn = *prog; instn_type = instn >> 12; if ((n = n_words[instn_type]) > 0) - return (n); + return n; switch (instn_type) { case 0: if (((instn & 0xf00) >> 8) == i_IPA_NAME) { n = ((instn & 0xff) + 1) / 2; - return (n+1); + return n+1; } - return (1);; + return 1; case 6: type2 = (instn & 0xf00) >> 9; if ((type2 == 5) || (type2 == 6)) - return (12); // switch on vowel type - return (1); + return 12; // switch on vowel type + return 1; case 2: case 3: // a condition, check for a 2-word instruction if (((n = instn & 0x0f00) == 0x600) || (n == 0x0d00)) - return (2); - return (1); + return 2; + return 1; default: // instn_type 11 to 15, 2 words instn2 = prog[2]; if ((instn2 >> 12) == 0xf) { // This instruction is followed by addWav(), 2 more words - return (4); + return 4; } if (instn2 == i_CONTINUE) { - return (3); + return 3; } - return (2); + return 2; } } diff --git a/src/libespeak-ng/synthesize.c b/src/libespeak-ng/synthesize.c index 28c64a16..102151a7 100644 --- a/src/libespeak-ng/synthesize.c +++ b/src/libespeak-ng/synthesize.c @@ -88,7 +88,7 @@ const char *WordToString(unsigned int word) for (ix = 0; ix < 4; ix++) buf[ix] = word >> (ix*8); buf[4] = 0; - return (buf); + return buf; } @@ -199,7 +199,7 @@ int PauseLength(int pause, int control) if (len < speed.min_pause) { len = speed.min_pause; // mS, limit the amount to which pauses can be shortened } - return (len); + return len; } @@ -258,7 +258,7 @@ static int DoSample2(int index, int which, int std_length, int control, int leng wav_length += p[0]; // length in bytes if (wav_length == 0) - return (0); + return 0; min_length = speed.min_sample_len; @@ -304,7 +304,7 @@ static int DoSample2(int index, int which, int std_length, int control, int leng } if (amp < 0) - return (length); + return length; len4 = wav_length / 4; @@ -319,7 +319,7 @@ static int DoSample2(int index, int which, int std_length, int control, int leng q[2] = (intptr_t)(&wavefile_data[index]); q[3] = wav_scale + (amp << 8); WcmdqInc(); - return (length); + return length; } if (length > wav_length) { @@ -368,7 +368,7 @@ static int DoSample2(int index, int which, int std_length, int control, int leng WcmdqInc(); } - return (length); + return length; } @@ -397,7 +397,7 @@ int DoSample3(PHONEME_DATA *phdata, int length_mod, int amp) len = DoSample2(phdata->sound_addr[pd_WAV], 2, phdata->pd_param[pd_LENGTHMOD]*2, phdata->pd_control, length_mod, amp2); } last_frame = NULL; - return (len); + return len; } @@ -416,7 +416,7 @@ static frame_t *AllocFrame() ix++; if (ix >= N_FRAME_POOL) ix = 0; - return (&frame_pool[ix]); + return &frame_pool[ix]; } @@ -489,7 +489,7 @@ static frame_t *CopyFrame(frame_t *frame1, int copy) if ((copy == 0) && (frame1->frflags & FRFLAG_COPIED)) { // this frame has already been copied in temporary rw memory - return (frame1); + return frame1; } frame2 = AllocFrame(); @@ -498,7 +498,7 @@ static frame_t *CopyFrame(frame_t *frame1, int copy) frame2->length = 0; frame2->frflags |= FRFLAG_COPIED; } - return (frame2); + return frame2; } @@ -562,12 +562,12 @@ static int VowelCloseness(frame_t *fr) int f1; if ((f1 = fr->ffreq[1]) < 300) - return (3); + return 3; if (f1 < 400) - return (2); + return 2; if (f1 < 500) - return (1); - return (0); + return 1; + return 0; } @@ -598,7 +598,7 @@ int FormantTransition2(frameref_t *seq, int *n_frames, unsigned int data1, unsig frame_t *fr = NULL; if (*n_frames < 2) - return (0); + return 0; len = (data1 & 0x3f) * 2; rms = (data1 >> 6) & 0x3f; @@ -699,8 +699,8 @@ int FormantTransition2(frameref_t *seq, int *n_frames, unsigned int data1, unsig DoPause(20, 0); // add a short pause after the consonant if (flags & 16) - return (len); - return (0); + return len; + return 0; } @@ -914,7 +914,7 @@ int DoSpect2(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params, PHONEME_L int frame_lengths[N_SEQ_FRAMES]; if (fmt_params->fmt_addr == 0) - return (0); + return 0; length_mod = plist->length; if (length_mod == 0) length_mod = 256; @@ -937,7 +937,7 @@ int DoSpect2(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params, PHONEME_L modn_flags = 0; frames = LookupSpect(this_ph, which, fmt_params, &n_frames, plist); if (frames == NULL) - return (0); // not found + return 0; // not found if (fmt_params->fmt_amp != fmt_amplitude) { // an amplitude adjustment is specified for this sequence @@ -1073,7 +1073,7 @@ int DoSpect2(PHONEME_TAB *this_ph, int which, FMT_PARAMS *fmt_params, PHONEME_L } - return (total_len); + return total_len; } @@ -1223,13 +1223,13 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, int resume) static WORD_PH_DATA worddata; if (option_quiet) - return (0); + return 0; if (option_phoneme_events & espeakINITIALIZE_PHONEME_IPA) use_ipa = 1; if (mbrola_name[0] != 0) - return (MbrolaGenerate(phoneme_list, n_ph, resume)); + return MbrolaGenerate(phoneme_list, n_ph, resume); if (resume == 0) { ix = 1; @@ -1259,7 +1259,7 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, int resume) free_min = MIN_WCMDQ; // 25 if (WcmdqFree() <= free_min) - return (1); // wait + return 1; // wait prev = &phoneme_list[ix-1]; next = &phoneme_list[ix+1]; @@ -1614,7 +1614,7 @@ int Generate(PHONEME_LIST *phoneme_list, int *n_ph, int resume) *n_ph = 0; } - return (0); // finished the phoneme list + return 0; // finished the phoneme list } @@ -1626,7 +1626,7 @@ static int paused = 0; int SynthOnTimer() { if (!timer_on) { - return (WavegenCloseSound()); + return WavegenCloseSound(); } do { @@ -1638,13 +1638,13 @@ int SynthOnTimer() } } while (skipping_text); - return (0); + return 0; } int SynthStatus() { - return (timer_on | paused); + return timer_on | paused; } @@ -1670,9 +1670,9 @@ int SpeakNextClause(FILE *f_in, const void *text_in, int control) if (control == 4) { if ((f_text == NULL) && (p_text == NULL)) - return (0); + return 0; else - return (1); + return 1; } if (control == 2) { @@ -1686,7 +1686,7 @@ int SpeakNextClause(FILE *f_in, const void *text_in, int control) n_phoneme_list = 0; WcmdqStop(); - return (0); + return 0; } if (control == 3) { @@ -1700,14 +1700,14 @@ int SpeakNextClause(FILE *f_in, const void *text_in, int control) paused = 0; Generate(phoneme_list, &n_phoneme_list, 0); // re-start from beginning of clause } - return (0); + return 0; } if (control == 5) { // stop speaking, but continue looking for text n_phoneme_list = 0; WcmdqStop(); - return (0); + return 0; } if ((f_in != NULL) || (text_in != NULL)) { @@ -1720,14 +1720,14 @@ int SpeakNextClause(FILE *f_in, const void *text_in, int control) if ((f_text == NULL) && (p_text == NULL)) { skipping_text = 0; timer_on = 0; - return (0); + return 0; } if ((f_text != NULL) && feof(f_text)) { timer_on = 0; fclose(f_text); f_text = NULL; - return (0); + return 0; } if (current_phoneme_table != voice->phoneme_tab_ix) { @@ -1754,7 +1754,7 @@ int SpeakNextClause(FILE *f_in, const void *text_in, int control) if (skipping_text) { n_phoneme_list = 0; - return (1); + return 1; } Generate(phoneme_list, &n_phoneme_list, 0); @@ -1772,5 +1772,5 @@ int SpeakNextClause(FILE *f_in, const void *text_in, int control) new_voice = NULL; } - return (1); + return 1; } diff --git a/src/libespeak-ng/tr_languages.c b/src/libespeak-ng/tr_languages.c index 8d6eac3e..fcee88d9 100644 --- a/src/libespeak-ng/tr_languages.c +++ b/src/libespeak-ng/tr_languages.c @@ -115,9 +115,9 @@ ALPHABET *AlphabetFromName(const char *name) for (alphabet = alphabets; alphabet->name != NULL; alphabet++) { if (strcmp(name, &alphabet->name[1]) == 0) - return (alphabet); + return alphabet; } - return (NULL); + return NULL; } @@ -129,13 +129,13 @@ ALPHABET *AlphabetFromChar(int c) while (alphabet->name != NULL) { if (c <= alphabet->range_max) { if (c >= alphabet->range_min) - return (alphabet); + return alphabet; else break; } alphabet++; } - return (NULL); + return NULL; } @@ -239,7 +239,7 @@ static Translator *NewTranslator(void) tr = (Translator *)Alloc(sizeof(Translator)); if (tr == NULL) - return (NULL); + return NULL; tr->charset_a0 = charsets[1]; // ISO-8859-1, this is for when the input is not utf8 dictionary_name[0] = 0; @@ -314,7 +314,7 @@ static Translator *NewTranslator(void) memcpy(tr->langopts.tunes, default_tunes, sizeof(tr->langopts.tunes)); - return (tr); + return tr; } // common letter pairs, encode these as a single byte @@ -1629,7 +1629,7 @@ Translator *SelectTranslator(const char *name) tr->translator_name = name2; ProcessLanguageOptions(&tr->langopts); - return (tr); + return tr; } diff --git a/src/libespeak-ng/translate.c b/src/libespeak-ng/translate.c index 4d1b7d66..72c37797 100644 --- a/src/libespeak-ng/translate.c +++ b/src/libespeak-ng/translate.c @@ -382,80 +382,80 @@ int IsAlpha(unsigned int c) }; if (iswalpha2(c)) - return (1); + return 1; if (c < 0x300) - return (0); + return 0; if ((c >= 0x901) && (c <= 0xdf7)) { // Indic scripts: Devanagari, Tamil, etc if ((c & 0x7f) < 0x64) - return (1); + return 1; if (lookupwchar(extra_indic_alphas, c) != 0) - return (1); + return 1; if ((c >= 0xd7a) && (c <= 0xd7f)) - return (1); // malaytalam chillu characters + return 1; // malaytalam chillu characters - return (0); + return 0; } if ((c >= 0x5b0) && (c <= 0x5c2)) - return (1); // Hebrew vowel marks + return 1; // Hebrew vowel marks if (c == 0x0605) - return (1); + return 1; if ((c == 0x670) || ((c >= 0x64b) && (c <= 0x65e))) - return (1); // arabic vowel marks + return 1; // arabic vowel marks if ((c >= 0x300) && (c <= 0x36f)) - return (1); // combining accents + return 1; // combining accents if ((c >= 0x780) && (c <= 0x7b1)) - return (1); // taani/divehi (maldives) + return 1; // taani/divehi (maldives) if ((c >= 0xf40) && (c <= 0xfbc)) - return (1); // tibetan + return 1; // tibetan if ((c >= 0x1100) && (c <= 0x11ff)) - return (1); // Korean jamo + return 1; // Korean jamo if ((c >= 0x2800) && (c <= 0x28ff)) - return (1); // braille + return 1; // braille if ((c > 0x3040) && (c <= 0xa700)) - return (1); // Chinese/Japanese. Should never get here, but Mac OS 10.4's iswalpha seems to be broken, so just make sure + return 1; // Chinese/Japanese. Should never get here, but Mac OS 10.4's iswalpha seems to be broken, so just make sure - return (0); + return 0; } int IsDigit09(unsigned int c) { if ((c >= '0') && (c <= '9')) - return (1); - return (0); + return 1; + return 0; } int IsDigit(unsigned int c) { if (iswdigit(c)) - return (1); + return 1; if ((c >= 0x966) && (c <= 0x96f)) - return (1); + return 1; - return (0); + return 0; } int IsSpace(unsigned int c) { if (c == 0) - return (0); + return 0; if ((c >= 0x2500) && (c < 0x25a0)) - return (1); // box drawing characters + return 1; // box drawing characters if ((c >= 0xfff9) && (c <= 0xffff)) - return (1); // unicode specials - return (iswspace(c)); + return 1; // unicode specials + return iswspace(c); } @@ -474,9 +474,9 @@ int lookupwchar(const unsigned short *list, int c) for (ix = 0; list[ix] != 0; ix++) { if (list[ix] == c) - return (ix+1); + return ix+1; } - return (0); + return 0; } @@ -488,17 +488,17 @@ int lookupwchar2(const unsigned short *list, int c) for (ix = 0; list[ix] != 0; ix += 2) { if (list[ix] == c) - return (list[ix+1]); + return list[ix+1]; } - return (0); + return 0; } int IsBracket(int c) { if ((c >= 0x2014) && (c <= 0x201f)) - return (1); - return (lookupwchar(brackets, c)); + return 1; + return lookupwchar(brackets, c); } @@ -513,11 +513,11 @@ int utf8_out(unsigned int c, char *buf) if (c < 0x80) { buf[0] = c; - return (1); + return 1; } if (c >= 0x110000) { buf[0] = ' '; // out of range character code - return (1); + return 1; } if (c < 0x0800) n_bytes = 1; @@ -532,7 +532,7 @@ int utf8_out(unsigned int c, char *buf) shift -= 6; buf[j+1] = 0x80 + ((c >> shift) & 0x3f); } - return (n_bytes+1); + return n_bytes+1; } @@ -541,12 +541,12 @@ int utf8_nbytes(const char *buf) // Returns the number of bytes for the first UTF-8 character in buf unsigned char c = (unsigned char)buf[0]; if (c < 0x80) - return (1); + return 1; if (c < 0xe0) - return (2); + return 2; if (c < 0xf0) - return (3); - return (4); + return 3; + return 4; } @@ -585,7 +585,7 @@ int utf8_in2(int *c, const char *buf, int backwards) } } *c = c1; - return (n_bytes+1); + return n_bytes+1; } @@ -594,7 +594,7 @@ int utf8_in(int *c, const char *buf) { // Read a unicode characater from a UTF8 string // Returns the number of UTF8 bytes used. - return (utf8_in2(c, buf, 0)); + return utf8_in2(c, buf, 0); } #pragma GCC visibility pop @@ -603,8 +603,8 @@ char *strchr_w(const char *s, int c) { // return NULL for any non-ascii character if (c >= 0x80) - return (NULL); - return (strchr((char *)s, c)); // (char *) is needed for Borland compiler + return NULL; + return strchr((char *)s, c); // (char *) is needed for Borland compiler } @@ -614,9 +614,9 @@ int IsAllUpper(const char *word) while ((*word != 0) && !isspace2(*word)) { word += utf8_in(&c, word); if (!iswupper2(c)) - return (0); + return 0; } - return (1); + return 1; } @@ -638,11 +638,11 @@ static char *SpeakIndividualLetters(Translator *tr, char *word, char *phonemes, if (phonemes[0] == phonSWITCH) { // change to another language in order to translate this word strcpy(word_phonemes, phonemes); - return (NULL); + return NULL; } } SetSpellingStress(tr, phonemes, spell_word, posn); - return (word); + return word; } @@ -700,7 +700,7 @@ static int CheckDottedAbbrev(char *word1, WORD_TAB *wtab) word1[ix++] = ' '; dictionary_skipwords = (count - 1)*2; } - return (count); + return count; } @@ -725,13 +725,13 @@ int ChangeEquivalentPhonemes(Translator *tr, int lang2, char *phonemes) // has a phoneme equivalence table been specified for thus language pair? if ((ix = phoneme_tab_list[tr->phoneme_tab_ix].equivalence_tables) == 0) - return (0); + return 0; pb = (unsigned char *)&phondata_ptr[ix]; for (;;) { if (pb[0] == 0) - return (0); // table not found + return 0; // table not found if (pb[0] == lang2) break; @@ -783,7 +783,7 @@ int ChangeEquivalentPhonemes(Translator *tr, int lang2, char *phonemes) DecodePhonemes(phonemes, phonbuf); fprintf(f_trans, "%s\n\n", phonbuf); } - return (1); + return 1; } @@ -862,7 +862,7 @@ int TranslateWord(Translator *tr, char *word_start, int next_pause, WORD_TAB *wt if (tr->data_dictlist == NULL) { // dictionary is not loaded word_phonemes[0] = 0; - return (0); + return 0; } // count the length of the word @@ -961,7 +961,7 @@ int TranslateWord(Translator *tr, char *word_start, int next_pause, WORD_TAB *wt if (phonemes[0] == phonSWITCH) { // change to another language in order to translate this word strcpy(word_phonemes, phonemes); - return (0); + return 0; } if ((wmark > 0) && (wmark < 8)) { @@ -977,12 +977,12 @@ int TranslateWord(Translator *tr, char *word_start, int next_pause, WORD_TAB *wt if (!found && iswdigit(first_char)) { Lookup(tr, "_0lang", word_phonemes); if (word_phonemes[0] == phonSWITCH) - return (0); + return 0; if ((tr->langopts.numbers2 & NUM2_ENGLISH_NUMERALS) && !(wtab->flags & FLAG_CHAR_REPLACED)) { // for this language, speak English numerals (0-9) with the English voice sprintf(word_phonemes, "%c", phonSWITCH); - return (0); + return 0; } found = TranslateNumber(tr, word1, phonemes, dictionary_flags, wtab, 0); @@ -1019,13 +1019,13 @@ int TranslateWord(Translator *tr, char *word_start, int next_pause, WORD_TAB *wt if (SpeakIndividualLetters(tr, word1, phonemes, spell_word) == NULL) { if (word_length > 1) - return (FLAG_SPELLWORD); // a mixture of languages, retranslate as individual letters, separated by spaces - return (0); + return FLAG_SPELLWORD; // a mixture of languages, retranslate as individual letters, separated by spaces + return 0; } strcpy(word_phonemes, phonemes); if (wflags & FLAG_TRANSLATOR2) - return (0); - return (dictionary_flags[0] & FLAG_SKIPWORDS); // for "b.c.d" + return 0; + return dictionary_flags[0] & FLAG_SKIPWORDS; // for "b.c.d" } else if (found == 0) { int posn; int non_initial; @@ -1056,8 +1056,8 @@ int TranslateWord(Translator *tr, char *word_start, int next_pause, WORD_TAB *wt // change to another language in order to translate this word strcpy(word_phonemes, unpron_phonemes); if (strcmp(&unpron_phonemes[1], "en") == 0) - return (FLAG_SPELLWORD); // _^_en must have been set in TranslateLetter(), not *_rules which uses only _^_ - return (0); + return FLAG_SPELLWORD; // _^_en must have been set in TranslateLetter(), not *_rules which uses only _^_ + return 0; } length = 0; @@ -1078,7 +1078,7 @@ int TranslateWord(Translator *tr, char *word_start, int next_pause, WORD_TAB *wt if (phonemes[0] == phonSWITCH) { // change to another language in order to translate this word strcpy(word_phonemes, phonemes); - return (0); + return 0; } if ((phonemes[0] == 0) && (end_phonemes[0] == 0)) { @@ -1088,10 +1088,10 @@ int TranslateWord(Translator *tr, char *word_start, int next_pause, WORD_TAB *wt utf8_in(&wc, wordx); if ((word_length == 1) && (IsAlpha(wc) || IsSuperscript(wc))) { if ((wordx = SpeakIndividualLetters(tr, wordx, phonemes, spell_word)) == NULL) { - return (0); + return 0; } strcpy(word_phonemes, phonemes); - return (0); + return 0; } } @@ -1199,7 +1199,7 @@ int TranslateWord(Translator *tr, char *word_start, int next_pause, WORD_TAB *wt // change to another language in order to translate this word wordx[-1] = c_temp; strcpy(word_phonemes, phonemes); - return (0); + return 0; } } } @@ -1228,7 +1228,7 @@ int TranslateWord(Translator *tr, char *word_start, int next_pause, WORD_TAB *wt // change to another language in order to translate this word memcpy(wordx, word_copy, strlen(word_copy)); strcpy(word_phonemes, phonemes); - return (0); + return 0; } if (dictionary_flags[0] == 0) { dictionary_flags[0] = dictionary_flags2[0]; @@ -1246,7 +1246,7 @@ int TranslateWord(Translator *tr, char *word_start, int next_pause, WORD_TAB *wt // change to another language in order to translate this word memcpy(wordx, word_copy, strlen(word_copy)); strcpy(word_phonemes, phonemes); - return (0); + return 0; } if (dictionary_flags2[0] & FLAG_ABBREV) { @@ -1290,7 +1290,7 @@ int TranslateWord(Translator *tr, char *word_start, int next_pause, WORD_TAB *wt strcpy(word_phonemes, phonemes); memcpy(wordx, word_copy, strlen(word_copy)); wordx[-1] = c_temp; - return (0); + return 0; } } } @@ -1473,7 +1473,7 @@ int TranslateWord(Translator *tr, char *word_start, int next_pause, WORD_TAB *wt dictionary_flags[0] |= was_unpronouncable; memcpy(word_start, word_copy2, word_copy_length); - return (dictionary_flags[0]); + return dictionary_flags[0]; } @@ -1496,7 +1496,7 @@ static int CountSyllables(unsigned char *phonemes) if (phoneme_tab[phon]->type == phVOWEL) count++; } - return (count); + return count; } @@ -1582,7 +1582,7 @@ int SetTranslator2(const char *new_language) } if (translator2 != NULL) translator2->phonemes_repeat[0] = 0; - return (new_phoneme_tab); + return new_phoneme_tab; } @@ -1651,7 +1651,7 @@ static int TranslateWord2(Translator *tr, char *word, WORD_TAB *wtab, int pre_pa embedded_flag = 0; } word_phonemes[0] = 0; - return (0); + return 0; } // after a $pause word attribute, ignore a $pause attribute on the next two words @@ -1716,7 +1716,7 @@ static int TranslateWord2(Translator *tr, char *word, WORD_TAB *wtab, int pre_pa if (flags & FLAG_SPELLWORD) { // re-translate the word as individual letters, separated by spaces memcpy(word, word_copy, word_copy_len); - return (flags); + return flags; } if ((flags & FLAG_COMBINE) && !(wtab[1].flags & FLAG_PHONEMES)) { @@ -1811,7 +1811,7 @@ static int TranslateWord2(Translator *tr, char *word, WORD_TAB *wtab, int pre_pa // strcpy((char *)p,translator2->word_phonemes); if (p[0] == phonSWITCH) - return (FLAG_SPELLWORD); + return FLAG_SPELLWORD; if (switch_phonemes < 0) { // language code is not recognised or 2nd translator won't translate it @@ -2044,7 +2044,7 @@ static int TranslateWord2(Translator *tr, char *word, WORD_TAB *wtab, int pre_pa } tr->prev_dict_flags[0] = flags; - return (flags); + return flags; } @@ -2080,10 +2080,10 @@ static int EmbeddedCommand(unsigned int *source_index_out) c = source[source_index++]; if (embedded_ix >= (N_EMBEDDED_LIST - 2)) - return (0); // list is full + return 0; // list is full if ((p = strchr_w(commands, c)) == NULL) - return (0); + return 0; cmd = (p - commands)+1; if (value == -1) { value = embedded_default[cmd]; @@ -2103,7 +2103,7 @@ static int EmbeddedCommand(unsigned int *source_index_out) embedded_list[embedded_ix++] = cmd + sign + (value << 8); *source_index_out = source_index; - return (1); + return 1; } @@ -2119,12 +2119,12 @@ static int SubstituteChar(Translator *tr, unsigned int c, unsigned int next_in, if (ignore_next) { ignore_next = 0; - return (8); + return 8; } - if (c == 0) return (0); + if (c == 0) return 0; if ((replace_chars = tr->langopts.replace_chars) == NULL) - return (c); + return c; // there is a list of character codes to be substituted with alternative codes @@ -2149,7 +2149,7 @@ static int SubstituteChar(Translator *tr, unsigned int c, unsigned int next_in, } if (new_c == 0) - return (c); // no substitution + return c; // no substitution if (new_c & 0xffe00000) { // there is a second character to be inserted @@ -2165,7 +2165,7 @@ static int SubstituteChar(Translator *tr, unsigned int c, unsigned int next_in, new_c = towupper2(new_c); *wordflags |= FLAG_CHAR_REPLACED; - return (new_c); + return new_c; } @@ -2207,10 +2207,10 @@ static int TranslateChar(Translator *tr, char *ptr, int prev_in, unsigned int c, c = initial + 0x1100; *insert = (11*28*21) + (medial*28) + final + 0xac00; } - return (c); + return c; } else if (((code = c - 0x3130) >= 0) && (code < 0x34)) { // Hangul compatibility jamo - return (hangul_compatibility[code] + 0x1100); + return hangul_compatibility[code] + 0x1100; } switch (tr->translator_name) @@ -2227,17 +2227,17 @@ static int TranslateChar(Translator *tr, char *ptr, int prev_in, unsigned int c, if ((next_in == 'n') && (tr->translator_name == L('a', 'f'))) { // n preceded by either apostrophe or U2019 "right single quotation mark" ptr[0] = ' '; // delete the n - return (0x0259); // replace ' by unicode schwa character + return 0x0259; // replace ' by unicode schwa character } if ((next_in == 'n') || (next_in == 't')) { // Dutch, [@n] and [@t] - return (0x0259); // replace ' by unicode schwa character + return 0x0259; // replace ' by unicode schwa character } } } break; } - return (SubstituteChar(tr, c, next_in, insert, wordflags)); + return SubstituteChar(tr, c, next_in, insert, wordflags); } @@ -2258,11 +2258,11 @@ int UpperCaseInWord(Translator *tr, char *word, int c) len = strlen(p); if ((word[-len] == ' ') && (memcmp(&word[-len+1], p, len-1) == 0)) { if ((c == p[len-1]) || ((p[len-1] == 'A') && IsVowel(tr, c))) - return (1); + return 1; } } } - return (0); + return 0; } @@ -2315,7 +2315,7 @@ void *TranslateClause(Translator *tr, FILE *f_text, const void *vp_input, int *t int tone2; if (tr == NULL) { - return (NULL); + return NULL; } p_textinput = (unsigned char *)vp_input; @@ -3049,12 +3049,12 @@ void *TranslateClause(Translator *tr, FILE *f_text, const void *vp_input, int *t } if (Eof() || (vp_input == NULL)) - return (NULL); + return NULL; if (option_multibyte == espeakCHARS_WCHAR) - return ((void *)p_wchar_input); + return (void *)p_wchar_input; else - return ((void *)p_textinput); + return (void *)p_textinput; } diff --git a/src/libespeak-ng/voices.c b/src/libespeak-ng/voices.c index bcb9c5da..e25bae90 100644 --- a/src/libespeak-ng/voices.c +++ b/src/libespeak-ng/voices.c @@ -201,11 +201,11 @@ static char *fgets_strip(char *buf, int size, FILE *f_in) char *p; if (fgets(buf, size, f_in) == NULL) - return (NULL); + return NULL; if (buf[0] == '#') { buf[0] = 0; - return (buf); + return buf; } len = strlen(buf); @@ -215,7 +215,7 @@ static char *fgets_strip(char *buf, int size, FILE *f_in) if ((p = strstr(buf, "//")) != NULL) *p = 0; - return (buf); + return buf; } @@ -225,9 +225,9 @@ static int LookupTune(const char *name) for (ix = 0; ix < n_tunes; ix++) { if (strcmp(name, tunes[ix].name) == 0) - return (ix); + return ix; } - return (-1); + return -1; } @@ -315,7 +315,7 @@ static espeak_VOICE *ReadVoiceFile(FILE *f_in, const char *fname, const char *le sprintf(fname_buf, "%s/mbrola/%s", path_home, vname); if (GetFileLength(fname_buf) <= 0) - return (0); + return 0; } #endif @@ -353,7 +353,7 @@ static espeak_VOICE *ReadVoiceFile(FILE *f_in, const char *fname, const char *le gender = LookupMnem(genders, vgender); if (n_languages == 0) { - return (NULL); // no language lines in the voice file + return NULL; // no language lines in the voice file } p = (char *)calloc(sizeof(espeak_VOICE) + langix + strlen(fname) + strlen(vname) + 3, 1); @@ -377,7 +377,7 @@ static espeak_VOICE *ReadVoiceFile(FILE *f_in, const char *fname, const char *le voice_data->gender = gender; voice_data->variant = 0; voice_data->xx1 = n_variants; - return (voice_data); + return voice_data; } @@ -509,8 +509,8 @@ static int Read8Numbers(char *data_in, int *data) { // Read 8 integer numbers memset(data, 0, 8+sizeof(int)); - return (sscanf(data_in, "%d %d %d %d %d %d %d %d", - &data[0], &data[1], &data[2], &data[3], &data[4], &data[5], &data[6], &data[7])); + return sscanf(data_in, "%d %d %d %d %d %d %d %d", + &data[0], &data[1], &data[2], &data[3], &data[4], &data[5], &data[6], &data[7]); } @@ -524,7 +524,7 @@ static unsigned int StringToWord2(const char *string) for (ix = 0; (ix < 4) && ((c = string[ix]) != 0); ix++) { value = (value << 8) | (c & 0xff); } - return (value); + return value; } @@ -591,7 +591,7 @@ voice_t *LoadVoice(const char *vname, int control) if (control & 0x10) { strcpy(buf, vname); if (GetFileLength(buf) <= 0) - return (NULL); + return NULL; } else { if (voicename[0] == 0) strcpy(voicename, "default"); @@ -627,7 +627,7 @@ voice_t *LoadVoice(const char *vname, int control) language_type = "en"; // default if (f_voice == NULL) { if (control & 3) - return (NULL); // can't open file + return NULL; // can't open file if (SelectPhonemeTableName(voicename) >= 0) language_type = voicename; @@ -1023,7 +1023,7 @@ voice_t *LoadVoice(const char *vname, int control) LoadDictionary(new_translator, new_dictionary, control & 4); if (dictionary_name[0] == 0) { DeleteTranslator(new_translator); - return (NULL); // no dictionary loaded + return NULL; // no dictionary loaded } new_translator->dict_condition = conditional_rules; @@ -1057,7 +1057,7 @@ voice_t *LoadVoice(const char *vname, int control) translator->stress_amps_r[ix] = stress_amps[ix] -1; } - return (voice); + return voice; } @@ -1096,7 +1096,7 @@ static char *ExtractVoiceVariantName(char *vname, int variant_num, int add_dir) sprintf(variant_name, "%sf%d", variant_prefix, variant_num-10); // female } - return (variant_name); + return variant_name; } @@ -1114,12 +1114,12 @@ voice_t *LoadVoiceVariant(const char *vname, int variant_num) variant_name = ExtractVoiceVariantName(buf, variant_num, 1); if ((v = LoadVoice(buf, 0)) == NULL) - return (NULL); + return NULL; if (variant_name[0] != 0) { v = LoadVoice(variant_name, 2); } - return (v); + return v; } @@ -1132,10 +1132,10 @@ static int __cdecl VoiceNameSorter(const void *p1, const void *p2) if ((ix = strcmp(&v1->languages[1], &v2->languages[1])) != 0) // primary language name - return (ix); + return ix; if ((ix = v1->languages[0] - v2->languages[0]) != 0) // priority number - return (ix); - return (strcmp(v1->name, v2->name)); + return ix; + return strcmp(v1->name, v2->name); } @@ -1146,8 +1146,8 @@ static int __cdecl VoiceScoreSorter(const void *p1, const void *p2) espeak_VOICE *v2 = *(espeak_VOICE **)p2; if ((ix = v2->score - v1->score) != 0) - return (ix); - return (strcmp(v1->name, v2->name)); + return ix; + return strcmp(v1->name, v2->name); } @@ -1171,8 +1171,8 @@ static int ScoreVoice(espeak_VOICE *voice_spec, const char *spec_language, int s if (spec_n_parts < 0) { // match on the subdirectory if (memcmp(voice->identifier, spec_language, spec_lang_len) == 0) - return (100); - return (0); + return 100; + return 0; } if (spec_n_parts == 0) { @@ -1231,7 +1231,7 @@ static int ScoreVoice(espeak_VOICE *voice_spec, const char *spec_language, int s } } if (score == 0) - return (0); + return 0; if (voice_spec->name != NULL) { if (strcmp(voice_spec->name, voice->name) == 0) { @@ -1274,7 +1274,7 @@ static int ScoreVoice(espeak_VOICE *voice_spec, const char *spec_language, int s } if (score < 1) score = 1; - return (score); + return score; } @@ -1332,12 +1332,12 @@ static int SetVoiceScores(espeak_VOICE *voice_select, espeak_VOICE **voices, int voices[nv] = NULL; // list terminator if (nv == 0) - return (0); + return 0; // sort the selected voices by their score qsort(voices, nv, sizeof(espeak_VOICE *), (int(__cdecl *)(const void *, const void *))VoiceScoreSorter); - return (nv); + return nv; } @@ -1391,9 +1391,9 @@ espeak_VOICE *SelectVoiceByName(espeak_VOICE **voices, const char *name2) } if (match_name < 0) - return (NULL); + return NULL; - return (voices[match_name]); + return voices[match_name]; } @@ -1446,10 +1446,10 @@ char const *SelectVoice(espeak_VOICE *voice_select, int *found) if ((voice_select2.gender == 0) && (voice_select2.age == 0) && (voice_select2.variant == 0)) { if (variant_name[0] != 0) { sprintf(voice_id, "%s+%s", vp->identifier, variant_name); - return (voice_id); + return voice_id; } - return (vp->identifier); + return vp->identifier; } } } @@ -1520,16 +1520,16 @@ char const *SelectVoice(espeak_VOICE *voice_select, int *found) // index the sorted list by the required variant number if (ix2 == 0) - return (NULL); + return NULL; vp = voices2[voice_select2.variant % ix2]; if (vp->variant != 0) { variant_name = ExtractVoiceVariantName(NULL, vp->variant, 0); sprintf(voice_id, "%s+%s", vp->identifier, variant_name); - return (voice_id); + return voice_id; } - return (vp->identifier); + return vp->identifier; } @@ -1697,7 +1697,7 @@ espeak_ERROR SetVoiceByName(const char *name) DoVoiceChange(voice); voice_selector.languages = voice->language_name; SetVoiceStack(&voice_selector, variant_name); - return (EE_OK); + return EE_OK; } if (n_voices_list == 0) @@ -1711,10 +1711,10 @@ espeak_ERROR SetVoiceByName(const char *name) DoVoiceChange(voice); voice_selector.languages = voice->language_name; SetVoiceStack(&voice_selector, variant_name); - return (EE_OK); + return EE_OK; } } - return (EE_INTERNAL_ERROR); // voice name not found + return EE_INTERNAL_ERROR; // voice name not found } @@ -1727,13 +1727,13 @@ espeak_ERROR SetVoiceByProperties(espeak_VOICE *voice_selector) voice_id = SelectVoice(voice_selector, &voice_found); if (voice_found == 0) - return (EE_NOT_FOUND); + return EE_NOT_FOUND; LoadVoiceVariant(voice_id, 0); DoVoiceChange(voice); SetVoiceStack(voice_selector, ""); - return (EE_OK); + return EE_OK; } @@ -1765,7 +1765,7 @@ ESPEAK_API const espeak_VOICE **espeak_ListVoices(espeak_VOICE *voice_spec) GetVoices(path_voices); voices_list[n_voices_list] = NULL; // voices list terminator } - return ((const espeak_VOICE **)voices_list); + return (const espeak_VOICE **)voices_list; #else int ix; @@ -1802,7 +1802,7 @@ ESPEAK_API const espeak_VOICE **espeak_ListVoices(espeak_VOICE *voice_spec) } voices[j] = NULL; } - return ((const espeak_VOICE **)voices); + return (const espeak_VOICE **)voices; #endif } @@ -1810,7 +1810,7 @@ ESPEAK_API const espeak_VOICE **espeak_ListVoices(espeak_VOICE *voice_spec) ESPEAK_API espeak_VOICE *espeak_GetCurrentVoice(void) { - return (¤t_voice_selected); + return ¤t_voice_selected; } #pragma GCC visibility pop diff --git a/src/libespeak-ng/wave.c b/src/libespeak-ng/wave.c index 7204e551..fe8f3727 100644 --- a/src/libespeak-ng/wave.c +++ b/src/libespeak-ng/wave.c @@ -392,7 +392,7 @@ static int pa_callback(const void *inputBuffer, void *outputBuffer, } #endif - return (aResult); + return aResult; } @@ -420,7 +420,7 @@ static int wave_open_sound() if (active == 1) { SHOW_TIME("wave_open_sound > already active"); - return (0); + return 0; } if (active < 0) { out_channels = 1; @@ -519,7 +519,7 @@ static int wave_open_sound() SHOW("wave_open_sound > %s\n", "LEAVE"); - return (err != paNoError); + return err != paNoError; } #if (USE_PORTAUDIO == 19) @@ -656,7 +656,7 @@ void *wave_open(const char *the_api) select_device("alsa"); once = 1; } - return ((void *)1); + return (void *)1; } static size_t copyBuffer(char *dest, char *src, const size_t theSizeInBytes) @@ -906,7 +906,7 @@ int wave_is_busy(void *theHandler) SHOW("wave_is_busy: %d\n", active); - return (active == 1); + return active == 1; } void wave_terminate() @@ -996,7 +996,7 @@ extern void *wave_test_get_write_buffer() { int wave_get_remaining_time(uint32_t sample, uint32_t *time) { - if (!time) return (-1); + if (!time) return -1; *time = (uint32_t)0; return 0; } diff --git a/src/libespeak-ng/wave_pulse.c b/src/libespeak-ng/wave_pulse.c index 22351b59..deeaeda7 100644 --- a/src/libespeak-ng/wave_pulse.c +++ b/src/libespeak-ng/wave_pulse.c @@ -591,7 +591,7 @@ int wave_init(int srate) void *wave_open(const char *the_api) { ENTER("wave_open"); - return ((void *)1); + return (void *)1; } size_t wave_write(void *theHandler, char *theMono16BitsWaveBuffer, size_t theSize) @@ -786,7 +786,7 @@ extern void *wave_test_get_write_buffer() { int wave_get_remaining_time(uint32_t sample, uint32_t *time) { - if (!time) return (-1); + if (!time) return -1; *time = (uint32_t)0; return 0; } diff --git a/src/libespeak-ng/wave_sada.c b/src/libespeak-ng/wave_sada.c index bd0e590e..67623541 100644 --- a/src/libespeak-ng/wave_sada.c +++ b/src/libespeak-ng/wave_sada.c @@ -100,7 +100,7 @@ int wave_init(int srate) { SHOW("wave_init() sun_audio_fd: %d\n", sun_audio_fd); if (sun_audio_fd < 0) { - return (0); + return 0; } ioctl(sun_audio_fd, AUDIO_GETINFO, &ainfo); @@ -113,9 +113,9 @@ int wave_init(int srate) { if (ioctl(sun_audio_fd, AUDIO_SETINFO, &ainfo) == -1) { SHOW("wave_init() failed to set audio params: %s\n", strerror(errno)); close(sun_audio_fd); - return (0); + return 0; } - return (1); + return 1; } // wave_open @@ -143,7 +143,7 @@ int wave_init(int srate) { void *wave_open(const char *the_api) { ENTER("wave_open"); - return ((void *)sun_audio_fd); + return (void *)sun_audio_fd; } // wave_write @@ -471,7 +471,7 @@ int wave_get_remaining_time(uint32_t sample, uint32_t *time) audio_info_t ainfo; ENTER("wave_get_remaining_time"); if (!time) { - return (-1); + return -1; SHOW_TIME("wave_get_remaining_time > LEAVE"); } @@ -529,7 +529,7 @@ extern void *wave_test_get_write_buffer() { int wave_get_remaining_time(uint32_t sample, uint32_t *time) { - if (!time) return (-1); + if (!time) return -1; *time = (uint32_t)0; return 0; } diff --git a/src/libespeak-ng/wavegen.c b/src/libespeak-ng/wavegen.c index f1953b21..211763c5 100644 --- a/src/libespeak-ng/wavegen.c +++ b/src/libespeak-ng/wavegen.c @@ -292,12 +292,12 @@ int WcmdqFree() int i; i = wcmdq_head - wcmdq_tail; if (i <= 0) i += N_WCMDQ; - return (i); + return i; } int WcmdqUsed() { - return (N_WCMDQ - WcmdqFree()); + return N_WCMDQ - WcmdqFree(); } @@ -470,7 +470,7 @@ static int WaveCallback(const void *inputBuffer, void *outputBuffer, #if USE_PORTAUDIO == 18 #ifdef PLATFORM_WINDOWS - return (result); + return result; #endif if (result != 0) { static int end_timer = 0; @@ -479,12 +479,12 @@ static int WaveCallback(const void *inputBuffer, void *outputBuffer, if (end_timer > 0) { end_timer--; if (end_timer == 0) - return (1); + return 1; } } - return (0); + return 0; #else - return (result); + return result; #endif } @@ -528,7 +528,7 @@ static PaError Pa_OpenDefaultStream2(PaStream **stream, result = Pa_OpenStream( stream, NULL, &hostApiOutputParameters, sampleRate, framesPerBuffer, paNoFlag, streamCallback, userData); - return (result); + return result; } #endif @@ -540,7 +540,7 @@ int WavegenOpenSound() if (option_waveout || option_quiet) { // writing to WAV file, not to portaudio - return (0); + return 0; } #if USE_PORTAUDIO == 18 @@ -550,7 +550,7 @@ int WavegenOpenSound() #endif if (active == 1) - return (0); + return 0; if (active < 0) { out_channels = 1; @@ -587,7 +587,7 @@ int WavegenOpenSound() exit(2); } - return (0); + return 0; } @@ -607,13 +607,13 @@ int WavegenCloseSound() if (active == 0) { Pa_CloseStream(pa_stream); pa_stream = NULL; - return (1); + return 1; } } else { WavegenOpenSound(); // still items in the queue, shouldn't be closed } } - return (0); + return 0; } @@ -622,29 +622,29 @@ int WavegenInitSound() PaError err; if (option_quiet) - return (0); + return 0; // PortAudio sound output library err = Pa_Initialize(); pa_init_err = err; if (err != paNoError) { fprintf(stderr, "Failed to initialise the PortAudio sound\n"); - return (1); + return 1; } - return (0); + return 0; } #else int WavegenOpenSound() { - return (0); + return 0; } int WavegenCloseSound() { - return (0); + return 0; } int WavegenInitSound() { - return (0); + return 0; } #endif @@ -706,7 +706,7 @@ int GetAmplitude(void) amp = (embedded_value[EMBED_A])*55/100; general_amplitude = amp * amp_emphasis[embedded_value[EMBED_F]] / 16; - return (general_amplitude); + return general_amplitude; } @@ -775,12 +775,12 @@ int PeaksToHarmspect(wavegen_peaks_t *peaks, int pitch, int *htab, int control) #ifdef SPECT_EDITOR if (harm_sqrt_n > 0) - return (HarmToHarmspect(pitch, htab)); + return HarmToHarmspect(pitch, htab); #endif // initialise as much of *out as we will need if (wvoice == NULL) - return (1); + return 1; hmax = (peaks[wvoice->n_harmonic_peaks].freq + peaks[wvoice->n_harmonic_peaks].right)/pitch; if (hmax >= MAX_HARMONIC) hmax = MAX_HARMONIC-1; @@ -866,7 +866,7 @@ int PeaksToHarmspect(wavegen_peaks_t *peaks, int pitch, int *htab, int control) } } - return (hmax); // highest harmonic number + return hmax; // highest harmonic number } @@ -1029,7 +1029,7 @@ static int ApplyBreath(void) } } #endif - return (value); + return value; } @@ -1060,7 +1060,7 @@ int Wavegen() for (;;) { if ((end_wave == 0) && (samplecount == nsamples)) - return (0); + return 0; if ((samplecount & 0x3f) == 0) { // every 64 samples, adjust the parameters @@ -1105,7 +1105,7 @@ int Wavegen() // sign has changed, reached a quiet point in the waveform cbytes = wavemult_offset - (cycle_samples)/2; if (samplecount > nsamples) - return (0); + return 0; cycle_count++; @@ -1257,9 +1257,9 @@ int Wavegen() echo_head = 0; if (out_ptr >= out_end) - return (1); + return 1; } - return (0); + return 0; } @@ -1273,7 +1273,7 @@ static int PlaySilence(int length, int resume) wavephase = 0x7fffffff; if (length == 0) - return (0); + return 0; if (resume == 0) n_samples = length; @@ -1292,9 +1292,9 @@ static int PlaySilence(int length, int resume) echo_head = 0; if (out_ptr >= out_end) - return (1); + return 1; } - return (0); + return 0; } @@ -1347,19 +1347,19 @@ static int PlayWave(int length, int resume, unsigned char *data, int scale, int echo_head = 0; if (out_ptr >= out_end) - return (1); + return 1; } - return (0); + return 0; } static int SetWithRange0(int value, int max) { if (value < 0) - return (0); + return 0; if (value > max) - return (max); - return (value); + return max; + return value; } @@ -1615,7 +1615,7 @@ static int Wavegen2(int length, int modulation, int resume, frame_t *fr1, frame_ if (resume == 0) SetSynth(length, modulation, fr1, fr2, wvoice); - return (Wavegen()); + return Wavegen(); } void Write4Bytes(FILE *f, int value) @@ -1650,14 +1650,14 @@ int WavegenFill2(int fill_zeros) // continue to play silence until echo is completed resume = PlaySilence(echo_complete, resume); if (resume == 1) - return (0); // not yet finished + return 0; // not yet finished } if (fill_zeros) { while (out_ptr < out_end) *out_ptr++ = 0; } - return (1); // queue empty, close sound channel + return 1; // queue empty, close sound channel } result = 0; @@ -1767,7 +1767,7 @@ int WavegenFill2(int fill_zeros) } } - return (0); + return 0; } @@ -1787,7 +1787,7 @@ static int SpeedUp(short *outbuf, int length_in, int length_out, int end_of_text } if (sonicSpeedupStream == NULL) - return (0); + return 0; if (end_of_text) { sonicFlushStream(sonicSpeedupStream); diff --git a/src/speak-ng.c b/src/speak-ng.c index 89de0cee..3e48d75c 100644 --- a/src/speak-ng.c +++ b/src/speak-ng.c @@ -204,7 +204,7 @@ static int OpenWaveFile(const char *path, int rate) }; if (path == NULL) - return (2); + return 2; while (isspace(*path)) path++; @@ -225,9 +225,9 @@ static int OpenWaveFile(const char *path, int rate) Write4Bytes(f_wave, rate); Write4Bytes(f_wave, rate * 2); fwrite(&wave_hdr[32], 1, 12, f_wave); - return (0); + return 0; } - return (1); + return 1; } @@ -270,12 +270,12 @@ static int WavegenFile(void) finished = WavegenFill(0); if (quiet) - return (finished); + return finished; if (f_wave == NULL) { sprintf(fname, "%s_%.2d%s", wavefile, ++wavefile_count, filetype); if (OpenWaveFile(fname, samplerate) != 0) - return (1); + return 1; } if (end_of_sentence) { @@ -290,7 +290,7 @@ static int WavegenFile(void) samples_total += (out_ptr - wav_outbuf)/2; fwrite(wav_outbuf, 1, out_ptr - wav_outbuf, f_wave); } - return (finished); + return finished; } @@ -386,7 +386,7 @@ static int initialise(void) for (param = 0; param < N_SPEECH_PARAM; param++) param_stack[0].parameter[param] = param_defaults[param]; - return (0); + return 0; } @@ -816,7 +816,7 @@ int main(int argc, char **argv) if (option_quiet) { while (SpeakNextClause(NULL, NULL, 1) != 0) ; - return (0); + return 0; } speaking = 1; @@ -843,5 +843,5 @@ int main(int argc, char **argv) if ((f_trans != stdout) && (f_trans != stderr)) fclose(f_trans); // needed for WinCe - return (0); + return 0; }