mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
[AFV] Ref T730, improved volume handling
* for the asymmetric output volume -60/18dB, make sure that normalized 50 means 0dB * slider is centered * return value if value for volume was changed
This commit is contained in:
@@ -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; }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<TransceiverDto> newTransceivers { transceiverCom1, transceiverCom2 };
|
||||
QVector<TransceiverDto> newEnabledTransceivers;
|
||||
QVector<TxTransceiverDto> 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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user