1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-16 13:21:50 -05:00

Implemented a minimalist file source plugin (recording reader) compilable but untested

This commit is contained in:
f4exb 2015-08-03 01:04:20 +02:00
parent 6c93c0b9c7
commit f9029e8572
12 changed files with 1153 additions and 0 deletions

View File

@ -128,6 +128,7 @@ Done since the fork
- Trigger line display for all trigger modes - Trigger line display for all trigger modes
- Coarse and fine trigger level sliders - Coarse and fine trigger level sliders
- Minimalist recording - Minimalist recording
- Minimalist file source (recording reader) compilable but untested
===== =====
To Do To Do

View File

@ -31,3 +31,4 @@ if(LIBUSB_FOUND AND LIBBLADERF_FOUND)
add_subdirectory(bladerf) add_subdirectory(bladerf)
endif(LIBUSB_FOUND AND LIBBLADERF_FOUND) endif(LIBUSB_FOUND AND LIBBLADERF_FOUND)
add_subdirectory(filesource)

View File

@ -0,0 +1,50 @@
project(filesource)
set(filesource_SOURCES
filesourcegui.cpp
filesourceinput.cpp
filesourceplugin.cpp
filesourcethread.cpp
)
set(filesource_HEADERS
filesourcegui.h
filesourceinput.h
filesourceplugin.h
filesourcethread.h
)
set(filesource_FORMS
filesourcegui.ui
)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/include-gpl
${LIBRTLSDR_INCLUDE_DIR}
)
#include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_PLUGIN)
add_definitions(-DQT_SHARED)
#qt4_wrap_cpp(filesource_HEADERS_MOC ${filesource_HEADERS})
qt5_wrap_ui(filesource_FORMS_HEADERS ${filesource_FORMS})
add_library(inputfilesource SHARED
${filesource_SOURCES}
${filesource_HEADERS_MOC}
${filesource_FORMS_HEADERS}
)
target_link_libraries(inputfilesource
${QT_LIBRARIES}
${LIBBLADERF_LIBRARIES}
${LIBUSB_LIBRARIES}
sdrbase
)
qt5_use_modules(inputfilesource Core Widgets OpenGL Multimedia)

View File

@ -0,0 +1,136 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
// //
// This program 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 as version 3 of the License, or //
// //
// This program 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 V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include "ui_filesourcegui.h"
#include "plugin/pluginapi.h"
#include "gui/colormapper.h"
#include "mainwindow.h"
#include "filesourcegui.h"
FileSourceGui::FileSourceGui(PluginAPI* pluginAPI, QWidget* parent) :
QWidget(parent),
ui(new Ui::FileSourceGui),
m_pluginAPI(pluginAPI),
m_settings(),
m_sampleSource(NULL)
{
ui->setupUi(this);
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
ui->centerFrequency->setValueRange(7, 0, pow(10,7));
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
displaySettings();
m_sampleSource = new FileSourceInput(m_pluginAPI->getMainWindowMessageQueue(), m_pluginAPI->getMainWindow()->getMasterTimer());
m_pluginAPI->setSampleSource(m_sampleSource);
}
FileSourceGui::~FileSourceGui()
{
delete ui;
}
void FileSourceGui::destroy()
{
delete this;
}
void FileSourceGui::setName(const QString& name)
{
setObjectName(name);
}
QString FileSourceGui::getName() const
{
return objectName();
}
void FileSourceGui::resetToDefaults()
{
m_generalSettings.resetToDefaults();
m_settings.resetToDefaults();
displaySettings();
sendSettings();
}
QByteArray FileSourceGui::serializeGeneral() const
{
return m_generalSettings.serialize();
}
bool FileSourceGui::deserializeGeneral(const QByteArray&data)
{
if(m_generalSettings.deserialize(data)) {
displaySettings();
sendSettings();
return true;
} else {
resetToDefaults();
return false;
}
}
qint64 FileSourceGui::getCenterFrequency() const
{
return m_generalSettings.m_centerFrequency;
}
QByteArray FileSourceGui::serialize() const
{
return m_settings.serialize();
}
bool FileSourceGui::deserialize(const QByteArray& data)
{
if(m_settings.deserialize(data)) {
displaySettings();
sendSettings();
return true;
} else {
resetToDefaults();
return false;
}
}
bool FileSourceGui::handleMessage(Message* message)
{
if(FileSourceInput::MsgReportFileSource::match(message)) {
displaySettings();
message->completed();
return true;
} else {
return false;
}
}
void FileSourceGui::displaySettings()
{
}
void FileSourceGui::sendSettings()
{
if(!m_updateTimer.isActive())
m_updateTimer.start(100);
}
void FileSourceGui::updateHardware()
{
FileSourceInput::MsgConfigureFileSource* message = FileSourceInput::MsgConfigureFileSource::create(m_generalSettings, m_settings);
message->submit(m_pluginAPI->getDSPEngineMessageQueue());
m_updateTimer.stop();
}

