speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 5/8] implemented pitch_range support for the generic and Espeak m


From: Luke Yelavich
Subject: [PATCH 5/8] implemented pitch_range support for the generic and Espeak modules
Date: Fri, 24 Oct 2014 14:44:42 -0400

From: Hussain Jasim <address@hidden>
To: address@hidden

---
 src/modules/espeak.c       | 34 +++++++++++++++++++++++++++++-----
 src/modules/generic.c      | 25 +++++++++++++++++++++++++
 src/modules/module_utils.c |  1 +
 src/modules/module_utils.h |  2 ++
 4 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/src/modules/espeak.c b/src/modules/espeak.c
index 8d5f39e..8439804 100644
--- a/src/modules/espeak.c
+++ b/src/modules/espeak.c
@@ -135,6 +135,10 @@ pthread_cond_t playback_queue_condition;
    SSIP PITCH commands then adjust relative to this. */
 static int espeak_voice_pitch_baseline = 50;
 
+/* When a voice is set, this is the baseline pitch range of the voice.
+   SSIP PITCH range commands then adjust relative to this. */
+static int espeak_voice_pitch_range_baseline = 50;
+
 /* <Function prototypes*/
 
 static void espeak_state_reset();
@@ -151,13 +155,11 @@ static int uri_callback(int type, const char *uri, const 
char *base);
 /* Basic parameters */
 static void espeak_set_rate(signed int rate);
 static void espeak_set_pitch(signed int pitch);
+static void espeak_set_pitch_range(signed int pitch_range);
 static void espeak_set_volume(signed int volume);
 static void espeak_set_punctuation_mode(SPDPunctuation punct_mode);
 static void espeak_set_cap_let_recogn(SPDCapitalLetters cap_mode);
 
-#if 0
-static void espeak_set_pitch_range(signed int pitch_range);
-#endif
 
 /* Voices and languages */
 static void espeak_set_language(char *lang);
@@ -188,7 +190,6 @@ static void *_espeak_stop_or_pause(void *);
 /* > */
 /* < Module configuration options*/
 
-MOD_OPTION_1_INT(EspeakPitchRange)
     MOD_OPTION_1_STR(EspeakPunctuationList)
     MOD_OPTION_1_INT(EspeakCapitalPitchRise)
     MOD_OPTION_1_INT(EspeakMinRate)
@@ -215,7 +216,6 @@ int module_load(void)
                             "/usr/share/sounds/sound-icons/");
        MOD_OPTION_1_INT_REG(EspeakSoundIconVolume, 0);
 
-       MOD_OPTION_1_INT_REG(EspeakPitchRange, 0);
        MOD_OPTION_1_INT_REG(EspeakMinRate, 80);
        MOD_OPTION_1_INT_REG(EspeakNormalRate, 170);
        MOD_OPTION_1_INT_REG(EspeakMaxRate, 390);
@@ -350,6 +350,7 @@ int module_speak(gchar * data, size_t bytes, SPDMessageType 
msgtype)
        UPDATE_PARAMETER(rate, espeak_set_rate);
        UPDATE_PARAMETER(volume, espeak_set_volume);
        UPDATE_PARAMETER(pitch, espeak_set_pitch);
+       UPDATE_PARAMETER(pitch_range, espeak_set_pitch_range);
        UPDATE_PARAMETER(punctuation_mode, espeak_set_punctuation_mode);
        UPDATE_PARAMETER(cap_let_recogn, espeak_set_cap_let_recogn);
 
@@ -655,6 +656,29 @@ static void espeak_set_pitch(signed int pitch)
        }
 }
 
