]> git.mxchange.org Git - flightgear.git/commitdiff
Changes to voice + atis
authorTorsten Dreyer <torsten@t3r.de>
Tue, 6 May 2014 08:23:04 +0000 (10:23 +0200)
committerTorsten Dreyer <torsten@t3r.de>
Tue, 6 May 2014 08:23:04 +0000 (10:23 +0200)
- Add a very simple line-of-sight propagation model for the radio
  range computation.
- Remove some no longer used debug log messages
- Some code cleanup
- add-noise is now on by default

src/Instrumentation/commradio.cxx
src/Instrumentation/commradio.hxx
src/Sound/VoiceSynthesizer.cxx
src/Sound/voice.cxx

index cf6e32d937d4ff302dd7b1f23ad3e432c2d5440f..786cb23a6cc6f30b7691568d49832c229c212533 100644 (file)
@@ -86,7 +86,7 @@ AtisSpeaker::~AtisSpeaker()
 void AtisSpeaker::valueChanged(SGPropertyNode * node)
 {
   if (!fgGetBool("/sim/sound/working", false))
-    return;
+  return;
 
   string newText = node->getStringValue();
   if (_synthesizeRequest.text == newText) return;
@@ -115,32 +115,27 @@ SignalQualityComputer::~SignalQualityComputer()
 
 class SimpleDistanceSquareSignalQualityComputer: public SignalQualityComputer {
 public:
-  SimpleDistanceSquareSignalQualityComputer(double range)
-      : _rangeM(range), _rangeM2(range * range)
+  SimpleDistanceSquareSignalQualityComputer()
+      : _altitudeAgl_ft(fgGetNode("/position/altitude-agl-ft", true))
   {
   }
-  virtual double computeSignalQuality(const SGGeod & sender, const SGGeod & receiver) const;
-  virtual double computeSignalQuality(const SGVec3d & sender, const SGVec3d & receiver) const;
-  virtual double computeSignalQuality(double slantDistanceM) const;
-  private:
-  double _rangeM;
-  double _rangeM2;
-};
 
-double SimpleDistanceSquareSignalQualityComputer::computeSignalQuality(const SGVec3d & sender, const SGVec3d & receiver) const
-    {
-  return computeSignalQuality(dist(sender, receiver));
-}
+  ~SimpleDistanceSquareSignalQualityComputer()
+  {
+  }
 
-double SimpleDistanceSquareSignalQualityComputer::computeSignalQuality(const SGGeod & sender, const SGGeod & receiver) const
-    {
-  return computeSignalQuality(SGGeodesy::distanceM(sender, receiver));
-}
+  double computeSignalQuality(double distance_nm) const
+  {
+    // Very simple line of sight propagation model. It's cheap but it does the trick for now.
+    // assume transmitter and receiver antennas are at some elevation above ground
+    // so we have at least a range of 5NM. Add the approx. distance to the horizon.
+    double range_nm = 5.0 + 1.23 * ::sqrt(SGMiscd::max(.0, _altitudeAgl_ft));
+    return distance_nm < range_nm ? 1.0 : (range_nm * range_nm / distance_nm / distance_nm);
+  }
 
-double SimpleDistanceSquareSignalQualityComputer::computeSignalQuality(double distanceM) const
-    {
-  return distanceM < _rangeM ? 1.0 : (_rangeM2 / (distanceM * distanceM));
-}
+private:
+  PropertyObject<double> _altitudeAgl_ft;
+};
 
 class OnExitHandler {
 public:
@@ -368,7 +363,7 @@ CommRadioImpl::CommRadioImpl(SGPropertyNode_ptr node)
         _stbyFrequencyFormatter(_rootNode->getNode("frequencies/standby-mhz", true),
             _rootNode->getNode("frequencies/standby-mhz-fmt", true), 0.025, 118.0, 136.0),
 
-        _signalQualityComputer(new SimpleDistanceSquareSignalQualityComputer(50 * SG_NM_TO_METER)),
+        _signalQualityComputer(new SimpleDistanceSquareSignalQualityComputer()),
 
         _stationTTL(0.0),
         _frequency(-1.0),
@@ -420,6 +415,10 @@ void CommRadioImpl::init()
   // initialize squelch to a sane value if unset
   s = _cutoffSignalQuality.node()->getStringValue();
   if (s.empty()) _cutoffSignalQuality = 0.4;
+
+  // initialize add-noize to true if unset
+  s = _addNoise.node()->getStringValue();
+  if (s.empty()) _addNoise = true;
 }
 
 void CommRadioImpl::update(double dt)
