mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T730, style
This commit is contained in:
committed by
Mat Sutcliffe
parent
bed49ff072
commit
e33e06b21e
@@ -29,26 +29,26 @@ namespace BlackCore
|
||||
{
|
||||
Q_ASSERT(audioFormat.channelCount() == 1);
|
||||
|
||||
mixer = new CMixingSampleProvider(this);
|
||||
crackleSoundProvider = new CResourceSoundSampleProvider(Samples::instance().crackle(), mixer);
|
||||
crackleSoundProvider->setLooping(true);
|
||||
crackleSoundProvider->setGain(0.0);
|
||||
whiteNoise = new CResourceSoundSampleProvider(Samples::instance().whiteNoise(), mixer);
|
||||
whiteNoise->setLooping(true);
|
||||
whiteNoise->setGain(0.0);
|
||||
acBusNoise = new CSawToothGenerator(400, mixer);
|
||||
audioInput = new CBufferedWaveProvider(audioFormat, mixer);
|
||||
m_mixer = new CMixingSampleProvider(this);
|
||||
m_crackleSoundProvider = new CResourceSoundSampleProvider(Samples::instance().crackle(), m_mixer);
|
||||
m_crackleSoundProvider->setLooping(true);
|
||||
m_crackleSoundProvider->setGain(0.0);
|
||||
m_whiteNoise = new CResourceSoundSampleProvider(Samples::instance().whiteNoise(), m_mixer);
|
||||
m_whiteNoise->setLooping(true);
|
||||
m_whiteNoise->setGain(0.0);
|
||||
m_acBusNoise = new CSawToothGenerator(400, m_mixer);
|
||||
m_audioInput = new CBufferedWaveProvider(audioFormat, m_mixer);
|
||||
|
||||
// Create the compressor
|
||||
simpleCompressorEffect = new CSimpleCompressorEffect(audioInput, mixer);
|
||||
simpleCompressorEffect->setMakeUpGain(-5.5);
|
||||
m_simpleCompressorEffect = new CSimpleCompressorEffect(m_audioInput, m_mixer);
|
||||
m_simpleCompressorEffect->setMakeUpGain(-5.5);
|
||||
|
||||
// Create the voice EQ
|
||||
voiceEq = new CEqualizerSampleProvider(simpleCompressorEffect, EqualizerPresets::VHFEmulation, mixer);
|
||||
m_voiceEq = new CEqualizerSampleProvider(m_simpleCompressorEffect, EqualizerPresets::VHFEmulation, m_mixer);
|
||||
|
||||
mixer->addMixerInput(whiteNoise);
|
||||
mixer->addMixerInput(acBusNoise);
|
||||
mixer->addMixerInput(voiceEq);
|
||||
m_mixer->addMixerInput(m_whiteNoise);
|
||||
m_mixer->addMixerInput(m_acBusNoise);
|
||||
m_mixer->addMixerInput(m_voiceEq);
|
||||
|
||||
m_timer.setInterval(100);
|
||||
connect(&m_timer, &QTimer::timeout, this, &CallsignSampleProvider::timerElapsed);
|
||||
@@ -56,15 +56,15 @@ namespace BlackCore
|
||||
|
||||
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();
|
||||
m_lastPacketLatch = false;
|
||||
}
|
||||
|
||||
if (m_inUse && !m_underflow && audioInput->getBufferedBytes() == 0)
|
||||
if (m_inUse && !m_underflow && m_audioInput->getBufferedBytes() == 0)
|
||||
{
|
||||
qDebug() << "[" << m_callsign << "] [Delay++]";
|
||||
CallsignDelayCache::instance().underflow(m_callsign);
|
||||
@@ -76,14 +76,12 @@ namespace BlackCore
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CallsignSampleProvider::active(const QString &callsign, const QString &aircraftType)
|
||||
{
|
||||
m_callsign = callsign;
|
||||
@@ -100,7 +98,7 @@ namespace BlackCore
|
||||
{
|
||||
int phaseDelayLength = (m_audioFormat.sampleRate() / 1000) * delayMs;
|
||||
QVector<qint16> phaseDelay(phaseDelayLength * 2, 0);
|
||||
audioInput->addSamples(phaseDelay);
|
||||
m_audioInput->addSamples(phaseDelay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +116,7 @@ namespace BlackCore
|
||||
void CallsignSampleProvider::clear()
|
||||
{
|
||||
idle();
|
||||
audioInput->clearBuffer();
|
||||
m_audioInput->clearBuffer();
|
||||
}
|
||||
|
||||
void CallsignSampleProvider::addOpusSamples(const IAudioDto &audioDto, float distanceRatio)
|
||||
@@ -126,11 +124,9 @@ namespace BlackCore
|
||||
m_distanceRatio = distanceRatio;
|
||||
|
||||
QVector<qint16> audio = decodeOpus(audioDto.audio);
|
||||
audioInput->addSamples(audio);
|
||||
m_audioInput->addSamples(audio);
|
||||
m_lastPacketLatch = audioDto.lastPacket;
|
||||
if (audioDto.lastPacket && !m_underflow)
|
||||
CallsignDelayCache::instance().success(m_callsign);
|
||||
|
||||
if (audioDto.lastPacket && !m_underflow) { CallsignDelayCache::instance().success(m_callsign); }
|
||||
m_lastSamplesAddedUtc = QDateTime::currentDateTimeUtc();
|
||||
if (!m_timer.isActive()) { m_timer.start(); }
|
||||
}
|
||||
@@ -167,25 +163,25 @@ namespace BlackCore
|
||||
{
|
||||
if (noEffects || m_bypassEffects || !m_inUse)
|
||||
{
|
||||
crackleSoundProvider->setGain(0.0);
|
||||
whiteNoise->setGain(0.0);
|
||||
acBusNoise->setGain(0.0);
|
||||
simpleCompressorEffect->setEnabled(false);
|
||||
voiceEq->setBypassEffects(true);
|
||||
m_crackleSoundProvider->setGain(0.0);
|
||||
m_whiteNoise->setGain(0.0);
|
||||
m_acBusNoise->setGain(0.0);
|
||||
m_simpleCompressorEffect->setEnabled(false);
|
||||
m_voiceEq->setBypassEffects(true);
|
||||
}
|
||||
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.20f) { crackleFactor = 0.20f; }
|
||||
if (crackleFactor < 0.00) { crackleFactor = 0.0f; }
|
||||
if (crackleFactor > 0.20) { crackleFactor = 0.20f; }
|
||||
|
||||
crackleSoundProvider->setGain(crackleFactor * 2);
|
||||
whiteNoise->setGain(whiteNoiseGainMin);
|
||||
acBusNoise->setGain(acBusGainMin);
|
||||
simpleCompressorEffect->setEnabled(true);
|
||||
voiceEq->setBypassEffects(false);
|
||||
voiceEq->setOutputGain(1.0 - crackleFactor * 3.7);
|
||||
m_crackleSoundProvider->setGain(crackleFactor * 2);
|
||||
m_whiteNoise->setGain(m_whiteNoiseGainMin);
|
||||
m_acBusNoise->setGain(m_acBusGainMin);
|
||||
m_simpleCompressorEffect->setEnabled(true);
|
||||
m_voiceEq->setBypassEffects(false);
|
||||
m_voiceEq->setOutputGain(1.0 - crackleFactor * 3.7);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,10 +69,10 @@ namespace BlackCore
|
||||
|
||||
QAudioFormat m_audioFormat;
|
||||
|
||||
const double whiteNoiseGainMin = 0.15; //0.01;
|
||||
const double acBusGainMin = 0.003; //0.002;
|
||||
const int frameCount = 960;
|
||||
const int idleTimeoutMs = 500;
|
||||
const double m_whiteNoiseGainMin = 0.15; //0.01;
|
||||
const double m_acBusGainMin = 0.003; //0.002;
|
||||
const int m_frameCount = 960;
|
||||
const int m_idleTimeoutMs = 500;
|
||||
|
||||
QString m_callsign;
|
||||
QString m_type;
|
||||
@@ -82,13 +82,13 @@ namespace BlackCore
|
||||
|
||||
float m_distanceRatio = 1.0;
|
||||
|
||||
BlackSound::SampleProvider::CMixingSampleProvider *mixer = nullptr;
|
||||
BlackSound::SampleProvider::CResourceSoundSampleProvider *crackleSoundProvider = nullptr;
|
||||
BlackSound::SampleProvider::CResourceSoundSampleProvider *whiteNoise = nullptr;
|
||||
BlackSound::SampleProvider::CSawToothGenerator *acBusNoise = nullptr;
|
||||
BlackSound::SampleProvider::CSimpleCompressorEffect *simpleCompressorEffect = nullptr;
|
||||
BlackSound::SampleProvider::CEqualizerSampleProvider *voiceEq = nullptr;
|
||||
BlackSound::SampleProvider::CBufferedWaveProvider *audioInput = nullptr;
|
||||
BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr;
|
||||
BlackSound::SampleProvider::CResourceSoundSampleProvider *m_crackleSoundProvider = nullptr;
|
||||
BlackSound::SampleProvider::CResourceSoundSampleProvider *m_whiteNoise = nullptr;
|
||||
BlackSound::SampleProvider::CSawToothGenerator *m_acBusNoise = nullptr;
|
||||
BlackSound::SampleProvider::CSimpleCompressorEffect *m_simpleCompressorEffect = nullptr;
|
||||
BlackSound::SampleProvider::CEqualizerSampleProvider *m_voiceEq = nullptr;
|
||||
BlackSound::SampleProvider::CBufferedWaveProvider *m_audioInput = nullptr;
|
||||
QTimer m_timer;
|
||||
|
||||
BlackSound::Codecs::COpusDecoder m_decoder;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <cmath>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackSound;
|
||||
using namespace BlackSound::SampleProvider;
|
||||
|
||||
namespace BlackCore
|
||||
@@ -52,8 +53,8 @@ namespace BlackCore
|
||||
qint16 maxInt = std::numeric_limits<qint16>::max();
|
||||
outputVolumeStreamArgs.PeakRaw = m_maxSampleOutput / maxInt;
|
||||
outputVolumeStreamArgs.PeakDB = static_cast<float>(20 * std::log10(outputVolumeStreamArgs.PeakRaw));
|
||||
const double db = qBound(minDb, outputVolumeStreamArgs.PeakDB, maxDb);
|
||||
double ratio = (db - minDb) / (maxDb - minDb);
|
||||
const double db = qBound(m_minDb, outputVolumeStreamArgs.PeakDB, m_maxDb);
|
||||
double ratio = (db - m_minDb) / (m_maxDb - m_minDb);
|
||||
if (ratio < 0.30) { ratio = 0.0; }
|
||||
if (ratio > 1.0) { ratio = 1.0; }
|
||||
outputVolumeStreamArgs.PeakVU = ratio;
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace BlackCore
|
||||
{
|
||||
QAudioDeviceInfo DeviceNumber;
|
||||
double PeakRaw = 0.0;
|
||||
double PeakDB = -1 * std::numeric_limits<double>::infinity();
|
||||
double PeakVU = 0.0;
|
||||
double PeakDB = -1 * std::numeric_limits<double>::infinity();
|
||||
double PeakVU = 0.0;
|
||||
};
|
||||
|
||||
//! Output buffer
|
||||
@@ -41,27 +41,29 @@ namespace BlackCore
|
||||
//! Ctor
|
||||
CAudioOutputBuffer(BlackSound::SampleProvider::ISampleProvider *sampleProvider, QObject *parent = nullptr);
|
||||
|
||||
//! Related provider
|
||||
BlackSound::SampleProvider::ISampleProvider *m_sampleProvider = nullptr;
|
||||
|
||||
//! Set the format
|
||||
void setAudioFormat(const QAudioFormat &format) { m_outputFormat = format; }
|
||||
|
||||
signals:
|
||||
//! Volume stream
|
||||
void outputVolumeStream(const OutputVolumeStreamArgs &args);
|
||||
|
||||
protected:
|
||||
//! \copydoc QIODevice::readData
|
||||
virtual qint64 readData(char *data, qint64 maxlen) override;
|
||||
|
||||
//! \copydoc QIODevice::writeData
|
||||
virtual qint64 writeData(const char *data, qint64 len) override;
|
||||
|
||||
private:
|
||||
QAudioFormat m_outputFormat;
|
||||
BlackSound::SampleProvider::ISampleProvider *m_sampleProvider = nullptr; //!< related provider
|
||||
|
||||
static constexpr int SampleCountPerEvent = 4800;
|
||||
QAudioFormat m_outputFormat;
|
||||
double m_maxSampleOutput = 0;
|
||||
int m_sampleCount = 0;
|
||||
const int SampleCountPerEvent = 4800;
|
||||
const double maxDb = 0;
|
||||
const double minDb = -40;
|
||||
const double m_maxDb = 0;
|
||||
const double m_minDb = -40;
|
||||
};
|
||||
|
||||
//! Output
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Version : 1.12
|
||||
* 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
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
|
||||
@@ -28,24 +28,30 @@ namespace BlackSound
|
||||
VHFEmulation = 1
|
||||
};
|
||||
|
||||
//! Equalizer
|
||||
class BLACKSOUND_EXPORT CEqualizerSampleProvider : public ISampleProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Ctor
|
||||
CEqualizerSampleProvider(ISampleProvider *sourceProvider, EqualizerPresets preset, QObject *parent = nullptr);
|
||||
|
||||
//! \copydoc ISampleProvider::readSamples
|
||||
virtual int readSamples(QVector<qint16> &samples, qint64 count) override;
|
||||
|
||||
//! Bypassing?
|
||||
void setBypassEffects(bool value) { m_bypass = value; }
|
||||
|
||||
//! Gain @{
|
||||
double outputGain() const;
|
||||
void setOutputGain(double outputGain);
|
||||
//! @}
|
||||
|
||||
private:
|
||||
void setupPreset(EqualizerPresets preset);
|
||||
|
||||
ISampleProvider *m_sourceProvider;
|
||||
ISampleProvider *m_sourceProvider = nullptr;
|
||||
|
||||
int m_channels = 1;
|
||||
bool m_bypass = false;
|
||||
|
||||
@@ -24,14 +24,14 @@ namespace BlackSound
|
||||
{
|
||||
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++)
|
||||
{
|
||||
samples[n] *= m_volume;
|
||||
samples[n] = static_cast<qint16>(qRound(samples[n] * m_volume));
|
||||
}
|
||||
}
|
||||
return samplesRead;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -27,16 +27,19 @@ namespace BlackSound
|
||||
//! Noise generator
|
||||
CVolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent = nullptr);
|
||||
|
||||
//! \copydoc ISampleProvider::readSamples
|
||||
virtual int readSamples(QVector<qint16> &samples, qint64 count) override;
|
||||
|
||||
//! Volume @{
|
||||
double volume() const { return m_volume; }
|
||||
void setVolume(double volume) { m_volume = volume; }
|
||||
//! @}
|
||||
|
||||
private:
|
||||
ISampleProvider *m_sourceProvider = nullptr;
|
||||
double m_volume = 1.0;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -57,8 +57,8 @@ namespace BlackSound
|
||||
|
||||
bool CWavFile::open(const QString &fileName)
|
||||
{
|
||||
close();
|
||||
setFileName(fileName);
|
||||
this->close();
|
||||
this->setFileName(fileName);
|
||||
return QFile::open(QIODevice::ReadOnly) && readHeader();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user