From 8db784bf170fec7d5028068a927d42f8b3c64406 Mon Sep 17 00:00:00 2001 From: Richard Harrison Date: Thu, 21 Mar 2019 17:56:38 +0100 Subject: [PATCH] FGcomm: PTT usage and volume - PTT will now use whatever channel is selected; non zero simply means PTT active. - The volume as set in the comm[]/radio will now be used as a factor on the FGComm volume --- src/Network/fgcom.cxx | 27 +++++++++++++++++---------- src/Network/fgcom.hxx | 2 ++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Network/fgcom.cxx b/src/Network/fgcom.cxx index 11f50bb70..4bf30c2cb 100644 --- a/src/Network/fgcom.cxx +++ b/src/Network/fgcom.cxx @@ -312,7 +312,7 @@ void FGCom::postinit() // Mute the mic and set speaker at start iaxc_input_level_set( 0.0 ); - iaxc_output_level_set( _speakerLevel_node->getFloatValue() ); + iaxc_output_level_set(getCurrentCommVolume()); iaxc_millisleep(50); @@ -321,6 +321,17 @@ void FGCom::postinit() connectToCommFrequency(); } +double FGCom::getCurrentCommVolume() const { + double rv = 1.0; + + if (_speakerLevel_node) + rv = _speakerLevel_node->getFloatValue(); + + if (_commVolumeNode) + rv = rv * _commVolumeNode->getFloatValue(); + + return rv; +} double FGCom::getCurrentFrequencyKhz() const { return 10 * static_cast(_currentCommFrequency * 100 + 0.25); } @@ -348,6 +359,7 @@ void FGCom::setupCommFrequency(int channel) { SGPropertyNode *commRadioNode = fgGetNode("/instrumentation/")->getChild("comm", channel, false); if (commRadioNode) { SGPropertyNode *frequencyNode = commRadioNode->getChild("frequencies"); + _commVolumeNode = commRadioNode->getChild("volume"); if (frequencyNode) { frequencyNode = frequencyNode->getChild("selected-mhz"); if (frequencyNode) { @@ -493,13 +505,8 @@ void FGCom::valueChanged(SGPropertyNode *prop) if (prop == _ptt_node && _enabled) { if (_ptt_node->getIntValue()) { - // ensure that we are on the right channel by calling setupCommFrequency with the value of the PTT node. - // the two properties for the ptt channel and the current channel should be on the same channel - // but if not this will flip the radio for transmit and listen to whichever frequency last did a PTT - // - // NOTE: Probably the whole thing needs re-writing to be multi-comm capable; but fgcomm has always been a bit - // single oriented and I don't know if it would even work (with the right logic) in multi-channel mode. - setupCommFrequency(_ptt_node->getIntValue()); + // ensure that we are on the right channel by calling setupCommFrequency + setupCommFrequency(); iaxc_output_level_set(0.0); iaxc_input_level_set(_micLevel_node->getFloatValue()); //0.0 = min , 1.0 = max _mpTransmitFrequencyNode->setValue(_currentCallFrequency * 1000000); @@ -507,7 +514,7 @@ void FGCom::valueChanged(SGPropertyNode *prop) SG_LOG(SG_IO, SG_INFO, "FGCom: PTT active: " << _currentCallFrequency); } else { - iaxc_output_level_set(_speakerLevel_node->getFloatValue()); + iaxc_output_level_set(getCurrentCommVolume()); iaxc_input_level_set(0.0); SG_LOG(SG_IO, SG_INFO, "FGCom: PTT release: " << _currentCallFrequency); _mpTransmitFrequencyNode->setValue(0); @@ -586,7 +593,7 @@ void FGCom::testMode(bool testMode) iaxc_dump_all_calls(); iaxc_millisleep(IAX_DELAY); iaxc_input_level_set( 0.0 ); - iaxc_output_level_set( _speakerLevel_node->getFloatValue() ); + iaxc_output_level_set(getCurrentCommVolume()); _currentCallIdent = -1; _enabled = true; } diff --git a/src/Network/fgcom.hxx b/src/Network/fgcom.hxx index e981540d3..e5b5ac54c 100644 --- a/src/Network/fgcom.hxx +++ b/src/Network/fgcom.hxx @@ -44,6 +44,7 @@ class FGCom : public SGSubsystem, public SGPropertyChangeListener SGPropertyNode_ptr _ptt_node; // PTT; nonzero int indicating channel number (instrumentation/comm/[channel-1]) SGPropertyNode_ptr _selected_comm_node; // selected channel (fgcom); nonzero channel int indicating channel number (instrumentation/comm/[channel-1]) SGPropertyNode_ptr _commFrequencyNode; // current comm node in use; e.g. /instrumentation/comm[0] + SGPropertyNode_ptr _commVolumeNode; // current volume node in use; e.g. /instrumentation/comm[0]/volume SGPropertyNode_ptr _test_node; // sim/fgcom/test SGPropertyNode_ptr _text_node; // sim/fgcom/text SGPropertyNode_ptr _server_node; // sim/fgcom/server @@ -91,6 +92,7 @@ class FGCom : public SGSubsystem, public SGPropertyChangeListener // SGGeod getAirportPos(const double& freq) const; void setupCommFrequency(int channel = -1); double getCurrentFrequencyKhz() const; + double getCurrentCommVolume() const; bool isInRange(const double& freq) const; void updateCall();