@@ -447,7 +446,7 @@ void CommRadioImpl::update(double dt)
       // the speaker has created a new atis sample
       if (!_sampleGroup.valid()) {
         // create a sample group for our instrument on the fly
-        _sampleGroup = globals->get_soundmgr()->find(getSampleGroupRefname(), true );
+        _sampleGroup = globals->get_soundmgr()->find(getSampleGroupRefname(), true);
         _sampleGroup->tie_to_listener();
         if (_addNoise) {
           SGSharedPtr<SGSoundSample> noise = new SGSoundSample("Sounds/radionoise.wav", globals->get_fg_root());
@@ -509,7 +508,7 @@ void CommRadioImpl::update(double dt)
 
   _heightAboveStation_ft = SGMiscd::max(0.0, position.getElevationFt() - _commStationForFrequency->airport()->elevation());
 
-  _signalQuality_norm = _signalQualityComputer->computeSignalQuality(_slantDistance_m);
+  _signalQuality_norm = _signalQualityComputer->computeSignalQuality(_slantDistance_m * SG_METER_TO_NM );
   _stationType = _commStationForFrequency->nameForType(_commStationForFrequency->type());
   _stationName = _commStationForFrequency->ident();
   _airportId = _commStationForFrequency->airport()->getId();
index 746bd12847d9942cfb91f5a12ed568f5608697ab..0b912a0e69d3033d5ccc9b9e502ff57754ef588e 100644 (file)
@@ -31,9 +31,7 @@ namespace Instrumentation {
 class SignalQualityComputer : public SGReferenced {
 public:
   virtual ~SignalQualityComputer();
-  virtual double computeSignalQuality( const SGGeod & sender, const SGGeod & receiver ) const = 0;
-  virtual double computeSignalQuality( const SGVec3d & sender, const SGVec3d & receiver ) const = 0;
-  virtual double computeSignalQuality( double slantDistanceM ) const = 0;
+  virtual double computeSignalQuality( double distance_nm ) const = 0;
 };
 
 typedef SGSharedPtr<SignalQualityComputer> SignalQualityComputerRef;
index b91c90214270b11f1393db4d9b275b8c20a3b4be..855746371a705f62b107d713624ca71f304a4e41 100644 (file)
@@ -91,13 +91,10 @@ SGSoundSample * FLITEVoiceSynthesizer::synthesize(const std::string & text)
 
   if ( FALSE == Flite_HTS_Engine_synthesize(_engine, text.c_str(), scratch.getName())) return NULL;
 
-  SG_LOG(SG_SOUND, SG_ALERT, "created wav at " << scratch.getPath());
-
   ALenum format;
   ALsizei size;
   ALfloat freqf;
   ALvoid * data = simgear::loadWAVFromFile(scratch.getPath(), format, size, freqf);
-  SG_LOG(SG_ALL, SG_ALERT, "loaded wav at " << freqf << "Hz size=" << size << " format=" << format);
 
   if (data == NULL) {
     SG_LOG(SG_SOUND, SG_ALERT, "Failed to load wav file " << scratch.getPath());
index c808edd67c86cc5ea0ad2d359acc99b8d766d397..eec16ba530a5c1efb1c76b1e5d15d0a74e4d2632 100644 (file)
@@ -117,7 +117,6 @@ void FGVoiceMgr::init()
 void FGVoiceMgr::shutdown()
 {
 #if defined(ENABLE_THREADS)
-  SG_LOG(SG_ALL,SG_ALERT,"FGVoiceMgr::shutdown");
   if( _thread ) {
     _thread->cancel();
     _thread->join();