From dd127de32bab2dabd6dd8eebca9facc987099d71 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Tue, 6 May 2014 10:23:04 +0200 Subject: [PATCH] Changes to voice + atis - 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 | 49 +++++++++++++++---------------- src/Instrumentation/commradio.hxx | 4 +-- src/Sound/VoiceSynthesizer.cxx | 3 -- src/Sound/voice.cxx | 1 - 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/Instrumentation/commradio.cxx b/src/Instrumentation/commradio.cxx index cf6e32d93..786cb23a6 100644 --- a/src/Instrumentation/commradio.cxx +++ b/src/Instrumentation/commradio.cxx @@ -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 _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 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(); diff --git a/src/Instrumentation/commradio.hxx b/src/Instrumentation/commradio.hxx index 746bd1284..0b912a0e6 100644 --- a/src/Instrumentation/commradio.hxx +++ b/src/Instrumentation/commradio.hxx @@ -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 SignalQualityComputerRef; diff --git a/src/Sound/VoiceSynthesizer.cxx b/src/Sound/VoiceSynthesizer.cxx index b91c90214..855746371 100644 --- a/src/Sound/VoiceSynthesizer.cxx +++ b/src/Sound/VoiceSynthesizer.cxx @@ -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()); diff --git a/src/Sound/voice.cxx b/src/Sound/voice.cxx index c808edd67..eec16ba53 100644 --- a/src/Sound/voice.cxx +++ b/src/Sound/voice.cxx @@ -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(); -- 2.39.5