Implement VolumeSampleProvider to gain in and output

fixup! Implement VolumeSampleProvider to gain in and output
This commit is contained in:
Roland Rossgotterer
2019-09-20 21:46:51 +02:00
committed by Mat Sutcliffe
parent 8b1fb1baca
commit 8d1eea25b1
6 changed files with 119 additions and 31 deletions

View File

@@ -76,12 +76,12 @@ namespace BlackCore
m_opusBytesEncoded = opusBytesEncoded;
}
float Input::volume() const
double Input::volume() const
{
return m_volume;
}
void Input::setVolume(float volume)
void Input::setVolume(double volume)
{
m_volume = volume;
}
@@ -132,18 +132,24 @@ namespace BlackCore
{
const QVector<qint16> samples = convertBytesTo16BitPCM(frame);
int value = 0;
for (qint16 &sample : samples)
{
value = sample * m_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();
samples = static_cast<qint16>(value);
sampleInput = qAbs(sampleInput);
m_maxSampleInput = qMax(qAbs(sampleInput), m_maxSampleInput);
}
int length;
QByteArray encodedBuffer = m_encoder.encode(samples, samples.size(), &length);
m_opusBytesEncoded += length;
for (const qint16 sample : samples)
{
qint16 sampleInput = sample;
sampleInput = qAbs(sampleInput);
if (sampleInput > m_maxSampleInput)
m_maxSampleInput = sampleInput;
}
m_sampleCount += samples.size();
if (m_sampleCount >= c_sampleCountPerEvent)
{

View File

@@ -74,8 +74,8 @@ namespace BlackCore
int opusBytesEncoded() const;
void setOpusBytesEncoded(int opusBytesEncoded);
float volume() const;
void setVolume(float volume);
double volume() const;
void setVolume(double volume);
void start(const QAudioDeviceInfo &inputDevice);
void stop();
@@ -95,9 +95,9 @@ namespace BlackCore
bool m_started = false;
int m_opusBytesEncoded = 0;
float m_volume = 1.0f;
double m_volume = 1.0;
int m_sampleCount = 0;
float m_maxSampleInput = 0;
qint16 m_maxSampleInput = 0;
const int c_sampleCountPerEvent = 4800;
const float maxDb = 0;