From 7485828984c651670a896eedd43e0af858681f87 Mon Sep 17 00:00:00 2001 From: Yury Popov Date: Sun, 25 Dec 2022 02:28:51 +0300 Subject: [PATCH] code cleanup: next bunch of globals --- src/libespeak-ng/compiledict.c | 2 +- src/libespeak-ng/dictionary.c | 27 ++++++++++++++------------- src/libespeak-ng/klatt.c | 2 +- src/libespeak-ng/langopts.c | 2 -- src/libespeak-ng/numbers.c | 4 ++-- src/libespeak-ng/setlengths.c | 6 +++--- src/libespeak-ng/spect.c | 6 +++--- src/libespeak-ng/speech.c | 6 +++--- src/libespeak-ng/tr_languages.c | 2 +- src/libespeak-ng/voices.c | 2 +- src/libespeak-ng/wavegen.c | 4 ++-- 11 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/libespeak-ng/compiledict.c b/src/libespeak-ng/compiledict.c index 0fffdde2..9304f4e1 100644 --- a/src/libespeak-ng/compiledict.c +++ b/src/libespeak-ng/compiledict.c @@ -320,7 +320,7 @@ char *DecodeRule(const char *group_chars, int group_length, char *rule, int cont } c = ' '; } else if (rb == RULE_ENDING) { - static const char *flag_chars = "eipvdfq tba "; + static const char flag_chars[] = "eipvdfq tba "; flags = ((rule[0] & 0x7f)<< 8) + (rule[1] & 0x7f); suffix_char = 'S'; if (flags & (SUFX_P >> 8)) diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index be098448..32ce7de4 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -43,8 +43,8 @@ #include "synthesize.h" // for STRESS_IS_PRIMARY, phoneme... #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); +static int LookupFlags(Translator *tr, const char *word, unsigned int flags_out[2]); +static void DollarRule(char *word[], char *word_start, int consumed, int group_length, char *word_buf, Translator *tr, int command, int *failed, int *add_points); typedef struct { int points; @@ -63,7 +63,7 @@ static const unsigned short diereses_list[7] = { 0xe4, 0xeb, 0xef, 0xf6, 0xfc, 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] = { +static const 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 @@ -396,7 +396,7 @@ void DecodePhonemes(const char *inptr, char *outptr) unsigned char c; unsigned int mnem; PHONEME_TAB *ph; - static const char *stress_chars = "==,,'* "; + static const char stress_chars[] = "==,,'* "; sprintf(outptr, "* "); while ((phcode = *inptr++) > 0) { @@ -551,7 +551,7 @@ const char *GetTranslatedPhonemeString(int phoneme_mode) char phon_buf2[30]; PHONEME_LIST *plist; - static const char *stress_chars = "==,,''"; + static const char stress_chars[] = "==,,''"; if (phon_out_buf == NULL) { phon_out_size = N_PHON_OUT; @@ -1480,10 +1480,9 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ int n_bytes; int add_points; int command; - unsigned int *flags = NULL; MatchRecord match; - static MatchRecord best; + MatchRecord best; int total_consumed; // letters consumed for best match @@ -1699,7 +1698,7 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ else failed = 1; } else if (((command & 0xf0) == 0x20) || (command == DOLLAR_LIST)) { - DollarRule(word, word_start, consumed, group_length, word_buf, tr, flags, command, &failed, &add_points); + DollarRule(word, word_start, consumed, group_length, word_buf, tr, command, &failed, &add_points); } break; @@ -1888,7 +1887,7 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ pre_ptr++; command = *rule++; if ((command == DOLLAR_LIST) || ((command & 0xf0) == 0x20)) { - DollarRule(word, word_start, consumed, group_length, word_buf, tr, flags, command, &failed, &add_points); + DollarRule(word, word_start, consumed, group_length, word_buf, tr, command, &failed, &add_points); } break; case RULE_SYLLABLE: @@ -2842,7 +2841,7 @@ int Lookup(Translator *tr, const char *word, char *ph_out) return flags0; } -static int LookupFlags(Translator *tr, const char *word, unsigned int **flags_out) +static int LookupFlags(Translator *tr, const char *word, unsigned int flags_out[2]) { char buf[100]; static unsigned int flags[2]; @@ -2850,7 +2849,8 @@ static int LookupFlags(Translator *tr, const char *word, unsigned int **flags_ou flags[0] = flags[1] = 0; LookupDictList(tr, &word1, buf, flags, 0, NULL); - *flags_out = flags; + flags_out[0] = flags[0]; + flags_out[1] = flags[1]; return flags[0]; } @@ -2979,14 +2979,15 @@ 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) { +static void DollarRule(char *word[], char *word_start, int consumed, int group_length, char *word_buf, Translator *tr, 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); + unsigned int flags[2]; + LookupFlags(tr, &word_buf[1], flags); if ((command == DOLLAR_LIST) && (flags[0] & FLAG_FOUND) && !(flags[1] & FLAG_ONLY)) *add_points = 23; diff --git a/src/libespeak-ng/klatt.c b/src/libespeak-ng/klatt.c index c8396d5c..dfadcfd9 100644 --- a/src/libespeak-ng/klatt.c +++ b/src/libespeak-ng/klatt.c @@ -68,7 +68,7 @@ static klatt_global_t kt_globals; #define NUMBER_OF_SAMPLES 100 -static int scale_wav_tab[] = { 45, 38, 45, 45, 55, 45 }; // scale output from different voicing sources +static const int scale_wav_tab[] = { 45, 38, 45, 45, 55, 45 }; // scale output from different voicing sources // For testing, this can be overwritten in KlattInit() static const short natural_samples2[256] = { diff --git a/src/libespeak-ng/langopts.c b/src/libespeak-ng/langopts.c index 7d250a13..31760a08 100644 --- a/src/libespeak-ng/langopts.c +++ b/src/libespeak-ng/langopts.c @@ -42,8 +42,6 @@ static int CheckTranslator(Translator *tr, const MNEM_TAB *keyword_tab, int key); static int LookupTune(const char *name); -extern const MNEM_TAB langopts_tab[]; - void LoadLanguageOptions(Translator *translator, int key, char *keyValue ) { if (CheckTranslator(translator, langopts_tab, key) != 0) { return; diff --git a/src/libespeak-ng/numbers.c b/src/libespeak-ng/numbers.c index 02d3411a..a71e155f 100644 --- a/src/libespeak-ng/numbers.c +++ b/src/libespeak-ng/numbers.c @@ -553,7 +553,7 @@ void LookupLetter(Translator *tr, unsigned int letter, int next_byte, char *ph_b // this list must be in ascending order -static unsigned short derived_letters[] = { +static const unsigned short derived_letters[] = { 0x00aa, 'a'+L_SUP, 0x00b2, '2'+L_SUP, 0x00b3, '3'+L_SUP, @@ -769,7 +769,7 @@ int TranslateRoman(Translator *tr, char *word, char *ph_out, WORD_TAB *wtab) char ph_roman[30]; char number_chars[N_WORD_BYTES]; - static const char *roman_numbers = "ixcmvld"; + static const char roman_numbers[] = "ixcmvld"; static const int roman_values[] = { 1, 10, 100, 1000, 5, 50, 500 }; acc = 0; diff --git a/src/libespeak-ng/setlengths.c b/src/libespeak-ng/setlengths.c index 7c1e9381..4968cd16 100644 --- a/src/libespeak-ng/setlengths.c +++ b/src/libespeak-ng/setlengths.c @@ -46,7 +46,7 @@ extern int saved_parameters[]; // convert from words-per-minute to internal speed factor // Use this to calibrate speed for wpm 80-450 (espeakRATE_MINIMUM - espeakRATE_MAXIMUM) -static unsigned char speed_lookup[] = { +static const unsigned char speed_lookup[] = { 255, 255, 255, 255, 255, // 80 253, 249, 245, 242, 238, // 85 235, 232, 228, 225, 222, // 90 @@ -106,7 +106,7 @@ static unsigned char speed_lookup[] = { }; // speed_factor1 adjustments for speeds 350 to 374: pauses -static unsigned char pause_factor_350[] = { +static const unsigned char pause_factor_350[] = { 22, 22, 22, 22, 22, 22, 22, 21, 21, 21, // 350 21, 20, 20, 19, 19, 18, 17, 16, 15, 15, // 360 15, 15, 15, 15, 15 // 370 @@ -114,7 +114,7 @@ static unsigned char pause_factor_350[] = { // wav_factor adjustments for speeds 350 to 450 // Use this to calibrate speed for wpm 350-450 -static unsigned char wav_factor_350[] = { +static const unsigned char wav_factor_350[] = { 120, 121, 120, 119, 119, // 350 118, 118, 117, 116, 116, // 355 115, 114, 113, 112, 112, // 360 diff --git a/src/libespeak-ng/spect.c b/src/libespeak-ng/spect.c index 3227f3fc..a4a692d3 100644 --- a/src/libespeak-ng/spect.c +++ b/src/libespeak-ng/spect.c @@ -38,11 +38,11 @@ static int frame_width; -static int default_freq[N_PEAKS] = +static const int default_freq[N_PEAKS] = { 200, 500, 1200, 3000, 3500, 4000, 6900, 7800, 9000 }; -static int default_width[N_PEAKS] = +static const int default_width[N_PEAKS] = { 750, 500, 550, 550, 600, 700, 700, 700, 700 }; -static int default_klt_bw[N_PEAKS] = +static const int default_klt_bw[N_PEAKS] = { 89, 90, 140, 260, 260, 260, 500, 500, 500 }; static double read_double(FILE *stream) diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index d79996bc..c0bbd2ac 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -80,7 +80,7 @@ static void *my_user_data = NULL; static espeak_ng_OUTPUT_MODE my_mode = ENOUTPUT_MODE_SYNCHRONOUS; static int out_samplerate = 0; static int voice_samplerate = 22050; -static int min_buffer_length = 60; // minimum buffer length in ms +static const int min_buffer_length = 60; // minimum buffer length in ms static espeak_ng_STATUS err = ENS_OK; static t_espeak_callback *synth_callback = NULL; @@ -659,7 +659,7 @@ espeak_ng_Synthesize(const void *text, size_t size, { (void)size; // unused in non-async modes - static unsigned int temp_identifier; + unsigned int temp_identifier; if (unique_identifier == NULL) unique_identifier = &temp_identifier; @@ -708,7 +708,7 @@ espeak_ng_SynthesizeMark(const void *text, { (void)size; // unused in non-async modes - static unsigned int temp_identifier; + unsigned int temp_identifier; if (unique_identifier == NULL) unique_identifier = &temp_identifier; diff --git a/src/libespeak-ng/tr_languages.c b/src/libespeak-ng/tr_languages.c index c221291d..5ca95055 100644 --- a/src/libespeak-ng/tr_languages.c +++ b/src/libespeak-ng/tr_languages.c @@ -1342,7 +1342,7 @@ Translator *SelectTranslator(const char *name) case L('s', 'k'): // Slovak case L('c', 's'): // Czech { - static const char *sk_voiced = "bdgjlmnrvwzaeiouy"; + static const char sk_voiced[] = "bdgjlmnrvwzaeiouy"; SetupTranslator(tr, stress_lengths_sk, stress_amps_sk); tr->encoding = ESPEAKNG_ENCODING_ISO_8859_2; diff --git a/src/libespeak-ng/voices.c b/src/libespeak-ng/voices.c index 915f5841..b507902e 100644 --- a/src/libespeak-ng/voices.c +++ b/src/libespeak-ng/voices.c @@ -64,7 +64,7 @@ static const MNEM_TAB genders[] = { int tone_points[12] = { 600, 170, 1200, 135, 2000, 110, 3000, 110, -1, 0 }; // limit the rate of change for each formant number -static int formant_rate_22050[9] = { 240, 170, 170, 170, 170, 170, 170, 170, 170 }; // values for 22kHz sample rate +static const int formant_rate_22050[9] = { 240, 170, 170, 170, 170, 170, 170, 170, 170 }; // values for 22kHz sample rate int formant_rate[9]; // values adjusted for actual sample rate #define DEFAULT_LANGUAGE_PRIORITY 5 diff --git a/src/libespeak-ng/wavegen.c b/src/libespeak-ng/wavegen.c index 8a28dcfb..ba14d707 100644 --- a/src/libespeak-ng/wavegen.c +++ b/src/libespeak-ng/wavegen.c @@ -119,7 +119,7 @@ int wcmdq_tail = 0; // pitch,speed, const int embedded_default[N_EMBEDDED_VALUES] = { 0, 50, espeakRATE_NORMAL, 100, 50, 0, 0, 0, espeakRATE_NORMAL, 0, 0, 0, 0, 0, 0 }; -static int embedded_max[N_EMBEDDED_VALUES] = { 0, 0x7fff, 750, 300, 99, 99, 99, 0, 750, 0, 0, 0, 0, 4, 0 }; +static const int embedded_max[N_EMBEDDED_VALUES] = { 0, 0x7fff, 750, 300, 99, 99, 99, 0, 750, 0, 0, 0, 0, 4, 0 }; #if USE_LIBSONIC static sonicStream sonicSpeedupStream = NULL; @@ -130,7 +130,7 @@ static double sonicSpeed = 1.0; // 2nd index=modulation_type // value: bits 0-3 amplitude (16ths), bits 4-7 every n cycles #define N_ROUGHNESS 8 -static unsigned char modulation_tab[N_ROUGHNESS][8] = { +static const unsigned char modulation_tab[N_ROUGHNESS][8] = { { 0, 0x00, 0x00, 0x00, 0, 0x46, 0xf2, 0x29 }, { 0, 0x2f, 0x00, 0x2f, 0, 0x45, 0xf2, 0x29 }, { 0, 0x2f, 0x00, 0x2e, 0, 0x45, 0xf2, 0x28 },