1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-18 07:35:47 -05:00

Deep redesign: Rest of demods: Mutex to prevent concurrent critical updates with feed method

This commit is contained in:
f4exb 2015-08-24 23:23:45 +02:00
parent 69986fd186
commit d2ed278ba3
11 changed files with 74 additions and 13 deletions

View File

@ -28,7 +28,8 @@
MESSAGE_CLASS_DEFINITION(AMDemod::MsgConfigureAMDemod, Message) MESSAGE_CLASS_DEFINITION(AMDemod::MsgConfigureAMDemod, Message)
AMDemod::AMDemod() : AMDemod::AMDemod() :
m_audioFifo(4, 48000) m_audioFifo(4, 48000),
m_settingsMutex(QMutex::Recursive)
{ {
setObjectName("AMDemod"); setObjectName("AMDemod");
@ -66,10 +67,7 @@ void AMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_itera
{ {
Complex ci; Complex ci;
if (m_audioFifo.size() == 0) m_settingsMutex.lock();
{
return;
}
for (SampleVector::const_iterator it = begin; it != end; ++it) 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_sampleBuffer.clear();
m_settingsMutex.unlock();
} }
void AMDemod::start() void AMDemod::start()
@ -223,15 +223,19 @@ void AMDemod::apply()
if((m_config.m_inputSampleRate != m_running.m_inputSampleRate) || if((m_config.m_inputSampleRate != m_running.m_inputSampleRate) ||
(m_config.m_rfBandwidth != m_running.m_rfBandwidth)) (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_interpolator.create(16, m_config.m_inputSampleRate, m_config.m_rfBandwidth / 2.2);
m_interpolatorDistanceRemain = 0; m_interpolatorDistanceRemain = 0;
m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_audioSampleRate; m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_audioSampleRate;
m_settingsMutex.unlock();
} }
if((m_config.m_afBandwidth != m_running.m_afBandwidth) || if((m_config.m_afBandwidth != m_running.m_afBandwidth) ||
(m_config.m_audioSampleRate != m_running.m_audioSampleRate)) (m_config.m_audioSampleRate != m_running.m_audioSampleRate))
{ {
m_settingsMutex.lock();
m_lowpass.create(21, m_config.m_audioSampleRate, m_config.m_afBandwidth); m_lowpass.create(21, m_config.m_audioSampleRate, m_config.m_afBandwidth);
m_settingsMutex.unlock();
} }
if(m_config.m_squelch != m_running.m_squelch) if(m_config.m_squelch != m_running.m_squelch)

View File

@ -17,6 +17,7 @@
#ifndef INCLUDE_AMDEMOD_H #ifndef INCLUDE_AMDEMOD_H
#define INCLUDE_AMDEMOD_H #define INCLUDE_AMDEMOD_H
#include <QMutex>
#include <vector> #include <vector>
#include "dsp/samplesink.h" #include "dsp/samplesink.h"
#include "dsp/nco.h" #include "dsp/nco.h"
@ -27,8 +28,6 @@
#include "audio/audiofifo.h" #include "audio/audiofifo.h"
#include "util/message.h" #include "util/message.h"
class AudioFifo;
class AMDemod : public SampleSink { class AMDemod : public SampleSink {
Q_OBJECT Q_OBJECT
public: public:
@ -123,6 +122,7 @@ private:
AudioFifo m_audioFifo; AudioFifo m_audioFifo;
SampleVector m_sampleBuffer; SampleVector m_sampleBuffer;
QMutex m_settingsMutex;
void apply(); void apply();
}; };

View File

@ -27,7 +27,8 @@
MESSAGE_CLASS_DEFINITION(ChannelAnalyzer::MsgConfigureChannelAnalyzer, Message) MESSAGE_CLASS_DEFINITION(ChannelAnalyzer::MsgConfigureChannelAnalyzer, Message)
ChannelAnalyzer::ChannelAnalyzer(SampleSink* sampleSink) : ChannelAnalyzer::ChannelAnalyzer(SampleSink* sampleSink) :
m_sampleSink(sampleSink) m_sampleSink(sampleSink),
m_settingsMutex(QMutex::Recursive)
{ {
m_Bandwidth = 5000; m_Bandwidth = 5000;
m_LowCutoff = 300; m_LowCutoff = 300;
@ -66,6 +67,8 @@ void ChannelAnalyzer::feed(SampleVector::const_iterator begin, SampleVector::con
int decim = 1<<m_spanLog2; int decim = 1<<m_spanLog2;
unsigned char decim_mask = decim - 1; // counter LSB bit mask for decimation by 2^(m_scaleLog2 - 1) 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) for(SampleVector::const_iterator it = begin; it < end; ++it)
{ {
Complex c(it->real() / 32768.0, it->imag() / 32768.0); 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_sampleBuffer.clear();
m_settingsMutex.unlock();
} }
void ChannelAnalyzer::start() void ChannelAnalyzer::start()
@ -163,6 +168,8 @@ bool ChannelAnalyzer::handleMessage(const Message& cmd)
lowCutoff = 0; lowCutoff = 0;
} }
m_settingsMutex.lock();
m_Bandwidth = band; m_Bandwidth = band;
m_LowCutoff = lowCutoff; m_LowCutoff = lowCutoff;
@ -172,6 +179,8 @@ bool ChannelAnalyzer::handleMessage(const Message& cmd)
m_spanLog2 = cfg.getSpanLog2(); m_spanLog2 = cfg.getSpanLog2();
m_ssb = cfg.getSSB(); m_ssb = cfg.getSSB();
m_settingsMutex.unlock();
qDebug() << " - MsgConfigureChannelAnalyzer: m_Bandwidth: " << m_Bandwidth qDebug() << " - MsgConfigureChannelAnalyzer: m_Bandwidth: " << m_Bandwidth
<< " m_LowCutoff: " << m_LowCutoff << " m_LowCutoff: " << m_LowCutoff
<< " m_spanLog2: " << m_spanLog2 << " m_spanLog2: " << m_spanLog2

View File

@ -18,6 +18,7 @@
#ifndef INCLUDE_CHANALYZER_H #ifndef INCLUDE_CHANALYZER_H
#define INCLUDE_CHANALYZER_H #define INCLUDE_CHANALYZER_H
#include <QMutex>
#include <vector> #include <vector>
#include "dsp/samplesink.h" #include "dsp/samplesink.h"
#include "dsp/nco.h" #include "dsp/nco.h"
@ -99,6 +100,7 @@ private:
SampleSink* m_sampleSink; SampleSink* m_sampleSink;
SampleVector m_sampleBuffer; SampleVector m_sampleBuffer;
QMutex m_settingsMutex;
}; };
#endif // INCLUDE_CHANALYZER_H #endif // INCLUDE_CHANALYZER_H

View File

@ -27,7 +27,8 @@
MESSAGE_CLASS_DEFINITION(LoRaDemod::MsgConfigureLoRaDemod, Message) MESSAGE_CLASS_DEFINITION(LoRaDemod::MsgConfigureLoRaDemod, Message)
LoRaDemod::LoRaDemod(SampleSink* sampleSink) : LoRaDemod::LoRaDemod(SampleSink* sampleSink) :
m_sampleSink(sampleSink) m_sampleSink(sampleSink),
m_settingsMutex(QMutex::Recursive)
{ {
setObjectName("LoRaDemod"); setObjectName("LoRaDemod");
@ -242,6 +243,8 @@ void LoRaDemod::feed(SampleVector::const_iterator begin, SampleVector::const_ite
m_sampleBuffer.clear(); m_sampleBuffer.clear();
m_settingsMutex.lock();
for(SampleVector::const_iterator it = begin; it < end; ++it) for(SampleVector::const_iterator it = begin; it < end; ++it)
{ {
Complex c(it->real() / 32768.0, it->imag() / 32768.0); 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_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), false);
} }
m_settingsMutex.unlock();
} }
void LoRaDemod::start() void LoRaDemod::start()
@ -283,11 +288,15 @@ bool LoRaDemod::handleMessage(const Message& cmd)
{ {
Channelizer::MsgChannelizerNotification& notif = (Channelizer::MsgChannelizerNotification&) cmd; Channelizer::MsgChannelizerNotification& notif = (Channelizer::MsgChannelizerNotification&) cmd;
m_settingsMutex.lock();
m_sampleRate = notif.getSampleRate(); m_sampleRate = notif.getSampleRate();
m_nco.setFreq(-notif.getFrequencyOffset(), m_sampleRate); m_nco.setFreq(-notif.getFrequencyOffset(), m_sampleRate);
m_interpolator.create(16, m_sampleRate, m_Bandwidth/1.9); m_interpolator.create(16, m_sampleRate, m_Bandwidth/1.9);
m_sampleDistanceRemain = m_sampleRate / m_Bandwidth; m_sampleDistanceRemain = m_sampleRate / m_Bandwidth;
m_settingsMutex.unlock();
qDebug() << "LoRaDemod::handleMessage: MsgChannelizerNotification: m_sampleRate: " << m_sampleRate qDebug() << "LoRaDemod::handleMessage: MsgChannelizerNotification: m_sampleRate: " << m_sampleRate
<< " frequencyOffset: " << notif.getFrequencyOffset(); << " frequencyOffset: " << notif.getFrequencyOffset();
@ -297,9 +306,13 @@ bool LoRaDemod::handleMessage(const Message& cmd)
{ {
MsgConfigureLoRaDemod& cfg = (MsgConfigureLoRaDemod&) cmd; MsgConfigureLoRaDemod& cfg = (MsgConfigureLoRaDemod&) cmd;
m_settingsMutex.lock();
m_Bandwidth = cfg.getBandwidth(); m_Bandwidth = cfg.getBandwidth();
m_interpolator.create(16, m_sampleRate, m_Bandwidth/1.9); m_interpolator.create(16, m_sampleRate, m_Bandwidth/1.9);
m_settingsMutex.unlock();
qDebug() << " MsgConfigureLoRaDemod: m_Bandwidth: " << m_Bandwidth; qDebug() << " MsgConfigureLoRaDemod: m_Bandwidth: " << m_Bandwidth;
return true; return true;

View File

@ -18,6 +18,7 @@
#ifndef INCLUDE_LoRaDEMOD_H #ifndef INCLUDE_LoRaDEMOD_H
#define INCLUDE_LoRaDEMOD_H #define INCLUDE_LoRaDEMOD_H
#include <QMutex>
#include <vector> #include <vector>
#include "dsp/samplesink.h" #include "dsp/samplesink.h"
#include "dsp/nco.h" #include "dsp/nco.h"
@ -97,6 +98,7 @@ private:
SampleSink* m_sampleSink; SampleSink* m_sampleSink;
SampleVector m_sampleBuffer; SampleVector m_sampleBuffer;
QMutex m_settingsMutex;
}; };
#endif // INCLUDE_LoRaDEMOD_H #endif // INCLUDE_LoRaDEMOD_H

View File

@ -32,7 +32,6 @@
#include "audio/audiofifo.h" #include "audio/audiofifo.h"
#include "util/message.h" #include "util/message.h"
class AudioFifo;
class NFMDemodGUI; class NFMDemodGUI;
class NFMDemod : public SampleSink { class NFMDemod : public SampleSink {

View File

@ -28,7 +28,8 @@ MESSAGE_CLASS_DEFINITION(SSBDemod::MsgConfigureSSBDemod, Message)
SSBDemod::SSBDemod(SampleSink* sampleSink) : SSBDemod::SSBDemod(SampleSink* sampleSink) :
m_sampleSink(sampleSink), m_sampleSink(sampleSink),
m_audioFifo(4, 24000) m_audioFifo(4, 24000),
m_settingsMutex(QMutex::Recursive)
{ {
setObjectName("SSBDemod"); setObjectName("SSBDemod");
@ -76,6 +77,9 @@ void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter
fftfilt::cmplx *sideband, sum; fftfilt::cmplx *sideband, sum;
Real avg; Real avg;
int n_out; int n_out;
m_settingsMutex.lock();
int decim = 1<<(m_spanLog2 - 1); int decim = 1<<(m_spanLog2 - 1);
unsigned char decim_mask = decim - 1; // counter LSB bit mask for decimation by 2^(m_scaleLog2 - 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_sampleBuffer.clear();
m_settingsMutex.unlock();
} }
void SSBDemod::start() void SSBDemod::start()
@ -162,11 +168,15 @@ bool SSBDemod::handleMessage(const Message& cmd)
{ {
Channelizer::MsgChannelizerNotification& notif = (Channelizer::MsgChannelizerNotification&) cmd; Channelizer::MsgChannelizerNotification& notif = (Channelizer::MsgChannelizerNotification&) cmd;
m_settingsMutex.lock();
m_sampleRate = notif.getSampleRate(); m_sampleRate = notif.getSampleRate();
m_nco.setFreq(-notif.getFrequencyOffset(), m_sampleRate); m_nco.setFreq(-notif.getFrequencyOffset(), m_sampleRate);
m_interpolator.create(16, m_sampleRate, m_Bandwidth); m_interpolator.create(16, m_sampleRate, m_Bandwidth);
m_sampleDistanceRemain = m_sampleRate / m_audioSampleRate; m_sampleDistanceRemain = m_sampleRate / m_audioSampleRate;
m_settingsMutex.unlock();
qDebug() << "SSBDemod::handleMessage: MsgChannelizerNotification: m_sampleRate: " << m_sampleRate qDebug() << "SSBDemod::handleMessage: MsgChannelizerNotification: m_sampleRate: " << m_sampleRate
<< " frequencyOffset" << notif.getFrequencyOffset(); << " frequencyOffset" << notif.getFrequencyOffset();
@ -176,6 +186,8 @@ bool SSBDemod::handleMessage(const Message& cmd)
{ {
MsgConfigureSSBDemod& cfg = (MsgConfigureSSBDemod&) cmd; MsgConfigureSSBDemod& cfg = (MsgConfigureSSBDemod&) cmd;
m_settingsMutex.lock();
band = cfg.getBandwidth(); band = cfg.getBandwidth();
lowCutoff = cfg.getLoCutoff(); lowCutoff = cfg.getLoCutoff();
@ -191,7 +203,6 @@ bool SSBDemod::handleMessage(const Message& cmd)
band = 100.0f; band = 100.0f;
lowCutoff = 0; lowCutoff = 0;
} }
m_Bandwidth = band; m_Bandwidth = band;
m_LowCutoff = lowCutoff; m_LowCutoff = lowCutoff;
@ -203,6 +214,8 @@ bool SSBDemod::handleMessage(const Message& cmd)
m_spanLog2 = cfg.getSpanLog2(); m_spanLog2 = cfg.getSpanLog2();
m_settingsMutex.unlock();
qDebug() << " - MsgConfigureSSBDemod: m_Bandwidth: " << m_Bandwidth qDebug() << " - MsgConfigureSSBDemod: m_Bandwidth: " << m_Bandwidth
<< " m_LowCutoff: " << m_LowCutoff << " m_LowCutoff: " << m_LowCutoff
<< " m_volume: " << m_volume << " m_volume: " << m_volume

View File

@ -18,6 +18,7 @@
#ifndef INCLUDE_SSBDEMOD_H #ifndef INCLUDE_SSBDEMOD_H
#define INCLUDE_SSBDEMOD_H #define INCLUDE_SSBDEMOD_H
#include <QMutex>
#include <vector> #include <vector>
#include "dsp/samplesink.h" #include "dsp/samplesink.h"
#include "dsp/nco.h" #include "dsp/nco.h"
@ -97,6 +98,8 @@ private:
uint m_audioBufferFill; uint m_audioBufferFill;
AudioFifo m_audioFifo; AudioFifo m_audioFifo;
quint32 m_audioSampleRate; quint32 m_audioSampleRate;
QMutex m_settingsMutex;
}; };
#endif // INCLUDE_SSBDEMOD_H #endif // INCLUDE_SSBDEMOD_H

View File

@ -25,7 +25,8 @@ MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcConfigure, Message)
MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcConnection, Message) MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcConnection, Message)
MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcSpectrum, 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"); setObjectName("TCPSrc");
@ -78,6 +79,8 @@ void TCPSrc::feed(SampleVector::const_iterator begin, SampleVector::const_iterat
m_sampleBuffer.clear(); m_sampleBuffer.clear();
m_settingsMutex.lock();
// Rtl-Sdr uses full 16-bit scale; FCDPP does not // Rtl-Sdr uses full 16-bit scale; FCDPP does not
int rescale = 30000 * (1 << m_boost); 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() void TCPSrc::start()
@ -166,11 +171,15 @@ bool TCPSrc::handleMessage(const Message& cmd)
{ {
Channelizer::MsgChannelizerNotification& notif = (Channelizer::MsgChannelizerNotification&) cmd; Channelizer::MsgChannelizerNotification& notif = (Channelizer::MsgChannelizerNotification&) cmd;
m_settingsMutex.lock();
m_inputSampleRate = notif.getSampleRate(); m_inputSampleRate = notif.getSampleRate();
m_nco.setFreq(-notif.getFrequencyOffset(), m_inputSampleRate); m_nco.setFreq(-notif.getFrequencyOffset(), m_inputSampleRate);
m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.0); m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.0);
m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate; m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate;
m_settingsMutex.unlock();
qDebug() << "TCPSrc::handleMessage: MsgChannelizerNotification: m_inputSampleRate: " << m_inputSampleRate qDebug() << "TCPSrc::handleMessage: MsgChannelizerNotification: m_inputSampleRate: " << m_inputSampleRate
<< " frequencyOffset: " << notif.getFrequencyOffset(); << " frequencyOffset: " << notif.getFrequencyOffset();
@ -180,6 +189,8 @@ bool TCPSrc::handleMessage(const Message& cmd)
{ {
MsgTCPSrcConfigure& cfg = (MsgTCPSrcConfigure&) cmd; MsgTCPSrcConfigure& cfg = (MsgTCPSrcConfigure&) cmd;
m_settingsMutex.lock();
m_sampleFormat = cfg.getSampleFormat(); m_sampleFormat = cfg.getSampleFormat();
m_outputSampleRate = cfg.getOutputSampleRate(); m_outputSampleRate = cfg.getOutputSampleRate();
m_rfBandwidth = cfg.getRFBandwidth(); 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); TCPFilter->create_filter(0.0, m_rfBandwidth / 2.0 / m_outputSampleRate);
} }
m_settingsMutex.unlock();
qDebug() << " - MsgTCPSrcConfigure: m_sampleFormat: " << m_sampleFormat qDebug() << " - MsgTCPSrcConfigure: m_sampleFormat: " << m_sampleFormat
<< " m_outputSampleRate: " << m_outputSampleRate << " m_outputSampleRate: " << m_outputSampleRate
<< " m_rfBandwidth: " << m_rfBandwidth << " m_rfBandwidth: " << m_rfBandwidth

View File

@ -1,6 +1,7 @@
#ifndef INCLUDE_TCPSRC_H #ifndef INCLUDE_TCPSRC_H
#define INCLUDE_TCPSRC_H #define INCLUDE_TCPSRC_H
#include <QMutex>
#include <QHostAddress> #include <QHostAddress>
#include "dsp/samplesink.h" #include "dsp/samplesink.h"
#include "dsp/nco.h" #include "dsp/nco.h"
@ -156,6 +157,8 @@ protected:
quint32 m_nextSSBId; quint32 m_nextSSBId;
quint32 m_nextS16leId; quint32 m_nextS16leId;
QMutex m_settingsMutex;
void closeAllSockets(Sockets* sockets); void closeAllSockets(Sockets* sockets);
protected slots: protected slots: