[AFV] Renamed to "setGainRatio" as the value does not represent a volume, but a multiplier

This commit is contained in:
Klaus Basan
2020-04-24 00:49:48 +02:00
committed by Mat Sutcliffe
parent 8848faadfa
commit f2e0e7b22e
6 changed files with 53 additions and 33 deletions

View File

@@ -79,10 +79,10 @@ namespace BlackCore
m_encoder.setBitRate(16 * 1024);
}
bool CInput::setVolume(double volume)
bool CInput::setGainRatio(double gainRatio)
{
if (qFuzzyCompare(m_volume, volume)) { return false; }
m_volume = volume;
if (qFuzzyCompare(m_gainRatio, gainRatio)) { return false; }
m_gainRatio = gainRatio;
return true;
}
@@ -176,9 +176,10 @@ namespace BlackCore
samples = convertFromStereoToMono(samples);
}
const double volume = m_gainRatio;
for (qint16 &sample : samples)
{
int value = qRound(sample * m_volume);
int value = qRound(sample * volume);
if (value > std::numeric_limits<qint16>::max()) value = std::numeric_limits<qint16>::max();
if (value < std::numeric_limits<qint16>::min()) value = std::numeric_limits<qint16>::min();
sample = static_cast<qint16>(value);

View File

@@ -101,10 +101,16 @@ namespace BlackCore
void setOpusBytesEncoded(int opusBytesEncoded) { m_opusBytesEncoded = opusBytesEncoded; }
//! @}
//! Volume 0..1 @{
double volume() const { return m_volume; }
bool setVolume(double volume);
//! Gain ratio, value a amplitude need to be multiplied with
//! \see http://www.sengpielaudio.com/calculator-amplification.htm
//! \remark gain ratio is voltage ratio/or amplitude ratio, something between 0.001-7.95 for -60dB to 80dB
//! @{
double getGainRatio() const { return m_gainRatio; }
bool setGainRatio(double gainRatio);
//! @}
// those used to be the original function names
// double volume() const { return m_volume; }
// bool setVolume(double volume);
/* disabled as not needed
//! The device's volume 0..1 @{
@@ -146,7 +152,7 @@ namespace BlackCore
bool m_started = false;
int m_opusBytesEncoded = 0;
int m_sampleCount = 0;
double m_volume = 1.0;
double m_gainRatio = 1.0;
qint16 m_maxSampleInput = 0.0;
const int SampleCountPerEvent = 4800;