Issue #100 Seperate COM1/2 output volumes

This commit is contained in:
Lars Toenning
2021-09-03 00:54:40 +02:00
committed by Mat Sutcliffe
parent 577431ae49
commit c1b75f7532
24 changed files with 270 additions and 509 deletions

View File

@@ -89,6 +89,9 @@ namespace BlackCore
//! Get frequency in Hz
uint getFrequencyHz() const;
//! Set gain ratio
bool setGainRatio(double gainRatio) { return m_volume->setGainRatio(gainRatio); }
//! Log all inputs
//! \private DEBUG only
void logVoiceInputs(const QString &prefix = {}, qint64 timeCheckOffsetMs = -1);

View File

@@ -187,6 +187,17 @@ namespace BlackCore
return m_receiverInputs.at(transceiverID)->getReceivingCallsignsString();
}
bool CSoundcardSampleProvider::setGainRatioForTransceiver(quint16 transceiverID, double gainRatio)
{
auto receiverInput = std::find_if(m_receiverInputs.begin(), m_receiverInputs.end(),
[&](const auto receiver)
{
return receiver->getId() == transceiverID;
});
if (receiverInput == m_receiverInputs.end()) { return false; }
return (*receiverInput)->setGainRatio(gainRatio);
}
BlackMisc::Aviation::CCallsignSet CSoundcardSampleProvider::getReceivingCallsigns(quint16 transceiverID) const
{
return m_receiverInputs.at(transceiverID)->getReceivingCallsigns();

View File

@@ -58,6 +58,9 @@ namespace BlackCore
//! Receiving callsign as single string
BlackMisc::Aviation::CCallsignSet getReceivingCallsigns(quint16 transceiverID) const;
//! Setting gain for specified receiver
bool setGainRatioForTransceiver(quint16 transceiverID, double gainRatio);
signals:
//! Changed callsigns
void receivingCallsignsChanged(const TransceiverReceivingCallsignsChangedArgs &args);

View File

@@ -268,15 +268,16 @@ namespace BlackCore
bool CAfvClient::isMuted() const
{
const int v = this->getNormalizedOutputVolume();
return v < 1;
const int v1 = this->getNormalizedOutputVolume(CComSystem::Com1);
const int v2 = this->getNormalizedOutputVolume(CComSystem::Com2);
return v1 < 1 && v2 < 1;
}
void CAfvClient::setMuted(bool mute)
{
if (this->isMuted() == mute) { return; }
this->setNormalizedOutputVolume(mute ? 0 : 50);
this->setNormalizedOutputVolume(CComSystem::Com1, mute ? 0 : 50);
this->setNormalizedOutputVolume(CComSystem::Com2, mute ? 0 : 50);
emit this->changedMute(mute);
}
@@ -316,7 +317,6 @@ namespace BlackCore
this->initTransceivers();
// threadsafe block
const double outputVolume = this->getOutputGainRatio();
{
// lock block 1
{
@@ -331,7 +331,7 @@ namespace BlackCore
if (m_outputSampleProvider) { m_outputSampleProvider->deleteLater(); }
m_outputSampleProvider = new CVolumeSampleProvider(m_soundcardSampleProvider, this);
m_outputSampleProvider->setGainRatio(outputVolume);
//m_outputSampleProvider->setGainRatio(outputVolume); // 2021-09 LT Disabled. Output volume is controlled independently for COM1/2
}
// lock block 2
@@ -768,16 +768,26 @@ namespace BlackCore
return changed;
}
double CAfvClient::getOutputVolumeDb() const
double CAfvClient::getOutputVolumeDb(CComSystem::ComUnit comUnit) const
{
QMutexLocker lock(&m_mutexVolume);
return m_outputVolumeDb;
if (comUnit == CComSystem::Com1)
return m_outputVolumeDbCom1;
else if (comUnit == CComSystem::Com2)
return m_outputVolumeDbCom2;
qFatal("Invalid COM unit");
return 0;
}
double CAfvClient::getOutputGainRatio() const
double CAfvClient::getOutputGainRatio(CComSystem::ComUnit comUnit) const
{
QMutexLocker lock(&m_mutexVolume);
return m_outputGainRatio;
if (comUnit == CComSystem::Com1)
return m_outputGainRatioCom1;
else if (comUnit == CComSystem::Com2)
return m_outputGainRatioCom2;
qFatal("Invalid COM unit");
return 0;
}
int CAfvClient::getNormalizedInputVolume() const
@@ -788,9 +798,9 @@ namespace BlackCore
return i;
}
int CAfvClient::getNormalizedOutputVolume() const
int CAfvClient::getNormalizedOutputVolume(CComSystem::ComUnit comUnit) const
{
double db = this->getOutputVolumeDb();
double db = this->getOutputVolumeDb(comUnit);
double range = MaxDbOut;
int v = 50;
if (db < 0)
@@ -814,7 +824,7 @@ namespace BlackCore
return this->setInputVolumeDb(dB);
}
void CAfvClient::setNormalizedOutputVolume(int volume)
void CAfvClient::setNormalizedOutputVolume(CComSystem::ComUnit comUnit, int volume)
{
if (volume < 0) { volume = 0; }
else if (volume > 100) { volume = 100; }
@@ -834,7 +844,7 @@ namespace BlackCore
dB += (volume * range / 50.0);
// converted to MinDbOut-MaxDbOut
this->setOutputVolumeDb(dB);
this->setOutputVolumeDb(comUnit, dB);
}
double CAfvClient::getInputVolumePeakVU() const
@@ -1089,10 +1099,12 @@ namespace BlackCore
{
const CSettings audioSettings = m_audioSettings.get();
const int iv = audioSettings.getInVolume();
const int ov = audioSettings.getOutVolume();
const int ov1 = audioSettings.getOutVolumeCom1();
const int ov2 = audioSettings.getOutVolumeCom2();
this->setNormalizedInputVolume(iv);
this->setNormalizedOutputVolume(ov);
this->setNormalizedOutputVolume(CComSystem::Com1, ov1);
this->setNormalizedOutputVolume(CComSystem::Com2, ov2);
this->setBypassEffects(!audioSettings.isAudioEffectsEnabled());
}
@@ -1145,6 +1157,12 @@ namespace BlackCore
const bool tx2 = com2.isTransmitEnabled(); // we only allow one (1) transmit
const bool rx2 = com2.isReceiveEnabled();
const int vol1 = com1.getVolumeReceive();
const int vol2 = com2.getVolumeReceive();
this->setNormalizedOutputVolume(CComSystem::Com1, vol1);
this->setNormalizedOutputVolume(CComSystem::Com2, vol2);
// enable, we currently treat receive as enable
// flight sim cockpits normally use rx and tx
// AFV uses tx and enable
@@ -1397,7 +1415,7 @@ namespace BlackCore
return sApp && !sApp->isShuttingDown() && sApp->getIContextOwnAircraft() && sApp->getIContextNetwork() && sApp->getIContextSimulator();
}
bool CAfvClient::setOutputVolumeDb(double valueDb)
bool CAfvClient::setOutputVolumeDb(CComSystem::ComUnit comUnit, double valueDb)
{
if (!CThreadUtils::isInThisThread(this))
{
@@ -1406,11 +1424,11 @@ namespace BlackCore
QTimer::singleShot(0, this, [ = ]
{
if (!myself || !CAfvClient::hasContexts()) { return; }
myself->setOutputVolumeDb(valueDb);
myself->setOutputVolumeDb(comUnit, valueDb);
});
return true; // not exactly "true" as we do it async
}
if (comUnit != CComSystem::Com1 && comUnit != CComSystem::Com2) { return false; }
if (valueDb > MaxDbOut) { valueDb = MaxDbOut; }
else if (valueDb < MinDbOut) { valueDb = MinDbOut; }
@@ -1418,11 +1436,23 @@ namespace BlackCore
bool changed = false;
{
QMutexLocker lock(&m_mutexVolume);
changed = !qFuzzyCompare(m_outputVolumeDb, valueDb);
if (changed)
if (comUnit == CComSystem::Com1)
{
m_outputVolumeDb = valueDb;
m_outputGainRatio = gainRatio;
changed = !qFuzzyCompare(m_outputVolumeDbCom1, valueDb);
if (changed)
{
m_outputVolumeDbCom1 = valueDb;
m_outputGainRatioCom1 = gainRatio;
}
}
else
{
changed = !qFuzzyCompare(m_outputVolumeDbCom2, valueDb);
if (changed)
{
m_outputVolumeDbCom2 = valueDb;
m_outputGainRatioCom2 = gainRatio;
}
}
}
@@ -1436,7 +1466,7 @@ namespace BlackCore
if (m_outputSampleProvider)
{
changed = m_outputSampleProvider->setGainRatio(gainRatio);
changed = m_soundcardSampleProvider->setGainRatioForTransceiver(comUnit, gainRatio);
}
m_mutexSampleProviders.unlock();
return changed;

View File

@@ -237,21 +237,21 @@ namespace BlackCore
//! Output volume in dB, [MinDbOut, MaxDbOut]dB
//! \threadsafe
//! @{
double getOutputVolumeDb() const;
Q_INVOKABLE bool setOutputVolumeDb(double valueDb);
double getOutputVolumeDb(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const;
Q_INVOKABLE bool setOutputVolumeDb(BlackMisc::Aviation::CComSystem::ComUnit comUnit, double valueDb);
//! @}
//! Gain ratio
//! \threadsafe
double getOutputGainRatio() const;
double getOutputGainRatio(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const;
//! Normalized volumes 0..100
//! \threadsafe
//! @{
int getNormalizedInputVolume() const;
int getNormalizedOutputVolume() const;
int getNormalizedOutputVolume(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const;
bool setNormalizedInputVolume(int volume);
void setNormalizedOutputVolume(int volume);
void setNormalizedOutputVolume(BlackMisc::Aviation::CComSystem::ComUnit comUnit, int volume);
//! @}
//! VU values, 0..1
@@ -412,8 +412,10 @@ namespace BlackCore
QDateTime m_startDateTimeUtc;
double m_inputVolumeDb = 0.0;
double m_outputVolumeDb = 0.0;
double m_outputGainRatio = 1.0; //!< 0dB
double m_outputVolumeDbCom1 = 0.0;
double m_outputGainRatioCom1 = 1.0; //!< 0dB
double m_outputVolumeDbCom2 = 0.0;
double m_outputGainRatioCom2 = 1.0; //!< 0dB
double m_maxDbReadingInPTTInterval = -100;
QTimer *m_voiceServerTimer = nullptr;

View File

@@ -110,7 +110,8 @@ namespace BlackCore
else if (parser.commandStartsWith("vol") && parser.countParts() > 1)
{
const int v = parser.toInt(1);
this->setVoiceOutputVolume(v);
this->setVoiceOutputVolume(CComSystem::Com1, v);
this->setVoiceOutputVolume(CComSystem::Com2, v);
return true;
}
else if (afvClient() && parser.matchesCommand(".aliased") && parser.countParts() > 1)
@@ -148,7 +149,8 @@ namespace BlackCore
if (!myself || !sApp || sApp->isShuttingDown()) { return; }
const CSettings as = m_audioSettings.getThreadLocal();
this->setVoiceOutputVolume(as.getOutVolume());
this->setVoiceOutputVolume(CComSystem::Com1, as.getOutVolumeCom1());
this->setVoiceOutputVolume(CComSystem::Com2, as.getOutVolumeCom2());
m_selcalPlayer = new CSelcalPlayer(CAudioDeviceInfo::getDefaultOutputDevice(), this);
myself->changeDeviceSettings();
@@ -419,20 +421,22 @@ namespace BlackCore
m_voiceClient->startAudio(inputDevice, outputDevice);
}
void CContextAudioBase::setVoiceOutputVolume(int volume)
void CContextAudioBase::setVoiceOutputVolume(CComSystem::ComUnit comUnit, int volume)
{
if (comUnit != CComSystem::Com1 && comUnit != CComSystem::Com2) { return; }
if (!m_voiceClient) { return; }
const bool wasMuted = this->isMuted();
volume = CSettings::fixOutVolume(volume);
const int currentVolume = m_voiceClient->getNormalizedOutputVolume();
const int currentVolume = m_voiceClient->getNormalizedOutputVolume(comUnit);
const bool changedVoiceOutput = (currentVolume != volume);
if (changedVoiceOutput)
{
// TODO: KB 2020-05 the mute handling should entirely go to AFV client!
m_voiceClient->setNormalizedOutputVolume(volume);
m_outVolumeBeforeMute = volume;
m_voiceClient->setNormalizedOutputVolume(comUnit, volume);
if (comUnit == CComSystem::Com1) { m_outVolumeBeforeMuteCom1 = volume; }
if (comUnit == CComSystem::Com2) { m_outVolumeBeforeMuteCom2 = volume; }
emit this->changedAudioVolume(volume);
if ((volume > 0 && wasMuted) || (volume < 1 && !wasMuted))
@@ -443,17 +447,22 @@ namespace BlackCore
}
CSettings as(m_audioSettings.getThreadLocal());
if (as.getOutVolume() != volume)
if (comUnit == CComSystem::Com1 && as.getOutVolumeCom1() != volume)
{
as.setOutVolume(volume);
as.setOutVolumeCom1(volume);
m_audioSettings.set(as);
}
else if (comUnit == CComSystem::Com2 && as.getOutVolumeCom2() != volume)
{
as.setOutVolumeCom2(volume);
m_audioSettings.set(as);
}
}
int CContextAudioBase::getVoiceOutputVolume() const
int CContextAudioBase::getVoiceOutputVolume(CComSystem::ComUnit comUnit) const
{
if (!m_voiceClient) { return 0; }
return m_voiceClient->getNormalizedOutputVolume();
return m_voiceClient->getNormalizedOutputVolume(comUnit);
}
void CContextAudioBase::setMute(bool muted)
@@ -463,12 +472,16 @@ namespace BlackCore
if (muted)
{
const int nv = m_voiceClient->getNormalizedOutputVolume();
m_outVolumeBeforeMute = nv;
m_outVolumeBeforeMuteCom1 = m_voiceClient->getNormalizedOutputVolume(CComSystem::Com1);
m_outVolumeBeforeMuteCom2 = m_voiceClient->getNormalizedOutputVolume(CComSystem::Com2);
}
m_voiceClient->setMuted(muted);
if (!muted) { m_voiceClient->setNormalizedOutputVolume(m_outVolumeBeforeMute); }
if (!muted)
{
m_voiceClient->setNormalizedOutputVolume(CComSystem::Com1, m_outVolumeBeforeMuteCom1);
m_voiceClient->setNormalizedOutputVolume(CComSystem::Com2, m_outVolumeBeforeMuteCom2);
}
// signal no longer need, signaled by m_voiceClient->setMuted
// emit this->changedMute(muted);
@@ -581,7 +594,8 @@ namespace BlackCore
const CSettings s = m_audioSettings.get();
const QString dir = s.getNotificationSoundDirectory();
m_notificationPlayer.updateDirectory(dir);
this->setVoiceOutputVolume(s.getOutVolume());
this->setVoiceOutputVolume(CComSystem::Com1, s.getOutVolumeCom1());
this->setVoiceOutputVolume(CComSystem::Com2, s.getOutVolumeCom2());
}
void CContextAudioBase::onChangedVoiceSettings()
@@ -593,15 +607,19 @@ namespace BlackCore
void CContextAudioBase::audioIncreaseVolume(bool enabled)
{
if (!enabled) { return; }
const int v = qRound(this->getVoiceOutputVolume() * 1.05);
this->setVoiceOutputVolume(v);
const int v1 = qRound(this->getVoiceOutputVolume(CComSystem::Com1) * 1.05);
const int v2 = qRound(this->getVoiceOutputVolume(CComSystem::Com2) * 1.05);
this->setVoiceOutputVolume(CComSystem::Com1, v1);
this->setVoiceOutputVolume(CComSystem::Com2, v2);
}
void CContextAudioBase::audioDecreaseVolume(bool enabled)
{
if (!enabled) { return; }
const int v = qRound(this->getVoiceOutputVolume() / 1.05);
this->setVoiceOutputVolume(v);
const int v1 = qRound(this->getVoiceOutputVolume(CComSystem::Com1) / 1.05);
const int v2 = qRound(this->getVoiceOutputVolume(CComSystem::Com2) / 1.05);
this->setVoiceOutputVolume(CComSystem::Com1, v1);
this->setVoiceOutputVolume(CComSystem::Com2, v2);
}
void CContextAudioBase::xCtxNetworkConnectionStatusChanged(const CConnectionStatus &from, const CConnectionStatus &to)

View File

@@ -178,8 +178,8 @@ namespace BlackCore
//! Volume
//! @{
void setVoiceOutputVolume(int volume);
int getVoiceOutputVolume() const;
void setVoiceOutputVolume(BlackMisc::Aviation::CComSystem::ComUnit comUnit, int volume);
int getVoiceOutputVolume(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const;
void setMute(bool muted);
bool isMuted() const;
//! @}
@@ -354,7 +354,8 @@ namespace BlackCore
CActionBind m_actionAudioVolumeIncrease { BlackMisc::Input::audioVolumeIncreaseHotkeyAction(), BlackMisc::Input::audioVolumeIncreaseHotkeyIcon(), this, &CContextAudioBase::audioIncreaseVolume };
CActionBind m_actionAudioVolumeDecrease { BlackMisc::Input::audioVolumeDecreaseHotkeyAction(), BlackMisc::Input::audioVolumeDecreaseHotkeyIcon(), this, &CContextAudioBase::audioDecreaseVolume };
int m_outVolumeBeforeMute = 90;
int m_outVolumeBeforeMuteCom1 = 90;
int m_outVolumeBeforeMuteCom2 = 90;
static constexpr int MinUnmuteVolume = 20; //!< minimum volume when unmuted
//! Do we use a local core

View File

@@ -156,9 +156,6 @@ namespace BlackCore
//! Own SELCAL code
virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator) = 0;
//! Output volume 0..300
virtual void setAudioOutputVolume(int outputVolume) = 0;
//! Default situation
//! \remark normally used when no driver is attached
static const BlackMisc::Aviation::CAircraftSituation &getDefaultSituation();

View File

@@ -134,13 +134,6 @@ namespace BlackCore
return false;
}
//! \copydoc IContextOwnAircraft::setAudioOutputVolume
virtual void setAudioOutputVolume(int outputVolume) override
{
Q_UNUSED(outputVolume);
logEmptyContextWarning(Q_FUNC_INFO);
}
//! \copydoc IContextOwnAircraft::toggleTransponderMode
virtual void toggleTransponderMode() override
{

View File

@@ -474,13 +474,6 @@ namespace BlackCore
return true;
}
void CContextOwnAircraft::setAudioOutputVolume(int outputVolume)
{
if (m_debugEnabled) { CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO << outputVolume; }
CContextAudioBase *audio = qobject_cast<CContextAudioBase *>(this->getIContextAudio());
if (audio) { audio->setVoiceOutputVolume(outputVolume); }
}
void CContextOwnAircraft::xCtxChangedAtcStationOnlineConnectionStatus(const CAtcStation &atcStation, bool connected)
{
Q_UNUSED(connected)

View File

@@ -176,9 +176,6 @@ namespace BlackCore
//! \copydoc IContextOwnAircraft::setTransponderMode
virtual bool setTransponderMode(BlackMisc::Aviation::CTransponder::TransponderMode mode) override;
//! \copydoc IContextOwnAircraft::setAudioOutputVolume
virtual void setAudioOutputVolume(int outputVolume) override;
//! \addtogroup swiftdotcommands
//! @{
//! <pre>

View File

@@ -132,11 +132,6 @@ namespace BlackCore
return m_dBusInterface->callDBusRet<bool>(QLatin1String("updateOwnIcaoCodes"), aircraftIcaoCode, airlineIcaoCode);
}
void CContextOwnAircraftProxy::setAudioOutputVolume(int outputVolume)
{
m_dBusInterface->callDBus(QLatin1String("setAudioOutputVolume"), outputVolume);
}
void CContextOwnAircraftProxy::toggleTransponderMode()
{
m_dBusInterface->callDBus(QLatin1String("toggleTransponderMode"));

View File

@@ -76,7 +76,6 @@ namespace BlackCore
virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const BlackMisc::CIdentifier &originator) override;
virtual bool updateOwnCallsign(const BlackMisc::Aviation::CCallsign &callsign) override;
virtual bool updateOwnIcaoCodes(const BlackMisc::Aviation::CAircraftIcaoCode &aircraftIcaoCode, const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcaoCode) override;
virtual void setAudioOutputVolume(int outputVolume) override;
virtual void toggleTransponderMode() override;
virtual bool setTransponderMode(BlackMisc::Aviation::CTransponder::TransponderMode mode) override;
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override;