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

@@ -122,9 +122,10 @@ namespace BlackCore
soundcardSampleProvider = new SoundcardSampleProvider(c_sampleRate, transceiverIDs, this);
connect(soundcardSampleProvider, &SoundcardSampleProvider::receivingCallsignsChanged, this, &AFVClient::receivingCallsignsChanged);
// TODO outputSampleProvider = new VolumeSampleProvider(soundcardSampleProvider);
outputSampleProvider = new VolumeSampleProvider(soundcardSampleProvider, this);
outputSampleProvider->setVolume(m_outputVolume);
m_output->start(outputDevice, soundcardSampleProvider);
m_output->start(outputDevice, outputSampleProvider);
m_input->start(inputDevice);
m_startDateTimeUtc = QDateTime::currentDateTimeUtc();
@@ -140,7 +141,8 @@ namespace BlackCore
soundcardSampleProvider = new SoundcardSampleProvider(c_sampleRate, { 0, 1 }, this);
connect(soundcardSampleProvider, &SoundcardSampleProvider::receivingCallsignsChanged, this, &AFVClient::receivingCallsignsChanged);
// TODO outputSampleProvider = new VolumeSampleProvider(soundcardSampleProvider);
outputSampleProvider = new VolumeSampleProvider(soundcardSampleProvider, this);
outputSampleProvider->setVolume(m_outputVolume);
QAudioDeviceInfo inputDevice = QAudioDeviceInfo::defaultInputDevice();
for (const auto &device : QAudioDeviceInfo::availableDevices(QAudio::AudioInput))
@@ -162,7 +164,7 @@ namespace BlackCore
}
}
m_output->start(outputDevice, soundcardSampleProvider);
m_output->start(outputDevice, outputSampleProvider);
m_input->start(inputDevice);
m_startDateTimeUtc = QDateTime::currentDateTimeUtc();
@@ -296,12 +298,12 @@ namespace BlackCore
qDebug() << "PTT:" << active;
}
void AFVClient::setInputVolumeDb(float value)
void AFVClient::setInputVolumeDb(double value)
{
if (value > 18) { value = 18; }
if (value < -18) { value = -18; }
m_inputVolumeDb = value;
// TODO input.Volume = (float)System.Math.Pow(10, value / 20);
m_input->setVolume(qPow(10, value / 20));
}
void AFVClient::opusDataAvailable(const OpusDataAvailableArgs &args)
@@ -404,17 +406,20 @@ namespace BlackCore
updateTransceivers();
}
float AFVClient::getOutputVolume() const
float AFVClient::getOutputVolumeDb() const
{
return m_outputVolume;
}
void AFVClient::setOutputVolume(float outputVolume)
void AFVClient::setOutputVolumeDb(double outputVolume)
{
if (outputVolume > 18) { m_outputVolume = 18; }
if (outputVolume < -60) { m_outputVolume = -60; }
// m_outputVolume = (float)System.Math.Pow(10, value / 20);
// TODO outputSampleProvider.Volume = outputVolume;
m_outputVolume = qPow(10, m_outputVolume / 20);
if (outputSampleProvider)
{
outputSampleProvider->setVolume(outputVolume);
}
}
AFVClient::ConnectionStatus AFVClient::getConnectionStatus() const

View File

@@ -19,6 +19,7 @@
#include "blackcore/blackcoreexport.h"
#include "blackcore/context/contextownaircraft.h"
#include "blacksound/sampleprovider/volumesampleprovider.h"
#include <QAudioDeviceInfo>
#include <QDateTime>
@@ -89,15 +90,15 @@ namespace BlackCore
Q_INVOKABLE void setLoopBack(bool on) { m_loopbackOn = on; }
float inputVolumeDb() const
double inputVolumeDb() const
{
return m_inputVolumeDb;
}
void setInputVolumeDb(float value);
void setInputVolumeDb(double value);
float getOutputVolume() const;
void setOutputVolume(float outputVolume);
float getOutputVolumeDb() const;
void setOutputVolumeDb(double outputVolume);
float getInputVolumePeakVU() const { return m_inputVolumeStream.PeakVU; }
float getOutputVolumePeakVU() const { return m_outputVolumeStream.PeakVU; }
@@ -136,7 +137,7 @@ namespace BlackCore
Audio::Output *m_output = nullptr;
Audio::SoundcardSampleProvider *soundcardSampleProvider = nullptr;
// TODO VolumeSampleProvider outputSampleProvider;
VolumeSampleProvider *outputSampleProvider = nullptr;
bool m_transmit = false;
bool m_transmitHistory = false;
@@ -145,8 +146,8 @@ namespace BlackCore
bool m_isStarted = false;
QDateTime m_startDateTimeUtc;
float m_inputVolumeDb;
float m_outputVolume = 1;
double m_inputVolumeDb;
double m_outputVolume = 1.0;
double m_maxDbReadingInPTTInterval = -100;