diff --git a/src/blackcore/context_audio.h b/src/blackcore/context_audio.h index 9fcb645ba..3e0e2f7a8 100644 --- a/src/blackcore/context_audio.h +++ b/src/blackcore/context_audio.h @@ -146,6 +146,9 @@ namespace BlackCore //! Get the squelch value virtual double getSquelchValue() const = 0; + + //! Enable audio loopback + virtual void enableAudioLoopback(bool enable = true) = 0; }; } diff --git a/src/blackcore/context_audio_impl.cpp b/src/blackcore/context_audio_impl.cpp index 6edb1c1c7..23115907a 100644 --- a/src/blackcore/context_audio_impl.cpp +++ b/src/blackcore/context_audio_impl.cpp @@ -307,6 +307,13 @@ namespace BlackCore return static_cast(this->m_voice->inputSquelch()); } + void CContextAudio::enableAudioLoopback(bool enable) + { + Q_ASSERT(this->m_voice); + if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO); + m_voice->enableAudioLoopback(enable); + } + /* * Settings changed */ diff --git a/src/blackcore/context_audio_impl.h b/src/blackcore/context_audio_impl.h index b53de919c..f37c36139 100644 --- a/src/blackcore/context_audio_impl.h +++ b/src/blackcore/context_audio_impl.h @@ -97,6 +97,9 @@ namespace BlackCore //! \copydoc IContextAudio::getSquelchValue() virtual double getSquelchValue() const override; + //! \copydoc IContextAudio::enableAudioLoopback() + virtual void enableAudioLoopback(bool enable = true) override; + protected: //! \brief Constructor CContextAudio(CRuntimeConfig::ContextMode mode, CRuntime *runtime); diff --git a/src/blackcore/context_audio_proxy.cpp b/src/blackcore/context_audio_proxy.cpp index 4e1d6f4e2..5899883ca 100644 --- a/src/blackcore/context_audio_proxy.cpp +++ b/src/blackcore/context_audio_proxy.cpp @@ -211,4 +211,9 @@ namespace BlackCore return this->m_dBusInterface->callDBusRet(QLatin1Literal("isMuted")); } + void CContextAudioProxy::enableAudioLoopback(bool enable) + { + return this->m_dBusInterface->callDBus(QLatin1Literal("enableAudioLoopback"), enable); + } + } // namespace diff --git a/src/blackcore/context_audio_proxy.h b/src/blackcore/context_audio_proxy.h index 38521f83d..089efa6cd 100644 --- a/src/blackcore/context_audio_proxy.h +++ b/src/blackcore/context_audio_proxy.h @@ -110,6 +110,9 @@ namespace BlackCore //! \copydoc IContextAudio::getSquelchValue() virtual double getSquelchValue() const override; + + //! \copydoc IContextAudio::enableAudioLoopback() + virtual void enableAudioLoopback(bool enable = true) override; }; } diff --git a/src/blackcore/voice.h b/src/blackcore/voice.h index f420fef9b..b01326518 100644 --- a/src/blackcore/voice.h +++ b/src/blackcore/voice.h @@ -213,6 +213,12 @@ namespace BlackCore */ virtual void switchAudioOutput(const ComUnit comUnit, bool enable) = 0; + /*! + * \brief Enable audio loopback to route recorded voice from microphone to speakers + * \param enable (default true) + */ + virtual void enableAudioLoopback(bool enable = true) = 0; + signals: //! The status of a room has changed. diff --git a/src/blackcore/voice_vatlib.cpp b/src/blackcore/voice_vatlib.cpp index 726530106..0cee8d014 100644 --- a/src/blackcore/voice_vatlib.cpp +++ b/src/blackcore/voice_vatlib.cpp @@ -21,6 +21,7 @@ namespace BlackCore m_audioOutput(new QAudioOutput()), m_inputSquelch(-1), m_micTestResult(Cvatlib_Voice_Simple::agc_Ok), + m_isAudioLoopbackEnabled(false), m_temporaryUserRoomIndex(CVoiceVatlib::InvalidRoomIndex), m_lockVoiceRooms(QReadWriteLock::Recursive), m_lockCallsigns(QReadWriteLock::Recursive), @@ -239,6 +240,26 @@ namespace BlackCore } } + void CVoiceVatlib::enableAudioLoopback(bool enable) + { + if (enable == m_isAudioLoopbackEnabled) + return; + + QMutexLocker lockerVatlib(&m_mutexVatlib); + Q_ASSERT_X(m_voice->IsValid() && m_voice->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!"); + try + { + m_voice->SetAudioLoopback(0, enable); + } + catch (...) + { + this->exceptionDispatcher(Q_FUNC_INFO); + } + + // bools are atomic. No need to protect it with a mutex + m_isAudioLoopbackEnabled = enable; + } + /* * Squelch test */ diff --git a/src/blackcore/voice_vatlib.h b/src/blackcore/voice_vatlib.h index c4cb51f69..6ce9b5739 100644 --- a/src/blackcore/voice_vatlib.h +++ b/src/blackcore/voice_vatlib.h @@ -128,6 +128,9 @@ namespace BlackCore //! \copydoc IVoice::switchAudioOutput virtual void switchAudioOutput(const ComUnit comUnit, bool enable) override; + //! \copydoc IVoice::enableAudioLoopback + virtual void enableAudioLoopback(bool enable = true) override; + //! \copydoc IVoice::isMuted virtual bool isMuted() const override { @@ -235,6 +238,7 @@ namespace BlackCore BlackMisc::Aviation::CCallsignList m_temporaryVoiceRoomCallsigns; /*!< temp. storage of voice rooms during update */ QMap m_outputEnabled; /*!< output enabled, basically a mute flag */ QMap m_connectionStatus; /*!< holds connection status for each com unit */ + bool m_isAudioLoopbackEnabled; /*!< A flag whether audio loopback is enabled or not */ // Need to keep the roomIndex? // KB: I would remove this approach, it is potentially unsafe