+static void espeak_set_pitch_range(signed int pitch_range)
+{
+       assert(pitch_range >= -100 && pitch_range <= +100);
+       int pitchRangeBaseline;
+       /* Possible range 0 to 100. */
+       if (pitch_range < 0) {
+               pitchRangeBaseline =
+                   ((float)(pitch_range + 100) * 
espeak_voice_pitch_range_baseline) /
+                   (float)100;
+       } else {
+               pitchRangeBaseline =
+                   (((float)pitch_range * (100 - 
espeak_voice_pitch_range_baseline))
+                    / (float)100) + espeak_voice_pitch_range_baseline;
+       }
+       assert(pitchRangeBaseline >= 0 && pitchRangeBaseline <= 100);
+       espeak_ERROR ret = espeak_SetParameter(espeakRANGE, pitchRangeBaseline, 
0);
+       if (ret != EE_OK) {
+               DBG("Espeak: Error setting pitch range %i.", 
pitchRangeBaseline);
+       } else {
+               DBG("Espeak: Pitch range set to %i.", pitchRangeBaseline);
+       }
+}
+
 static void espeak_set_punctuation_mode(SPDPunctuation punct_mode)
 {
        espeak_PUNCT_TYPE espeak_punct_mode = espeakPUNCT_SOME;
diff --git a/src/modules/generic.c b/src/modules/generic.c
index 4378a96..4c9106b 100644
--- a/src/modules/generic.c
+++ b/src/modules/generic.c
@@ -61,6 +61,7 @@ static void generic_child_close(TModuleDoublePipe dpipe);
 
 void generic_set_rate(signed int rate);
 void generic_set_pitch(signed int pitch);
+void generic_set_pitch_range(signed int pitch_range);
 void generic_set_voice(SPDVoiceType voice);
 void generic_set_language(char *language);
 void generic_set_volume(signed int volume);
@@ -83,12 +84,16 @@ MOD_OPTION_1_STR(GenericExecuteSynth)
     MOD_OPTION_1_INT(GenericPitchAdd)
     MOD_OPTION_1_FLOAT(GenericPitchMultiply)
     MOD_OPTION_1_INT(GenericPitchForceInteger)
+    MOD_OPTION_1_INT(GenericPitchRangeAdd)
+    MOD_OPTION_1_FLOAT(GenericPitchRangeMultiply)
+    MOD_OPTION_1_INT(GenericPitchRangeForceInteger)
     MOD_OPTION_1_INT(GenericVolumeAdd)
     MOD_OPTION_1_FLOAT(GenericVolumeMultiply)
     MOD_OPTION_1_INT(GenericVolumeForceInteger)
     MOD_OPTION_3_HT(GenericLanguage, code, name, charset)
 
 static char generic_msg_pitch_str[16];
+static char generic_msg_pitch_range_str[16];
 static char generic_msg_rate_str[16];
 static char generic_msg_volume_str[16];
 static char *generic_msg_voice_str = NULL;
@@ -118,6 +123,10 @@ int module_load(void)
        MOD_OPTION_1_FLOAT_REG(GenericPitchMultiply, 1);
        MOD_OPTION_1_INT_REG(GenericPitchForceInteger, 0);
 
+       MOD_OPTION_1_INT_REG(GenericPitchRangeAdd, 0);
+       MOD_OPTION_1_FLOAT_REG(GenericPitchRangeMultiply, 1);
+       MOD_OPTION_1_INT_REG(GenericPitchRangeForceInteger, 0);
+       
        MOD_OPTION_1_INT_REG(GenericVolumeAdd, 0);
        MOD_OPTION_1_FLOAT_REG(GenericVolumeMultiply, 1);
        MOD_OPTION_1_INT_REG(GenericVolumeForceInteger, 0);
@@ -189,6 +198,7 @@ int module_speak(gchar * data, size_t bytes, SPDMessageType 
msgtype)
        UPDATE_PARAMETER(voice_type, generic_set_voice);
        UPDATE_PARAMETER(punctuation_mode, generic_set_punct);
        UPDATE_PARAMETER(pitch, generic_set_pitch);
+       UPDATE_PARAMETER(pitch_range, generic_set_pitch_range);
        UPDATE_PARAMETER(rate, generic_set_rate);
        UPDATE_PARAMETER(volume, generic_set_volume);
 
@@ -407,6 +417,9 @@ void *_generic_speak(void *nothing)
                                    string_replace(e_string, "$PITCH",
                                                   generic_msg_pitch_str);
                                e_string =
+                                   string_replace(e_string, "$PITCH_RANGE",
+                                                  generic_msg_pitch_range_str);
+                               e_string =
                                    string_replace(e_string, "$RATE",
                                                   generic_msg_rate_str);
                                e_string =
@@ -568,6 +581,18 @@ void generic_set_pitch(int pitch)
        }
 }
 
+void generic_set_pitch_range(int pitch_range)
+{
+       float hpitch_range;
+
+       hpitch_range = ((float)pitch_range) * GenericPitchRangeMultiply + 
GenericPitchRangeAdd;
+       if (!GenericPitchRangeForceInteger) {
+               snprintf(generic_msg_pitch_range_str, 15, "%.2f", hpitch_range);
+       } else {
+               snprintf(generic_msg_pitch_range_str, 15, "%d", 
(int)hpitch_range);
+       }
+}
+
 void generic_set_rate(int rate)
 {
        float hrate;
diff --git a/src/modules/module_utils.c b/src/modules/module_utils.c
index a0fdefb..63f863d 100644
--- a/src/modules/module_utils.c
+++ b/src/modules/module_utils.c
@@ -208,6 +208,7 @@ do_set(void)
             
             SET_PARAM_NUM(rate, ((number>=-100) && (number<=100)))
             else SET_PARAM_NUM(pitch, ((number>=-100) && (number<=100)))
+           else SET_PARAM_NUM(pitch_range, ((number>=-100) && (number<=100)))
            else SET_PARAM_NUM(volume, ((number>=-100) && (number<=100)))
             else SET_PARAM_STR_C(punctuation_mode, str2EPunctMode)
             else SET_PARAM_STR_C(spelling_mode, str2ESpellMode)
diff --git a/src/modules/module_utils.h b/src/modules/module_utils.h
index eacda04..9a0604b 100644
--- a/src/modules/module_utils.h
+++ b/src/modules/module_utils.h
@@ -62,6 +62,7 @@ int module_num_dc_options;
 #define CLEAN_OLD_SETTINGS_TABLE()\
  msg_settings_old.rate = -101;\
  msg_settings_old.pitch = -101;\
+ msg_settings_old.pitch_range = -101;\
  msg_settings_old.volume = -101;\
  msg_settings_old.punctuation_mode = -1;\
  msg_settings_old.spelling_mode = -1;\
@@ -74,6 +75,7 @@ int module_num_dc_options;
  module_dc_options = NULL;\
  msg_settings.rate = 0;\
  msg_settings.pitch = 0;\
+ msg_settings.pitch_range = 0;\
  msg_settings.volume = 0;\
  msg_settings.punctuation_mode = SPD_PUNCT_NONE;\
  msg_settings.spelling_mode = SPD_SPELL_OFF;\
-- 
2.1.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]