]> git.mxchange.org Git - flightgear.git/commitdiff
FGCom: add silence threshold setting
authorClément de l'Hamaide <clemaez@hotmail.fr>
Sun, 26 Jan 2014 15:38:23 +0000 (16:38 +0100)
committerClément de l'Hamaide <clemaez@hotmail.fr>
Sun, 26 Jan 2014 15:38:48 +0000 (16:38 +0100)
Require commit 1396848dcf31d181ab740c8eb728cff02f06fd3d from fgdata

src/Network/fgcom.cxx
src/Network/fgcom.hxx
utils/fgcom/fgcom.cxx
utils/fgcom/fgcom.hxx

index 3a1f7e1df1e53d96953b44df405394148d744206..8dff1536342d5bc51e9f9ae0029ca5c300061c59 100644 (file)
@@ -117,6 +117,7 @@ void FGCom::bind()
   _enabled_node            = node->getChild( "enabled", 0, true );
   _micBoost_node           = node->getChild( "mic-boost", 0, true );
   _micLevel_node           = node->getChild( "mic-level", 0, true );
+  _silenceThd_node         = node->getChild( "silence-threshold", 0, true );
   _speakerLevel_node       = node->getChild( "speaker-level", 0, true );
   _selectedInput_node      = node->getChild( "device-input", 0, true );
   _selectedOutput_node     = node->getChild( "device-output", 0, true );
@@ -153,6 +154,9 @@ void FGCom::bind()
   if ( !_micLevel_node->hasValue() )
       _micLevel_node->setFloatValue(1.0);
 
+  if ( !_silenceThd_node->hasValue() )
+      _silenceThd_node->setFloatValue(-20.0);
+
   if ( !_register_node->hasValue() )
       _register_node->setBoolValue(false);
 
@@ -168,6 +172,7 @@ void FGCom::bind()
   _selectedOutput_node->addChangeListener(this);
   _selectedInput_node->addChangeListener(this);
   _speakerLevel_node->addChangeListener(this);
+  _silenceThd_node->addChangeListener(this);
   _micBoost_node->addChangeListener(this);
   _micLevel_node->addChangeListener(this);
   _enabled_node->addChangeListener(this);
@@ -232,7 +237,7 @@ void FGCom::postinit()
     iaxc_set_formats (IAXC_FORMAT_SPEEX, IAXC_FORMAT_ULAW|IAXC_FORMAT_SPEEX);
     iaxc_set_speex_settings(1, 5, 0, 1, 0, 3);
     iaxc_set_filters(IAXC_FILTER_AGC | IAXC_FILTER_DENOISE);
-    iaxc_set_silence_threshold(-20.0);
+    iaxc_set_silence_threshold(_silenceThd_node->getFloatValue());
     iaxc_start_processing_thread ();
 
     // Now IAXClient is initialized
@@ -445,6 +450,13 @@ void FGCom::valueChanged(SGPropertyNode *prop)
     return;
   }
 
