diff --git a/src/blackcore/afv/audio/input.cpp b/src/blackcore/afv/audio/input.cpp index 3bda134b0..eef52b94f 100644 --- a/src/blackcore/afv/audio/input.cpp +++ b/src/blackcore/afv/audio/input.cpp @@ -94,6 +94,13 @@ namespace BlackCore m_encoder.setBitRate(16 * 1024); } + bool CInput::setVolume(double volume) + { + if (qFuzzyCompare(m_volume, volume)) { return false; } + m_volume = volume; + return true; + } + void CInput::start(const CAudioDeviceInfo &inputDevice) { if (m_started) { return; } diff --git a/src/blackcore/afv/audio/input.h b/src/blackcore/afv/audio/input.h index 2a5b03a30..66f3a4625 100644 --- a/src/blackcore/afv/audio/input.h +++ b/src/blackcore/afv/audio/input.h @@ -95,11 +95,15 @@ namespace BlackCore this->stop(); } + //! Number of encoded bytes @{ int opusBytesEncoded() const { return m_opusBytesEncoded; } void setOpusBytesEncoded(int opusBytesEncoded) { m_opusBytesEncoded = opusBytesEncoded; } + //! @} + //! Volume @{ double volume() const { return m_volume; } - void setVolume(double volume) { m_volume = volume; } + bool setVolume(double volume); + //! @} //! Started? bool started() const { return m_started; } @@ -132,9 +136,9 @@ namespace BlackCore QAudioFormat m_inputFormat; bool m_started = false; - int m_opusBytesEncoded = 0; - int m_sampleCount = 0; - double m_volume = 1.0; + int m_opusBytesEncoded = 0; + int m_sampleCount = 0; + double m_volume = 1.0; qint16 m_maxSampleInput = 0.0; const int SampleCountPerEvent = 4800; @@ -142,7 +146,6 @@ namespace BlackCore const double minDb = -40; uint m_audioSequenceCounter = 0; - CAudioInputBuffer m_audioInputBuffer; #ifdef Q_OS_MAC diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index 74d827400..c0546c29c 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -165,7 +165,8 @@ namespace BlackCore bool CAfvClient::isMuted() const { - return this->getNormalizedOutputVolume() < 1; + const int v = this->getNormalizedOutputVolume(); + return v < 1; } void CAfvClient::setMuted(bool mute) @@ -475,17 +476,19 @@ namespace BlackCore return m_inputVolumeDb; } - void CAfvClient::setInputVolumeDb(double valueDb) + bool CAfvClient::setInputVolumeDb(double valueDb) { if (valueDb > MaxDbIn) { valueDb = MaxDbIn; } else if (valueDb < MinDbIn) { valueDb = MinDbIn; } QMutexLocker lock(&m_mutex); + bool changed = !qFuzzyCompare(m_inputVolumeDb, valueDb); m_inputVolumeDb = valueDb; if (m_input) { - m_input->setVolume(qPow(10, valueDb / 20.0)); + changed = m_input->setVolume(qPow(10, valueDb / 20.0)); } + return changed; } double CAfvClient::getOutputVolumeDb() const @@ -504,27 +507,46 @@ namespace BlackCore int CAfvClient::getNormalizedOutputVolume() const { - const double db = this->getOutputVolumeDb(); - const double range = MaxDbOut - MinDbOut; - const int i = qRound((db - MinDbOut) / range * 100); - return i; + double db = this->getOutputVolumeDb(); + double range = MaxDbOut; + int v = 50; + if (db < 0) + { + v = 0; + db -= MinDbOut; + range = qAbs(MinDbOut); + } + v += qRound(db * 50 / range); + return v; } - void CAfvClient::setNormalizedInputVolume(int volume) + bool CAfvClient::setNormalizedInputVolume(int volume) { if (volume < 0) { volume = 0; } else if (volume > 100) { volume = 100; } const double range = MaxDbIn - MinDbIn; const double dB = MinDbIn + (volume * range / 100.0); - this->setInputVolumeDb(dB); + return this->setInputVolumeDb(dB); } void CAfvClient::setNormalizedOutputVolume(int volume) { if (volume < 0) { volume = 0; } else if (volume > 100) { volume = 100; } - const double range = MaxDbOut - MinDbOut; - const double dB = MinDbOut + (volume * range / 100.0); + + // Asymetric + double range = MaxDbOut; + double dB = 0; + if (volume >= 50) + { + volume -= 50; + } + else + { + dB = MinDbOut; + range = qAbs(MinDbOut); + } + dB += (volume * range / 50.0); this->setOutputVolumeDb(dB); } @@ -555,8 +577,8 @@ namespace BlackCore audioData.lastPacket = false; audioData.sequenceCounter = 0; - RxTransceiverDto com1 = { 0, transceivers.size() > 0 ? transceivers[0].frequencyHz : UniCom, 1.0 }; - RxTransceiverDto com2 = { 1, transceivers.size() > 1 ? transceivers[1].frequencyHz : UniCom, 1.0 }; + const RxTransceiverDto com1 = { 0, transceivers.size() > 0 ? transceivers[0].frequencyHz : UniCom, 1.0 }; + const RxTransceiverDto com2 = { 1, transceivers.size() > 1 ? transceivers[1].frequencyHz : UniCom, 1.0 }; QMutexLocker lock(&m_mutex); m_soundcardSampleProvider->addOpusSamples(audioData, { com1, com2 }); @@ -719,8 +741,8 @@ namespace BlackCore QVector newTransceivers { transceiverCom1, transceiverCom2 }; QVector newEnabledTransceivers; QVector newTransmittingTransceivers; - if (e1) { newEnabledTransceivers.push_back(transceiverCom1); newEnabledTransceiverIds.insert(transceiverCom1.id); } - if (e2) { newEnabledTransceivers.push_back(transceiverCom2); newEnabledTransceiverIds.insert(transceiverCom2.id); } + if (e1) { newEnabledTransceivers.push_back(transceiverCom1); newEnabledTransceiverIds.insert(transceiverCom1.id); } + if (e2) { newEnabledTransceivers.push_back(transceiverCom2); newEnabledTransceiverIds.insert(transceiverCom2.id); } // Transmitting transceivers, currently ALLOW ONLY ONE if (tx1 && e1) { newTransmittingTransceivers.push_back(transceiverCom1); } @@ -807,19 +829,21 @@ namespace BlackCore return sApp && !sApp->isShuttingDown() && sApp->getIContextOwnAircraft(); } - void CAfvClient::setOutputVolumeDb(double valueDb) + bool CAfvClient::setOutputVolumeDb(double valueDb) { if (valueDb > MaxDbOut) { valueDb = MaxDbOut; } - if (valueDb < MinDbOut) { valueDb = MinDbOut; } + else if (valueDb < MinDbOut) { valueDb = MinDbOut; } QMutexLocker lock(&m_mutex); + bool changed = !qFuzzyCompare(m_outputVolumeDb, valueDb); m_outputVolumeDb = valueDb; m_outputVolume = qPow(10, m_outputVolumeDb / 20.0); if (m_outputSampleProvider) { - m_outputSampleProvider->setVolume(m_outputVolume); + changed = m_outputSampleProvider->setVolume(m_outputVolume); } + return changed; } const CAudioDeviceInfo &CAfvClient::getInputDevice() const diff --git a/src/blackcore/afv/clients/afvclient.h b/src/blackcore/afv/clients/afvclient.h index 79403c1c2..5dcb8ff87 100644 --- a/src/blackcore/afv/clients/afvclient.h +++ b/src/blackcore/afv/clients/afvclient.h @@ -178,14 +178,14 @@ namespace BlackCore //! \threadsafe //! @{ double getInputVolumeDb() const; - Q_INVOKABLE void setInputVolumeDb(double valueDb); + Q_INVOKABLE bool setInputVolumeDb(double valueDb); //! @} //! Output volume in dB, +-18dB //! \threadsafe //! @{ double getOutputVolumeDb() const; - Q_INVOKABLE void setOutputVolumeDb(double valueDb); + Q_INVOKABLE bool setOutputVolumeDb(double valueDb); //! @} //! Normalized volumes 0..100 @@ -193,7 +193,7 @@ namespace BlackCore //! @{ int getNormalizedInputVolume() const; int getNormalizedOutputVolume() const; - void setNormalizedInputVolume(int volume); + bool setNormalizedInputVolume(int volume); void setNormalizedOutputVolume(int volume); //! @} @@ -262,13 +262,13 @@ namespace BlackCore quint32 getAliasFrequencyHz(quint32 frequencyHz) const; static constexpr int PositionUpdatesMs = 5000; //!< position timer - 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 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); diff --git a/src/blackcore/context/contextaudio.cpp b/src/blackcore/context/contextaudio.cpp index 8a63f1e27..5432ac06c 100644 --- a/src/blackcore/context/contextaudio.cpp +++ b/src/blackcore/context/contextaudio.cpp @@ -207,7 +207,7 @@ namespace BlackCore if (changedVoiceOutput) { m_voiceClient->setNormalizedOutputVolume(volume); - m_outVolumeBeforeMute = currentVolume; + m_outVolumeBeforeMute = volume; emit this->changedAudioVolume(volume); if ((volume > 0 && wasMuted) || (volume < 1 && !wasMuted)) diff --git a/src/blacksound/sampleprovider/volumesampleprovider.cpp b/src/blacksound/sampleprovider/volumesampleprovider.cpp index d9fab070f..2eea9dc35 100644 --- a/src/blacksound/sampleprovider/volumesampleprovider.cpp +++ b/src/blacksound/sampleprovider/volumesampleprovider.cpp @@ -33,5 +33,12 @@ namespace BlackSound } return samplesRead; } + + bool CVolumeSampleProvider::setVolume(double volume) + { + const bool changed = !qFuzzyCompare(m_volume, volume); + m_volume = volume; + return changed; + } } // ns } // ns diff --git a/src/blacksound/sampleprovider/volumesampleprovider.h b/src/blacksound/sampleprovider/volumesampleprovider.h index 691d406e6..f1581d441 100644 --- a/src/blacksound/sampleprovider/volumesampleprovider.h +++ b/src/blacksound/sampleprovider/volumesampleprovider.h @@ -32,7 +32,7 @@ namespace BlackSound //! Volume @{ double volume() const { return m_volume; } - void setVolume(double volume) { m_volume = volume; } + bool setVolume(double volume); //! @} private: