From a476f8a6f05e624ed5d964967268e0fb6ef65988 Mon Sep 17 00:00:00 2001 From: John Greb Date: Thu, 6 Nov 2014 21:03:17 +0000 Subject: [PATCH] Settings. --- plugins/samplesource/v4l/v4lgui.cpp | 10 ++++--- plugins/samplesource/v4l/v4lgui.h | 2 +- plugins/samplesource/v4l/v4lgui.ui | 8 +++--- plugins/samplesource/v4l/v4linput.cpp | 23 ++++++++------- plugins/samplesource/v4l/v4linput.h | 12 ++++---- plugins/samplesource/v4l/v4lplugin.cpp | 8 +++--- plugins/samplesource/v4l/v4lsource.cpp | 18 ++++++++---- plugins/samplesource/v4l/v4lsource.h | 40 -------------------------- plugins/samplesource/v4l/v4lthread.cpp | 15 ++++------ plugins/samplesource/v4l/v4lthread.h | 6 ++-- 10 files changed, 53 insertions(+), 89 deletions(-) delete mode 100644 plugins/samplesource/v4l/v4lsource.h diff --git a/plugins/samplesource/v4l/v4lgui.cpp b/plugins/samplesource/v4l/v4lgui.cpp index 8c9ca6706..d91b1e558 100644 --- a/plugins/samplesource/v4l/v4lgui.cpp +++ b/plugins/samplesource/v4l/v4lgui.cpp @@ -95,7 +95,7 @@ bool V4LGui::handleMessage(Message* message) void V4LGui::displaySettings() { ui->centerFrequency->setValue(m_generalSettings.m_centerFrequency / 1000); - ui->decimation->setValue(m_settings.m_decimation); + ui->samplerate->setValue(m_settings.m_samplerate); if(m_gains.size() > 0) { int dist = abs(m_settings.m_gain - m_gains[0]); @@ -139,10 +139,12 @@ void V4LGui::on_gain_valueChanged(int value) sendSettings(); } -void V4LGui::on_decimation_valueChanged(int value) +void V4LGui::on_samplerate_valueChanged(int value) { - ui->decimationText->setText(tr("1:%1").arg(1 << value)); - m_settings.m_decimation = value; + int Rates[] = { 2500, 1536, 3072, 288, 1000, 0}; + int newrate = Rates[value]; + ui->samplerateText->setText(tr("%1kHz").arg(newrate)); + m_settings.m_samplerate = 1000 * newrate; sendSettings(); } diff --git a/plugins/samplesource/v4l/v4lgui.h b/plugins/samplesource/v4l/v4lgui.h index f713ed1b3..2e84be2d4 100644 --- a/plugins/samplesource/v4l/v4lgui.h +++ b/plugins/samplesource/v4l/v4lgui.h @@ -45,7 +45,7 @@ private: private slots: void on_centerFrequency_changed(quint64 value); void on_gain_valueChanged(int value); - void on_decimation_valueChanged(int value); + void on_samplerate_valueChanged(int value); void updateHardware(); }; diff --git a/plugins/samplesource/v4l/v4lgui.ui b/plugins/samplesource/v4l/v4lgui.ui index 7dad38cb1..17b3f5c5e 100644 --- a/plugins/samplesource/v4l/v4lgui.ui +++ b/plugins/samplesource/v4l/v4lgui.ui @@ -106,9 +106,9 @@ 3 - + - Signal decimation factor + Device Samplerate 4 @@ -130,12 +130,12 @@ - Zoom Out + Samplerate - + 40 diff --git a/plugins/samplesource/v4l/v4linput.cpp b/plugins/samplesource/v4l/v4linput.cpp index 28495f39c..668f2276d 100644 --- a/plugins/samplesource/v4l/v4linput.cpp +++ b/plugins/samplesource/v4l/v4linput.cpp @@ -19,7 +19,6 @@ #include #include "v4linput.h" #include "v4lthread.h" -#include "v4lsource.h" #include "v4lgui.h" #include "util/simpleserializer.h" @@ -28,21 +27,21 @@ MESSAGE_CLASS_DEFINITION(V4LInput::MsgReportV4L, Message) V4LInput::Settings::Settings() : m_gain(0), - m_decimation(0) + m_samplerate(2500000) { } void V4LInput::Settings::resetToDefaults() { m_gain = 0; - m_decimation = 0; + m_samplerate = 2500000; } QByteArray V4LInput::Settings::serialize() const { SimpleSerializer s(1); s.writeS32(1, m_gain); - s.writeS32(2, m_decimation); + s.writeS32(2, m_samplerate); return s.final(); } @@ -57,7 +56,7 @@ bool V4LInput::Settings::deserialize(const QByteArray& data) if(d.getVersion() == 1) { d.readS32(1, &m_gain, 0); - d.readS32(2, &m_decimation, 0); + d.readS32(2, &m_samplerate, 0); return true; } else { resetToDefaults(); @@ -187,7 +186,9 @@ const QString& V4LInput::getDeviceDescription() const int V4LInput::getSampleRate() const { - return 96000 * (1 << m_settings.m_decimation); + int result = m_settings.m_samplerate / 4; + if (result > 200000) result /= 4; + return result; } quint64 V4LInput::getCenterFrequency() const @@ -215,18 +216,18 @@ bool V4LInput::applySettings(const GeneralSettings& generalSettings, const Setti if((m_generalSettings.m_centerFrequency != generalSettings.m_centerFrequency) || force) { m_generalSettings.m_centerFrequency = generalSettings.m_centerFrequency; if(m_dev > 0) - V4LInput::set_center_freq( (double)(m_generalSettings.m_centerFrequency - + 384000) ); // samplerate/4 + V4LInput::set_center_freq( (double)(generalSettings.m_centerFrequency + + (settings.m_samplerate / 4) )); } if((m_settings.m_gain != settings.m_gain) || force) { m_settings.m_gain = settings.m_gain; if(m_dev > 0) V4LInput::set_tuner_gain((double)m_settings.m_gain); } - if((m_settings.m_decimation != settings.m_decimation) || force) { - m_settings.m_decimation = settings.m_decimation; + if((m_settings.m_samplerate != settings.m_samplerate) || force) { + m_settings.m_samplerate = settings.m_samplerate; if(m_dev > 0) - m_V4LThread->setDecimation(m_settings.m_decimation); + m_V4LThread->setSamplerate((double)settings.m_samplerate); } return true; } diff --git a/plugins/samplesource/v4l/v4linput.h b/plugins/samplesource/v4l/v4linput.h index 12d8613c0..282da68f7 100644 --- a/plugins/samplesource/v4l/v4linput.h +++ b/plugins/samplesource/v4l/v4linput.h @@ -20,7 +20,11 @@ #include "dsp/samplesource/samplesource.h" #include -#include "v4lsource.h" + +struct v4l_buffer { + void *start; + size_t length; +}; class V4LThread; @@ -28,7 +32,7 @@ class V4LInput : public SampleSource { public: struct Settings { qint32 m_gain; - qint32 m_decimation; + qint32 m_samplerate; Settings(); void resetToDefaults(); @@ -96,9 +100,7 @@ public: void set_center_freq(double freq); void set_bandwidth(double bandwidth); void set_tuner_gain(double gain); - int work(int noutput_items, - void* input_items, - void* output_items); + int work(int noutput_items, qint16* output_items); private: int fd; quint32 pixelformat; diff --git a/plugins/samplesource/v4l/v4lplugin.cpp b/plugins/samplesource/v4l/v4lplugin.cpp index 702e4968c..57ad54663 100644 --- a/plugins/samplesource/v4l/v4lplugin.cpp +++ b/plugins/samplesource/v4l/v4lplugin.cpp @@ -35,7 +35,7 @@ void V4LPlugin::initPlugin(PluginAPI* pluginAPI) PluginInterface::SampleSourceDevices V4LPlugin::enumSampleSources() { SampleSourceDevices result; - int count = rtlsdr_get_device_count(); + int count = 1; //rtlsdr_get_device_count(); char vendor[256]; char product[256]; char serial[256]; @@ -45,9 +45,9 @@ PluginInterface::SampleSourceDevices V4LPlugin::enumSampleSources() product[0] = '\0'; serial[0] = '\0'; - if(rtlsdr_get_device_usb_strings((uint32_t)i, vendor, product, serial) != 0) - continue; - QString displayedName(QString("SDR #%1 (%2 #%3)").arg(i + 1).arg(product).arg(serial)); +// if(rtlsdr_get_device_usb_strings((uint32_t)i, vendor, product, serial) != 0) +// continue; + QString displayedName(QString("SDR #%1").arg(i + 1)); SimpleSerializer s(1); s.writeS32(1, i); result.append(SampleSourceDevice(displayedName, "org.osmocom.sdr.samplesource.v4l", s.final())); diff --git a/plugins/samplesource/v4l/v4lsource.cpp b/plugins/samplesource/v4l/v4lsource.cpp index dddaa4219..5ec363aba 100644 --- a/plugins/samplesource/v4l/v4lsource.cpp +++ b/plugins/samplesource/v4l/v4lsource.cpp @@ -17,8 +17,16 @@ * Boston, MA 02110-1301, USA. */ -#include "v4lsource.h" #include "v4linput.h" +#include +#include +#include +#include +#include +#include +#include "/usr/local/include/libv4l2.h" +#include +#include /* Control classes */ #define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */ @@ -47,7 +55,7 @@ static void xioctl(int fh, unsigned long int request, void *arg) ret = v4l2_ioctl(fh, request, arg); } while (ret == -1 && ((errno == EINTR) || (errno == EAGAIN))); if (ret == -1) { - fprintf(stderr, "error %d\n", errno); + qCritical("error %d\n", errno); } } @@ -77,7 +85,7 @@ V4LInput::OpenSource(const char *filename) fmt.fmt.sdr.pixelformat = pixelformat; xioctl(fd, VIDIOC_S_FMT, &fmt); if (fmt.fmt.sdr.pixelformat != pixelformat) { - printf("Libv4l didn't accept FLOAT format. Cannot proceed. Pixelformat %4.4s\n", + qCritical("Libv4l didn't accept FLOAT format. Cannot proceed. Pixelformat %4.4s\n", (char *)&fmt.fmt.sdr.pixelformat); } @@ -211,9 +219,7 @@ V4LInput::set_tuner_gain(double gain) } int -V4LInput::work(int noutput_items, - void* input_items, - void* output_items) +V4LInput::work(int noutput_items, int16_t* output_items) { //complex *out = (complex *) output_items; int ret; diff --git a/plugins/samplesource/v4l/v4lsource.h b/plugins/samplesource/v4l/v4lsource.h deleted file mode 100644 index 5f691def7..000000000 --- a/plugins/samplesource/v4l/v4lsource.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2013 Antti Palosaari - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_KERNEL_LIBV4L2_X_IMPL_H -#define INCLUDED_KERNEL_LIBV4L2_X_IMPL_H - -#include -#include -#include -#include -#include -#include -#include "/usr/local/include/libv4l2.h" -#include "fcntl.h" -#include - -struct v4l_buffer { - void *start; - size_t length; -}; - - -#endif /* INCLUDED_KERNEL_LIBV4L2_X_IMPL_H */ - diff --git a/plugins/samplesource/v4l/v4lthread.cpp b/plugins/samplesource/v4l/v4lthread.cpp index c15c6faeb..69d668743 100644 --- a/plugins/samplesource/v4l/v4lthread.cpp +++ b/plugins/samplesource/v4l/v4lthread.cpp @@ -27,10 +27,9 @@ V4LThread::V4LThread(SampleFifo* sampleFifo, QObject* parent) : m_running(false), m_dev(1), m_convertBuffer(BLOCKSIZE), - m_sampleFifo(sampleFifo), - m_decimation(2) + m_sampleFifo(sampleFifo) { - m_localdecimation = 0; + m_samplerate = 2500000; } V4LThread::~V4LThread() @@ -53,9 +52,9 @@ void V4LThread::stopWork() wait(); } -void V4LThread::setDecimation(int decimation) +void V4LThread::setSamplerate(int samplerate) { - m_decimation = decimation; + m_samplerate = samplerate; } void V4LThread::run() @@ -140,12 +139,8 @@ void V4LThread::callback(const quint8* buf, qint32 len) { qint16 xreal, yimag, phase; SampleVector::iterator it = m_convertBuffer.begin(); - int decimationFactor[] = {1, 1, 1, 2, 4, 0}; - if (++m_localdecimation < decimationFactor[m_decimation]) return; - m_localdecimation = 0; - - switch(4 - m_decimation) { + switch(4) { case 0: // 1:1 = no decimation // just rotation phase = -(1<<2); diff --git a/plugins/samplesource/v4l/v4lthread.h b/plugins/samplesource/v4l/v4lthread.h index 773f400e0..5eddc05bf 100644 --- a/plugins/samplesource/v4l/v4lthread.h +++ b/plugins/samplesource/v4l/v4lthread.h @@ -34,7 +34,7 @@ public: void startWork(); void stopWork(); - void setDecimation(int decimation); + void setSamplerate(int samplerate); private: QMutex m_startWaitMutex; @@ -44,9 +44,7 @@ private: int m_dev; SampleVector m_convertBuffer; SampleFifo* m_sampleFifo; - - int m_decimation; - int m_localdecimation; + int m_samplerate; void run();