View File

@ -0,0 +1,69 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
// //
// This program 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 as version 3 of the License, or //
// //
// This program 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 V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_FILESOURCEGUI_H
#define INCLUDE_FILESOURCEGUI_H
#include <QTimer>
#include "plugin/plugingui.h"
#include "filesourceinput.h"
class PluginAPI;
namespace Ui {
class FileSourceGui;
}
class FileSourceGui : public QWidget, public PluginGUI {
Q_OBJECT
public:
explicit FileSourceGui(PluginAPI* pluginAPI, QWidget* parent = NULL);
~FileSourceGui();
void destroy();
void setName(const QString& name);
QString getName() const;
void resetToDefaults();
QByteArray serializeGeneral() const;
bool deserializeGeneral(const QByteArray&data);
qint64 getCenterFrequency() const;
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
bool handleMessage(Message* message);
private:
Ui::FileSourceGui* ui;
PluginAPI* m_pluginAPI;
SampleSource::GeneralSettings m_generalSettings;
FileSourceInput::Settings m_settings;
QTimer m_updateTimer;
std::vector<int> m_gains;
SampleSource* m_sampleSource;
void displaySettings();
void sendSettings();
void updateHardware();
private slots:
void on_playLoop_toggled(bool checked);
void on_play_toggled(bool checked);
};
#endif // INCLUDE_FILESOURCEGUI_H

View File

