From 04dbb028aa541f2e8c76d1d9e7ae85be76a649db Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 9 Dec 2020 01:15:38 +0100 Subject: [PATCH] FreeDV: removed useless set callback functions. Use mutex appropriately --- .../channelrx/demodfreedv/freedvdemodsink.cpp | 18 +++++++++--------- .../channelrx/demodfreedv/freedvdemodsink.h | 2 ++ .../channeltx/modfreedv/freedvmodsource.cpp | 11 ++++------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/plugins/channelrx/demodfreedv/freedvdemodsink.cpp b/plugins/channelrx/demodfreedv/freedvdemodsink.cpp index 1aaec6e73..6171a02c0 100644 --- a/plugins/channelrx/demodfreedv/freedvdemodsink.cpp +++ b/plugins/channelrx/demodfreedv/freedvdemodsink.cpp @@ -141,16 +141,17 @@ FreeDVDemodSink::FreeDVDemodSink() : m_agcActive(false), m_squelchDelayLine(2*48000), m_audioActive(false), - m_spectrumSink(0), + m_spectrumSink(nullptr), m_audioFifo(24000), - m_freeDV(0), + m_freeDV(nullptr), m_nSpeechSamples(0), m_nMaxModemSamples(0), m_iSpeech(0), m_iModem(0), - m_speechOut(0), - m_modIn(0), - m_levelInNbSamples(480) // 10ms @ 48 kS/s + m_speechOut(nullptr), + m_modIn(nullptr), + m_levelInNbSamples(480), // 10ms @ 48 kS/s + m_mutex(QMutex::Recursive) { m_audioBuffer.resize(1<<14); m_audioBufferFill = 0; @@ -184,6 +185,7 @@ void FreeDVDemodSink::feed(const SampleVector::const_iterator& begin, const Samp return; } + QMutexLocker mlock(&m_mutex); Complex ci; for(SampleVector::const_iterator it = begin; it < end; ++it) @@ -393,6 +395,7 @@ void FreeDVDemodSink::applyFreeDVMode(FreeDVDemodSettings::FreeDVMode mode) m_hiCutoff = FreeDVDemodSettings::getHiCutoff(mode); m_lowCutoff = FreeDVDemodSettings::getLowCutoff(mode); uint32_t modemSampleRate = FreeDVDemodSettings::getModSampleRate(mode); + QMutexLocker mlock(&m_mutex); SSBFilter->create_filter(m_lowCutoff / (float) modemSampleRate, m_hiCutoff / (float) modemSampleRate); @@ -457,10 +460,6 @@ void FreeDVDemodSink::applyFreeDVMode(FreeDVDemodSettings::FreeDVMode mode) freedv_set_ext_vco(m_freeDV, 0); freedv_set_sync(m_freeDV, FREEDV_SYNC_MANUAL); - freedv_set_callback_txt(m_freeDV, nullptr, nullptr, nullptr); - freedv_set_callback_protocol(m_freeDV, nullptr, nullptr, nullptr); - freedv_set_callback_data(m_freeDV, nullptr, nullptr, nullptr); - int nSpeechSamples = freedv_get_n_speech_samples(m_freeDV); int nMaxModemSamples = freedv_get_n_max_modem_samples(m_freeDV); int Fs = freedv_get_modem_sample_rate(m_freeDV); @@ -563,5 +562,6 @@ void FreeDVDemodSink::getSNRLevels(double& avg, double& peak, int& nbSamples) void FreeDVDemodSink::resyncFreeDV() { + QMutexLocker mlock(&m_mutex); freedv_set_sync(m_freeDV, FREEDV_SYNC_UNSYNC); } diff --git a/plugins/channelrx/demodfreedv/freedvdemodsink.h b/plugins/channelrx/demodfreedv/freedvdemodsink.h index b047a7690..b26f3923d 100644 --- a/plugins/channelrx/demodfreedv/freedvdemodsink.h +++ b/plugins/channelrx/demodfreedv/freedvdemodsink.h @@ -21,6 +21,7 @@ #include #include +#include #include "dsp/channelsamplesink.h" #include "dsp/ncof.h" @@ -198,6 +199,7 @@ private: int m_levelInNbSamples; Real m_rmsLevel; Real m_peakLevel; + QMutex m_mutex; static const unsigned int m_ssbFftLen; static const float m_agcTarget; diff --git a/plugins/channeltx/modfreedv/freedvmodsource.cpp b/plugins/channeltx/modfreedv/freedvmodsource.cpp index f185e58b9..0a65c5dd7 100644 --- a/plugins/channeltx/modfreedv/freedvmodsource.cpp +++ b/plugins/channeltx/modfreedv/freedvmodsource.cpp @@ -32,7 +32,7 @@ FreeDVModSource::FreeDVModSource() : m_lowCutoff(0.0), m_hiCutoff(6000.0), m_SSBFilter(nullptr), - m_SSBFilterBuffer(0), + m_SSBFilterBuffer(nullptr), m_SSBFilterBufferIndex(0), m_audioSampleRate(48000), m_audioFifo(12000), @@ -45,7 +45,7 @@ FreeDVModSource::FreeDVModSource() : m_iSpeech(0), m_iModem(0), m_speechIn(nullptr), - m_modOut(0), + m_modOut(nullptr), m_scaleFactor(SDR_TX_SCALEF), m_mutex(QMutex::Recursive) { @@ -82,6 +82,7 @@ FreeDVModSource::~FreeDVModSource() void FreeDVModSource::pull(SampleVector::iterator begin, unsigned int nbSamples) { + QMutexLocker mlock(&m_mutex); std::for_each( begin, begin + nbSamples, @@ -427,6 +428,7 @@ void FreeDVModSource::applyFreeDVMode(FreeDVModSettings::FreeDVMode mode) m_hiCutoff = FreeDVModSettings::getHiCutoff(mode); m_lowCutoff = FreeDVModSettings::getLowCutoff(mode); int modemSampleRate = FreeDVModSettings::getModSampleRate(mode); + QMutexLocker mlock(&m_mutex); m_SSBFilter->create_filter(m_lowCutoff / modemSampleRate, m_hiCutoff / modemSampleRate); @@ -493,10 +495,6 @@ void FreeDVModSource::applyFreeDVMode(FreeDVModSettings::FreeDVMode mode) freedv_set_tx_bpf(m_freeDV, 1); freedv_set_ext_vco(m_freeDV, 0); - freedv_set_callback_txt(m_freeDV, nullptr, nullptr, nullptr); - freedv_set_callback_protocol(m_freeDV, nullptr, nullptr, nullptr); - freedv_set_callback_data(m_freeDV, nullptr, nullptr, nullptr); - int nSpeechSamples = freedv_get_n_speech_samples(m_freeDV); int nNomModemSamples = freedv_get_n_nom_modem_samples(m_freeDV); int Fs = freedv_get_modem_sample_rate(m_freeDV); @@ -557,7 +555,6 @@ void FreeDVModSource::applySettings(const FreeDVModSettings& settings, bool forc void FreeDVModSource::handleAudio() { - QMutexLocker mlock(&m_mutex); unsigned int nbRead; while ((nbRead = m_audioFifo.read(reinterpret_cast(&m_audioReadBuffer[m_audioReadBufferFill]), 4096)) != 0)