From acdc87ccc5fa878e8b3665b598bc116e837ae07d Mon Sep 17 00:00:00 2001 From: John Greb Date: Wed, 3 Dec 2014 00:13:18 +0000 Subject: [PATCH] Set frequency before first capture. --- plugins/samplesource/v4l/v4linput.cpp | 29 +++++++++++++++----------- plugins/samplesource/v4l/v4linput.h | 2 +- plugins/samplesource/v4l/v4lsource.cpp | 1 + plugins/samplesource/v4l/v4lthread.cpp | 3 ++- plugins/samplesource/v4l/v4lthread.h | 4 +++- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/plugins/samplesource/v4l/v4linput.cpp b/plugins/samplesource/v4l/v4linput.cpp index 0d51a79f0..074c8f38b 100644 --- a/plugins/samplesource/v4l/v4linput.cpp +++ b/plugins/samplesource/v4l/v4linput.cpp @@ -78,6 +78,7 @@ V4LInput::~V4LInput() bool V4LInput::startInput(int device) { QMutexLocker mutexLocker(&m_mutex); + double freq; if(m_V4LThread) return false; @@ -87,7 +88,8 @@ bool V4LInput::startInput(int device) return false; } - if((m_V4LThread = new V4LThread(&m_sampleFifo)) == NULL) { + freq = (double)getCenterFrequency(); + if((m_V4LThread = new V4LThread(&m_sampleFifo, freq)) == NULL) { qFatal("out of memory"); return false; } @@ -95,8 +97,7 @@ bool V4LInput::startInput(int device) m_deviceDescription = QString("RTL-SDR /dev/swradio0"); qDebug("V4LInput: start"); - MsgReportV4L::create(m_gains)->submit(m_guiMessageQueue); -// applySettings(m_generalSettings, m_settings, true); + //MsgReportV4L::create(m_gains)->submit(m_guiMessageQueue); return true; } @@ -134,8 +135,7 @@ bool V4LInput::handleMessage(Message* message) { if(MsgConfigureV4L::match(message)) { MsgConfigureV4L* conf = (MsgConfigureV4L*)message; - if(!applySettings(conf->getGeneralSettings(), conf->getSettings(), false)) - qDebug("V4L config error"); + applySettings(conf->getGeneralSettings(), conf->getSettings(), false); message->completed(); return true; } else { @@ -143,20 +143,25 @@ bool V4LInput::handleMessage(Message* message) } } -bool V4LInput::applySettings(const GeneralSettings& generalSettings, const Settings& settings, bool force) +void V4LInput::applySettings(const GeneralSettings& generalSettings, const Settings& settings, bool force) { QMutexLocker mutexLocker(&m_mutex); + if (!m_V4LThread) { + m_generalSettings.m_centerFrequency = generalSettings.m_centerFrequency; + return; + } + if((m_generalSettings.m_centerFrequency != generalSettings.m_centerFrequency) || force) { - m_generalSettings.m_centerFrequency = generalSettings.m_centerFrequency; - if(m_V4LThread) - m_V4LThread->set_center_freq( (double)(generalSettings.m_centerFrequency + m_V4LThread->set_center_freq( (double)(generalSettings.m_centerFrequency + (SAMPLERATE / 4) )); } + m_generalSettings.m_centerFrequency = generalSettings.m_centerFrequency; +#if 0 if((m_settings.m_gain != settings.m_gain) || force) { m_settings.m_gain = settings.m_gain; - if(m_V4LThread) - m_V4LThread->set_tuner_gain((double)m_settings.m_gain); + m_V4LThread->set_tuner_gain((double)m_settings.m_gain); } - return true; +#endif } + diff --git a/plugins/samplesource/v4l/v4linput.h b/plugins/samplesource/v4l/v4linput.h index c79c1d678..680d65c53 100644 --- a/plugins/samplesource/v4l/v4linput.h +++ b/plugins/samplesource/v4l/v4linput.h @@ -100,7 +100,7 @@ private: QString m_deviceDescription; std::vector m_gains; - bool applySettings(const GeneralSettings& generalSettings, const Settings& settings, bool force); + void applySettings(const GeneralSettings& generalSettings, const Settings& settings, bool force); }; #endif // INCLUDE_V4L_H diff --git a/plugins/samplesource/v4l/v4lsource.cpp b/plugins/samplesource/v4l/v4lsource.cpp index 2ed077a0b..af5b1d850 100644 --- a/plugins/samplesource/v4l/v4lsource.cpp +++ b/plugins/samplesource/v4l/v4lsource.cpp @@ -120,6 +120,7 @@ V4LThread::OpenSource(const char *filename) } set_sample_rate((double)SAMPLERATE); + set_center_freq( centerFreq + (SAMPLERATE / 4) ); // start streaming type = V4L2_BUF_TYPE_SDR_CAPTURE; xioctl(fd, VIDIOC_STREAMON, &type); diff --git a/plugins/samplesource/v4l/v4lthread.cpp b/plugins/samplesource/v4l/v4lthread.cpp index 65ef49d96..57f517560 100644 --- a/plugins/samplesource/v4l/v4lthread.cpp +++ b/plugins/samplesource/v4l/v4lthread.cpp @@ -20,12 +20,13 @@ #include "v4lthread.h" #include "dsp/samplefifo.h" -V4LThread::V4LThread(SampleFifo* sampleFifo, QObject* parent) : +V4LThread::V4LThread(SampleFifo* sampleFifo, double frequency, QObject* parent) : QThread(parent), m_running(false), m_convertBuffer(BLOCKSIZE), m_sampleFifo(sampleFifo) { + centerFreq = frequency; start(); } diff --git a/plugins/samplesource/v4l/v4lthread.h b/plugins/samplesource/v4l/v4lthread.h index d3c21995d..cf4318761 100644 --- a/plugins/samplesource/v4l/v4lthread.h +++ b/plugins/samplesource/v4l/v4lthread.h @@ -31,7 +31,7 @@ class V4LThread : public QThread { Q_OBJECT public: - V4LThread(SampleFifo* sampleFifo, QObject* parent = NULL); + V4LThread(SampleFifo* sampleFifo, double frequency, QObject* parent = NULL); ~V4LThread(); void stopWork(); @@ -51,6 +51,8 @@ private: unsigned int recebuf_len; unsigned int recebuf_mmap_index; + double centerFreq; + QMutex m_startWaitMutex; QWaitCondition m_startWaiter; bool m_running;