@ -0,0 +1,269 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FileSourceGui</class>
<widget class="QWidget" name="FileSourceGui">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>198</width>
<height>88</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>BladeRF</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_freq">
<item>
<spacer name="freqLeftSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="ValueDial" name="centerFrequency" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>16</height>
</size>
</property>
<property name="font">
<font>
<family>Monospace</family>
<pointsize>20</pointsize>
</font>
</property>
<property name="cursor">
<cursorShape>SizeVerCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="toolTip">
<string>Tuner center frequency in kHz</string>
</property>
</widget>
</item>
<item>
<spacer name="freqRightlSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_freq">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="rateTimeLayout">
<item>
<widget class="QLabel" name="rateText">
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="toolTip">
<string>Rate</string>
</property>
<property name="text">
<string>0k</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Line" name="absTimeLine">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="absTimeText">
<property name="enabled">
<bool>false</bool>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>20150101 00:00:00.000</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_rate">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="playControllLayout">
<item>
<widget class="ButtonSwitch" name="playLoop">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>:/playloop.png</normaloff>:/playloop.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="ButtonSwitch" name="play">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>:/play.png</normaloff>:/play.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Line" name="relTimeLine">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="relTimeText">
<property name="enabled">
<bool>false</bool>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>00:00:00.000</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ValueDial</class>
<extends>QWidget</extends>
<header>gui/valuedial.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ButtonSwitch</class>
<extends>QToolButton</extends>
<header>gui/buttonswitch.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,196 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
// //
// This program 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 as version 3 of the License, or //
// //
// This program 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 V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <string.h>
#include <errno.h>
#include <cstdio>
#include <iostream>
#include "util/simpleserializer.h"
#include "dsp/filesink.h"
#include "filesourcegui.h"
#include "filesourceinput.h"
#include "filesourcethread.h"
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSource, Message)
MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSource, Message)
FileSourceInput::Settings::Settings() :
m_fileName("./test.sdriq")
{
}
void FileSourceInput::Settings::resetToDefaults()
{
m_fileName = "./test.sdriq";
}
QByteArray FileSourceInput::Settings::serialize() const
{
SimpleSerializer s(1);
s.writeString(1, m_fileName);
return s.final();
}
bool FileSourceInput::Settings::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if(!d.isValid()) {
resetToDefaults();
return false;
}
if(d.getVersion() == 1) {
int intval;
d.readString(1, &m_fileName, "./test.sdriq");
return true;
} else {
resetToDefaults();
return false;
}
}
FileSourceInput::FileSourceInput(MessageQueue* msgQueueToGUI, const QTimer& masterTimer) :
SampleSource(msgQueueToGUI),
m_settings(),
m_fileSourceThread(NULL),
m_deviceDescription(),
m_sampleRate(0),
m_centerFrequency(0),
m_startingTimeStamp(0),
m_masterTimer(masterTimer)
{
}
FileSourceInput::~FileSourceInput()
{
stopInput();
}
void FileSourceInput::openFileStream()
{
m_ifstream.open(m_settings.m_fileName.toStdString().c_str(), std::ios::binary);
FileSink::Header header;
FileSink::readHeader(m_ifstream, header);
m_sampleRate = header.sampleRate;
m_centerFrequency = header.centerFrequency;
m_startingTimeStamp = header.startTimeStamp;
}
bool FileSourceInput::startInput(int device)
{
QMutexLocker mutexLocker(&m_mutex);
openFileStream();
if((m_fileSourceThread = new FileSourceThread(&m_ifstream, &m_sampleFifo)) == NULL) {
qFatal("out of memory");
goto failed;
}
m_fileSourceThread->setSamplerate(m_sampleRate);
m_fileSourceThread->connectTimer(m_masterTimer);
m_fileSourceThread->startWork();
mutexLocker.unlock();
applySettings(m_generalSettings, m_settings, true);
qDebug("bladerfInput: start");
//MsgReportBladerf::create(m_gains)->submit(m_guiMessageQueue); Pass anything here
return true;
failed:
stopInput();
return false;
}
void FileSourceInput::stopInput()
{
QMutexLocker mutexLocker(&m_mutex);
if(m_fileSourceThread != NULL) {
m_fileSourceThread->stopWork();
delete m_fileSourceThread;
m_fileSourceThread = NULL;
}
m_deviceDescription.clear();
}
const QString& FileSourceInput::getDeviceDescription() const
{
return m_deviceDescription;
}
int FileSourceInput::getSampleRate() const
{
return m_sampleRate;
}
quint64 FileSourceInput::getCenterFrequency() const
{
return m_centerFrequency;
}
std::time_t FileSourceInput::getStartingTimeStamp() const
{
return m_startingTimeStamp;
}
bool FileSourceInput::handleMessage(Message* message)
{
if(MsgConfigureFileSource::match(message)) {
MsgConfigureFileSource* conf = (MsgConfigureFileSource*)message;
if(!applySettings(conf->getGeneralSettings(), conf->getSettings(), false))
qDebug("File Source config error");
message->completed();
return true;
} else {
return false;
}
}
bool FileSourceInput::applySettings(const GeneralSettings& generalSettings, const Settings& settings, bool force)
{
QMutexLocker mutexLocker(&m_mutex);
if((m_settings.m_fileName != settings.m_fileName) || force) {
m_settings.m_fileName = settings.m_fileName;
if (m_fileSourceThread != 0) {
m_fileSourceThread->stopWork();
}
if (m_ifstream.is_open()) {
m_ifstream.close();
}
openFileStream();
if (m_fileSourceThread != 0) {
m_fileSourceThread->setSamplerate(m_sampleRate);
}
std::cerr << "FileSourceInput: center freq: " << m_generalSettings.m_centerFrequency << " Hz"
<< " file name: " << settings.m_fileName.toStdString() << std::endl;
}
return true;
}

View File

