Browse Source

Add more const qualifiers on static arrays

So we know they are just tables, get protected from overflows, and get shared between processes
master
Samuel Thibault 3 years ago
parent
commit
a660fc04cc

+ 3
- 3
src/espeak-ng.c View File

@@ -143,7 +143,7 @@ static void DisplayVoices(FILE *f_out, char *language)
const espeak_VOICE **voices;
espeak_VOICE voice_select;

static char genders[4] = { '-', 'M', 'F', '-' };
static const char genders[4] = { '-', 'M', 'F', '-' };

if ((language != NULL) && (language[0] != 0)) {
// display only voices for the specified language, in order of priority
@@ -201,7 +201,7 @@ static void Write4Bytes(FILE *f, int value)

static int OpenWavFile(char *path, int rate)
{
static unsigned char wave_hdr[44] = {
static const 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
@@ -304,7 +304,7 @@ static void PrintVersion()

int main(int argc, char **argv)
{
static struct option long_options[] = {
static const struct option long_options[] = {
{ "help", no_argument, 0, 'h' },
{ "stdin", no_argument, 0, 0x100 },
{ "compile-debug", optional_argument, 0, 0x101 },

+ 1
- 1
src/libespeak-ng/compiledata.c View File

@@ -1559,7 +1559,7 @@ static void CompileSound(int keyword, int isvowel)
int addr = 0;
int value = 0;
char path[N_ITEM_STRING];
static int sound_instns[] = { i_FMT, i_WAV, i_VWLSTART, i_VWLENDING, i_WAVADD };
static const int sound_instns[] = { i_FMT, i_WAV, i_VWLSTART, i_VWLENDING, i_WAVADD };

NextItemBrackets(tSTRING, 2);
strcpy(path, item_string);

+ 4
- 4
src/libespeak-ng/compiledict.c View File

@@ -223,14 +223,14 @@ char *DecodeRule(const char *group_chars, int group_length, char *rule, int cont
char suffix[20];
static char output[80];

static char symbols[] = {
static const char symbols[] = {
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
'&', '%', '+', '#', 'S', 'D', 'Z', 'A', 'L', '!',
' ', '@', '?', 'J', 'N', 'K', 'V', '?', 'T', 'X',
'?', 'W'
};

static char symbols_lg[] = { 'A', 'B', 'C', 'H', 'F', 'G', 'Y' };
static const char symbols_lg[] = { 'A', 'B', 'C', 'H', 'F', 'G', 'Y' };

match_type = 0;
buf_pre[0] = 0;
@@ -766,8 +766,8 @@ static int isHexDigit(int c)
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 *const outbuf[5] = { rule_cond, rule_pre, rule_match, rule_post, rule_phonemes };
static const int next_state[5] = { 2, 2, 4, 4, 4 };
char *output;
char *p;
int ix;

+ 4
- 4
src/libespeak-ng/dictionary.c View File

@@ -1060,7 +1060,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 const char consonant_types[16] = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 };

stressflags = tr->langopts.stress_flags;

@@ -1226,9 +1226,9 @@ void SetWordStress(Translator *tr, char *output, unsigned int *dictionary_flags,
// LANG=Russian
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 const char guess_ru[16] = { 0, 0, 1, 1, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10, 11 };
static const 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 const 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) {

+ 2
- 2
src/libespeak-ng/intonation.c View File

@@ -539,10 +539,10 @@ static int calc_pitch_segment(SYLLABLE *syllable_tab, int ix, int end_ix, TONE_H
int pitch_range;
int pitch_range_abs;
int *drops;
signed char *overflow_tab;
const signed char *overflow_tab;
SYLLABLE *syl;

static signed char continue_tab[5] = { -26, 32, 20, 8, 0 };
static const signed char continue_tab[5] = { -26, 32, 20, 8, 0 };

drops = th->body_drops;
pitch_range = (th->body_end - th->body_start) * 256;

+ 8
- 8
src/libespeak-ng/klatt.c View File

@@ -483,7 +483,7 @@ void KlattFini(void)
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 const double amp_par_factor[7] = { 0.6, 0.4, 0.15, 0.06, 0.04, 0.022, 0.03 };
long Gain0_tmp;
int ix;

@@ -552,7 +552,7 @@ static void frame_init(klatt_frame_ptr frame)

static double impulsive_source()
{
static double doublet[] = { 0.0, 13000000.0, -13000000.0 };
static const double doublet[] = { 0.0, 13000000.0, -13000000.0 };
static double vwave;

if (kt_globals.nper < 3)
@@ -623,7 +623,7 @@ static void pitch_synch_par_reset(klatt_frame_ptr frame)
long temp;
double temp1;
static long skew;
static short B0[224] = {
static const 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,
@@ -836,7 +836,7 @@ static double gen_noise(double noise)

static double DBtoLIN(long dB)
{
static short amptable[88] = {
static const 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,
@@ -1076,10 +1076,10 @@ static void SetSynth_Klatt(int length, frame_t *fr1, frame_t *fr2, voice_t *wvoi
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 const short formant_hz[10] = { 280, 688, 1064, 2806, 3260, 3700, 6500, 7000, 8000, 280 };
static const short bandwidth[10] = { 89, 160, 70, 160, 200, 200, 500, 500, 500, 89 };
static const short parallel_amp[10] = { 0, 59, 59, 59, 59, 59, 59, 0, 0, 0 };
static const short parallel_bw[10] = { 59, 59, 89, 149, 200, 200, 500, 0, 0, 0 };

int ix;


+ 2
- 2
src/libespeak-ng/numbers.c View File

@@ -691,7 +691,7 @@ int TranslateLetter(Translator *tr, char *word, char *phonemes, int control, ALP
char ph_buf2[80];
char ph_alphabet[80];
char hexbuf[12];
static char pause_string[] = { phonPAUSE, 0 };
static const char pause_string[] = { phonPAUSE, 0 };

ph_buf[0] = 0;
ph_alphabet[0] = 0;
@@ -1039,7 +1039,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 const int roman_values[] = { 1, 10, 100, 1000, 5, 50, 500 };

acc = 0;
prev = 0;

+ 1
- 1
src/libespeak-ng/phonemelist.c View File

@@ -461,7 +461,7 @@ void MakePhonemeList(Translator *tr, int post_pause, bool start_sentence)
}

if ((plist3+1)->synthflags & SFLAG_LENGTHEN) {
static char types_double[] = { phFRICATIVE, phVFRICATIVE, phNASAL, phLIQUID, 0 };
static const 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()

+ 17
- 17
src/libespeak-ng/ssml.c View File

@@ -275,13 +275,13 @@ static const char *VoiceFromStack(SSML_STACK *ssml_stack, int n_ssml_stack, espe
}


static wchar_t *GetSsmlAttribute(wchar_t *pw, const char *name)
static const 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 const wchar_t empty[1] = { 0 };

while (*pw != 0) {
if (iswspace(pw[-1])) {
@@ -315,11 +315,11 @@ static int GetVoiceAttributes(wchar_t *pw, int tag_type, SSML_STACK *ssml_sp, SS
// a voice change.
// Returns CLAUSE_TYPE_VOICE_CHANGE if there is a voice change

wchar_t *lang;
wchar_t *gender;
wchar_t *name;
wchar_t *age;
wchar_t *variant;
const wchar_t *lang;
const wchar_t *gender;
const wchar_t *name;
const wchar_t *age;
const wchar_t *variant;
int value;
const char *new_voice_id;

@@ -384,7 +384,7 @@ static void ProcessParamStack(char *outbuf, int *outix, int n_param_stack, PARAM
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 const 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 < N_SPEECH_PARAM; param++)
new_parameters[param] = -1;
@@ -482,7 +482,7 @@ static int ReplaceKeyName(char *outbuf, int index, int *outix)
return 0;
}

static void SetProsodyParameter(int param_type, wchar_t *attr1, PARAM_STACK *sp, PARAM_STACK *param_stack, int *speech_parameters)
static void SetProsodyParameter(int param_type, const wchar_t *attr1, PARAM_STACK *sp, PARAM_STACK *param_stack, int *speech_parameters)
{
int value;
int sign;
@@ -564,9 +564,9 @@ int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outbuf, con
int value3;
int voice_change_flag;
wchar_t *px;
wchar_t *attr1;
wchar_t *attr2;
wchar_t *attr3;
const wchar_t *attr1;
const wchar_t *attr2;
const wchar_t *attr3;
int terminator;
char *uri;
int param_type;
@@ -581,7 +581,7 @@ int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outbuf, con
}

// these tags have no effect if they are self-closing, eg. <voice />
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 const char ignore_if_self_closing[] = { 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0 };

bool self_closing = false;
int len;
@@ -711,13 +711,13 @@ int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outbuf, con
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 };
static const unsigned char emphasis_to_pitch_range[] = { 50, 50, 40, 70, 90, 100 };
static const 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 };
static const unsigned char emphasis_to_volume2[] = { 100, 100, 75, 100, 120, 150 };
sp->parameter[espeakVOLUME] = emphasis_to_volume2[value];
sp->parameter[espeakEMPHASIS] = value;
}
@@ -855,7 +855,7 @@ int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outbuf, con
terminator = CLAUSE_NONE;

if ((attr1 = GetSsmlAttribute(px, "strength")) != NULL) {
static int break_value[6] = { 0, 7, 14, 21, 40, 80 }; // *10mS
static const 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

+ 1
- 1
src/libespeak-ng/synthdata.c View File

@@ -428,7 +428,7 @@ static bool StressCondition(Translator *tr, PHONEME_LIST *plist, int condition,
{
int stress_level;
PHONEME_LIST *pl;
static int condition_level[4] = { 1, 2, 4, 15 };
static const int condition_level[4] = { 1, 2, 4, 15 };

if (phoneme_tab[plist[0].phcode]->type == phVOWEL)
pl = plist;

+ 1
- 1
src/libespeak-ng/synthesize.c View File

@@ -553,7 +553,7 @@ int FormantTransition2(frameref_t *seq, int *n_frames, unsigned int data1, unsig

#define N_VCOLOUR 2
// percentage change for each formant in 256ths
static short vcolouring[N_VCOLOUR][5] = {
static const short vcolouring[N_VCOLOUR][5] = {
{ 243, 272, 256, 256, 256 }, // palatal consonant follows
{ 256, 256, 240, 240, 240 }, // retroflex
};

+ 2
- 2
src/libespeak-ng/tr_languages.c View File

@@ -1210,7 +1210,7 @@ Translator *SelectTranslator(const char *name)
break;
case L('m', 'k'): // Macedonian
{
static wchar_t vowels_cyrillic[] = {
static const wchar_t vowels_cyrillic[] = {
// also include 'р' [R]
0x440, 0x430, 0x435, 0x438, 0x439, 0x43e, 0x443, 0x44b, 0x44d,
0x44e, 0x44f, 0x450, 0x451, 0x456, 0x457, 0x45d, 0x45e, 0
@@ -1558,7 +1558,7 @@ Translator *SelectTranslator(const char *name)
{
static const short stress_lengths_vi[8] = { 150, 150, 180, 180, 210, 230, 230, 240 };
static const unsigned char stress_amps_vi[] = { 16, 16, 16, 16, 22, 22, 22, 22 };
static wchar_t vowels_vi[] = {
static const wchar_t vowels_vi[] = {
0x61, 0xe0, 0xe1, 0x1ea3, 0xe3, 0x1ea1, // a
0x103, 0x1eb1, 0x1eaf, 0x1eb3, 0x1eb5, 0x1eb7, // ă
0xe2, 0x1ea7, 0x1ea5, 0x1ea9, 0x1eab, 0x1ead, // â

+ 3
- 3
src/libespeak-ng/voices.c View File

@@ -356,10 +356,10 @@ void VoiceReset(int tone_only)
// Set voice to the default values

int pk;
static unsigned char default_heights[N_PEAKS] = { 130, 128, 120, 116, 100, 100, 128, 128, 128 }; // changed for v.1.47
static unsigned char default_widths[N_PEAKS] = { 140, 128, 128, 160, 171, 171, 128, 128, 128 };
static const unsigned char default_heights[N_PEAKS] = { 130, 128, 120, 116, 100, 100, 128, 128, 128 }; // changed for v.1.47
static const unsigned char default_widths[N_PEAKS] = { 140, 128, 128, 160, 171, 171, 128, 128, 128 };

static int breath_widths[N_PEAKS] = { 0, 200, 200, 400, 400, 400, 600, 600, 600 };
static const int breath_widths[N_PEAKS] = { 0, 200, 200, 400, 400, 400, 600, 600, 600 };

// default is: pitch 80,118
voice->pitch_base = 0x47000;

+ 2
- 2
src/libespeak-ng/wavegen.c View File

@@ -1172,8 +1172,8 @@ static void SetSynth(int length, int modn, frame_t *fr1, frame_t *fr2, voice_t *
int length4;
int qix;
int cmd;
static int glottal_reduce_tab1[4] = { 0x30, 0x30, 0x40, 0x50 }; // vowel before [?], amp * 1/256
static int glottal_reduce_tab2[4] = { 0x90, 0xa0, 0xb0, 0xc0 }; // vowel after [?], amp * 1/256
static const int glottal_reduce_tab1[4] = { 0x30, 0x30, 0x40, 0x50 }; // vowel before [?], amp * 1/256
static const int glottal_reduce_tab2[4] = { 0x90, 0xa0, 0xb0, 0xc0 }; // vowel after [?], amp * 1/256

end_wave = 1;


Loading…
Cancel
Save