mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-12-17 23:28:50 -05:00
Deep redesign: Rest of demods: Mutex to prevent concurrent critical updates with feed method
This commit is contained in:
parent
69986fd186
commit
d2ed278ba3
@ -28,7 +28,8 @@
|
||||
MESSAGE_CLASS_DEFINITION(AMDemod::MsgConfigureAMDemod, Message)
|
||||
|
||||
AMDemod::AMDemod() :
|
||||
m_audioFifo(4, 48000)
|
||||
m_audioFifo(4, 48000),
|
||||
m_settingsMutex(QMutex::Recursive)
|
||||
{
|
||||
setObjectName("AMDemod");
|
||||
|
||||
@ -66,10 +67,7 @@ void AMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_itera
|
||||
{
|
||||
Complex ci;
|
||||
|
||||
if (m_audioFifo.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_settingsMutex.lock();
|
||||
|
||||
for (SampleVector::const_iterator it = begin; it != end; ++it)
|
||||
{
|
||||
@ -152,6 +150,8 @@ void AMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_itera
|
||||
}
|
||||
|
||||
m_sampleBuffer.clear();
|
||||
|
||||
m_settingsMutex.unlock();
|
||||
}
|
||||
|
||||
void AMDemod::start()
|
||||
@ -223,15 +223,19 @@ void AMDemod::apply()
|
||||
if((m_config.m_inputSampleRate != m_running.m_inputSampleRate) ||
|
||||
(m_config.m_rfBandwidth != m_running.m_rfBandwidth))
|
||||
{
|
||||
m_settingsMutex.lock();
|
||||
m_interpolator.create(16, m_config.m_inputSampleRate, m_config.m_rfBandwidth / 2.2);
|
||||
m_interpolatorDistanceRemain = 0;
|
||||
m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_audioSampleRate;
|
||||
m_settingsMutex.unlock();
|
||||
}
|
||||
|
||||
if((m_config.m_afBandwidth != m_running.m_afBandwidth) ||
|
||||
(m_config.m_audioSampleRate != m_running.m_audioSampleRate))
|
||||
{
|
||||
m_settingsMutex.lock();
|
||||
m_lowpass.create(21, m_config.m_audioSampleRate, m_config.m_afBandwidth);
|
||||
m_settingsMutex.unlock();
|
||||
}
|
||||
|
||||
if(m_config.m_squelch != m_running.m_squelch)
|
||||
|
@ -17,6 +17,7 @@
|
||||
#ifndef INCLUDE_AMDEMOD_H
|
||||
#define INCLUDE_AMDEMOD_H
|
||||
|
||||
#include <QMutex>
|
||||
#include <vector>
|
||||
#include "dsp/samplesink.h"
|
||||
#include "dsp/nco.h"
|
||||
@ -27,8 +28,6 @@
|
||||
#include "audio/audiofifo.h"
|
||||
#include "util/message.h"
|
||||
|
||||
class AudioFifo;
|
||||
|
||||
class AMDemod : public SampleSink {
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -123,6 +122,7 @@ private:
|
||||
|
||||
AudioFifo m_audioFifo;
|
||||
SampleVector m_sampleBuffer;
|
||||
QMutex m_settingsMutex;
|
||||
|
||||
void apply();
|
||||
};
|
||||
|
@ -27,7 +27,8 @@
|
||||
MESSAGE_CLASS_DEFINITION(ChannelAnalyzer::MsgConfigureChannelAnalyzer, Message)
|
||||
|
||||
ChannelAnalyzer::ChannelAnalyzer(SampleSink* sampleSink) :
|
||||
m_sampleSink(sampleSink)
|
||||
m_sampleSink(sampleSink),
|
||||
m_settingsMutex(QMutex::Recursive)
|
||||
{
|
||||
m_Bandwidth = 5000;
|
||||
m_LowCutoff = 300;
|
||||
@ -66,6 +67,8 @@ void ChannelAnalyzer::feed(SampleVector::const_iterator begin, SampleVector::con
|
||||
int decim = 1<<m_spanLog2;
|
||||
unsigned char decim_mask = decim - 1; // counter LSB bit mask for decimation by 2^(m_scaleLog2 - 1)
|
||||
|
||||
m_settingsMutex.lock();
|
||||
|
||||
for(SampleVector::const_iterator it = begin; it < end; ++it)
|
||||
{
|
||||
Complex c(it->real() / 32768.0, it->imag() / 32768.0);
|
||||
@ -111,6 +114,8 @@ void ChannelAnalyzer::feed(SampleVector::const_iterator begin, SampleVector::con
|
||||
}
|
||||
|
||||
m_sampleBuffer.clear();
|
||||
|
||||
m_settingsMutex.unlock();
|
||||
}
|
||||
|
||||
void ChannelAnalyzer::start()
|
||||
@ -163,6 +168,8 @@ bool ChannelAnalyzer::handleMessage(const Message& cmd)
|
||||
lowCutoff = 0;
|
||||
}
|
||||
|
||||
m_settingsMutex.lock();
|
||||
|
||||
m_Bandwidth = band;
|
||||
m_LowCutoff = lowCutoff;
|
||||
|
||||
@ -172,6 +179,8 @@ bool ChannelAnalyzer::handleMessage(const Message& cmd)
|
||||
m_spanLog2 = cfg.getSpanLog2();
|
||||
m_ssb = cfg.getSSB();
|
||||
|
||||
m_settingsMutex.unlock();
|
||||
|
||||
qDebug() << " - MsgConfigureChannelAnalyzer: m_Bandwidth: " << m_Bandwidth
|
||||
<< " m_LowCutoff: " << m_LowCutoff
|
||||
<< " m_spanLog2: " << m_spanLog2
|
||||
|
@ -18,6 +18,7 @@
|
||||
#ifndef INCLUDE_CHANALYZER_H
|
||||
#define INCLUDE_CHANALYZER_H
|
||||
|
||||
#include <QMutex>
|
||||
#include <vector>
|
||||
#include "dsp/samplesink.h"
|
||||
#include "dsp/nco.h"
|
||||
@ -99,6 +100,7 @@ private:
|
||||
|
||||
SampleSink* m_sampleSink;
|
||||
SampleVector m_sampleBuffer;
|
||||
QMutex m_settingsMutex;
|
||||
};
|
||||
|
||||
#endif // INCLUDE_CHANALYZER_H
|
||||
|
@ -27,7 +27,8 @@
|
||||
MESSAGE_CLASS_DEFINITION(LoRaDemod::MsgConfigureLoRaDemod, Message)
|
||||
|
||||
LoRaDemod::LoRaDemod(SampleSink* sampleSink) :
|
||||
m_sampleSink(sampleSink)
|
||||
m_sampleSink(sampleSink),
|
||||
m_settingsMutex(QMutex::Recursive)
|
||||
{
|
||||
setObjectName("LoRaDemod");
|
||||
|
||||
@ -242,6 +243,8 @@ void LoRaDemod::feed(SampleVector::const_iterator begin, SampleVector::const_ite
|
||||
|
||||
m_sampleBuffer.clear();
|
||||
|
||||
m_settingsMutex.lock();
|
||||
|
||||
for(SampleVector::const_iterator it = begin; it < end; ++it)
|
||||
{
|
||||
Complex c(it->real() / 32768.0, it->imag() / 32768.0);
|
||||
@ -265,6 +268,8 @@ void LoRaDemod::feed(SampleVector::const_iterator begin, SampleVector::const_ite
|
||||
{
|
||||
m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), false);
|
||||
}
|
||||
|
||||
m_settingsMutex.unlock();
|
||||
}
|
||||
|
||||
void LoRaDemod::start()
|
||||
@ -283,11 +288,15 @@ bool LoRaDemod::handleMessage(const Message& cmd)
|
||||
{
|
||||
Channelizer::MsgChannelizerNotification& notif = (Channelizer::MsgChannelizerNotification&) cmd;
|
||||
|
||||
m_settingsMutex.lock();
|
||||
|
||||
m_sampleRate = notif.getSampleRate();
|
||||
m_nco.setFreq(-notif.getFrequencyOffset(), m_sampleRate);
|
||||
m_interpolator.create(16, m_sampleRate, m_Bandwidth/1.9);
|
||||
m_sampleDistanceRemain = m_sampleRate / m_Bandwidth;
|
||||
|
||||
m_settingsMutex.unlock();
|
||||
|
||||
qDebug() << "LoRaDemod::handleMessage: MsgChannelizerNotification: m_sampleRate: " << m_sampleRate
|
||||
<< " frequencyOffset: " << notif.getFrequencyOffset();
|
||||
|
||||
@ -297,9 +306,13 @@ bool LoRaDemod::handleMessage(const Message& cmd)
|
||||
{
|
||||
MsgConfigureLoRaDemod& cfg = (MsgConfigureLoRaDemod&) cmd;
|
||||
|
||||
m_settingsMutex.lock();
|
||||
|
||||
m_Bandwidth = cfg.getBandwidth();
|
||||
m_interpolator.create(16, m_sampleRate, m_Bandwidth/1.9);
|
||||
|
||||
m_settingsMutex.unlock();
|
||||
|
||||
qDebug() << " MsgConfigureLoRaDemod: m_Bandwidth: " << m_Bandwidth;
|
||||
|
||||
return true;
|
||||
|
@ -18,6 +18,7 @@
|
||||
#ifndef INCLUDE_LoRaDEMOD_H
|
||||
#define INCLUDE_LoRaDEMOD_H
|
||||
|
||||
#include <QMutex>
|
||||
#include <vector>
|
||||
#include "dsp/samplesink.h"
|
||||
#include "dsp/nco.h"
|
||||
@ -97,6 +98,7 @@ private:
|
||||
|
||||
SampleSink* m_sampleSink;
|
||||
SampleVector m_sampleBuffer;
|
||||
QMutex m_settingsMutex;
|
||||
};
|
||||
|
||||
#endif // INCLUDE_LoRaDEMOD_H
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include "audio/audiofifo.h"
|
||||
#include "util/message.h"
|
||||
|
||||
class AudioFifo;
|
||||
class NFMDemodGUI;
|
||||
|
||||
class NFMDemod : public SampleSink {
|
||||
|
@ -28,7 +28,8 @@ MESSAGE_CLASS_DEFINITION(SSBDemod::MsgConfigureSSBDemod, Message)
|
||||
|
||||
SSBDemod::SSBDemod(SampleSink* sampleSink) :
|
||||
m_sampleSink(sampleSink),
|
||||
m_audioFifo(4, 24000)
|
||||
m_audioFifo(4, 24000),
|
||||
m_settingsMutex(QMutex::Recursive)
|
||||
{
|
||||
setObjectName("SSBDemod");
|
||||
|
||||
@ -76,6 +77,9 @@ void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter
|
||||
fftfilt::cmplx *sideband, sum;
|
||||
Real avg;
|
||||
int n_out;
|
||||
|
||||
m_settingsMutex.lock();
|
||||
|
||||
int decim = 1<<(m_spanLog2 - 1);
|
||||
unsigned char decim_mask = decim - 1; // counter LSB bit mask for decimation by 2^(m_scaleLog2 - 1)
|
||||
|
||||
@ -142,6 +146,8 @@ void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter
|
||||
}
|
||||
|
||||
m_sampleBuffer.clear();
|
||||
|
||||
m_settingsMutex.unlock();
|
||||
}
|
||||
|
||||
void SSBDemod::start()
|
||||
@ -162,11 +168,15 @@ bool SSBDemod::handleMessage(const Message& cmd)
|
||||
{
|
||||
Channelizer::MsgChannelizerNotification& notif = (Channelizer::MsgChannelizerNotification&) cmd;
|
||||
|
||||
m_settingsMutex.lock();
|
||||
|
||||
m_sampleRate = notif.getSampleRate();
|
||||
m_nco.setFreq(-notif.getFrequencyOffset(), m_sampleRate);
|
||||
m_interpolator.create(16, m_sampleRate, m_Bandwidth);
|
||||
m_sampleDistanceRemain = m_sampleRate / m_audioSampleRate;
|
||||
|
||||
m_settingsMutex.unlock();
|
||||
|
||||
qDebug() << "SSBDemod::handleMessage: MsgChannelizerNotification: m_sampleRate: " << m_sampleRate
|
||||
<< " frequencyOffset" << notif.getFrequencyOffset();
|
||||
|
||||
@ -176,6 +186,8 @@ bool SSBDemod::handleMessage(const Message& cmd)
|
||||
{
|
||||
MsgConfigureSSBDemod& cfg = (MsgConfigureSSBDemod&) cmd;
|
||||
|
||||
m_settingsMutex.lock();
|
||||
|
||||
band = cfg.getBandwidth();
|
||||
lowCutoff = cfg.getLoCutoff();
|
||||
|
||||
@ -191,7 +203,6 @@ bool SSBDemod::handleMessage(const Message& cmd)
|
||||
band = 100.0f;
|
||||
lowCutoff = 0;
|
||||
}
|
||||
|
||||
m_Bandwidth = band;
|
||||
m_LowCutoff = lowCutoff;
|
||||
|
||||
@ -203,6 +214,8 @@ bool SSBDemod::handleMessage(const Message& cmd)
|
||||
|
||||
m_spanLog2 = cfg.getSpanLog2();
|
||||
|
||||
m_settingsMutex.unlock();
|
||||
|
||||
qDebug() << " - MsgConfigureSSBDemod: m_Bandwidth: " << m_Bandwidth
|
||||
<< " m_LowCutoff: " << m_LowCutoff
|
||||
<< " m_volume: " << m_volume
|
||||
|
@ -18,6 +18,7 @@
|
||||
#ifndef INCLUDE_SSBDEMOD_H
|
||||
#define INCLUDE_SSBDEMOD_H
|
||||
|
||||
#include <QMutex>
|
||||
#include <vector>
|
||||
#include "dsp/samplesink.h"
|
||||
#include "dsp/nco.h"
|
||||
@ -97,6 +98,8 @@ private:
|
||||
uint m_audioBufferFill;
|
||||
AudioFifo m_audioFifo;
|
||||
quint32 m_audioSampleRate;
|
||||
|
||||
QMutex m_settingsMutex;
|
||||
};
|
||||
|
||||
#endif // INCLUDE_SSBDEMOD_H
|
||||
|
@ -25,7 +25,8 @@ MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcConfigure, Message)
|
||||
MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcConnection, Message)
|
||||
MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcSpectrum, Message)
|
||||
|
||||
TCPSrc::TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, SampleSink* spectrum)
|
||||
TCPSrc::TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, SampleSink* spectrum) :
|
||||
m_settingsMutex(QMutex::Recursive)
|
||||
{
|
||||
setObjectName("TCPSrc");
|
||||
|
||||
@ -78,6 +79,8 @@ void TCPSrc::feed(SampleVector::const_iterator begin, SampleVector::const_iterat
|
||||
|
||||
m_sampleBuffer.clear();
|
||||
|
||||
m_settingsMutex.lock();
|
||||
|
||||
// Rtl-Sdr uses full 16-bit scale; FCDPP does not
|
||||
int rescale = 30000 * (1 << m_boost);
|
||||
|
||||
@ -139,6 +142,8 @@ void TCPSrc::feed(SampleVector::const_iterator begin, SampleVector::const_iterat
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_settingsMutex.unlock();
|
||||
}
|
||||
|
||||
void TCPSrc::start()
|
||||
@ -166,11 +171,15 @@ bool TCPSrc::handleMessage(const Message& cmd)
|
||||
{
|
||||
Channelizer::MsgChannelizerNotification& notif = (Channelizer::MsgChannelizerNotification&) cmd;
|
||||
|
||||
m_settingsMutex.lock();
|
||||
|
||||
m_inputSampleRate = notif.getSampleRate();
|
||||
m_nco.setFreq(-notif.getFrequencyOffset(), m_inputSampleRate);
|
||||
m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.0);
|
||||
m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate;
|
||||
|
||||
m_settingsMutex.unlock();
|
||||
|
||||
qDebug() << "TCPSrc::handleMessage: MsgChannelizerNotification: m_inputSampleRate: " << m_inputSampleRate
|
||||
<< " frequencyOffset: " << notif.getFrequencyOffset();
|
||||
|
||||
@ -180,6 +189,8 @@ bool TCPSrc::handleMessage(const Message& cmd)
|
||||
{
|
||||
MsgTCPSrcConfigure& cfg = (MsgTCPSrcConfigure&) cmd;
|
||||
|
||||
m_settingsMutex.lock();
|
||||
|
||||
m_sampleFormat = cfg.getSampleFormat();
|
||||
m_outputSampleRate = cfg.getOutputSampleRate();
|
||||
m_rfBandwidth = cfg.getRFBandwidth();
|
||||
@ -209,6 +220,8 @@ bool TCPSrc::handleMessage(const Message& cmd)
|
||||
TCPFilter->create_filter(0.0, m_rfBandwidth / 2.0 / m_outputSampleRate);
|
||||
}
|
||||
|
||||
m_settingsMutex.unlock();
|
||||
|
||||
qDebug() << " - MsgTCPSrcConfigure: m_sampleFormat: " << m_sampleFormat
|
||||
<< " m_outputSampleRate: " << m_outputSampleRate
|
||||
<< " m_rfBandwidth: " << m_rfBandwidth
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef INCLUDE_TCPSRC_H
|
||||
#define INCLUDE_TCPSRC_H
|
||||
|
||||
#include <QMutex>
|
||||
#include <QHostAddress>
|
||||
#include "dsp/samplesink.h"
|
||||
#include "dsp/nco.h"
|
||||
@ -156,6 +157,8 @@ protected:
|
||||
quint32 m_nextSSBId;
|
||||
quint32 m_nextS16leId;
|
||||
|
||||
QMutex m_settingsMutex;
|
||||
|
||||
void closeAllSockets(Sockets* sockets);
|
||||
|
||||
protected slots:
|
||||
|
Loading…
Reference in New Issue
Block a user