From cf6434f49b7fdf78396369ae04ab46b6d5005b44 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 29 Sep 2019 23:55:42 +0200 Subject: [PATCH] Ref T730, fixed using wrong member "m_outputVolume", added new member "m_outputVolumeDb" --- src/blackcore/afv/clients/afvclient.cpp | 44 +++++++++++----------- src/blackcore/afv/clients/afvclient.h | 19 ++++++---- src/blackcore/context/contextaudioimpl.cpp | 2 +- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index ee6a9a838..454a7bd34 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -342,27 +342,30 @@ namespace BlackCore // qDebug() << "PTT:" << active; } - void CAfvClient::setInputVolumeDb(double value) + void CAfvClient::setInputVolumeDb(double valueDb) { - if (value > MaxDb) { value = MaxDb; } - if (value < MinDb) { value = MinDb; } - m_inputVolumeDb = value; - m_input->setVolume(qPow(10, value / 20.0)); + if (valueDb > MaxDbIn) { valueDb = MaxDbIn; } + if (valueDb < MinDbIn) { valueDb = MinDbIn; } + m_inputVolumeDb = valueDb; + if (m_input) + { + m_input->setVolume(qPow(10, valueDb / 20.0)); + } } int CAfvClient::getNormalizedInputVolume() const { const double db = this->getInputVolumeDb(); - const double range = MaxDb - MinDb; - const int i = qRound((db - MinDb) / range * 100); + const double range = MaxDbIn - MinDbIn; + const int i = qRound((db - MinDbIn) / range * 100); return i; } int CAfvClient::getNormalizedOutputVolume() const { const double db = this->getOutputVolumeDb(); - const double range = MaxDb - MinDb; - const int i = qRound((db - MinDb) / range * 100); + const double range = MaxDbIn - MinDbIn; + const int i = qRound((db - MinDbIn) / range * 100); return i; } @@ -370,8 +373,8 @@ namespace BlackCore { if (volume < 0) { volume = 0; } else if (volume > 100) { volume = 100; } - const double range = MaxDb - MinDb; - const double dB = MinDb + (volume * range / 100.0); + const double range = MaxDbIn - MinDbIn; + const double dB = MinDbIn + (volume * range / 100.0); this->setInputVolumeDb(dB); } @@ -379,8 +382,8 @@ namespace BlackCore { if (volume < 0) { volume = 0; } else if (volume > 100) { volume = 100; } - const double range = MaxDb - MinDb; - const double dB = MinDb + (volume * range / 100.0); + const double range = MaxDbIn - MinDbIn; + const double dB = MinDbIn + (volume * range / 100.0); this->setOutputVolumeDb(dB); } @@ -532,19 +535,16 @@ namespace BlackCore return sApp && !sApp->isShuttingDown() && sApp->getIContextOwnAircraft(); } - double CAfvClient::getOutputVolumeDb() const + void CAfvClient::setOutputVolumeDb(double valueDb) { - return m_outputVolume; - } + if (valueDb > MaxDbOut) { valueDb = MaxDbOut; } + if (valueDb < MinDbOut) { valueDb = MinDbOut; } + m_outputVolumeDb = valueDb; - void CAfvClient::setOutputVolumeDb(double outputVolume) - { - if (outputVolume > 18) { m_outputVolume = 18; } - if (outputVolume < -60) { m_outputVolume = -60; } - m_outputVolume = qPow(10, m_outputVolume / 20); + m_outputVolume = qPow(10, m_outputVolumeDb / 20.0); if (outputSampleProvider) { - outputSampleProvider->setVolume(outputVolume); + outputSampleProvider->setVolume(m_outputVolume); } } diff --git a/src/blackcore/afv/clients/afvclient.h b/src/blackcore/afv/clients/afvclient.h index 1e681b037..e24a188c4 100644 --- a/src/blackcore/afv/clients/afvclient.h +++ b/src/blackcore/afv/clients/afvclient.h @@ -134,12 +134,12 @@ namespace BlackCore //! Input volume in dB, +-18dB @{ double getInputVolumeDb() const { return m_inputVolumeDb; } - Q_INVOKABLE void setInputVolumeDb(double value); + Q_INVOKABLE void setInputVolumeDb(double valueDb); //! @} //! Output volume in dB, +-18dB @{ - double getOutputVolumeDb() const; - Q_INVOKABLE void setOutputVolumeDb(double outputVolume); + double getOutputVolumeDb() const { return m_outputVolumeDb; } + Q_INVOKABLE void setOutputVolumeDb(double valueDb); //! @} //! Normalized volumes 0..100 @{ @@ -192,11 +192,13 @@ namespace BlackCore void updateTransceivers(); void updateTransceiversFromContext(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); - static constexpr int SampleRate = 48000; - static constexpr int FrameSize = 960; // 20ms - static constexpr double MinDb = -18.0; - static constexpr double MaxDb = 18.0; - static constexpr quint32 UniCom = 122800000; + static constexpr int SampleRate = 48000; + static constexpr int FrameSize = 960; // 20ms + static constexpr double MinDbIn = -18.0; + static constexpr double MaxDbIn = 18.0; + static constexpr double MinDbOut = -60.0; + static constexpr double MaxDbOut = 18.0; + static constexpr quint32 UniCom = 122800000; static quint16 comUnitToTransceiverId(BlackMisc::Aviation::CComSystem::ComUnit comUnit); static BlackMisc::Aviation::CComSystem::ComUnit transceiverIdToComUnit(quint16 id); @@ -221,6 +223,7 @@ namespace BlackCore QDateTime m_startDateTimeUtc; double m_inputVolumeDb; + double m_outputVolumeDb; double m_outputVolume = 1.0; double m_maxDbReadingInPTTInterval = -100; diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index 4d19c02f5..7b56b3976 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -141,7 +141,7 @@ namespace BlackCore const bool changedVoiceOutput = (currentVolume != volume); if (changedVoiceOutput) { - m_voiceClient.setOutputVolumeDb(volume); + m_voiceClient.setNormalizedOutputVolume(volume); m_outVolumeBeforeMute = currentVolume; emit this->changedAudioVolume(volume);