@ -0,0 +1,108 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
// //
// This program 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 as version 3 of the License, or //
// //
// This program 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 V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_FILESOURCEINPUT_H
#define INCLUDE_FILESOURCEINPUT_H
#include "dsp/samplesource/samplesource.h"
#include <QString>
#include <QTimer>
#include <ctime>
#include <iostream>
#include <fstream>
class FileSourceThread;
class FileSourceInput : public SampleSource {
public:
struct Settings {
QString m_fileName;
Settings();
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};
class MsgConfigureFileSource : public Message {
MESSAGE_CLASS_DECLARATION
public:
const GeneralSettings& getGeneralSettings() const { return m_generalSettings; }
const Settings& getSettings() const { return m_settings; }
static MsgConfigureFileSource* create(const GeneralSettings& generalSettings, const Settings& settings)
{
return new MsgConfigureFileSource(generalSettings, settings);
}
private:
GeneralSettings m_generalSettings;
Settings m_settings;
MsgConfigureFileSource(const GeneralSettings& generalSettings, const Settings& settings) :
Message(),
m_generalSettings(generalSettings),
m_settings(settings)
{ }
};
class MsgReportFileSource : public Message {
MESSAGE_CLASS_DECLARATION
public:
static MsgReportFileSource* create()
{
return new MsgReportFileSource();
}
protected:
MsgReportFileSource() :
Message()
{ }
};
FileSourceInput(MessageQueue* msgQueueToGUI, const QTimer& masterTimer);
~FileSourceInput();
bool startInput(int device);
void stopInput();
const QString& getDeviceDescription() const;
int getSampleRate() const;
quint64 getCenterFrequency() const;
std::time_t getStartingTimeStamp() const;
bool handleMessage(Message* message);
private:
QMutex m_mutex;
Settings m_settings;
std::ifstream m_ifstream;
FileSourceThread* m_fileSourceThread;
QString m_deviceDescription;
int m_sampleRate;
quint64 m_centerFrequency;
std::time_t m_startingTimeStamp;
const QTimer& m_masterTimer;
bool applySettings(const GeneralSettings& generalSettings, const Settings& settings, bool force);
void openFileStream();
};
#endif // INCLUDE_FILESOURCEINPUT_H

View File

@ -0,0 +1,77 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
// //
// This program 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 as version 3 of the License, or //
// //
// This program 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 V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QtPlugin>
#include <QAction>
#include <libbladeRF.h>
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
#include "filesourcegui.h"
#include "filesourceplugin.h"
const PluginDescriptor FileSourcePlugin::m_pluginDescriptor = {
QString("File source input"),
QString("1.0"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/rtl-sdrangelove/tree/f4exb"),
true,
QString("https://github.com/f4exb/rtl-sdrangelove/tree/f4exb")
};
FileSourcePlugin::FileSourcePlugin(QObject* parent) :
QObject(parent)
{
}
const PluginDescriptor& FileSourcePlugin::getPluginDescriptor() const
{
return m_pluginDescriptor;
}
void FileSourcePlugin::initPlugin(PluginAPI* pluginAPI)
{
m_pluginAPI = pluginAPI;
m_pluginAPI->registerSampleSource("org.osmocom.sdr.samplesource.filesource", this);
}
PluginInterface::SampleSourceDevices FileSourcePlugin::enumSampleSources()
{
SampleSourceDevices result;
int count = 1;
for(int i = 0; i < count; i++)
{
QString displayedName(QString("FileSource #%1 choose file").arg(i));
SimpleSerializer s(1);
s.writeS32(1, i);
s.writeString(2, "");
result.append(SampleSourceDevice(displayedName, "org.osmocom.sdr.samplesource.filesource", s.final()));
}
return result;
}
PluginGUI* FileSourcePlugin::createSampleSource(const QString& sourceName, const QByteArray& address)
{
if(sourceName == "org.osmocom.sdr.samplesource.filesource") {
FileSourceGui* gui = new FileSourceGui(m_pluginAPI);
m_pluginAPI->setInputGUI(gui);
return gui;
} else {
return NULL;
}
}

View File

@ -0,0 +1,43 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
// //
// This program 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 as version 3 of the License, or //
// //
// This program 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 V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_FILESOURCEPLUGIN_H
#define INCLUDE_FILESOURCEPLUGIN_H
#include <QObject>
#include "plugin/plugininterface.h"
class FileSourcePlugin : public QObject, PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)
Q_PLUGIN_METADATA(IID "org.osmocom.sdr.samplesource.filesource")
public:
explicit FileSourcePlugin(QObject* parent = NULL);
const PluginDescriptor& getPluginDescriptor() const;
void initPlugin(PluginAPI* pluginAPI);
SampleSourceDevices enumSampleSources();
PluginGUI* createSampleSource(const QString& sourceName, const QByteArray& address);
private:
static const PluginDescriptor m_pluginDescriptor;
PluginAPI* m_pluginAPI;
};
#endif // INCLUDE_FILESOURCEPLUGIN_H

