From 16a5b5d15cc8364b827647736ea49995894ad08d Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 3 Mar 2018 23:38:52 +0200 Subject: [PATCH] move attr_prosody_value() --- src/libespeak-ng/readclause.c | 49 ----------------------------------- src/libespeak-ng/ssml.c | 49 +++++++++++++++++++++++++++++++++++ src/libespeak-ng/ssml.h | 1 + 3 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/libespeak-ng/readclause.c b/src/libespeak-ng/readclause.c index 671d8edf..d2b7190c 100644 --- a/src/libespeak-ng/readclause.c +++ b/src/libespeak-ng/readclause.c @@ -738,55 +738,6 @@ wchar_t *GetSsmlAttribute(wchar_t *pw, const char *name) return NULL; } -static int attr_prosody_value(int param_type, const wchar_t *pw, int *value_out) -{ - int sign = 0; - wchar_t *tail; - double value; - - while (iswspace(*pw)) pw++; - if (*pw == '+') { - pw++; - sign = 1; - } - if (*pw == '-') { - pw++; - sign = -1; - } - value = (double)wcstod(pw, &tail); - if (tail == pw) { - // failed to find a number, return 100% - *value_out = 100; - return 2; - } - - if (*tail == '%') { - if (sign != 0) - value = 100 + (sign * value); - *value_out = (int)value; - return 2; // percentage - } - - if ((tail[0] == 's') && (tail[1] == 't')) { - double x; - // convert from semitones to a frequency percentage - x = pow((double)2.0, (double)((value*sign)/12)) * 100; - *value_out = (int)x; - return 2; // percentage - } - - if (param_type == espeakRATE) { - if (sign == 0) - *value_out = (int)(value * 100); - else - *value_out = 100 + (int)(sign * value * 100); - return 2; // percentage - } - - *value_out = (int)value; - return sign; // -1, 0, or 1 -} - static int AddNameData(const char *name, int wide) { // Add the name to the namedata and return its position diff --git a/src/libespeak-ng/ssml.c b/src/libespeak-ng/ssml.c index 8b05a3ac..9b61641f 100644 --- a/src/libespeak-ng/ssml.c +++ b/src/libespeak-ng/ssml.c @@ -109,6 +109,55 @@ int attrcopy_utf8(char *buf, const wchar_t *pw, int len) return ix; } +int attr_prosody_value(int param_type, const wchar_t *pw, int *value_out) +{ + int sign = 0; + wchar_t *tail; + double value; + + while (iswspace(*pw)) pw++; + if (*pw == '+') { + pw++; + sign = 1; + } + if (*pw == '-') { + pw++; + sign = -1; + } + value = (double)wcstod(pw, &tail); + if (tail == pw) { + // failed to find a number, return 100% + *value_out = 100; + return 2; + } + + if (*tail == '%') { + if (sign != 0) + value = 100 + (sign * value); + *value_out = (int)value; + return 2; // percentage + } + + if ((tail[0] == 's') && (tail[1] == 't')) { + double x; + // convert from semitones to a frequency percentage + x = pow((double)2.0, (double)((value*sign)/12)) * 100; + *value_out = (int)x; + return 2; // percentage + } + + if (param_type == espeakRATE) { + if (sign == 0) + *value_out = (int)(value * 100); + else + *value_out = 100 + (int)(sign * value * 100); + return 2; // percentage + } + + *value_out = (int)value; + return sign; // -1, 0, or 1 +} + int GetVoiceAttributes(wchar_t *pw, int tag_type, SSML_STACK *ssml_sp, SSML_STACK *ssml_stack, int n_ssml_stack, char current_voice_id[]) { // Determines whether voice attribute are specified in this tag, and if so, whether this means diff --git a/src/libespeak-ng/ssml.h b/src/libespeak-ng/ssml.h index 0ab59221..36df1471 100644 --- a/src/libespeak-ng/ssml.h +++ b/src/libespeak-ng/ssml.h @@ -71,6 +71,7 @@ static MNEM_TAB ssmltags[] = { int attrcmp(const wchar_t *string1, const char *string2); int attrlookup(const wchar_t *string1, const MNEM_TAB *mtab); int attrnumber(const wchar_t *pw, int default_value, int type); +int attr_prosody_value(int param_type, const wchar_t *pw, int *value_out); int attrcopy_utf8(char *buf, const wchar_t *pw, int len); int GetVoiceAttributes(wchar_t *pw, int tag_type, SSML_STACK *ssml_sp, SSML_STACK *ssml_stack, int n_ssml_stack, char current_voice_id[]);