Browse Source

cleanup: reduce variable scopes in ssml.c

Contributes to #9.
master
Juho Hiltunen 2 years ago
parent
commit
9e3ade9004
1 changed files with 22 additions and 21 deletions
  1. 22
    21
      src/libespeak-ng/ssml.c

+ 22
- 21
src/libespeak-ng/ssml.c View File

@@ -132,16 +132,16 @@ static int attrnumber(const wchar_t *pw, int default_value, int type)
static int attrcopy_utf8(char *buf, const wchar_t *pw, int len)
{
// Convert attribute string into utf8, write to buf, and return its utf8 length
unsigned int c;
int ix = 0;
int n;
int prev_c = 0;

if (pw != NULL) {
unsigned int c;
int prev_c = 0;
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]);

int n = utf8_out(c, &buf[ix]);
ix += n;
prev_c = c;
}
@@ -208,12 +208,10 @@ static const char *VoiceFromStack(SSML_STACK *ssml_stack, int n_ssml_stack, espe
const char *p;
SSML_STACK *sp;
const char *v_id;
int voice_name_specified;
int voice_found;
espeak_VOICE voice_select;
static char voice_name[40];
char language[40];
char buf[80];

MAKE_MEM_UNDEFINED(&voice_name, sizeof(voice_name));

@@ -226,7 +224,7 @@ static const char *VoiceFromStack(SSML_STACK *ssml_stack, int n_ssml_stack, espe

for (ix = 0; ix < n_ssml_stack; ix++) {
sp = &ssml_stack[ix];
voice_name_specified = 0;
int voice_name_specified = 0;

if ((sp->voice_name[0] != 0) && (SelectVoiceByName(NULL, sp->voice_name) != NULL)) {
voice_name_specified = 1;
@@ -270,6 +268,7 @@ static const char *VoiceFromStack(SSML_STACK *ssml_stack, int n_ssml_stack, espe

if ((strchr(v_id, '+') == NULL) && ((voice_select.gender == ENGENDER_UNKNOWN) || (voice_select.gender == base_voice->gender)) && (base_voice_variant_name[0] != 0)) {
// a voice variant has not been selected, use the original voice variant
char buf[80];
sprintf(buf, "%s+%s", v_id, base_voice_variant_name);
strncpy0(voice_name, buf, sizeof(voice_name));
return voice_name;
@@ -318,12 +317,6 @@ 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

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;

static const MNEM_TAB mnem_gender[] = {
@@ -338,6 +331,12 @@ static int GetVoiceAttributes(wchar_t *pw, int tag_type, SSML_STACK *ssml_sp, SS
if (n_ssml_stack > 1)
n_ssml_stack--;
} else {
const wchar_t *lang;
const wchar_t *gender;
const wchar_t *name;
const wchar_t *age;
const wchar_t *variant;

// add a stack frame if any voice details are specified
lang = GetSsmlAttribute(pw, "xml:lang");

@@ -359,6 +358,8 @@ static int GetVoiceAttributes(wchar_t *pw, int tag_type, SSML_STACK *ssml_sp, SS

ssml_sp = &ssml_stack[n_ssml_stack++];

int value;

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)
@@ -384,7 +385,6 @@ static void ProcessParamStack(char *outbuf, int *outix, int n_param_stack, PARAM
// Set the speech parameters from the parameter stack
int param;
int ix;
int value;
char buf[20];
int new_parameters[N_SPEECH_PARAM];
static const char cmd_letter[N_SPEECH_PARAM] = { 0, 'S', 'A', 'P', 'R', 0, 'C', 0, 0, 0, 0, 0, 'F' }; // embedded command letters
@@ -400,6 +400,7 @@ static void ProcessParamStack(char *outbuf, int *outix, int n_param_stack, PARAM
}

for (param = 0; param < N_SPEECH_PARAM; param++) {
int value;
if ((value = new_parameters[param]) != speech_parameters[param]) {
buf[0] = 0;

@@ -471,14 +472,14 @@ static int ReplaceKeyName(char *outbuf, int index, int *outix)
{ NULL, 0 }
};

int ix;
int letter;
char *p;

p = &outbuf[index];

if ((letter = LookupMnem(keynames, p)) != 0) {
ix = utf8_out(letter, p);
int ix;
ix = utf8_out(letter, p);
*outix = index + ix;
return letter;
}
@@ -488,7 +489,7 @@ static int ReplaceKeyName(char *outbuf, int index, int *outix)
static void SetProsodyParameter(int param_type, const wchar_t *attr1, PARAM_STACK *sp, PARAM_STACK *param_stack, int *speech_parameters)
{
int value;
int sign;

static const MNEM_TAB mnem_volume[] = {
{ "default", 100 },
@@ -539,7 +540,7 @@ static void SetProsodyParameter(int param_type, const wchar_t *attr1, PARAM_STAC
// 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);
int sign = attr_prosody_value(param_type, attr1, &value);

if (sign == 0)
sp->parameter[param_type] = value; // absolute value in Hz
@@ -560,7 +561,6 @@ int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outbuf, con

unsigned int ix;
int index;
int c;
int tag_type;
int value;
int value2;
@@ -571,7 +571,6 @@ int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outbuf, con
const wchar_t *attr2;
const wchar_t *attr3;
int terminator;
char *uri;
int param_type;
char tag_name[40];
char buf[160];
@@ -653,6 +652,7 @@ int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outbuf, con
};

for (ix = 0; ix < (sizeof(tag_name)-1); ix++) {
int c;
if (((c = xml_buf[ix]) == 0) || iswspace(c))
break;
tag_name[ix] = tolower((char)c);
@@ -815,11 +815,11 @@ int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outbuf, con
sp = PushParamStack(tag_type, n_param_stack, (PARAM_STACK *)param_stack);

if ((attr1 = GetSsmlAttribute(px, "src")) != NULL) {
char fname[256];
attrcopy_utf8(buf, attr1, sizeof(buf));

if (uri_callback == NULL) {
if ((xmlbase != NULL) && (buf[0] != '/')) {
char fname[256];
sprintf(fname, "%s/%s", xmlbase, buf);
index = LoadSoundFile2(fname);
} else
@@ -832,6 +832,7 @@ int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int *outix, int n_outbuf, con
}
} else {
if ((index = AddNameData(buf, 0)) >= 0) {
char *uri;
uri = &namedata[index];
if (uri_callback(1, uri, xmlbase) == 0) {
sprintf(buf, "%c%dU", CTRL_EMBEDDED, index);

Loading…
Cancel
Save