View File

@ -0,0 +1,137 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
// //
// This program 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 as version 3 of the License, or //
// //
// This program 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 V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <errno.h>
#include "dsp/samplefifo.h"
#include "filesourcethread.h"
const int FileSourceThread::m_rateDivider = 1000/FILESOURCE_THROTTLE_MS;
FileSourceThread::FileSourceThread(std::ifstream *samplesStream, SampleFifo* sampleFifo, QObject* parent) :
QThread(parent),
m_running(false),
m_ifstream(samplesStream),
m_buf(0),
m_bufsize(0),
m_chunksize(0),
m_sampleFifo(sampleFifo),
m_samplerate(0)
{
}
FileSourceThread::~FileSourceThread()
{
if (m_running) {
stopWork();
}
if (m_buf != 0) {
free(m_buf);
}
}
void FileSourceThread::startWork()
{
m_startWaitMutex.lock();
start();
while(!m_running)
m_startWaiter.wait(&m_startWaitMutex, 100);
m_startWaitMutex.unlock();
}
void FileSourceThread::stopWork()
{
m_running = false;
wait();
}
void FileSourceThread::setSamplerate(int samplerate)
{
if (samplerate != m_samplerate)
{
if (m_running) {
stopWork();
}
m_bufsize = (m_samplerate / m_rateDivider)*4;
if (m_buf == 0) {
m_buf = (quint8*) malloc(m_bufsize);
} else {
m_buf = (quint8*) realloc((void*) m_buf, m_bufsize);
}
}
m_samplerate = samplerate;
m_chunksize = (m_samplerate / m_rateDivider)*4;
}
void FileSourceThread::run()
{
int res;
m_running = true;
m_startWaiter.wakeAll();
while(m_running)
{
sleep(1);
}
m_running = false;
}
void FileSourceThread::connectTimer(const QTimer& timer)
{
std::cerr << "FileSourceThread::connectTimer" << std::endl;
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
}
void FileSourceThread::tick()
{
if (m_running)
{
// read samples directly feeding the SampleFifo (no callback)
m_ifstream->read(reinterpret_cast<char*>(m_buf), m_chunksize);
m_sampleFifo->write(m_buf, m_chunksize);
}
}
/*
void FileSourceThread::decimate1(SampleVector::iterator* it, const qint16* buf, qint32 len)
{
qint16 xreal, yimag;
for (int pos = 0; pos < len; pos += 2) {
xreal = buf[pos+0];
yimag = buf[pos+1];
Sample s( xreal * 16, yimag * 16 ); // shift by 4 bit positions (signed)
**it = s;
(*it)++;
}
}
// Decimate according to specified log2 (ex: log2=4 => decim=16)
void FileSourceThread::callback(const qint16* buf, qint32 len)
{
SampleVector::iterator it = m_convertBuffer.begin();
decimate1(&it, buf, len);
m_sampleFifo->write(m_convertBuffer.begin(), it);
}
*/

View File

@ -0,0 +1,66 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
// //
// This program 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 as version 3 of the License, or //
// //
// This program 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 V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_FILESOURCETHREAD_H
#define INCLUDE_FILESOURCETHREAD_H
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <QTimer>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include "dsp/samplefifo.h"
#include "dsp/inthalfbandfilter.h"
#define FILESOURCE_THROTTLE_MS 50
class FileSourceThread : public QThread {
Q_OBJECT
public:
FileSourceThread(std::ifstream *samplesStream, SampleFifo* sampleFifo, QObject* parent = NULL);
~FileSourceThread();
void startWork();
void stopWork();
void setSamplerate(int samplerate);
void connectTimer(const QTimer& timer);
private:
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
bool m_running;
std::ifstream* m_ifstream;
quint8 *m_buf;
std::size_t m_bufsize;
std::size_t m_chunksize;
SampleFifo* m_sampleFifo;
int m_samplerate;
static const int m_rateDivider;
void run();
//void decimate1(SampleVector::iterator* it, const qint16* buf, qint32 len);
//void callback(const qint16* buf, qint32 len);
private slots:
void tick();
};
#endif // INCLUDE_FILESOURCETHREAD_H