Browse Source

Merge branch 'duplicates'

master
Juho Hiltunen 2 years ago
parent
commit
bf6d99cb89
2 changed files with 34 additions and 42 deletions
  1. 12
    11
      src/libespeak-ng/compiledata.c
  2. 22
    31
      src/libespeak-ng/dictionary.c

+ 12
- 11
src/libespeak-ng/compiledata.c View File

#include "voice.h" // for LoadVoice, voice #include "voice.h" // for LoadVoice, voice
#include "wavegen.h" // for WavegenInit, WavegenSetVoice #include "wavegen.h" // for WavegenInit, WavegenSetVoice


static int CalculateSample(unsigned char c3, int c1);

#define N_ITEM_STRING 256 #define N_ITEM_STRING 256


typedef struct { typedef struct {
{ {
int displ; int displ;
unsigned char c1; unsigned char c1;
unsigned char c3;
int c2;
int sample; int sample;
int sample2; int sample2;
float x; float x;


if ((c = fgetc(f)) == EOF) if ((c = fgetc(f)) == EOF)
break; 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) if (sample > max)
max = sample; max = sample;


while (!feof(f)) { while (!feof(f)) {
c1 = fgetc(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; if (feof(f)) break;


} }


#pragma GCC visibility pop #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;
}

+ 22
- 31
src/libespeak-ng/dictionary.c View File

#include "translate.h" // for Translator, utf8_in, LANGU... #include "translate.h" // for Translator, utf8_in, LANGU...


static int LookupFlags(Translator *tr, const char *word, unsigned int **flags_out); 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 { typedef struct {
int points; int points;


char *rule_start; // start of current match template char *rule_start; // start of current match template
char *p; char *p;
int ix;

int match_type; // left, right, or consume int match_type; // left, right, or consume
int syllable_count; int syllable_count;
int vowel; int vowel;
int n_bytes; int n_bytes;
int add_points; int add_points;
int command; int command;
unsigned int *flags;
unsigned int *flags = NULL;


MatchRecord match; MatchRecord match;
static MatchRecord best; static MatchRecord best;
else else
failed = 1; 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;
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; break;
case '-': case '-':
if ((letter == '-') || ((letter == ' ') && (word_flags & FLAG_HYPHEN_AFTER))) if ((letter == '-') || ((letter == ' ') && (word_flags & FLAG_HYPHEN_AFTER)))
pre_ptr++; pre_ptr++;
command = *rule++; 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;
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; break;
case RULE_SYLLABLE: case RULE_SYLLABLE:


return end_flags; 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;
}

Loading…
Cancel
Save