diff --git a/src/libespeak-ng/compiledata.c b/src/libespeak-ng/compiledata.c index 0d26cab5..91c367c8 100644 --- a/src/libespeak-ng/compiledata.c +++ b/src/libespeak-ng/compiledata.c @@ -47,6 +47,8 @@ #include "voice.h" // for LoadVoice, voice #include "wavegen.h" // for WavegenInit, WavegenSetVoice +static int CalculateSample(unsigned char c3, int c1); + #define N_ITEM_STRING 256 typedef struct { @@ -1088,8 +1090,6 @@ static int LoadWavefile(CompileContext *ctx, FILE *f, const char *fname) { int displ; unsigned char c1; - unsigned char c3; - int c2; int sample; int sample2; float x; @@ -1125,12 +1125,8 @@ static int LoadWavefile(CompileContext *ctx, FILE *f, const char *fname) if ((c = fgetc(f)) == EOF) break; - c3 = (unsigned char)c; - c2 = c3 << 24; - c2 = c2 >> 16; // sign extend - - sample = (c1 & 0xff) + c2; + sample = CalculateSample((unsigned char) c, c1); if (sample > max) max = sample; @@ -1150,11 +1146,9 @@ static int LoadWavefile(CompileContext *ctx, FILE *f, const char *fname) while (!feof(f)) { c1 = fgetc(f); - c3 = fgetc(f); - c2 = c3 << 24; - c2 = c2 >> 16; // sign extend + unsigned char c3 = fgetc(f); - sample = (c1 & 0xff) + c2; + sample = CalculateSample(c3, c1); if (feof(f)) break; @@ -2807,3 +2801,10 @@ espeak_ng_CompileIntonationPath(const char *source_path, } #pragma GCC visibility pop + +static int CalculateSample(unsigned char c3, int c1) { + int c2 = c3 << 24; + c2 = c2 >> 16; // sign extend + + return (c1 & 0xff) + c2; +} \ No newline at end of file diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index 1f835dbc..8f69ba5d 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -44,6 +44,7 @@ #include "translate.h" // for Translator, utf8_in, LANGU... static int LookupFlags(Translator *tr, const char *word, unsigned int **flags_out); +static void DollarRule(char *word[], char *word_start, int consumed, int group_length, char *word_buf, Translator *tr, unsigned int *flags, int command, int *failed, int *add_points); typedef struct { int points; @@ -1471,8 +1472,6 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ char *rule_start; // start of current match template char *p; - int ix; - int match_type; // left, right, or consume int syllable_count; int vowel; @@ -1481,7 +1480,7 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ int n_bytes; int add_points; int command; - unsigned int *flags; + unsigned int *flags = NULL; MatchRecord match; static MatchRecord best; @@ -1700,21 +1699,9 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ else failed = 1; } 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; - memcpy(word_buf, word_start-1, ix); - word_buf[ix] = ' '; - word_buf[ix+1] = 0; - LookupFlags(tr, &word_buf[1], &flags); - - 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)))) - add_points = 23; - else - failed = 1; + DollarRule(word, word_start, consumed, group_length, word_buf, tr, flags, command, &failed, &add_points); } + break; case '-': if ((letter == '-') || ((letter == ' ') && (word_flags & FLAG_HYPHEN_AFTER))) @@ -1901,20 +1888,7 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ pre_ptr++; command = *rule++; 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; - memcpy(word_buf, word_start-1, ix); - word_buf[ix] = ' '; - word_buf[ix+1] = 0; - LookupFlags(tr, &word_buf[1], &flags); - - 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)))) - add_points = 23; - else - failed = 1; + DollarRule(word, word_start, consumed, group_length, word_buf, tr, flags, command, &failed, &add_points); } break; case RULE_SYLLABLE: @@ -3004,3 +2978,20 @@ int RemoveEnding(Translator *tr, char *word, int end_type, char *word_copy) return end_flags; } + +static void DollarRule(char *word[], char *word_start, int consumed, int group_length, char *word_buf, Translator *tr, unsigned int *flags, int command, int *failed, int *add_points) { + // $list or $p_alt + // make a copy of the word up to the post-match characters + int ix = *word - word_start + consumed + group_length + 1; + memcpy(word_buf, word_start-1, ix); + word_buf[ix] = ' '; + word_buf[ix+1] = 0; + LookupFlags(tr, &word_buf[1], &flags); + + 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)))) + *add_points = 23; + else + *failed = 1; +} \ No newline at end of file