+  if (prop == _silenceThd_node && _initialized) {
+    float silenceThd = prop->getFloatValue();
+    SG_CLAMP_RANGE<float>( silenceThd, -60, 0 );
+    iaxc_set_silence_threshold( silenceThd );
+    return;
+  }
+
   //FIXME: not implemented in IAX audio driver (audio_openal.c)
   if (prop == _micBoost_node && _initialized) {
     int micBoost = prop->getIntValue();
index 10533fd14e759e10aeec95377a1c6e71152a5317..e12b52d27f025ea4fd300115d016fce9a0c27282 100644 (file)
@@ -55,6 +55,7 @@ class FGCom : public SGSubsystem, public SGPropertyChangeListener
     SGPropertyNode_ptr _username_node;                        // sim/fgcom/register/username
     SGPropertyNode_ptr _password_node;                        // sim/fgcom/register/password
     SGPropertyNode_ptr _micLevel_node;                        // sim/fgcom/mic-level
+    SGPropertyNode_ptr _silenceThd_node;                      // sim/fgcom/silence-threshold
     SGPropertyNode_ptr _speakerLevel_node;                    // sim/fgcom/speaker-level
     SGPropertyNode_ptr _deviceID_node[4];                     // sim/fgcom/device[n]/id
     SGPropertyNode_ptr _deviceName_node[4];                   // sim/fgcom/device[n]/name
index a18202f4f0e095e3e4f08d88e454b8965ef76f06..f3f972df74a83b099dd1e6011736684636578fbe 100644 (file)
@@ -80,6 +80,7 @@ double *special_frequencies;
 double previous_com_frequency = 0.0;
 int previous_ptt = 0;
 float previous_vol = 0.0;
+float previous_thd = 0.0;
 int com_select = 0;
 int max_com_instruments = 2;
 struct airport *airportlist;
@@ -97,6 +98,7 @@ static const char *audio_in;
 static const char *audio_out;
 static double level_in = 0.7;
 static double level_out = 0.7;
+static double silence_thd = -20.0;
 static bool mic_boost;
 static char codec_option;
 static const char *callsign;
@@ -130,6 +132,8 @@ static const OptionEntry fgcomOptionArray[] = {
    "speaker output level (0.0 - 1.0)", 0},
   {"mic-boost", 'b', false, OPTION_BOOL, &mic_boost, 0, "enable mic boost",
    0},
+  {"silence-threshold", 't', false, OPTION_DOUBLE, &silence_thd, 0, "set silence threshold (-60.0 - 0.0)",
+   0},
   {"list-audio", 'l', false, OPTION_BOOL, &list_audio, 0,
    "list audio devices", 0},
   {"set-audio-in", 'r', true, OPTION_STRING, &audio_in, 0,
@@ -213,6 +217,15 @@ process_packet (char *buf)
       previous_vol = data.OUTPUT_VOL;
     }
 
+  /* Check for silence threshold change */
+  if (previous_thd != data.SILENCE_THD)
+    {
+      SG_LOG( SG_GENERAL, SG_ALERT, "Set silent threshold to " << data.SILENCE_THD );
+
+      iaxc_set_silence_threshold( data.SILENCE_THD );
+      previous_thd = data.SILENCE_THD;
+    }
+
   /* Check for callsign change */
   if (strcmp(callsign, data.CALLSIGN) != 0)
     {
@@ -451,7 +464,7 @@ main (int argc, char *argv[])
   iaxc_set_formats (IAXC_FORMAT_SPEEX, IAXC_FORMAT_ULAW|IAXC_FORMAT_SPEEX);
   iaxc_set_speex_settings(1, 5, 0, 1, 0, 3);
   iaxc_set_filters(IAXC_FILTER_AGC | IAXC_FILTER_DENOISE);
-  iaxc_set_silence_threshold(-20.0);
+  iaxc_set_silence_threshold(silence_thd);
   iaxc_set_event_callback (iaxc_callback);
 
   iaxc_start_processing_thread ();
@@ -1198,6 +1211,11 @@ parse_fgdata (struct fgdata *data, char *buf)
          data->OUTPUT_VOL = atof (fields[1]);
           SG_LOG( SG_GENERAL, SG_DEBUG, "OUTPUT_VOL=" << data->OUTPUT_VOL );
        }
+      else if (strcmp (fields[0], "SILENCE_THD") == 0)
+       {
+         data->SILENCE_THD = atof (fields[1]);
+          SG_LOG( SG_GENERAL, SG_DEBUG, "SILENCE_THD=" << data->SILENCE_THD );
+       }
       else if (strcmp (fields[0], "CALLSIGN") == 0)
        {
          data->CALLSIGN = fields[1];
index bef4aa0056f77467d5a90f5d322c779de56009fc..7f48ad87500a143f1dc7d41a49424d6aac802a8c 100644 (file)
@@ -124,6 +124,7 @@ struct fgdata
   int ALT;
   float HEAD;
   float OUTPUT_VOL;
+  float SILENCE_THD;
   char* CALLSIGN;
 };