From 64044e521e2dc279fe4dda209c8c3d1382dd9879 Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 16 Feb 2018 00:04:07 +0100 Subject: [PATCH] Perseus: workaround to fix sample rate setting and removal of useless passing to thread --- plugins/samplesource/perseus/perseusinput.cpp | 46 +++++++++++-------- .../samplesource/perseus/perseusthread.cpp | 6 --- plugins/samplesource/perseus/perseusthread.h | 2 - 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/plugins/samplesource/perseus/perseusinput.cpp b/plugins/samplesource/perseus/perseusinput.cpp index 7c277762f..35e0f9430 100644 --- a/plugins/samplesource/perseus/perseusinput.cpp +++ b/plugins/samplesource/perseus/perseusinput.cpp @@ -300,16 +300,22 @@ bool PerseusInput::applySettings(const PerseusSettings& settings, bool force) if (m_perseusDescriptor != 0) { int rate = m_sampleRates[settings.m_devSampleRateIndex < m_sampleRates.size() ? settings.m_devSampleRateIndex: 0]; - int rc = perseus_set_sampling_rate(m_perseusDescriptor, rate); + int rc; - if (rc < 0) { - qCritical("PerseusInput::applySettings: could not set sample rate index %u (%d S/s): %s", - settings.m_devSampleRateIndex, rate, perseus_errorstr()); - } - else if (m_perseusThread != 0) + for (int i = 0; i < 2; i++) // it turns out that it has to be done twice { - qDebug("PerseusInput::applySettings: sample rate set to index: %u (%d S/s)", settings.m_devSampleRateIndex, rate); - m_perseusThread->setSamplerate(rate); + rc = perseus_set_sampling_rate(m_perseusDescriptor, rate); + + if (rc < 0) { + qCritical("PerseusInput::applySettings: could not set sample rate index %u (%d S/s): %s", + settings.m_devSampleRateIndex, rate, perseus_errorstr()); + break; + } + else + { + qDebug("PerseusInput::applySettings: sample rate set to index #%d: %u (%d S/s)", + i, settings.m_devSampleRateIndex, rate); + } } } } @@ -329,7 +335,8 @@ bool PerseusInput::applySettings(const PerseusSettings& settings, bool force) || (m_settings.m_LOppmTenths != settings.m_LOppmTenths) || (m_settings.m_wideBand != settings.m_wideBand) || (m_settings.m_transverterMode != settings.m_transverterMode) - || (m_settings.m_transverterDeltaFrequency != settings.m_transverterDeltaFrequency)) + || (m_settings.m_transverterDeltaFrequency != settings.m_transverterDeltaFrequency) + || (m_settings.m_devSampleRateIndex != settings.m_devSampleRateIndex)) { qint64 deviceCenterFrequency = settings.m_centerFrequency; deviceCenterFrequency -= settings.m_transverterMode ? settings.m_transverterDeltaFrequency : 0; @@ -377,17 +384,20 @@ bool PerseusInput::applySettings(const PerseusSettings& settings, bool force) m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); } - if ((m_settings.m_devSampleRateIndex != settings.m_devSampleRateIndex) || force) - { - if (m_perseusThread && m_perseusThread->isRunning()) - { - stop(); - start(); - } - } - m_settings = settings; m_settings.m_devSampleRateIndex = sampleRateIndex; + + qDebug() << "PerseusInput::applySettings: " + << " m_LOppmTenths: " << m_settings.m_LOppmTenths + << " m_devSampleRateIndex: " << m_settings.m_devSampleRateIndex + << " m_log2Decim: " << m_settings.m_log2Decim + << " m_transverterMode: " << m_settings.m_transverterMode + << " m_transverterDeltaFrequency: " << m_settings.m_transverterDeltaFrequency + << " m_adcDither: " << m_settings.m_adcDither + << " m_adcPreamp: " << m_settings.m_adcPreamp + << " m_wideBand: " << m_settings.m_wideBand + << " m_attenuator: " << m_settings.m_attenuator; + return true; } diff --git a/plugins/samplesource/perseus/perseusthread.cpp b/plugins/samplesource/perseus/perseusthread.cpp index 611c273f6..a64b84e47 100644 --- a/plugins/samplesource/perseus/perseusthread.cpp +++ b/plugins/samplesource/perseus/perseusthread.cpp @@ -25,7 +25,6 @@ PerseusThread::PerseusThread(perseus_descr* dev, SampleSinkFifo* sampleFifo, QOb m_dev(dev), m_convertBuffer(PERSEUS_NBSAMPLES), m_sampleFifo(sampleFifo), - m_samplerate(10), m_log2Decim(0) { m_this = this; @@ -54,11 +53,6 @@ void PerseusThread::stopWork() wait(); } -void PerseusThread::setSamplerate(uint32_t samplerate) -{ - m_samplerate = samplerate; -} - void PerseusThread::setLog2Decimation(unsigned int log2_decim) { m_log2Decim = log2_decim; diff --git a/plugins/samplesource/perseus/perseusthread.h b/plugins/samplesource/perseus/perseusthread.h index 766fd03c7..6fe21e93d 100644 --- a/plugins/samplesource/perseus/perseusthread.h +++ b/plugins/samplesource/perseus/perseusthread.h @@ -37,7 +37,6 @@ public: void startWork(); void stopWork(); - void setSamplerate(uint32_t samplerate); void setLog2Decimation(unsigned int log2_decim); private: @@ -50,7 +49,6 @@ private: SampleVector m_convertBuffer; SampleSinkFifo* m_sampleFifo; - int m_samplerate; unsigned int m_log2Decim; static PerseusThread *m_this;