[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

@@ -29,20 +29,20 @@ namespace BlackSound
int CVolumeSampleProvider::readSamples(QVector<float> &samples, qint64 count)
{
const int samplesRead = m_sourceProvider->readSamples(samples, count);
if (!qFuzzyCompare(m_volume, 1.0))
if (!qFuzzyCompare(m_gainRatio, 1.0))
{
for (int n = 0; n < samplesRead; n++)
{
samples[n] = static_cast<float>(m_volume * samples[n]);
samples[n] = static_cast<float>(m_gainRatio * samples[n]);
}
}
return samplesRead;
}
bool CVolumeSampleProvider::setVolume(double volume)
bool CVolumeSampleProvider::setGainRatio(double volume)
{
const bool changed = !qFuzzyCompare(m_volume, volume);
if (changed) { m_volume = volume; }
const bool changed = !qFuzzyCompare(m_gainRatio, volume);
if (changed) { m_gainRatio = volume; }
return changed;
}
} // ns

View File

@@ -30,14 +30,20 @@ namespace BlackSound
//! \copydoc ISampleProvider::readSamples
virtual int readSamples(QVector<float> &samples, qint64 count) override;
//! Volume @{
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);
private:
ISampleProvider *m_sourceProvider = nullptr;
double m_volume = 1.0;
double m_gainRatio = 1.0;
};
} // ns
} // ns