Ref T730, Ref T739 avoid timer stopping issue during shutdown

* use timer with parent
* avoid QObject::~QObject: Timers cannot be stopped from another thread
* see https://discordapp.com/channels/539048679160676382/623947987822837779/630521007056224286
This commit is contained in:
Klaus Basan
2019-10-07 18:07:14 +02:00
committed by Mat Sutcliffe
parent b0f1f5fae4
commit 713d2ee626
4 changed files with 32 additions and 23 deletions

View File

@@ -13,6 +13,7 @@
#include "blacksound/sampleprovider/samples.h"
#include "blacksound/audioutilities.h"
#include "blackcore/afv/audio/receiversampleprovider.h"
#include <QtMath>
#include <QDebug>
@@ -32,6 +33,7 @@ namespace BlackCore
{
Q_ASSERT(audioFormat.channelCount() == 1);
this->setObjectName("CallsignSampleProvider");
m_mixer = new CMixingSampleProvider(this);
m_crackleSoundProvider = new CResourceSoundSampleProvider(Samples::instance().crackle(), m_mixer);
m_crackleSoundProvider->setLooping(true);
@@ -57,8 +59,11 @@ namespace BlackCore
m_mixer->addMixerInput(m_hfWhiteNoise);
m_mixer->addMixerInput(m_voiceEq);
m_timer.setInterval(100);
connect(&m_timer, &QTimer::timeout, this, &CallsignSampleProvider::timerElapsed);
m_timer = new QTimer(this);
m_timer->setObjectName(this->objectName() + "m_timer");
m_timer->setInterval(100);
connect(m_timer, &QTimer::timeout, this, &CallsignSampleProvider::timerElapsed);
}
int CallsignSampleProvider::readSamples(QVector<float> &samples, qint64 count)
@@ -136,7 +141,7 @@ namespace BlackCore
m_lastPacketLatch = audioDto.lastPacket;
if (audioDto.lastPacket && !m_underflow) { CallsignDelayCache::instance().success(m_callsign); }
m_lastSamplesAddedUtc = QDateTime::currentDateTimeUtc();
if (!m_timer.isActive()) { m_timer.start(); }
if (!m_timer->isActive()) { m_timer->start(); }
}
void CallsignSampleProvider::addSilentSamples(const IAudioDto &audioDto)
@@ -148,16 +153,16 @@ namespace BlackCore
m_lastPacketLatch = audioDto.lastPacket;
m_lastSamplesAddedUtc = QDateTime::currentDateTimeUtc();
if (!m_timer.isActive()) { m_timer.start(); }
if (!m_timer->isActive()) { m_timer->start(); }
}
void CallsignSampleProvider::idle()
{
m_timer.stop();
m_timer->stop();
m_inUse = false;
setEffects();
m_callsign = QString();
m_type = QString();
m_callsign.clear();
m_type.clear();
}
QVector<qint16> CallsignSampleProvider::decodeOpus(const QByteArray &opusData)
@@ -184,7 +189,7 @@ namespace BlackCore
{
double crackleFactor = (((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350.0) - 0.00776652);
if (crackleFactor < 0.0f) { crackleFactor = 0.0f; }
if (crackleFactor < 0.0f) { crackleFactor = 0.00f; }
if (crackleFactor > 0.20f) { crackleFactor = 0.20f; }
m_hfWhiteNoise->setGain(m_hfWhiteNoiseGainMin);
@@ -198,7 +203,7 @@ namespace BlackCore
{
double crackleFactor = (((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350.0) - 0.00776652);
if (crackleFactor < 0.0) { crackleFactor = 0.0; }
if (crackleFactor < 0.0) { crackleFactor = 0.0; }
if (crackleFactor > 0.20) { crackleFactor = 0.20; }
m_crackleSoundProvider->setGain(crackleFactor * 2);

View File

@@ -81,10 +81,8 @@ namespace BlackCore
QString m_type;
bool m_inUse = false;
bool m_bypassEffects = false;
bool m_bypassEffects = false;
float m_distanceRatio = 1.0;
const CReceiverSampleProvider *m_receiver = nullptr;
BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr;
BlackSound::SampleProvider::CResourceSoundSampleProvider *m_crackleSoundProvider = nullptr;
@@ -94,7 +92,7 @@ namespace BlackCore
BlackSound::SampleProvider::CSimpleCompressorEffect *m_simpleCompressorEffect = nullptr;
BlackSound::SampleProvider::CEqualizerSampleProvider *m_voiceEq = nullptr;
BlackSound::SampleProvider::CBufferedWaveProvider *m_audioInput = nullptr;
QTimer m_timer;
QTimer *m_timer = nullptr;
BlackSound::Codecs::COpusDecoder m_decoder;
bool m_lastPacketLatch = false;

View File

@@ -17,14 +17,18 @@ namespace BlackSound
ISampleProvider(parent),
m_sourceStream(source)
{
this->setObjectName("CSimpleCompressorEffect");
m_timer = new QTimer(this);
m_timer->setObjectName(this->objectName() + ":m_timer");
m_simpleCompressor.setAttack(5.0);
m_simpleCompressor.setRelease(10.0);
m_simpleCompressor.setSampleRate(48000.0);
m_simpleCompressor.setThresh(16.0);
m_simpleCompressor.setRatio(6.0);
m_simpleCompressor.setMakeUpGain(16.0);
m_timer.start(3000);
m_timer->start(3000);
}
int CSimpleCompressorEffect::readSamples(QVector<float> &samples, qint64 count)
@@ -33,14 +37,16 @@ namespace BlackSound
if (m_enabled)
{
for (int sample = 0; sample < samplesRead; sample += channels)
for (int sample = 0; sample < samplesRead; sample += m_channels)
{
double in1 = samples.at(sample);
double in2 = (channels == 1) ? 0 : samples.at(sample + 1);
double in2 = (m_channels == 1) ? 0 : samples.at(sample + 1);
m_simpleCompressor.process(in1, in2);
samples[sample] = in1;
if (channels > 1)
samples[sample + 1] = in2;
samples[sample] = static_cast<float>(in1);
if (m_channels > 1)
{
samples[sample + 1] = static_cast<float>(in2);
}
}
}
return samplesRead;

View File

@@ -41,11 +41,11 @@ namespace BlackSound
void setMakeUpGain(double gain);
private:
QTimer m_timer;
QTimer *m_timer = nullptr;
ISampleProvider *m_sourceStream = nullptr;
bool m_enabled = true;
bool m_enabled = true;
const int m_channels = 1;
chunkware_simple::SimpleComp m_simpleCompressor;
const int channels = 1;
};
} // ns
} // ns