Ref T730, style

This commit is contained in:
Klaus Basan
2019-09-28 19:26:24 +02:00
committed by Mat Sutcliffe
parent bed49ff072
commit e33e06b21e
9 changed files with 81 additions and 73 deletions

View File

@@ -29,26 +29,26 @@ namespace BlackCore
{ {
Q_ASSERT(audioFormat.channelCount() == 1); Q_ASSERT(audioFormat.channelCount() == 1);
mixer = new CMixingSampleProvider(this); m_mixer = new CMixingSampleProvider(this);
crackleSoundProvider = new CResourceSoundSampleProvider(Samples::instance().crackle(), mixer); m_crackleSoundProvider = new CResourceSoundSampleProvider(Samples::instance().crackle(), m_mixer);
crackleSoundProvider->setLooping(true); m_crackleSoundProvider->setLooping(true);
crackleSoundProvider->setGain(0.0); m_crackleSoundProvider->setGain(0.0);
whiteNoise = new CResourceSoundSampleProvider(Samples::instance().whiteNoise(), mixer); m_whiteNoise = new CResourceSoundSampleProvider(Samples::instance().whiteNoise(), m_mixer);
whiteNoise->setLooping(true); m_whiteNoise->setLooping(true);
whiteNoise->setGain(0.0); m_whiteNoise->setGain(0.0);
acBusNoise = new CSawToothGenerator(400, mixer); m_acBusNoise = new CSawToothGenerator(400, m_mixer);
audioInput = new CBufferedWaveProvider(audioFormat, mixer); m_audioInput = new CBufferedWaveProvider(audioFormat, m_mixer);
// Create the compressor // Create the compressor
simpleCompressorEffect = new CSimpleCompressorEffect(audioInput, mixer); m_simpleCompressorEffect = new CSimpleCompressorEffect(m_audioInput, m_mixer);
simpleCompressorEffect->setMakeUpGain(-5.5); m_simpleCompressorEffect->setMakeUpGain(-5.5);
// Create the voice EQ // Create the voice EQ
voiceEq = new CEqualizerSampleProvider(simpleCompressorEffect, EqualizerPresets::VHFEmulation, mixer); m_voiceEq = new CEqualizerSampleProvider(m_simpleCompressorEffect, EqualizerPresets::VHFEmulation, m_mixer);
mixer->addMixerInput(whiteNoise); m_mixer->addMixerInput(m_whiteNoise);
mixer->addMixerInput(acBusNoise); m_mixer->addMixerInput(m_acBusNoise);
mixer->addMixerInput(voiceEq); m_mixer->addMixerInput(m_voiceEq);
m_timer.setInterval(100); m_timer.setInterval(100);
connect(&m_timer, &QTimer::timeout, this, &CallsignSampleProvider::timerElapsed); connect(&m_timer, &QTimer::timeout, this, &CallsignSampleProvider::timerElapsed);
@@ -56,15 +56,15 @@ namespace BlackCore
int CallsignSampleProvider::readSamples(QVector<qint16> &samples, qint64 count) int CallsignSampleProvider::readSamples(QVector<qint16> &samples, qint64 count)
{ {
int noOfSamples = mixer->readSamples(samples, count); int noOfSamples = m_mixer->readSamples(samples, count);
if (m_inUse && m_lastPacketLatch && audioInput->getBufferedBytes() == 0) if (m_inUse && m_lastPacketLatch && m_audioInput->getBufferedBytes() == 0)
{ {
idle(); idle();
m_lastPacketLatch = false; m_lastPacketLatch = false;
} }
if (m_inUse && !m_underflow && audioInput->getBufferedBytes() == 0) if (m_inUse && !m_underflow && m_audioInput->getBufferedBytes() == 0)
{ {
qDebug() << "[" << m_callsign << "] [Delay++]"; qDebug() << "[" << m_callsign << "] [Delay++]";
CallsignDelayCache::instance().underflow(m_callsign); CallsignDelayCache::instance().underflow(m_callsign);
@@ -76,14 +76,12 @@ namespace BlackCore
void CallsignSampleProvider::timerElapsed() void CallsignSampleProvider::timerElapsed()
{ {
if (m_inUse && audioInput->getBufferedBytes() == 0 && m_lastSamplesAddedUtc.msecsTo(QDateTime::currentDateTimeUtc()) > idleTimeoutMs) if (m_inUse && m_audioInput->getBufferedBytes() == 0 && m_lastSamplesAddedUtc.msecsTo(QDateTime::currentDateTimeUtc()) > m_idleTimeoutMs)
{ {
idle(); idle();
} }
} }
void CallsignSampleProvider::active(const QString &callsign, const QString &aircraftType) void CallsignSampleProvider::active(const QString &callsign, const QString &aircraftType)
{ {
m_callsign = callsign; m_callsign = callsign;
@@ -100,7 +98,7 @@ namespace BlackCore
{ {
int phaseDelayLength = (m_audioFormat.sampleRate() / 1000) * delayMs; int phaseDelayLength = (m_audioFormat.sampleRate() / 1000) * delayMs;
QVector<qint16> phaseDelay(phaseDelayLength * 2, 0); QVector<qint16> phaseDelay(phaseDelayLength * 2, 0);
audioInput->addSamples(phaseDelay); m_audioInput->addSamples(phaseDelay);
} }
} }
@@ -118,7 +116,7 @@ namespace BlackCore
void CallsignSampleProvider::clear() void CallsignSampleProvider::clear()
{ {
idle(); idle();
audioInput->clearBuffer(); m_audioInput->clearBuffer();
} }
void CallsignSampleProvider::addOpusSamples(const IAudioDto &audioDto, float distanceRatio) void CallsignSampleProvider::addOpusSamples(const IAudioDto &audioDto, float distanceRatio)
@@ -126,11 +124,9 @@ namespace BlackCore
m_distanceRatio = distanceRatio; m_distanceRatio = distanceRatio;
QVector<qint16> audio = decodeOpus(audioDto.audio); QVector<qint16> audio = decodeOpus(audioDto.audio);
audioInput->addSamples(audio); m_audioInput->addSamples(audio);
m_lastPacketLatch = audioDto.lastPacket; m_lastPacketLatch = audioDto.lastPacket;
if (audioDto.lastPacket && !m_underflow) if (audioDto.lastPacket && !m_underflow) { CallsignDelayCache::instance().success(m_callsign); }
CallsignDelayCache::instance().success(m_callsign);
m_lastSamplesAddedUtc = QDateTime::currentDateTimeUtc(); m_lastSamplesAddedUtc = QDateTime::currentDateTimeUtc();
if (!m_timer.isActive()) { m_timer.start(); } if (!m_timer.isActive()) { m_timer.start(); }
} }
@@ -167,25 +163,25 @@ namespace BlackCore
{ {
if (noEffects || m_bypassEffects || !m_inUse) if (noEffects || m_bypassEffects || !m_inUse)
{ {
crackleSoundProvider->setGain(0.0); m_crackleSoundProvider->setGain(0.0);
whiteNoise->setGain(0.0); m_whiteNoise->setGain(0.0);
acBusNoise->setGain(0.0); m_acBusNoise->setGain(0.0);
simpleCompressorEffect->setEnabled(false); m_simpleCompressorEffect->setEnabled(false);
voiceEq->setBypassEffects(true); m_voiceEq->setBypassEffects(true);
} }
else else
{ {
float crackleFactor = (float)(((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350) - 0.00776652); double crackleFactor = static_cast<double>(((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350) - 0.00776652);
if (crackleFactor < 0.0f) { crackleFactor = 0.0f; } if (crackleFactor < 0.00) { crackleFactor = 0.0f; }
if (crackleFactor > 0.20f) { crackleFactor = 0.20f; } if (crackleFactor > 0.20) { crackleFactor = 0.20f; }
crackleSoundProvider->setGain(crackleFactor * 2); m_crackleSoundProvider->setGain(crackleFactor * 2);
whiteNoise->setGain(whiteNoiseGainMin); m_whiteNoise->setGain(m_whiteNoiseGainMin);
acBusNoise->setGain(acBusGainMin); m_acBusNoise->setGain(m_acBusGainMin);
simpleCompressorEffect->setEnabled(true); m_simpleCompressorEffect->setEnabled(true);
voiceEq->setBypassEffects(false); m_voiceEq->setBypassEffects(false);
voiceEq->setOutputGain(1.0 - crackleFactor * 3.7); m_voiceEq->setOutputGain(1.0 - crackleFactor * 3.7);
} }
} }

View File

@@ -69,10 +69,10 @@ namespace BlackCore
QAudioFormat m_audioFormat; QAudioFormat m_audioFormat;
const double whiteNoiseGainMin = 0.15; //0.01; const double m_whiteNoiseGainMin = 0.15; //0.01;
const double acBusGainMin = 0.003; //0.002; const double m_acBusGainMin = 0.003; //0.002;
const int frameCount = 960; const int m_frameCount = 960;
const int idleTimeoutMs = 500; const int m_idleTimeoutMs = 500;
QString m_callsign; QString m_callsign;
QString m_type; QString m_type;
@@ -82,13 +82,13 @@ namespace BlackCore
float m_distanceRatio = 1.0; float m_distanceRatio = 1.0;
BlackSound::SampleProvider::CMixingSampleProvider *mixer = nullptr; BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr;
BlackSound::SampleProvider::CResourceSoundSampleProvider *crackleSoundProvider = nullptr; BlackSound::SampleProvider::CResourceSoundSampleProvider *m_crackleSoundProvider = nullptr;
BlackSound::SampleProvider::CResourceSoundSampleProvider *whiteNoise = nullptr; BlackSound::SampleProvider::CResourceSoundSampleProvider *m_whiteNoise = nullptr;
BlackSound::SampleProvider::CSawToothGenerator *acBusNoise = nullptr; BlackSound::SampleProvider::CSawToothGenerator *m_acBusNoise = nullptr;
BlackSound::SampleProvider::CSimpleCompressorEffect *simpleCompressorEffect = nullptr; BlackSound::SampleProvider::CSimpleCompressorEffect *m_simpleCompressorEffect = nullptr;
BlackSound::SampleProvider::CEqualizerSampleProvider *voiceEq = nullptr; BlackSound::SampleProvider::CEqualizerSampleProvider *m_voiceEq = nullptr;
BlackSound::SampleProvider::CBufferedWaveProvider *audioInput = nullptr; BlackSound::SampleProvider::CBufferedWaveProvider *m_audioInput = nullptr;
QTimer m_timer; QTimer m_timer;
BlackSound::Codecs::COpusDecoder m_decoder; BlackSound::Codecs::COpusDecoder m_decoder;

View File

@@ -17,6 +17,7 @@
#include <cmath> #include <cmath>
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackSound;
using namespace BlackSound::SampleProvider; using namespace BlackSound::SampleProvider;
namespace BlackCore namespace BlackCore
@@ -52,8 +53,8 @@ namespace BlackCore
qint16 maxInt = std::numeric_limits<qint16>::max(); qint16 maxInt = std::numeric_limits<qint16>::max();
outputVolumeStreamArgs.PeakRaw = m_maxSampleOutput / maxInt; outputVolumeStreamArgs.PeakRaw = m_maxSampleOutput / maxInt;
outputVolumeStreamArgs.PeakDB = static_cast<float>(20 * std::log10(outputVolumeStreamArgs.PeakRaw)); outputVolumeStreamArgs.PeakDB = static_cast<float>(20 * std::log10(outputVolumeStreamArgs.PeakRaw));
const double db = qBound(minDb, outputVolumeStreamArgs.PeakDB, maxDb); const double db = qBound(m_minDb, outputVolumeStreamArgs.PeakDB, m_maxDb);
double ratio = (db - minDb) / (maxDb - minDb); double ratio = (db - m_minDb) / (m_maxDb - m_minDb);
if (ratio < 0.30) { ratio = 0.0; } if (ratio < 0.30) { ratio = 0.0; }
if (ratio > 1.0) { ratio = 1.0; } if (ratio > 1.0) { ratio = 1.0; }
outputVolumeStreamArgs.PeakVU = ratio; outputVolumeStreamArgs.PeakVU = ratio;

View File

@@ -28,8 +28,8 @@ namespace BlackCore
{ {
QAudioDeviceInfo DeviceNumber; QAudioDeviceInfo DeviceNumber;
double PeakRaw = 0.0; double PeakRaw = 0.0;
double PeakDB = -1 * std::numeric_limits<double>::infinity(); double PeakDB = -1 * std::numeric_limits<double>::infinity();
double PeakVU = 0.0; double PeakVU = 0.0;
}; };
//! Output buffer //! Output buffer
@@ -41,27 +41,29 @@ namespace BlackCore
//! Ctor //! Ctor
CAudioOutputBuffer(BlackSound::SampleProvider::ISampleProvider *sampleProvider, QObject *parent = nullptr); CAudioOutputBuffer(BlackSound::SampleProvider::ISampleProvider *sampleProvider, QObject *parent = nullptr);
//! Related provider
BlackSound::SampleProvider::ISampleProvider *m_sampleProvider = nullptr;
//! Set the format //! Set the format
void setAudioFormat(const QAudioFormat &format) { m_outputFormat = format; } void setAudioFormat(const QAudioFormat &format) { m_outputFormat = format; }
signals: signals:
//! Volume stream
void outputVolumeStream(const OutputVolumeStreamArgs &args); void outputVolumeStream(const OutputVolumeStreamArgs &args);
protected: protected:
//! \copydoc QIODevice::readData
virtual qint64 readData(char *data, qint64 maxlen) override; virtual qint64 readData(char *data, qint64 maxlen) override;
//! \copydoc QIODevice::writeData
virtual qint64 writeData(const char *data, qint64 len) override; virtual qint64 writeData(const char *data, qint64 len) override;
private: private:
QAudioFormat m_outputFormat; BlackSound::SampleProvider::ISampleProvider *m_sampleProvider = nullptr; //!< related provider
static constexpr int SampleCountPerEvent = 4800;
QAudioFormat m_outputFormat;
double m_maxSampleOutput = 0; double m_maxSampleOutput = 0;
int m_sampleCount = 0; int m_sampleCount = 0;
const int SampleCountPerEvent = 4800; const double m_maxDb = 0;
const double maxDb = 0; const double m_minDb = -40;
const double minDb = -40;
}; };
//! Output //! Output

View File

@@ -6,7 +6,7 @@
* Version : 1.12 * Version : 1.12
* Implements : void SimpleLimit::process( double &in1, double &in2 ) * Implements : void SimpleLimit::process( double &in1, double &in2 )
* *
* © 2006, ChunkWare Music Software, OPEN-SOURCE * 2006, ChunkWare Music Software, OPEN-SOURCE
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), * copy of this software and associated documentation files (the "Software"),

View File

@@ -28,24 +28,30 @@ namespace BlackSound
VHFEmulation = 1 VHFEmulation = 1
}; };
//! Equalizer
class BLACKSOUND_EXPORT CEqualizerSampleProvider : public ISampleProvider class BLACKSOUND_EXPORT CEqualizerSampleProvider : public ISampleProvider
{ {
Q_OBJECT Q_OBJECT
public: public:
//! Ctor
CEqualizerSampleProvider(ISampleProvider *sourceProvider, EqualizerPresets preset, QObject *parent = nullptr); CEqualizerSampleProvider(ISampleProvider *sourceProvider, EqualizerPresets preset, QObject *parent = nullptr);
//! \copydoc ISampleProvider::readSamples
virtual int readSamples(QVector<qint16> &samples, qint64 count) override; virtual int readSamples(QVector<qint16> &samples, qint64 count) override;
//! Bypassing?
void setBypassEffects(bool value) { m_bypass = value; } void setBypassEffects(bool value) { m_bypass = value; }
//! Gain @{
double outputGain() const; double outputGain() const;
void setOutputGain(double outputGain); void setOutputGain(double outputGain);
//! @}
private: private:
void setupPreset(EqualizerPresets preset); void setupPreset(EqualizerPresets preset);
ISampleProvider *m_sourceProvider; ISampleProvider *m_sourceProvider = nullptr;
int m_channels = 1; int m_channels = 1;
bool m_bypass = false; bool m_bypass = false;

View File

@@ -24,14 +24,14 @@ namespace BlackSound
{ {
int samplesRead = m_sourceProvider->readSamples(samples, count); int samplesRead = m_sourceProvider->readSamples(samples, count);
if (! qFuzzyCompare(m_volume, 1.0)) if (!qFuzzyCompare(m_volume, 1.0))
{ {
for (int n = 0; n < samplesRead; n++) for (int n = 0; n < samplesRead; n++)
{ {
samples[n] *= m_volume; samples[n] = static_cast<qint16>(qRound(samples[n] * m_volume));
} }
} }
return samplesRead; return samplesRead;
} }
} } // ns
} } // ns

View File

@@ -27,16 +27,19 @@ namespace BlackSound
//! Noise generator //! Noise generator
CVolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent = nullptr); CVolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent = nullptr);
//! \copydoc ISampleProvider::readSamples
virtual int readSamples(QVector<qint16> &samples, qint64 count) override; virtual int readSamples(QVector<qint16> &samples, qint64 count) override;
//! Volume @{
double volume() const { return m_volume; } double volume() const { return m_volume; }
void setVolume(double volume) { m_volume = volume; } void setVolume(double volume) { m_volume = volume; }
//! @}
private: private:
ISampleProvider *m_sourceProvider = nullptr; ISampleProvider *m_sourceProvider = nullptr;
double m_volume = 1.0; double m_volume = 1.0;
}; };
} } // ns
} } // ns
#endif // guard #endif // guard

View File

@@ -57,8 +57,8 @@ namespace BlackSound
bool CWavFile::open(const QString &fileName) bool CWavFile::open(const QString &fileName)
{ {
close(); this->close();
setFileName(fileName); this->setFileName(fileName);
return QFile::open(QIODevice::ReadOnly) && readHeader(); return QFile::open(QIODevice::ReadOnly) && readHeader();
} }