Save volume ratio as integer value to the config file 37/306437/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Fri, 16 Feb 2024 11:35:46 +0000 (20:35 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Wed, 21 Feb 2024 10:00:41 +0000 (19:00 +0900)
- Issue:
According to the app locale, sometimes the framework can fail to get
proper background volume ratio value from the configuration file.

- Solution:
This patch fixes the logic for saving background volume ratio value.
According to the spec. of snprintf() and atof(), these functions are
affected by the app locale. Thus, the app can represent the floating
point value with different way by the locale. And this can cause the
failure of getting proper value.
To avoid this situation, this patch converts the volume ratio as integer
value. Through this change, the locale will not affect the
representation for the volume ratio.

Change-Id: Ieb5c80098b91d56801b98183e8c524db6cf1b0bc
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
common/tts_config_parser.c
tts-config.xml

index 901b09ad6443b2e24695027d6d1dbc2c279d06d0..eb1f1030618738859dd0524fd51fc0602d80c7d7 100644 (file)
@@ -45,6 +45,7 @@
 #define TTS_TAG_VOICE_TYPE_CHILD       "child"
 
 #define TTS_MAX_TEXT_SIZE      2000
+#define VOLUME_BASE_VALUE      1000.0
 
 static xmlDocPtr g_config_doc = NULL;
 char g_engine_id[128] = {0,};
@@ -540,7 +541,7 @@ int tts_parser_load_config(void)
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
                        xmlChar *key = xmlNodeGetContent(cur);
                        if (NULL != key) {
-                               temp->bg_volume_ratio = atof((char*)key);
+                               temp->bg_volume_ratio = atoi((char*)key) / VOLUME_BASE_VALUE;
                                xmlFree(key);
                                key = NULL;
                        } else {
@@ -859,7 +860,7 @@ int tts_parser_set_bg_volume_ratio(double value)
 {
        char temp[10];
        memset(temp, '\0', 10);
-       snprintf(temp, 10, "%lf", value);
+       snprintf(temp, 10, "%d", (int)(value * VOLUME_BASE_VALUE));
 
        if (0 != __set_value_into_configuration(TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO, temp)) {
                return -1;
@@ -1100,7 +1101,7 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                                                if (0 != xmlStrcmp(key_old, key_new)) {
                                                        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old bg volume ratio(%s), New bg volume ratio(%s)",
                                                                (char*)key_old, (char*)key_new);
-                                                       *bg_volume_ratio = atof((char*)key_new);
+                                                       *bg_volume_ratio = atoi((char*)key_new) / VOLUME_BASE_VALUE;
                                                }
                                                xmlFree(key_new);
                                                key_new = NULL;
index 9d2696f13c6a709b4f8a775c1f74056683b62354..1323564f85867af66b88fd840e27fb5a8476b3f1 100644 (file)
@@ -7,5 +7,5 @@
         <voice-type>female</voice-type>
         <speech-rate>8</speech-rate>
         <pitch>8</pitch>
-        <background-volume-ratio>0.4</background-volume-ratio>
+        <background-volume-ratio>400</background-volume-ratio>
 </tts-config>