diff --git a/plugins/samplesource/CMakeLists.txt b/plugins/samplesource/CMakeLists.txt
index a39c819c3..524ff5fc3 100644
--- a/plugins/samplesource/CMakeLists.txt
+++ b/plugins/samplesource/CMakeLists.txt
@@ -58,4 +58,8 @@ if(ENABLE_SOAPYSDR AND SOAPYSDR_FOUND)
add_subdirectory(soapysdrinput)
endif()
+if(LIBSIGMF_FOUND)
+ add_subdirectory(sigmffileinput)
+endif()
+
add_subdirectory(kiwisdr)
\ No newline at end of file
diff --git a/plugins/samplesource/sigmffileinput/CMakeLists.txt b/plugins/samplesource/sigmffileinput/CMakeLists.txt
new file mode 100644
index 000000000..aa142c5b7
--- /dev/null
+++ b/plugins/samplesource/sigmffileinput/CMakeLists.txt
@@ -0,0 +1,61 @@
+project(sigmffileinput)
+
+set(sigmffileinput_SOURCES
+ sigmffileinput.cpp
+ sigmffileinputplugin.cpp
+ sigmffileinputthread.cpp
+ sigmffileinputsettings.cpp
+ sigmffileinputwebapiadapter.cpp
+)
+
+set(sigmffileinput_HEADERS
+ sigmffileinput.h
+ sigmffileinputplugin.h
+ sigmffileinputthread.h
+ sigmffileinputsettings.h
+ sigmffileinputwebapiadapter.h
+)
+
+include_directories(
+ ${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
+ ${LIBSIGMF_INCLUDE_DIR}
+)
+
+if(NOT SERVER_MODE)
+ set(sigmffileinput_SOURCES
+ ${sigmffileinput_SOURCES}
+ sigmffileinputgui.cpp
+ recordinfodialog.cpp
+ sigmffileinputgui.ui
+ recordinfodialog.ui
+ )
+ set(sigmffileinput_HEADERS
+ ${sigmffileinput_HEADERS}
+ sigmffileinputgui.h
+ recordinfodialog.h
+ )
+ set(TARGET_NAME inputsigmffileinput)
+ set(TARGET_LIB "Qt5::Widgets")
+ set(TARGET_LIB_GUI "sdrgui")
+ set(INSTALL_FOLDER ${INSTALL_PLUGINS_DIR})
+else()
+ set(TARGET_NAME inputsigmffileinputsrv)
+ set(TARGET_LIB "")
+ set(TARGET_LIB_GUI "")
+ set(INSTALL_FOLDER ${INSTALL_PLUGINSSRV_DIR})
+endif()
+
+add_library(${TARGET_NAME} SHARED
+ ${sigmffileinput_SOURCES}
+)
+
+target_link_libraries(${TARGET_NAME}
+ Qt5::Core
+ ${TARGET_LIB}
+ sdrbase
+ ${TARGET_LIB_GUI}
+ swagger
+ ${LIBSIGMF_LIBRARIES}
+)
+
+install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER})
diff --git a/plugins/samplesource/sigmffileinput/readme.md b/plugins/samplesource/sigmffileinput/readme.md
new file mode 100644
index 000000000..ac674f36b
--- /dev/null
+++ b/plugins/samplesource/sigmffileinput/readme.md
@@ -0,0 +1,113 @@
+
File input plugin
+
+Introduction
+
+This plugin reads a file of I/Q samples that have been previously saved with the file record button of other sampling source devices. The file starts with a 32 byte header of all unsigned integer of various sizes containing meta data:
+
+
+
+ | Displ. |
+ Bytes |
+ Description |
+
+
+ | 0 |
+ 4 |
+ Sample rate in S/s |
+
+
+ | 4 |
+ 8 |
+ Center frequency in Hz |
+
+
+ | 12 |
+ 8 |
+ Unix epoch (timestamp) of start |
+
+
+ | 20 |
+ 4 |
+ Sample size (16 or 24 bits) |
+
+
+ | 24 |
+ 4 |
+ Filler with zeroes |
+
+
+ | 28 |
+ 4 |
+ CRC32 of the previous 28 bytes |
+
+
+
+The header takes an integer number of 16 (4 bytes) or 24 (8 bytes) bits samples. To calculate CRC it is assumed that bytes are in little endian order.
+
+Interface
+
+
+
+1: Start/Stop
+
+Device start / stop button.
+
+ - Blue triangle icon: ready to be started
+ - Green square icon: currently running and can be stopped
+ - Magenta (or pink) square icon: an error occurred. The file may not be found or this can be a header CRC error or the file is too small (less than the header length). You may stop and choose another file.
+
+2: Stream sample rate
+
+Baseband I/Q sample rate in kS/s. This is the sample rate present in the header.
+
+3: Frequency
+
+This is the center frequency of reception in kHz when the record was taken and written in the header.
+
+4: Open file
+
+Opens a file dialog to select the input file. It expects a default extension of `.sdriq`. This button is disabled when the stream is running. You need to pause (button 11) to make it active and thus be able to select another file.
+
+5: File path
+
+Absolute path of the file being read
+
+6: File recorded sample rate
+
+Sample rate of the record in kS/s as written in the header. The reading process is based on this sample rate.
+
+7: Sample size
+
+This is the sample size in bits as written in the header. The reading process is based on this sample size.
+
+8: CRC indicator
+
+Indicates if the header block CRC check has succeeded (green) or failed (red) or undetermined yet (grey). If the header is corrupted you may try to reconstruct a valid header using the `rescuesdriq` utility in the folder with the same name. See the [readme](../../../rescuesdriq/readme.md) for details.
+
+9: Current timestamp
+
+This is the timestamp of the current pointer in the file based on the start time, number of samples read and sample rate.
+
+10: Loop
+
+Use this button to read in a loop or read only once
+
+11: Play/pause
+
+This is the play/pause button
+
+12: Playback acceleration
+
+Use this combo to select play back acceleration to values of 1 (no acceleration), 2, 5, 10, 20, 50, 100, 200, 500, 1k (1000) times. This is useful on long recordings used in conjunction with the spectrum "Max" averaging mode in order to see the waterfall over a long period. Thus the waterfall will be filled much faster.
+
+☞ Note that this control is enabled only in paused mode.
+
+⚠ The result when using channel plugins with acceleration is unpredictable. Use this tool to locate your signal of interest then play at normal speed to get proper demodulation or decoding.
+
+13: Relative timestamp and record length
+
+Left is the relative timestamp of the current pointer from the start of the record. Right is the total record time.
+
+14: Current pointer gauge
+
+This represents the position of the current pointer position in the complete recording. It can be used it paused mode to position the current pointer by moving the slider.
diff --git a/plugins/samplesource/sigmffileinput/recordinfodialog.cpp b/plugins/samplesource/sigmffileinput/recordinfodialog.cpp
new file mode 100644
index 000000000..76efae0b0
--- /dev/null
+++ b/plugins/samplesource/sigmffileinput/recordinfodialog.cpp
@@ -0,0 +1,15 @@
+#include "recordinfodialog.h"
+#include "ui_recordinfodialog.h"
+
+RecordInfoDialog::RecordInfoDialog(const QString& text, QWidget* parent) :
+ QDialog(parent),
+ ui(new Ui::RecordInfoDialog)
+{
+ ui->setupUi(this);
+ ui->infoText->setText(text);
+}
+
+RecordInfoDialog::~RecordInfoDialog()
+{
+ delete ui;
+}
diff --git a/plugins/samplesource/sigmffileinput/recordinfodialog.h b/plugins/samplesource/sigmffileinput/recordinfodialog.h
new file mode 100644
index 000000000..1f72bc43c
--- /dev/null
+++ b/plugins/samplesource/sigmffileinput/recordinfodialog.h
@@ -0,0 +1,23 @@
+#ifndef INCLUDE_ABOUTDIALOG_H
+#define INCLUDE_ABOUTDIALOG_H
+
+#include
+
+#include "export.h"
+
+namespace Ui {
+ class RecordInfoDialog;
+}
+
+class SDRGUI_API RecordInfoDialog : public QDialog {
+ Q_OBJECT
+
+public:
+ explicit RecordInfoDialog(const QString& text, QWidget* parent = nullptr);
+ ~RecordInfoDialog();
+
+private:
+ Ui::RecordInfoDialog* ui;
+};
+
+#endif // INCLUDE_ABOUTDIALOG_H
diff --git a/plugins/samplesource/sigmffileinput/recordinfodialog.ui b/plugins/samplesource/sigmffileinput/recordinfodialog.ui
new file mode 100644
index 000000000..11aa7da36
--- /dev/null
+++ b/plugins/samplesource/sigmffileinput/recordinfodialog.ui
@@ -0,0 +1,127 @@
+
+
+ RecordInfoDialog
+
+
+
+ 0
+ 0
+ 404
+ 300
+
+
+
+
+ 0
+ 0
+
+
+
+
+ 404
+ 300
+
+
+
+
+ Liberation Sans
+ 9
+
+
+
+ File information
+
+
+
+ 2
+
+
+ 2
+
+
+ 2
+
+
+ 2
+
+ -
+
+
+ SigMF file information (meta data)
+
+
+
+ -
+
+
+
+ 398
+ 0
+
+
+
+
+ Liberation Mono
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Ok
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ RecordInfoDialog
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ RecordInfoDialog
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+
diff --git a/plugins/samplesource/sigmffileinput/sigmffileconvert.h b/plugins/samplesource/sigmffileinput/sigmffileconvert.h
new file mode 100644
index 000000000..664ff9214
--- /dev/null
+++ b/plugins/samplesource/sigmffileinput/sigmffileconvert.h
@@ -0,0 +1,1554 @@
+///////////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 2020 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 //
+// (at your option) any later version. //
+// //
+// 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 . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#ifndef INCLUDE_SIGMFFILECONVERT_H
+#define INCLUDE_SIGMFFILECONVERT_H
+
+#include "dsp/dsptypes.h"
+
+// Convert from Little Endian
+
+template
+T sigMFFromLE(const T in) {
+ return in; // default assumes LE -> LE and is unused anyway
+}
+
+template<>
+float sigMFFromLE(const float in)
+{
+#if defined(__WINDOWS__) || (BYTE_ORDER == LITTLE_ENDIAN)
+ return in;
+#else
+ float retVal;
+ char *toConvert = ( char* ) & in;
+ char *converted = ( char* ) & retVal;
+
+ // swap the bytes into a temporary buffer
+ converted[0] = toConvert[3];
+ converted[1] = toConvert[2];
+ converted[2] = toConvert[1];
+ converted[3] = toConvert[0];
+
+ return retVal;
+#endif
+}
+
+template<>
+int16_t sigMFFromLE(const int16_t in)
+{
+#if defined(__WINDOWS__) || (BYTE_ORDER == LITTLE_ENDIAN)
+ return in;
+#else
+ int16_t retVal;
+ char *toConvert = ( char* ) & in;
+ char *converted = ( char* ) & retVal;
+
+ // swap the bytes into a temporary buffer
+ converted[0] = toConvert[1];
+ converted[1] = toConvert[0];
+
+ return retVal;
+#endif
+}
+
+template<>
+uint16_t sigMFFromLE(const uint16_t in)
+{
+#if defined(__WINDOWS__) || (BYTE_ORDER == LITTLE_ENDIAN)
+ return in;
+#else
+ uint16_t retVal;
+ char *toConvert = ( char* ) & in;
+ char *converted = ( char* ) & retVal;
+
+ // swap the bytes into a temporary buffer
+ converted[0] = toConvert[1];
+ converted[1] = toConvert[0];
+
+ return retVal;
+#endif
+}
+
+template<>
+int32_t sigMFFromLE(const int32_t in)
+{
+#if defined(__WINDOWS__) || (BYTE_ORDER == LITTLE_ENDIAN)
+ return in;
+#else
+ int32_t retVal;
+ char *toConvert = ( char* ) & in;
+ char *converted = ( char* ) & retVal;
+
+ // swap the bytes into a temporary buffer
+ converted[0] = toConvert[3];
+ converted[1] = toConvert[2];
+ converted[2] = toConvert[1];
+ converted[3] = toConvert[0];
+
+ return retVal;
+#endif
+}
+
+template<>
+uint32_t sigMFFromLE(const uint32_t in)
+{
+#if defined(__WINDOWS__) || (BYTE_ORDER == LITTLE_ENDIAN)
+ return in;
+#else
+ uint32_t retVal;
+ char *toConvert = ( char* ) & in;
+ char *converted = ( char* ) & retVal;
+
+ // swap the bytes into a temporary buffer
+ converted[0] = toConvert[3];
+ converted[1] = toConvert[2];
+ converted[2] = toConvert[1];
+ converted[3] = toConvert[0];
+
+ return retVal;
+#endif
+}
+
+// Convert from Big Endian
+
+template
+T sigMFFromBE(const T in) {
+ return in; // default assumes BE -> BE and is unused anyway
+}
+
+template<>
+float sigMFFromBE(const float in)
+{
+#if defined(__WINDOWS__) || (BYTE_ORDER == LITTLE_ENDIAN)
+ float retVal;
+ char *toConvert = ( char* ) & in;
+ char *converted = ( char* ) & retVal;
+
+ // swap the bytes into a temporary buffer
+ converted[0] = toConvert[3];
+ converted[1] = toConvert[2];
+ converted[2] = toConvert[1];
+ converted[3] = toConvert[0];
+
+ return retVal;
+#else
+ return in;
+#endif
+}
+
+template<>
+int16_t sigMFFromBE(const int16_t in)
+{
+#if defined(__WINDOWS__) || (BYTE_ORDER == LITTLE_ENDIAN)
+ int16_t retVal;
+ char *toConvert = ( char* ) & in;
+ char *converted = ( char* ) & retVal;
+
+ // swap the bytes into a temporary buffer
+ converted[0] = toConvert[1];
+ converted[1] = toConvert[0];
+
+ return retVal;
+#else
+ return in;
+#endif
+}
+
+template<>
+uint16_t sigMFFromBE(const uint16_t in)
+{
+#if defined(__WINDOWS__) || (BYTE_ORDER == LITTLE_ENDIAN)
+ uint16_t retVal;
+ char *toConvert = ( char* ) & in;
+ char *converted = ( char* ) & retVal;
+
+ // swap the bytes into a temporary buffer
+ converted[0] = toConvert[1];
+ converted[1] = toConvert[0];
+
+ return retVal;
+#else
+ return in;
+#endif
+}
+
+template<>
+int32_t sigMFFromBE(const int32_t in)
+{
+#if defined(__WINDOWS__) || (BYTE_ORDER == LITTLE_ENDIAN)
+ int32_t retVal;
+ char *toConvert = ( char* ) & in;
+ char *converted = ( char* ) & retVal;
+
+ // swap the bytes into a temporary buffer
+ converted[0] = toConvert[3];
+ converted[1] = toConvert[2];
+ converted[2] = toConvert[1];
+ converted[3] = toConvert[0];
+
+ return retVal;
+#else
+ return in;
+#endif
+}
+
+template<>
+uint32_t sigMFFromBE(const uint32_t in)
+{
+#if defined(__WINDOWS__) || (BYTE_ORDER == LITTLE_ENDIAN)
+ uint32_t retVal;
+ char *toConvert = ( char* ) & in;
+ char *converted = ( char* ) & retVal;
+
+ // swap the bytes into a temporary buffer
+ converted[0] = toConvert[3];
+ converted[1] = toConvert[2];
+ converted[2] = toConvert[1];
+ converted[3] = toConvert[0];
+
+ return retVal;
+#else
+ return in;
+#endif
+}
+
+// Sample conversions
+
+class SigMFConverterInterface
+{
+public:
+ virtual int convert(FixReal *convertBuffer, const quint8* buf, int nbBytes) = 0;
+};
+
+template
+class SigMFConverter : public SigMFConverterInterface
+{
+public:
+ virtual int convert(FixReal *convertBuffer, const quint8* buf, int nbBytes);
+};
+
+template
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const SigMFT *sigMFBuf = (SigMFT *) buf;
+ int nbSamples = nbBytes / ((IsComplex ? 2 : 1) * sizeof(SigMFT));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFBuf[2*is];
+ convertBuffer[2*is+1] = sigMFBuf[2*is+1];
+ }
+
+ return nbSamples;
+}
+
+// Specialized templates
+
+// =================
+// float input type
+// =================
+
+// float complex LE IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const float *sigMFBuf = (float *) buf;
+ int nbSamples = nbBytes / (2*sizeof(float));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]) * 32768.0f;
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is+1]) * 32768.0f;
+ }
+
+ return nbSamples;
+}
+
+// float complex LE IQ => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const float *sigMFBuf = (float *) buf;
+ int nbSamples = nbBytes / (2*sizeof(float));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]) * 8388608.0f;
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is+1]) * 8388608.0f;
+ }
+
+ return nbSamples;
+}
+
+// float complex LE QI => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const float *sigMFBuf = (float *) buf;
+ int nbSamples = nbBytes / (2*sizeof(float));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is+1]) * 32768.0f;
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is]) * 32768.0f;
+ }
+
+ return nbSamples;
+}
+
+// float complex LE QI => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const float *sigMFBuf = (float *) buf;
+ int nbSamples = nbBytes / (2*sizeof(float));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is+1]) * 8388608.0f;
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is]) * 8388608.0f;
+ }
+
+ return nbSamples;
+}
+
+// float real LE => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const float *sigMFBuf = (float *) buf;
+ int nbSamples = nbBytes / sizeof(float);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]) * 32768.0f;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// float real LE => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const float *sigMFBuf = (float *) buf;
+ int nbSamples = nbBytes / sizeof(float);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]) * 8388608.0f;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// float complex BE IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const float *sigMFBuf = (float *) buf;
+ int nbSamples = nbBytes / (2*sizeof(float));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]) * 32768.0f;
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is+1]) * 32768.0f;
+ }
+
+ return nbSamples;
+}
+
+// float complex BE IQ => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const float *sigMFBuf = (float *) buf;
+ int nbSamples = nbBytes / (2*sizeof(float));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]) * 8388608.0f;
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is+1]) * 8388608.0f;
+ }
+
+ return nbSamples;
+}
+
+// float complex BE QI => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const float *sigMFBuf = (float *) buf;
+ int nbSamples = nbBytes / (2*sizeof(float));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is+1]) * 32768.0f;
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is]) * 32768.0f;
+ }
+
+ return nbSamples;
+}
+
+// float complex BE QI => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const float *sigMFBuf = (float *) buf;
+ int nbSamples = nbBytes / (2*sizeof(float));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is+1]) * 8388608.0f;
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is]) * 8388608.0f;
+ }
+
+ return nbSamples;
+}
+
+// float real BE => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const float *sigMFBuf = (float *) buf;
+ int nbSamples = nbBytes / sizeof(float);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]) * 32768.0f;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// float real BE => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const float *sigMFBuf = (float *) buf;
+ int nbSamples = nbBytes / sizeof(float);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]) * 8388608.0f;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// ================================
+// 8 bit signed integer input type
+// ================================
+
+// s8 complex IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int8_t *sigMFBuf = (int8_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int8_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFBuf[2*is] << 8;
+ convertBuffer[2*is+1] = sigMFBuf[2*is+1] << 8;
+ }
+
+ return nbSamples;
+}
+
+// s8 complex IQ => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int8_t *sigMFBuf = (int8_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int8_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFBuf[2*is] << 16;
+ convertBuffer[2*is+1] = sigMFBuf[2*is+1] << 16;
+ }
+
+ return nbSamples;
+}
+
+// s8 complex QI => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int8_t *sigMFBuf = (int8_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int8_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFBuf[2*is+1] << 8;
+ convertBuffer[2*is+1] = sigMFBuf[2*is] << 8;
+ }
+
+ return nbSamples;
+}
+
+// s8 complex QI => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int8_t *sigMFBuf = (int8_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int8_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFBuf[2*is+1] << 16;
+ convertBuffer[2*is+1] = sigMFBuf[2*is] << 16;
+ }
+
+ return nbSamples;
+}
+
+// s8 real => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int8_t *sigMFBuf = (int8_t *) buf;
+ int nbSamples = nbBytes / sizeof(int8_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFBuf[2*is] << 8;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// s8 real => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int8_t *sigMFBuf = (int8_t *) buf;
+ int nbSamples = nbBytes / sizeof(int8_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFBuf[2*is] << 16;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// ==================================
+// 8 bit unsigned integer input type
+// ==================================
+
+// u8 complex IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* sigMFBuf, int nbBytes)
+{
+ int nbSamples = nbBytes / (2*sizeof(uint8_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFBuf[2*is] - 128) << 8;
+ convertBuffer[2*is+1] = (sigMFBuf[2*is+1] - 128) << 8;
+ }
+
+ return nbSamples;
+}
+
+// u8 complex IQ => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* sigMFBuf, int nbBytes)
+{
+ int nbSamples = nbBytes / (2*sizeof(uint8_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFBuf[2*is] - 128) << 16;
+ convertBuffer[2*is+1] = (sigMFBuf[2*is+1] - 128) << 16;
+ }
+
+ return nbSamples;
+}
+
+// u8 complex QI => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* sigMFBuf, int nbBytes)
+{
+ int nbSamples = nbBytes / (2*sizeof(uint8_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFBuf[2*is+1] - 128) << 8;
+ convertBuffer[2*is+1] = (sigMFBuf[2*is] - 128) << 8;
+ }
+
+ return nbSamples;
+}
+
+// u8 complex QI => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* sigMFBuf, int nbBytes)
+{
+ int nbSamples = nbBytes / (2*sizeof(uint8_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFBuf[2*is+1] - 128) << 16;
+ convertBuffer[2*is+1] = (sigMFBuf[2*is] - 128) << 16;
+ }
+
+ return nbSamples;
+}
+
+// u8 real => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* sigMFBuf, int nbBytes)
+{
+ int nbSamples = nbBytes / sizeof(uint8_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFBuf[2*is] - 128) << 8;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// u8 real => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* sigMFBuf, int nbBytes)
+{
+ int nbSamples = nbBytes / sizeof(uint8_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFBuf[2*is] - 128) << 16;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// =================================
+// 16 bit signed integer input type
+// =================================
+
+// i16 complex LE IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int16_t *sigMFBuf = (int16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int16_t));
+#if defined(__WINDOWS__) || (BYTE_ORDER == LITTLE_ENDIAN)
+ std::copy(sigMFBuf, sigMFBuf + 2*nbSamples, convertBuffer);
+ return nbSamples;
+#else
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]);
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is+1]);
+ }
+
+ return nbSamples;
+#endif
+}
+
+// i16 complex LE IQ => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int16_t *sigMFBuf = (int16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]) << 8;
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is+1]) << 8;
+ }
+
+ return nbSamples;
+}
+
+// i16 complex LE QI => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int16_t *sigMFBuf = (int16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is+1]);
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is]);
+ }
+
+ return nbSamples;
+}
+
+// i16 complex LE QI => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int16_t *sigMFBuf = (int16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is+1] << 8);
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is] << 8);
+ }
+
+ return nbSamples;
+}
+
+// i16 real LE => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int16_t *sigMFBuf = (int16_t *) buf;
+ int nbSamples = nbBytes / sizeof(int16_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]);
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// i16 real LE => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int16_t *sigMFBuf = (int16_t *) buf;
+ int nbSamples = nbBytes / sizeof(int16_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is] << 8);
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// i16 complex BE IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int16_t *sigMFBuf = (int16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]);
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is+1]);
+ }
+
+ return nbSamples;
+}
+
+// i16 complex BE IQ => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int16_t *sigMFBuf = (int16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]) << 8;
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is+1]) << 8;
+ }
+
+ return nbSamples;
+}
+
+// i16 complex BE QI => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int16_t *sigMFBuf = (int16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is+1]);
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is]);
+ }
+
+ return nbSamples;
+}
+
+// i16 complex BE QI => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int16_t *sigMFBuf = (int16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is+1]) << 8;
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is]) << 8;
+ }
+
+ return nbSamples;
+}
+
+// i16 real BE => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int16_t *sigMFBuf = (int16_t *) buf;
+ int nbSamples = nbBytes / sizeof(int16_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]);
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// i16 real BE => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int16_t *sigMFBuf = (int16_t *) buf;
+ int nbSamples = nbBytes / sizeof(int16_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]) << 8;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// ===================================
+// 16 bit unsigned integer input type
+// ===================================
+
+// u16 complex LE IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint16_t *sigMFBuf = (uint16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]) - 32768;
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is+1]) -32768;
+ }
+
+ return nbSamples;
+}
+
+// u16 complex LE IQ => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint16_t *sigMFBuf = (uint16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromLE(sigMFBuf[2*is]) - 32768) << 8;
+ convertBuffer[2*is+1] = (sigMFFromLE(sigMFBuf[2*is+1]) - 32768) << 8;
+ convertBuffer[2*is+1] <<= 8;
+ }
+
+ return nbSamples;
+}
+
+// u16 complex LE QI => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint16_t *sigMFBuf = (uint16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is+1]) - 32768;
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is]) -32768;
+ }
+
+ return nbSamples;
+}
+
+// u16 complex LE QI => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint16_t *sigMFBuf = (uint16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromLE(sigMFBuf[2*is+1]) - 32768) << 8;
+ convertBuffer[2*is+1] = (sigMFFromLE(sigMFBuf[2*is]) - 32768) << 8;
+ }
+
+ return nbSamples;
+}
+
+// u16 real LE => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint16_t *sigMFBuf = (uint16_t *) buf;
+ int nbSamples = nbBytes / sizeof(uint16_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]) - 32768;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// u16 real LE => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint16_t *sigMFBuf = (uint16_t *) buf;
+ int nbSamples = nbBytes / sizeof(uint16_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromLE(sigMFBuf[2*is]) - 32768) << 8;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// u16 complex BE IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint16_t *sigMFBuf = (uint16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]) - 32768;
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is+1]) -32768;
+ }
+
+ return nbSamples;
+}
+
+// u16 complex BE IQ => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint16_t *sigMFBuf = (uint16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromBE(sigMFBuf[2*is]) - 32768) << 8;
+ convertBuffer[2*is+1] = (sigMFFromBE(sigMFBuf[2*is+1]) -32768) << 8;
+ }
+
+ return nbSamples;
+}
+
+// u16 complex BE QI => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint16_t *sigMFBuf = (uint16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is+1]) - 32768;
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is]) -32768;
+ }
+
+ return nbSamples;
+}
+
+// u16 complex BE QI => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint16_t *sigMFBuf = (uint16_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint16_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromBE(sigMFBuf[2*is+1]) - 32768) << 8;
+ convertBuffer[2*is+1] = (sigMFFromBE(sigMFBuf[2*is]) -32768) << 8;
+ }
+
+ return nbSamples;
+}
+
+// u16 real BE => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint16_t *sigMFBuf = (uint16_t *) buf;
+ int nbSamples = nbBytes / sizeof(uint16_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]) - 32768;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// u16 real BE => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint16_t *sigMFBuf = (uint16_t *) buf;
+ int nbSamples = nbBytes / sizeof(uint16_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromBE(sigMFBuf[2*is]) - 32768) << 8;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// ======================================================
+// 24 bit signed integer input type - SDRangel exclusive
+// ======================================================
+
+// s24 complex LE IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]) >> 8;
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is+1]) >> 8;
+ }
+
+ return nbSamples;
+}
+
+// s24 complex LE IQ => FixReal 24 bits - SDRangel only
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int32_t));
+#if defined(__WINDOWS__) || (BYTE_ORDER == LITTLE_ENDIAN)
+ std::copy(sigMFBuf, sigMFBuf + 2*nbSamples, convertBuffer);
+ return nbSamples;
+#else
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]);
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is+1]);
+ }
+
+ return nbSamples;
+#endif
+}
+
+// =================================
+// 32 bit signed integer input type
+// =================================
+
+// s32 complex LE IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]) >> 16;
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is+1]) >> 16;
+ }
+
+ return nbSamples;
+}
+
+// s32 complex LE IQ => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]) >> 8;
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is+1]) >> 8;
+ }
+
+ return nbSamples;
+}
+
+// s32 complex LE QI => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is+1]) >> 16;
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is]) >> 16;
+ }
+
+ return nbSamples;
+}
+
+// s32 complex LE QI => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is+1]) >> 8;
+ convertBuffer[2*is+1] = sigMFFromLE(sigMFBuf[2*is]) >> 8;
+ }
+
+ return nbSamples;
+}
+
+// s32 real LE => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / sizeof(int32_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]) >> 16;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// s32 real LE => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / sizeof(int32_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromLE(sigMFBuf[2*is]) >> 8;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// s32 complex BE IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]) >> 16;
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is+1]) >> 16;
+ }
+
+ return nbSamples;
+}
+
+// s32 complex BE IQ => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]) >> 8;
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is+1]) >> 8;
+ }
+
+ return nbSamples;
+}
+
+// s32 complex BE QI => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is+1]) >> 16;
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is]) >> 16;
+ }
+
+ return nbSamples;
+}
+
+// s32 complex BE QI => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(int32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is+1]) >> 8;
+ convertBuffer[2*is+1] = sigMFFromBE(sigMFBuf[2*is]) >> 8;
+ }
+
+ return nbSamples;
+}
+
+// s32 real BE => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / sizeof(int32_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]) >> 16;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// s32 real BE => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const int32_t *sigMFBuf = (int32_t *) buf;
+ int nbSamples = nbBytes / sizeof(int32_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = sigMFFromBE(sigMFBuf[2*is]) >> 8;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// ===================================
+// 32 bit unsigned integer input type
+// ===================================
+
+// u32 complex LE IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint32_t *sigMFBuf = (uint32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromLE(sigMFBuf[2*is]) >> 16) - 32768;
+ convertBuffer[2*is+1] = (sigMFFromLE(sigMFBuf[2*is+1]) >> 16) - 32768;
+ }
+
+ return nbSamples;
+}
+
+// u32 complex LE IQ => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint32_t *sigMFBuf = (uint32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromLE(sigMFBuf[2*is]) >> 8) - 8388608;
+ convertBuffer[2*is+1] = (sigMFFromLE(sigMFBuf[2*is+1]) >> 8) - 8388608;
+ }
+
+ return nbSamples;
+}
+
+// u32 complex LE QI => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint32_t *sigMFBuf = (uint32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromLE(sigMFBuf[2*is+1]) >> 16) - 32768;
+ convertBuffer[2*is+1] = (sigMFFromLE(sigMFBuf[2*is]) >> 16) - 32768;
+ }
+
+ return nbSamples;
+}
+
+// u32 complex LE QI => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint32_t *sigMFBuf = (uint32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromLE(sigMFBuf[2*is+1]) >> 8) - 8388608;
+ convertBuffer[2*is+1] = (sigMFFromLE(sigMFBuf[2*is]) >> 8) - 8388608;
+ }
+
+ return nbSamples;
+}
+
+// u32 real LE => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint32_t *sigMFBuf = (uint32_t *) buf;
+ int nbSamples = nbBytes / sizeof(uint32_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromLE(sigMFBuf[2*is]) >> 16) - 32768;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// u32 real LE => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint32_t *sigMFBuf = (uint32_t *) buf;
+ int nbSamples = nbBytes / sizeof(uint32_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromLE(sigMFBuf[2*is]) >> 8) - 8388608;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// u32 complex BE IQ => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint32_t *sigMFBuf = (uint32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromBE(sigMFBuf[2*is]) >> 16) - 32768;
+ convertBuffer[2*is+1] = (sigMFFromBE(sigMFBuf[2*is+1]) >> 16) - 32768;
+ }
+
+ return nbSamples;
+}
+
+// u32 complex BE IQ => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint32_t *sigMFBuf = (uint32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromBE(sigMFBuf[2*is]) >> 8) - 8388608;
+ convertBuffer[2*is+1] = (sigMFFromBE(sigMFBuf[2*is+1]) >> 8) - 8388608;
+ }
+
+ return nbSamples;
+}
+
+// u32 complex BE QI => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint32_t *sigMFBuf = (uint32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromBE(sigMFBuf[2*is+1]) >> 16) - 32768;
+ convertBuffer[2*is+1] = (sigMFFromBE(sigMFBuf[2*is]) >> 16) - 32768;
+ }
+
+ return nbSamples;
+}
+
+// u32 complex BE QI => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint32_t *sigMFBuf = (uint32_t *) buf;
+ int nbSamples = nbBytes / (2*sizeof(uint32_t));
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromBE(sigMFBuf[2*is+1]) >> 8) - 8388608;
+ convertBuffer[2*is+1] = (sigMFFromBE(sigMFBuf[2*is]) >> 8) - 8388608;
+ }
+
+ return nbSamples;
+}
+
+// u32 real BE => FixReal 16 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint32_t *sigMFBuf = (uint32_t *) buf;
+ int nbSamples = nbBytes / sizeof(uint32_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromBE(sigMFBuf[2*is]) >> 16) - 32768;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+// u32 real BE => FixReal 24 bits
+
+template<>
+int SigMFConverter::convert(FixReal *convertBuffer, const quint8* buf, int nbBytes)
+{
+ const uint32_t *sigMFBuf = (uint32_t *) buf;
+ int nbSamples = nbBytes / sizeof(uint32_t);
+
+ for (int is = 0; is < nbSamples; is++)
+ {
+ convertBuffer[2*is] = (sigMFFromBE(sigMFBuf[2*is]) >> 8) - 8388608;
+ convertBuffer[2*is+1] = 0;
+ }
+
+ return nbSamples;
+}
+
+#endif // INCLUDE_SIGMFFILEDATA_H
\ No newline at end of file
diff --git a/plugins/samplesource/sigmffileinput/sigmffiledata.h b/plugins/samplesource/sigmffileinput/sigmffiledata.h
new file mode 100644
index 000000000..31d646beb
--- /dev/null
+++ b/plugins/samplesource/sigmffileinput/sigmffiledata.h
@@ -0,0 +1,216 @@
+///////////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 2020 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 //
+// (at your option) any later version. //
+// //
+// 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 . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#ifndef INCLUDE_SIGMFFILEDATA_H
+#define INCLUDE_SIGMFFILEDATA_H
+
+#include
+
+struct SigMFFileDataType
+{
+ bool m_complex;
+ bool m_floatingPoint;
+ bool m_signed;
+ bool m_bigEndian;
+ bool m_swapIQ;
+ int m_sampleBits;
+
+ SigMFFileDataType() :
+ m_complex(true),
+ m_floatingPoint(false),
+ m_signed(true),
+ m_bigEndian(false),
+ m_swapIQ(false),
+ m_sampleBits(32)
+ {}
+
+ SigMFFileDataType(const SigMFFileDataType& other) :
+ m_complex(other.m_complex),
+ m_floatingPoint(other.m_floatingPoint),
+ m_signed(other.m_signed),
+ m_bigEndian(other.m_bigEndian),
+ m_swapIQ(other.m_swapIQ),
+ m_sampleBits(other.m_sampleBits)
+ {}
+
+ SigMFFileDataType& operator=(const SigMFFileDataType& t)
+ {
+ // Check for self assignment
+ if (this != &t)
+ {
+ m_complex = t.m_complex;
+ m_floatingPoint = t.m_floatingPoint;
+ m_signed = t.m_signed;
+ m_bigEndian = t.m_bigEndian;
+ m_swapIQ = t.m_swapIQ;
+ m_sampleBits = t.m_sampleBits;
+ }
+
+ return *this;
+ }
+
+ explicit operator SigMFFileDataType() const {
+ return SigMFFileDataType{static_cast(*this)};
+ }
+};
+
+struct SigMFFileMetaInfo
+{
+ // core
+ QString m_dataTypeStr;
+ SigMFFileDataType m_dataType;
+ uint64_t m_totalSamples;
+ uint64_t m_totalTimeMs;
+ double m_coreSampleRate;
+ QString m_sigMFVersion;
+ QString m_sha512;
+ unsigned int m_offset;
+ QString m_description;
+ QString m_author;
+ QString m_metaDOI;
+ QString m_dataDOI;
+ QString m_recorder;
+ QString m_license;
+ QString m_hw;
+ // sdrangel
+ QString m_sdrAngelVersion;
+ QString m_qtVersion;
+ int m_rxBits;
+ QString m_arch;
+ QString m_os;
+ // lists
+ unsigned int m_nbCaptures;
+ unsigned int m_nbAnnotations;
+
+ SigMFFileMetaInfo()
+ {}
+
+ SigMFFileMetaInfo(const SigMFFileMetaInfo& other) :
+ m_dataTypeStr(other.m_dataTypeStr),
+ m_dataType(other.m_dataType),
+ m_totalSamples(other.m_totalSamples),
+ m_totalTimeMs(other.m_totalTimeMs),
+ m_coreSampleRate(other.m_coreSampleRate),
+ m_sigMFVersion(other.m_sigMFVersion),
+ m_sha512(other.m_sha512),
+ m_offset(other.m_offset),
+ m_description(other.m_description),
+ m_author(other.m_author),
+ m_metaDOI(other.m_metaDOI),
+ m_dataDOI(other.m_dataDOI),
+ m_recorder(other.m_recorder),
+ m_license(other.m_license),
+ m_hw(other.m_hw),
+ m_sdrAngelVersion(other.m_sdrAngelVersion),
+ m_qtVersion(other.m_qtVersion),
+ m_rxBits(other.m_rxBits),
+ m_arch(other.m_arch),
+ m_os(other.m_os),
+ m_nbCaptures(other.m_nbCaptures),
+ m_nbAnnotations(other.m_nbAnnotations)
+ {}
+
+ SigMFFileMetaInfo& operator=(const SigMFFileMetaInfo& t)
+ {
+ // Check for self assignment
+ if (this != &t)
+ {
+ m_dataTypeStr = t.m_dataTypeStr;
+ m_dataType = t.m_dataType;
+ m_totalSamples = t.m_totalSamples;
+ m_totalTimeMs = t.m_totalTimeMs;
+ m_coreSampleRate = t.m_coreSampleRate;
+ m_sigMFVersion = t.m_sigMFVersion;
+ m_sha512 = t.m_sha512;
+ m_offset = t.m_offset;
+ m_description = t.m_description;
+ m_author = t.m_author;
+ m_metaDOI = t.m_metaDOI;
+ m_dataDOI = t.m_dataDOI;
+ m_recorder = t.m_recorder;
+ m_license = t.m_license;
+ m_hw = t.m_hw;
+ m_sdrAngelVersion = t.m_sdrAngelVersion;
+ m_qtVersion = t.m_qtVersion;
+ m_rxBits = t.m_rxBits;
+ m_arch = t.m_arch;
+ m_os = t.m_os;
+ m_nbCaptures = t.m_nbCaptures;
+ m_nbAnnotations = t.m_nbAnnotations;
+ }
+
+ return *this;
+ }
+
+ explicit operator SigMFFileMetaInfo() const {
+ return SigMFFileMetaInfo{static_cast(*this)};
+ }
+};
+
+struct SigMFFileCapture
+{
+ uint64_t m_tsms; //!< Unix timestamp in milliseconds
+ uint64_t m_centerFrequency; //!< Center frequency in Hz
+ uint64_t m_sampleStart; //!< Sample index at which capture start
+ uint64_t m_length; //!< Length of capture in samples
+ uint64_t m_cumulativeTime; //!< Time since beginning of record (millisecond timestamp) at start
+ unsigned int m_sampleRate; //!< sdrangel extension - sample rate for this capture
+
+ SigMFFileCapture() :
+ m_tsms(0),
+ m_centerFrequency(0),
+ m_sampleStart(0),
+ m_length(0),
+ m_cumulativeTime(0),
+ m_sampleRate(1)
+ {}
+
+ SigMFFileCapture(const SigMFFileCapture& other) :
+ m_tsms(other.m_tsms),
+ m_centerFrequency(other.m_centerFrequency),
+ m_sampleStart(other.m_sampleStart),
+ m_length(other.m_length),
+ m_cumulativeTime(other.m_cumulativeTime),
+ m_sampleRate(other.m_sampleRate)
+ {}
+
+ SigMFFileCapture& operator=(const SigMFFileCapture& t)
+ {
+ // Check for self assignment
+ if (this != &t)
+ {
+ m_tsms = t.m_tsms;
+ m_centerFrequency = t.m_centerFrequency;
+ m_sampleStart = t.m_sampleStart;
+ m_length = t.m_length;
+ m_cumulativeTime = t.m_cumulativeTime;
+ m_sampleRate = t.m_sampleRate;
+ }
+
+ return *this;
+ }
+
+ explicit operator SigMFFileCapture() const {
+ return SigMFFileCapture{static_cast(*this)};
+ }
+
+ explicit operator SigMFFileCapture() {
+ return SigMFFileCapture{static_cast(*this)};
+ }
+};
+
+#endif // INCLUDE_SIGMFFILEDATA_H
\ No newline at end of file
diff --git a/plugins/samplesource/sigmffileinput/sigmffileinput.cpp b/plugins/samplesource/sigmffileinput/sigmffileinput.cpp
new file mode 100644
index 000000000..dc6366f4d
--- /dev/null
+++ b/plugins/samplesource/sigmffileinput/sigmffileinput.cpp
@@ -0,0 +1,1063 @@
+///////////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 2020 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 //
+// (at your option) any later version. //
+// //
+// 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 . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#include "libsigmf/sigmf_core_generated.h"
+#include "libsigmf/sigmf_sdrangel_generated.h"
+#include "libsigmf/sigmf.h"
+
+#include "SWGDeviceSettings.h"
+#include "SWGFileInputSettings.h"
+#include "SWGDeviceState.h"
+#include "SWGDeviceReport.h"
+
+#include "dsp/dspcommands.h"
+#include "dsp/dspdevicesourceengine.h"
+#include "dsp/dspengine.h"
+#include "device/deviceapi.h"
+#include "util/sha512.h"
+
+#include "sigmffileinput.h"
+#include "sigmffileinputthread.h"
+
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgConfigureSigMFFileInput, Message)
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgConfigureTrackWork, Message)
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgConfigureTrackIndex, Message)
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgConfigureTrackSeek, Message)
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgConfigureFileSeek, Message)
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgConfigureFileWork, Message)
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgStartStop, Message)
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgConfigureFileInputStreamTiming, Message)
+
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgReportStartStop, Message)
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgReportMetaData, Message)
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgReportTrackChange, Message)
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgReportFileInputStreamTiming, Message)
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgReportCRC, Message)
+MESSAGE_CLASS_DEFINITION(SigMFFileInput::MsgReportTotalSamplesCheck, Message)
+
+SigMFFileInput::SigMFFileInput(DeviceAPI *deviceAPI) :
+ m_deviceAPI(deviceAPI),
+ m_settings(),
+ m_trackMode(false),
+ m_currentTrackIndex(0),
+ m_recordOpen(false),
+ m_fileInputThread(nullptr),
+ m_deviceDescription(),
+ m_sampleRate(48000),
+ m_sampleBytes(1),
+ m_centerFrequency(0),
+ m_recordLength(0),
+ m_startingTimeStamp(0)
+{
+ m_deviceAPI->setNbSourceStreams(1);
+ qDebug("SigMFFileInput::SigMFFileInput: device source engine: %p", m_deviceAPI->getDeviceSourceEngine());
+ qDebug("SigMFFileInput::SigMFFileInput: device source engine message queue: %p", m_deviceAPI->getDeviceEngineInputMessageQueue());
+ qDebug("SigMFFileInput::SigMFFileInput: device source: %p", m_deviceAPI->getDeviceSourceEngine()->getSource());
+ m_networkManager = new QNetworkAccessManager();
+ connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
+ m_masterTimer.setTimerType(Qt::PreciseTimer);
+ m_masterTimer.start(50);
+}
+
+SigMFFileInput::~SigMFFileInput()
+{
+ m_masterTimer.stop();
+ disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
+ delete m_networkManager;
+
+ stop();
+}
+
+void SigMFFileInput::destroy()
+{
+ delete this;
+}
+
+bool SigMFFileInput::openFileStreams(const QString& fileName)
+{
+ if (m_metaStream.is_open()) {
+ m_metaStream.close();
+ }
+
+ if (m_dataStream.is_open()) {
+ m_dataStream.close();
+ }
+
+ QString metaFileName = fileName + ".sigmf-meta";
+ QString dataFileName = fileName + ".sigmf-data";
+
+#ifdef Q_OS_WIN
+ m_metaStream.open(metaFileName.toStdWString().c_str());
+#else
+ m_metaStream.open(metaFileName.toStdString().c_str());
+#endif
+
+#ifdef Q_OS_WIN
+ m_dataStream.open(dataFileName.toStdWString().c_str(), std::ios::binary | std::ios::ate);
+#else
+ m_dataStream.open(dataFileName.toStdString().c_str(), std::ios::binary | std::ios::ate);
+#endif
+
+ if (!m_dataStream.is_open())
+ {
+ qCritical("SigMFFileInput::openFileStreams: error opening data file %s", qPrintable(dataFileName));
+ return false;
+ }
+
+ uint64_t dataFileSize = m_dataStream.tellg();
+
+ sigmf::SigMF,
+ sigmf::Capture,
+ sigmf::Annotation > metaRecord;
+
+ std::ostringstream meta_buffer;
+ meta_buffer << m_metaStream.rdbuf();
+ from_json(json::parse(meta_buffer.str()), metaRecord);
+ extractMeta(&metaRecord, dataFileSize);
+ extractCaptures(&metaRecord);
+ m_metaInfo.m_totalTimeMs = m_captures.back().m_cumulativeTime + ((m_captures.back().m_length * 1000)/m_captures.back().m_sampleRate);
+
+ uint64_t centerFrequency = (m_captures.size() > 0) ? m_captures.at(0).m_centerFrequency : 0;
+ DSPSignalNotification *notif = new DSPSignalNotification(m_metaInfo.m_coreSampleRate, centerFrequency);
+ m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
+
+ if (getMessageQueueToGUI())
+ {
+ MsgReportMetaData *report = MsgReportMetaData::create(m_metaInfo, m_captures);
+ getMessageQueueToGUI()->push(report);
+ }
+
+ if (m_metaInfo.m_sha512.size() != 0)
+ {
+ qDebug("SigMFFileInput::openFileStreams: compute SHA512");
+ std::string sha512 = sw::sha512::file(dataFileName.toStdString());
+ bool crcOK = m_metaInfo.m_sha512 == QString::fromStdString(sha512);
+
+ if (crcOK) {
+ qDebug("SigMFFileInput::openFileStreams: SHA512 OK: %s", sha512.c_str());
+ } else {
+ qCritical("SigMFFileInput::openFileStreams: bad SHA512: %s expected: %s", sha512.c_str(), qPrintable(m_metaInfo.m_sha512));
+ }
+
+ if (getMessageQueueToGUI())
+ {
+ MsgReportCRC *report = MsgReportCRC::create(crcOK);
+ getMessageQueueToGUI()->push(report);
+ }
+
+ if (!crcOK) {
+ return false;
+ }
+ }
+
+ bool totalSamplesCheck = (m_metaInfo.m_totalSamples == m_captures.back().m_sampleStart + m_captures.back().m_length);
+
+ if (totalSamplesCheck) {
+ qDebug("SigMFFileInput::openFileStreams: total samples OK");
+ } else {
+ qCritical("SigMFFileInput::openFileStreams: invalid total samples: meta: %lu data: %lu",
+ m_captures.back().m_sampleStart + m_captures.back().m_length, m_metaInfo.m_totalSamples);
+ }
+
+ if (getMessageQueueToGUI())
+ {
+ MsgReportTotalSamplesCheck *report = MsgReportTotalSamplesCheck::create(totalSamplesCheck);
+ getMessageQueueToGUI()->push(report);
+ }
+
+ return true;
+}
+
+void SigMFFileInput::extractMeta(
+ sigmf::SigMF,
+ sigmf::Capture,
+ sigmf::Annotation >* metaRecord,
+ uint64_t dataFileSize
+)
+{
+ // core
+ m_metaInfo.m_dataTypeStr = QString::fromStdString(metaRecord->global.access().datatype);
+ analyzeDataType(m_metaInfo.m_dataTypeStr.toStdString(), m_metaInfo.m_dataType);
+ m_sampleBytes = SigMFFileInputSettings::bitsToBytes(m_metaInfo.m_dataType.m_sampleBits);
+ m_metaInfo.m_totalSamples = dataFileSize / (SigMFFileInputSettings::bitsToBytes(m_metaInfo.m_dataType.m_sampleBits)*2);
+ m_metaInfo.m_coreSampleRate = metaRecord->global.access().sample_rate;
+ m_metaInfo.m_sigMFVersion = QString::fromStdString(metaRecord->global.access().version);
+ m_metaInfo.m_sha512 = QString::fromStdString(metaRecord->global.access().sha512);
+ m_metaInfo.m_offset = metaRecord->global.access().offset;
+ m_metaInfo.m_description = QString::fromStdString(metaRecord->global.access().description);
+ m_metaInfo.m_author = QString::fromStdString(metaRecord->global.access().author);
+ m_metaInfo.m_metaDOI = QString::fromStdString(metaRecord->global.access().meta_doi);
+ m_metaInfo.m_dataDOI = QString::fromStdString(metaRecord->global.access().meta_doi);
+ m_metaInfo.m_recorder = QString::fromStdString(metaRecord->global.access().recorder);
+ m_metaInfo.m_license = QString::fromStdString(metaRecord->global.access().license);
+ m_metaInfo.m_hw = QString::fromStdString(metaRecord->global.access().hw);
+ // sdrangel
+ m_metaInfo.m_sdrAngelVersion = QString::fromStdString(metaRecord->global.access().version);
+ m_metaInfo.m_qtVersion = QString::fromStdString(metaRecord->global.access().qt_version);
+ m_metaInfo.m_rxBits = metaRecord->global.access().rx_bits;
+ m_metaInfo.m_arch = QString::fromStdString(metaRecord->global.access().arch);
+ m_metaInfo.m_os = QString::fromStdString(metaRecord->global.access().os);
+ // lists
+ m_metaInfo.m_nbCaptures = metaRecord->captures.size();
+ m_metaInfo.m_nbAnnotations = metaRecord->annotations.size();
+ // correct sample bits if sdrangel
+ if (m_metaInfo.m_sdrAngelVersion.size() > 0)
+ {
+ if (m_metaInfo.m_dataType.m_sampleBits == 32) {
+ m_metaInfo.m_dataType.m_sampleBits = 24;
+ }
+ }
+ // negative sample rate means inversion
+ m_metaInfo.m_dataType.m_swapIQ = m_metaInfo.m_coreSampleRate < 0;
+ if (m_metaInfo.m_coreSampleRate < 0) {
+ m_metaInfo.m_coreSampleRate = -m_metaInfo.m_coreSampleRate;
+ }
+}
+
+void SigMFFileInput::extractCaptures(
+ sigmf::SigMF,
+ sigmf::Capture,
+ sigmf::Annotation >* metaRecord
+)
+{
+ m_captures.clear();
+ std::regex datetime_reg("(\\d{4})-(\\d\\d)-(\\d\\d)T(\\d\\d):(\\d\\d):(\\d\\d)(\\.\\d+)?(([+-]\\d\\d:\\d\\d)|Z)?");
+ std::smatch datetime_match;
+
+ sigmf::SigMFVector>::iterator it =
+ metaRecord->captures.begin();
+ uint64_t lastSampleStart = 0;
+ unsigned int i = 0;
+ uint64_t cumulativeTime = 0;
+
+ for (; it != metaRecord->captures.end(); ++it, i++)
+ {
+ m_captures.push_back(SigMFFileCapture());
+ m_captures.back().m_centerFrequency = it->get().frequency;
+ m_captures.back().m_sampleStart = it->get().sample_start;
+ m_captureStarts.push_back(m_captures.back().m_sampleStart);
+ m_captures.back().m_cumulativeTime = cumulativeTime;
+ int sdrangelSampleRate = it->get().sample_rate;
+
+ if (sdrangelSampleRate == 0) {
+ m_captures.back().m_sampleRate = metaRecord->global.access().sample_rate;
+ } else {
+ m_captures.back().m_sampleRate = sdrangelSampleRate;
+ }
+
+ uint64_t tsms = it->get().tsms;
+
+ if (tsms)
+ {
+ m_captures.back().m_tsms = tsms;
+ }
+ else
+ {
+ std::regex_search(it->get().datetime, datetime_match, datetime_reg);
+ QString dateTimeString;
+ QDateTime dateTime;
+
+ if (datetime_match.size() > 6) {
+ dateTimeString = QString("%1-%2-%3T%4:%5:%6")
+ .arg(QString::fromStdString(datetime_match[1])) // year
+ .arg(QString::fromStdString(datetime_match[2])) // month
+ .arg(QString::fromStdString(datetime_match[3])) // day
+ .arg(QString::fromStdString(datetime_match[4])) // hour
+ .arg(QString::fromStdString(datetime_match[5])) // minute
+ .arg(QString::fromStdString(datetime_match[6])); // second
+ dateTime = QDateTime::fromString(dateTimeString, "yyyy-MM-ddThh:mm:ss");
+
+ // skip timezone calculation - assume UTC
+ if (dateTime.isValid()) {
+ dateTime.setTimeZone(QTimeZone::utc());
+ } else {
+ dateTime = QDateTime::currentDateTimeUtc();
+ }
+ }
+ else
+ {
+ dateTime = QDateTime::currentDateTimeUtc();
+ }
+
+ double seconds = dateTime.toSecsSinceEpoch();
+ // the subsecond part can be milli (strict ISO-8601) or micro or nano (RFC-3339). This will take any width
+ if (datetime_match.size() > 7)
+ {
+ try
+ {
+ double fractionalSecs = boost::lexical_cast(datetime_match[7]);
+ seconds += fractionalSecs;
+ }
+ catch (const boost::bad_lexical_cast &e)
+ {
+ qDebug("SigMFFileInput::extractCaptures: invalid fractional seconds");
+ }
+ }
+
+ m_captures.back().m_tsms = seconds * 1000.0;
+ }
+
+ m_captures.back().m_length = it->get().length;
+
+ if ((i != 0) && (m_captures.at(i-1).m_length == 0))
+ {
+ m_captures[i-1].m_length = m_captures.at(i).m_sampleStart - lastSampleStart;
+ lastSampleStart = m_captures.at(i).m_sampleStart;
+ }
+
+ cumulativeTime += (m_captures.back().m_length * 1000) / m_captures.back().m_sampleRate;
+ }
+
+ if (m_captures.back().m_length == 0) {
+ m_captures.back().m_length = m_metaInfo.m_totalSamples - m_captures.back().m_sampleStart;
+ }
+}
+
+void SigMFFileInput::analyzeDataType(const std::string& dataTypeString, SigMFFileDataType& dataType)
+{
+ std::regex dataType_reg("(\\w)(\\w)(\\d+)(_\\w\\w)?");
+ std::smatch dataType_match;
+ std::regex_search(dataTypeString, dataType_match, dataType_reg);
+
+ if (dataType_match.size() > 3)
+ {
+ dataType.m_complex = (dataType_match[1] == "c");
+
+ if (dataType_match[2] == "f")
+ {
+ dataType.m_floatingPoint = true;
+ dataType.m_signed = true;
+ }
+ else if (dataType_match[2] == "i")
+ {
+ dataType.m_floatingPoint = false;
+ dataType.m_signed = true;
+ }
+ else
+ {
+ dataType.m_floatingPoint = false;
+ dataType.m_signed = false;
+ }
+
+ try
+ {
+ dataType.m_sampleBits = boost::lexical_cast(dataType_match[3]);
+ }
+ catch(const boost::bad_lexical_cast &e)
+ {
+ qDebug("SigMFFileInput::analyzeDataType: invalid sample bits. Assume 32");
+ dataType.m_sampleBits = 32;
+ }
+ }
+
+ if (dataType_match.size() > 4) {
+ dataType.m_bigEndian = (dataType_match[4] == "_be");
+ }
+}
+
+uint64_t SigMFFileInput::getTrackSampleStart(int trackIndex)
+{
+ if (trackIndex < m_captureStarts.size()) {
+ return m_captureStarts[trackIndex];
+ } else {
+ return m_metaInfo.m_totalSamples;
+ }
+}
+
+int SigMFFileInput::getTrackIndex(uint64_t sampleIndex)
+{
+ auto it = std::upper_bound(m_captureStarts.begin(), m_captureStarts.end(), sampleIndex);
+ return (it - m_captureStarts.begin()) - 1;
+}
+
+void SigMFFileInput::seekFileStream(uint64_t sampleIndex)
+{
+ QMutexLocker mutexLocker(&m_mutex);
+
+ if (m_dataStream.is_open())
+ {
+ uint64_t seekPoint = sampleIndex*m_sampleBytes*2;
+ m_dataStream.clear();
+ m_dataStream.seekg(seekPoint, std::ios::beg);
+ }
+}
+
+void SigMFFileInput::seekTrackMillis(int seekMillis)
+{
+ seekFileStream(m_captures[m_currentTrackIndex].m_sampleStart + ((m_captures[m_currentTrackIndex].m_length*seekMillis)/1000UL));
+}
+
+void SigMFFileInput::seekFileMillis(int seekMillis)
+{
+ seekFileStream((m_metaInfo.m_totalSamples*seekMillis)/1000UL);
+}
+
+void SigMFFileInput::init()
+{
+ DSPSignalNotification *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency);
+ m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
+}
+
+bool SigMFFileInput::start()
+{
+ if (!m_dataStream.is_open())
+ {
+ qWarning("SigMFFileInput::start: file not open. not starting");
+ return false;
+ }
+
+ QMutexLocker mutexLocker(&m_mutex);
+ qDebug() << "SigMFFileInput::start";
+
+ if (m_dataStream.tellg() != (std::streampos) 0) {
+ m_dataStream.clear();
+ m_dataStream.seekg(0, std::ios::beg);
+ }
+
+ if(!m_sampleFifo.setSize(m_settings.m_accelerationFactor * m_sampleRate * sizeof(Sample))) {
+ qCritical("Could not allocate SampleFifo");
+ return false;
+ }
+
+ m_fileInputThread = new SigMFFileInputThread(&m_dataStream, &m_sampleFifo, m_masterTimer, &m_inputMessageQueue);
+ m_fileInputThread->setMetaInformation(&m_metaInfo, &m_captures);
+ m_fileInputThread->setAccelerationFactor(m_settings.m_accelerationFactor);
+ m_fileInputThread->setTrackIndex(0);
+ m_fileInputThread->startWork();
+ m_deviceDescription = "SigMFFileInput";
+
+ mutexLocker.unlock();
+ qDebug("SigMFFileInput::startInput: started");
+
+ if (getMessageQueueToGUI()) {
+ MsgReportStartStop *report = MsgReportStartStop::create(true);
+ getMessageQueueToGUI()->push(report);
+ }
+
+ return true;
+}
+
+void SigMFFileInput::stop()
+{
+ qDebug() << "SigMFFileInput::stop";
+ QMutexLocker mutexLocker(&m_mutex);
+
+ if (m_fileInputThread)
+ {
+ m_fileInputThread->stopWork();
+ delete m_fileInputThread;
+ m_fileInputThread = nullptr;
+ }
+
+ m_deviceDescription.clear();
+
+ if (getMessageQueueToGUI()) {
+ MsgReportStartStop *report = MsgReportStartStop::create(false);
+ getMessageQueueToGUI()->push(report);
+ }
+}
+
+QByteArray SigMFFileInput::serialize() const
+{
+ return m_settings.serialize();
+}
+
+bool SigMFFileInput::deserialize(const QByteArray& data)
+{
+ bool success = true;
+
+ if (!m_settings.deserialize(data))
+ {
+ m_settings.resetToDefaults();
+ success = false;
+ }
+
+ MsgConfigureSigMFFileInput* message = MsgConfigureSigMFFileInput::create(m_settings, true);
+ m_inputMessageQueue.push(message);
+
+ if (getMessageQueueToGUI())
+ {
+ MsgConfigureSigMFFileInput* messageToGUI = MsgConfigureSigMFFileInput::create(m_settings, true);
+ getMessageQueueToGUI()->push(messageToGUI);
+ }
+
+ return success;
+}
+
+const QString& SigMFFileInput::getDeviceDescription() const
+{
+ return m_deviceDescription;
+}
+
+int SigMFFileInput::getSampleRate() const
+{
+ return m_sampleRate;
+}
+
+quint64 SigMFFileInput::getCenterFrequency() const
+{
+ return m_centerFrequency;
+}
+
+void SigMFFileInput::setCenterFrequency(qint64 centerFrequency)
+{
+ SigMFFileInputSettings settings = m_settings;
+ m_centerFrequency = centerFrequency;
+
+ MsgConfigureSigMFFileInput* message = MsgConfigureSigMFFileInput::create(m_settings, false);
+ m_inputMessageQueue.push(message);
+
+ if (getMessageQueueToGUI())
+ {
+ MsgConfigureSigMFFileInput* messageToGUI = MsgConfigureSigMFFileInput::create(m_settings, false);
+ getMessageQueueToGUI()->push(messageToGUI);
+ }
+}
+
+quint64 SigMFFileInput::getStartingTimeStamp() const
+{
+ return m_startingTimeStamp;
+}
+
+bool SigMFFileInput::handleMessage(const Message& message)
+{
+ if (MsgConfigureSigMFFileInput::match(message))
+ {
+ MsgConfigureSigMFFileInput& conf = (MsgConfigureSigMFFileInput&) message;
+ SigMFFileInputSettings settings = conf.getSettings();
+ applySettings(settings);
+ return true;
+ }
+ else if (MsgConfigureTrackIndex::match(message))
+ {
+ MsgConfigureTrackIndex& conf = (MsgConfigureTrackIndex&) message;
+ m_currentTrackIndex = conf.getTrackIndex();
+ qDebug("SigMFFileInput::handleMessage MsgConfigureTrackIndex: m_currentTrackIndex: %d", m_currentTrackIndex);
+ seekTrackMillis(0);
+
+ if (m_fileInputThread)
+ {
+ bool working = m_fileInputThread->isRunning();
+
+ if (working) {
+ m_fileInputThread->stopWork();
+ }
+
+ m_fileInputThread->setTrackIndex(m_currentTrackIndex);
+ m_fileInputThread->setTotalSamples(
+ m_trackMode ?
+ m_captures[m_currentTrackIndex].m_sampleStart + m_captures[m_currentTrackIndex].m_length :
+ m_metaInfo.m_totalSamples
+ );
+
+ if (working) {
+ m_fileInputThread->startWork();
+ }
+ }
+ }
+ else if (MsgConfigureTrackWork::match(message))
+ {
+ MsgConfigureTrackWork& conf = (MsgConfigureTrackWork&) message;
+ bool working = conf.isWorking();
+ m_trackMode = true;
+
+ if (m_fileInputThread)
+ {
+ if (working)
+ {
+ m_fileInputThread->setTotalSamples(
+ m_captures[m_currentTrackIndex].m_sampleStart + m_captures[m_currentTrackIndex].m_length);
+ m_fileInputThread->startWork();
+ }
+ else
+ {
+ m_fileInputThread->stopWork();
+ }
+ }
+
+ return true;
+ }
+ else if (MsgConfigureTrackSeek::match(message))
+ {
+ MsgConfigureTrackSeek& conf = (MsgConfigureTrackSeek&) message;
+ int seekMillis = conf.getMillis();
+ seekTrackMillis(seekMillis);
+
+ if (m_fileInputThread)
+ {
+ bool working = m_fileInputThread->isRunning();
+
+ if (working) {
+ m_fileInputThread->stopWork();
+ }
+
+ m_fileInputThread->setSamplesCount(
+ m_captures[m_currentTrackIndex].m_sampleStart + ((m_captures[m_currentTrackIndex].m_length*seekMillis)/1000UL));
+
+ if (working) {
+ m_fileInputThread->startWork();
+ }
+ }
+
+ return true;
+ }
+ else if (MsgConfigureFileSeek::match(message))
+ {
+ MsgConfigureFileSeek& conf = (MsgConfigureFileSeek&) message;
+ int seekMillis = conf.getMillis();
+ seekFileStream(seekMillis);
+ uint64_t sampleCount = (m_metaInfo.m_totalSamples*seekMillis)/1000UL;
+ m_currentTrackIndex = getTrackIndex(sampleCount);
+
+ if (m_fileInputThread)
+ {
+ bool working = m_fileInputThread->isRunning();
+
+ if (working) {
+ m_fileInputThread->stopWork();
+ }
+
+ m_fileInputThread->setTrackIndex(m_currentTrackIndex);
+ m_fileInputThread->setSamplesCount(sampleCount);
+
+ if (working) {
+ m_fileInputThread->startWork();
+ }
+ }
+
+ return true;
+ }
+ else if (MsgConfigureFileWork::match(message))
+ {
+ MsgConfigureFileWork& conf = (MsgConfigureFileWork&) message;
+ bool working = conf.isWorking();
+ m_trackMode = false;
+
+ if (m_fileInputThread)
+ {
+ if (working)
+ {
+ m_fileInputThread->setTotalSamples(m_metaInfo.m_totalSamples);
+ m_fileInputThread->startWork();
+ }
+ else
+ {
+ m_fileInputThread->stopWork();
+ }
+ }
+
+ return true;
+ }
+ else if (MsgConfigureFileInputStreamTiming::match(message))
+ {
+ if (m_fileInputThread)
+ {
+ if (getMessageQueueToGUI())
+ {
+ quint64 totalSamplesCount = m_fileInputThread->getSamplesCount();
+ quint64 trackSamplesCount = totalSamplesCount - m_captures[m_currentTrackIndex].m_sampleStart;
+ MsgReportFileInputStreamTiming *report = MsgReportFileInputStreamTiming::create(
+ totalSamplesCount,
+ trackSamplesCount,
+ m_captures[m_currentTrackIndex].m_cumulativeTime,
+ m_currentTrackIndex
+ );
+ getMessageQueueToGUI()->push(report);
+ }
+ }
+
+ return true;
+ }
+ else if (MsgStartStop::match(message))
+ {
+ MsgStartStop& cmd = (MsgStartStop&) message;
+ qDebug() << "FileInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
+
+ if (cmd.getStartStop())
+ {
+ if (m_deviceAPI->initDeviceEngine()) {
+ m_deviceAPI->startDeviceEngine();
+ }
+ }
+ else
+ {
+ m_deviceAPI->stopDeviceEngine();
+ }
+
+ if (m_settings.m_useReverseAPI) {
+ webapiReverseSendStartStop(cmd.getStartStop());
+ }
+
+ return true;
+ }
+ else if (SigMFFileInputThread::MsgReportEOF::match(message)) // End Of File or end of track
+ {
+ qDebug() << "FileInput::handleMessage: MsgReportEOF";
+ bool working = m_fileInputThread->isRunning();
+
+ if (working) {
+ m_fileInputThread->stopWork();
+ }
+
+ if (m_trackMode)
+ {
+ if (m_settings.m_trackLoop)
+ {
+ seekFileStream(m_captures[m_currentTrackIndex].m_sampleStart);
+ m_fileInputThread->setTrackIndex(m_currentTrackIndex);
+ }
+ }
+ else
+ {
+ if (m_settings.m_fullLoop)
+ {
+ seekFileStream(0);
+ m_fileInputThread->setTrackIndex(0);
+ }
+ }
+
+ if (working) {
+ m_fileInputThread->startWork();
+ }
+
+ return true;
+ }
+ else if (SigMFFileInputThread::MsgReportTrackChange::match(message))
+ {
+ SigMFFileInputThread::MsgReportTrackChange& report = (SigMFFileInputThread::MsgReportTrackChange&) message;
+ m_currentTrackIndex = report.getTrackIndex();
+ qDebug("SigMFFileInput::handleMessage MsgReportTrackChange: m_currentTrackIndex: %d", m_currentTrackIndex);
+ int sampleRate = m_captures.at(m_currentTrackIndex).m_sampleRate;
+ uint64_t centerFrequency = m_captures.at(m_currentTrackIndex).m_centerFrequency;
+
+ if ((m_sampleRate != sampleRate) || (m_centerFrequency != centerFrequency))
+ {
+ DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, centerFrequency);
+ m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
+
+ m_sampleRate = sampleRate;
+ m_centerFrequency = centerFrequency;
+ }
+
+ if (getMessageQueueToGUI())
+ {
+ MsgReportTrackChange *msgToGUI = MsgReportTrackChange::create(m_currentTrackIndex);
+ getMessageQueueToGUI()->push(msgToGUI);
+ }
+ }
+ else
+ {
+ return false;
+ }
+}
+
+bool SigMFFileInput::applySettings(const SigMFFileInputSettings& settings, bool force)
+{
+ QList reverseAPIKeys;
+
+ if ((m_settings.m_accelerationFactor != settings.m_accelerationFactor) || force)
+ {
+ reverseAPIKeys.append("accelerationFactor");
+
+ if (m_fileInputThread)
+ {
+ QMutexLocker mutexLocker(&m_mutex);
+ if (!m_sampleFifo.setSize(m_settings.m_accelerationFactor * m_sampleRate * sizeof(Sample))) {
+ qCritical("SigMFFileInput::applySettings: could not reallocate sample FIFO size to %lu",
+ m_settings.m_accelerationFactor * m_sampleRate * sizeof(Sample));
+ }
+ m_fileInputThread->setAccelerationFactor(settings.m_accelerationFactor); // Fast Forward: 1 corresponds to live. 1/2 is half speed, 2 is double speed
+ }
+ }
+
+ if ((m_settings.m_trackLoop != settings.m_trackLoop)) {
+ reverseAPIKeys.append("trackLoop");
+ }
+
+ if ((m_settings.m_fileName != settings.m_fileName))
+ {
+ reverseAPIKeys.append("fileName");
+ openFileStreams(settings.m_fileName);
+ }
+
+ if (settings.m_useReverseAPI)
+ {
+ bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
+ (m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
+ (m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
+ (m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex);
+ webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
+ }
+
+ m_settings = settings;
+ return true;
+}
+
+int SigMFFileInput::webapiSettingsGet(
+ SWGSDRangel::SWGDeviceSettings& response,
+ QString& errorMessage)
+{
+ (void) errorMessage;
+ response.setFileInputSettings(new SWGSDRangel::SWGFileInputSettings());
+ response.getFileInputSettings()->init();
+ webapiFormatDeviceSettings(response, m_settings);
+ return 200;
+}
+
+int SigMFFileInput::webapiSettingsPutPatch(
+ bool force,
+ const QStringList& deviceSettingsKeys,
+ SWGSDRangel::SWGDeviceSettings& response, // query + response
+ QString& errorMessage)
+{
+ (void) errorMessage;
+ SigMFFileInputSettings settings = m_settings;
+ webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
+
+ MsgConfigureSigMFFileInput *msg = MsgConfigureSigMFFileInput::create(settings, force);
+ m_inputMessageQueue.push(msg);
+
+ if (m_guiMessageQueue) // forward to GUI if any
+ {
+ MsgConfigureSigMFFileInput *msgToGUI = MsgConfigureSigMFFileInput::create(settings, force);
+ m_guiMessageQueue->push(msgToGUI);
+ }
+
+ webapiFormatDeviceSettings(response, settings);
+ return 200;
+}
+
+void SigMFFileInput::webapiUpdateDeviceSettings(
+ SigMFFileInputSettings& settings,
+ const QStringList& deviceSettingsKeys,
+ SWGSDRangel::SWGDeviceSettings& response)
+{
+ if (deviceSettingsKeys.contains("fileName")) {
+ settings.m_fileName = *response.getFileInputSettings()->getFileName();
+ }
+ if (deviceSettingsKeys.contains("accelerationFactor")) {
+ settings.m_accelerationFactor = response.getFileInputSettings()->getAccelerationFactor();
+ }
+ if (deviceSettingsKeys.contains("trackLoop")) {
+ settings.m_trackLoop = response.getFileInputSettings()->getLoop() != 0;
+ }
+ if (deviceSettingsKeys.contains("useReverseAPI")) {
+ settings.m_useReverseAPI = response.getFileInputSettings()->getUseReverseApi() != 0;
+ }
+ if (deviceSettingsKeys.contains("reverseAPIAddress")) {
+ settings.m_reverseAPIAddress = *response.getFileInputSettings()->getReverseApiAddress();
+ }
+ if (deviceSettingsKeys.contains("reverseAPIPort")) {
+ settings.m_reverseAPIPort = response.getFileInputSettings()->getReverseApiPort();
+ }
+ if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) {
+ settings.m_reverseAPIDeviceIndex = response.getFileInputSettings()->getReverseApiDeviceIndex();
+ }
+}
+
+int SigMFFileInput::webapiRunGet(
+ SWGSDRangel::SWGDeviceState& response,
+ QString& errorMessage)
+{
+ (void) errorMessage;
+ m_deviceAPI->getDeviceEngineStateStr(*response.getState());
+ return 200;
+}
+
+int SigMFFileInput::webapiRun(
+ bool run,
+ SWGSDRangel::SWGDeviceState& response,
+ QString& errorMessage)
+{
+ (void) errorMessage;
+ m_deviceAPI->getDeviceEngineStateStr(*response.getState());
+ MsgStartStop *message = MsgStartStop::create(run);
+ m_inputMessageQueue.push(message);
+
+ if (getMessageQueueToGUI()) // forward to GUI if any
+ {
+ MsgStartStop *msgToGUI = MsgStartStop::create(run);
+ getMessageQueueToGUI()->push(msgToGUI);
+ }
+
+ return 200;
+}
+
+int SigMFFileInput::webapiReportGet(
+ SWGSDRangel::SWGDeviceReport& response,
+ QString& errorMessage)
+{
+ (void) errorMessage;
+ response.setFileInputReport(new SWGSDRangel::SWGFileInputReport());
+ response.getFileInputReport()->init();
+ webapiFormatDeviceReport(response);
+ return 200;
+}
+
+void SigMFFileInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const SigMFFileInputSettings& settings)
+{
+ response.getFileInputSettings()->setFileName(new QString(settings.m_fileName));
+ response.getFileInputSettings()->setAccelerationFactor(settings.m_accelerationFactor);
+ response.getFileInputSettings()->setLoop(settings.m_trackLoop ? 1 : 0);
+
+ response.getFileInputSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
+
+ if (response.getFileInputSettings()->getReverseApiAddress()) {
+ *response.getFileInputSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
+ } else {
+ response.getFileInputSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
+ }
+
+ response.getFileInputSettings()->setReverseApiPort(settings.m_reverseAPIPort);
+ response.getFileInputSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
+}
+
+void SigMFFileInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response)
+{
+ qint64 t_sec = 0;
+ qint64 t_msec = 0;
+ quint64 samplesCount = 0;
+
+ if (m_fileInputThread) {
+ samplesCount = m_fileInputThread->getSamplesCount();
+ }
+
+ if (m_sampleRate > 0)
+ {
+ t_sec = samplesCount / m_sampleRate;
+ t_msec = (samplesCount - (t_sec * m_sampleRate)) * 1000 / m_sampleRate;
+ }
+
+ QTime t(0, 0, 0, 0);
+ t = t.addSecs(t_sec);
+ t = t.addMSecs(t_msec);
+ response.getFileInputReport()->setElapsedTime(new QString(t.toString("HH:mm:ss.zzz")));
+
+ qint64 startingTimeStampMsec = m_startingTimeStamp * 1000LL;
+ QDateTime dt = QDateTime::fromMSecsSinceEpoch(startingTimeStampMsec);
+ dt = dt.addSecs(t_sec);
+ dt = dt.addMSecs(t_msec);
+ response.getFileInputReport()->setAbsoluteTime(new QString(dt.toString("yyyy-MM-dd HH:mm:ss.zzz")));
+
+ QTime recordLength(0, 0, 0, 0);
+ recordLength = recordLength.addSecs(m_recordLength);
+ response.getFileInputReport()->setDurationTime(new QString(recordLength.toString("HH:mm:ss")));
+
+ response.getFileInputReport()->setSampleRate(m_sampleRate);
+ response.getFileInputReport()->setSampleSize(m_sampleBytes);
+}
+
+void SigMFFileInput::webapiReverseSendSettings(QList& deviceSettingsKeys, const SigMFFileInputSettings& settings, bool force)
+{
+ SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
+ swgDeviceSettings->setDirection(0); // single Rx
+ swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
+ swgDeviceSettings->setDeviceHwType(new QString("SigMFFileInput"));
+ swgDeviceSettings->setFileInputSettings(new SWGSDRangel::SWGFileInputSettings());
+ SWGSDRangel::SWGFileInputSettings *swgFileInputSettings = swgDeviceSettings->getFileInputSettings();
+
+ // transfer data that has been modified. When force is on transfer all data except reverse API data
+
+ if (deviceSettingsKeys.contains("accelerationFactor") || force) {
+ swgFileInputSettings->setAccelerationFactor(settings.m_accelerationFactor);
+ }
+ if (deviceSettingsKeys.contains("loop") || force) {
+ swgFileInputSettings->setLoop(settings.m_trackLoop);
+ }
+ if (deviceSettingsKeys.contains("fileName") || force) {
+ swgFileInputSettings->setFileName(new QString(settings.m_fileName));
+ }
+
+ QString deviceSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/settings")
+ .arg(settings.m_reverseAPIAddress)
+ .arg(settings.m_reverseAPIPort)
+ .arg(settings.m_reverseAPIDeviceIndex);
+ m_networkRequest.setUrl(QUrl(deviceSettingsURL));
+ m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
+
+ QBuffer *buffer = new QBuffer();
+ buffer->open((QBuffer::ReadWrite));
+ buffer->write(swgDeviceSettings->asJson().toUtf8());
+ buffer->seek(0);
+
+ // Always use PATCH to avoid passing reverse API settings
+ QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
+ buffer->setParent(reply);
+
+ delete swgDeviceSettings;
+}
+
+void SigMFFileInput::webapiReverseSendStartStop(bool start)
+{
+ SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
+ swgDeviceSettings->setDirection(0); // single Rx
+ swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
+ swgDeviceSettings->setDeviceHwType(new QString("SigMFFileInput"));
+
+ QString deviceSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/run")
+ .arg(m_settings.m_reverseAPIAddress)
+ .arg(m_settings.m_reverseAPIPort)
+ .arg(m_settings.m_reverseAPIDeviceIndex);
+ m_networkRequest.setUrl(QUrl(deviceSettingsURL));
+ m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
+
+ QBuffer *buffer = new QBuffer();
+ buffer->open((QBuffer::ReadWrite));
+ buffer->write(swgDeviceSettings->asJson().toUtf8());
+ buffer->seek(0);
+ QNetworkReply *reply;
+
+ if (start) {
+ reply = m_networkManager->sendCustomRequest(m_networkRequest, "POST", buffer);
+ } else {
+ reply = m_networkManager->sendCustomRequest(m_networkRequest, "DELETE", buffer);
+ }
+
+ buffer->setParent(reply);
+ delete swgDeviceSettings;
+}
+
+void SigMFFileInput::networkManagerFinished(QNetworkReply *reply)
+{
+ QNetworkReply::NetworkError replyError = reply->error();
+
+ if (replyError)
+ {
+ qWarning() << "SigMFFileInput::networkManagerFinished:"
+ << " error(" << (int) replyError
+ << "): " << replyError
+ << ": " << reply->errorString();
+ }
+ else
+ {
+ QString answer = reply->readAll();
+ answer.chop(1); // remove last \n
+ qDebug("SigMFFileInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
+ }
+
+ reply->deleteLater();
+}
diff --git a/plugins/samplesource/sigmffileinput/sigmffileinput.h b/plugins/samplesource/sigmffileinput/sigmffileinput.h
new file mode 100644
index 000000000..cdd14ca10
--- /dev/null
+++ b/plugins/samplesource/sigmffileinput/sigmffileinput.h
@@ -0,0 +1,489 @@
+///////////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 2020 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 //
+// (at your option) any later version. //
+// //
+// 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 . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#ifndef INCLUDE_SIGMFFILEINPUT_H
+#define INCLUDE_SIGMFFILEINPUT_H
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#include "dsp/sigmf_forward.h"
+
+#include "dsp/devicesamplesource.h"
+#include "sigmffileinputsettings.h"
+#include "sigmffiledata.h"
+
+class QNetworkAccessManager;
+class QNetworkReply;
+class SigMFFileInputThread;
+class DeviceAPI;
+
+class SigMFFileInput : public DeviceSampleSource {
+ Q_OBJECT
+public:
+ /**
+ * Communicate settings
+ */
+ class MsgConfigureSigMFFileInput : public Message {
+ MESSAGE_CLASS_DECLARATION
+
+ public:
+ const SigMFFileInputSettings& getSettings() const { return m_settings; }
+ bool getForce() const { return m_force; }
+
+ static MsgConfigureSigMFFileInput* create(const SigMFFileInputSettings& settings, bool force)
+ {
+ return new MsgConfigureSigMFFileInput(settings, force);
+ }
+
+ private:
+ SigMFFileInputSettings m_settings;
+ bool m_force;
+
+ MsgConfigureSigMFFileInput(const SigMFFileInputSettings& settings, bool force) :
+ Message(),
+ m_settings(settings),
+ m_force(force)
+ { }
+ };
+
+ /**
+ * Start/stop track play
+ */
+ class MsgConfigureTrackWork : public Message {
+ MESSAGE_CLASS_DECLARATION
+
+ public:
+ bool isWorking() const { return m_working; }
+
+ static MsgConfigureTrackWork* create(bool working) {
+ return new MsgConfigureTrackWork(working);
+ }
+
+ private:
+ bool m_working;
+
+ MsgConfigureTrackWork(bool working) :
+ Message(),
+ m_working(working)
+ { }
+ };
+
+
+ /**
+ * Start/stop full file play
+ */
+ class MsgConfigureFileWork : public Message {
+ MESSAGE_CLASS_DECLARATION
+
+ public:
+ bool isWorking() const { return m_working; }
+
+ static MsgConfigureFileWork* create(bool working) {
+ return new MsgConfigureFileWork(working);
+ }
+
+ private:
+ bool m_working;
+
+ MsgConfigureFileWork(bool working) :
+ Message(),
+ m_working(working)
+ { }
+ };
+
+ /**
+ * Move to track
+ */
+ class MsgConfigureTrackIndex : public Message {
+ MESSAGE_CLASS_DECLARATION
+
+ public:
+ int getTrackIndex() const { return m_trackIndex; }
+
+ static MsgConfigureTrackIndex* create(int trackIndex)
+ {
+ return new MsgConfigureTrackIndex(trackIndex);
+ }
+
+ private:
+ int m_trackIndex;
+
+ MsgConfigureTrackIndex(int trackIndex) :
+ Message(),
+ m_trackIndex(trackIndex)
+ { }
+ };
+
+ /**
+ * Seek position in track
+ */
+ class MsgConfigureTrackSeek : public Message {
+ MESSAGE_CLASS_DECLARATION
+
+ public:
+ int getMillis() const { return m_seekMillis; }
+
+ static MsgConfigureTrackSeek* create(int seekMillis)
+ {
+ return new MsgConfigureTrackSeek(seekMillis);
+ }
+
+ protected:
+ int m_seekMillis; //!< millis of seek position from the beginning 0..1000
+
+ MsgConfigureTrackSeek(int seekMillis) :
+ Message(),
+ m_seekMillis(seekMillis)
+ { }
+ };
+
+ /**
+ * Seek position in full file
+ */
+ class MsgConfigureFileSeek : public Message {
+ MESSAGE_CLASS_DECLARATION
+
+ public:
+ int getMillis() const { return m_seekMillis; }
+
+ static MsgConfigureFileSeek* create(int seekMillis)
+ {
+ return new MsgConfigureFileSeek(seekMillis);
+ }
+
+ protected:
+ int m_seekMillis; //!< millis of seek position from the beginning 0..1000
+
+ MsgConfigureFileSeek(int seekMillis) :
+ Message(),
+ m_seekMillis(seekMillis)
+ { }
+ };
+
+ /**
+ * Pull stram timing information
+ */
+ class MsgConfigureFileInputStreamTiming : public Message {
+ MESSAGE_CLASS_DECLARATION
+
+ public:
+
+ static MsgConfigureFileInputStreamTiming* create()
+ {
+ return new MsgConfigureFileInputStreamTiming();
+ }
+
+ private:
+
+ MsgConfigureFileInputStreamTiming() :
+ Message()
+ { }
+ };
+
+ /**
+ * Start/stop plugin
+ */
+ class MsgStartStop : public Message {
+ MESSAGE_CLASS_DECLARATION
+
+ public:
+ bool getStartStop() const { return m_startStop; }
+
+ static MsgStartStop* create(bool startStop) {
+ return new MsgStartStop(startStop);
+ }
+
+ protected:
+ bool m_startStop;
+
+ MsgStartStop(bool startStop) :
+ Message(),
+ m_startStop(startStop)
+ { }
+ };
+
+ /**
+ * Push start/stop information
+ */
+ class MsgReportStartStop : public Message {
+ MESSAGE_CLASS_DECLARATION
+
+ public:
+ bool getStartStop() const { return m_startStop; }
+
+ static MsgReportStartStop* create(bool startStop)
+ {
+ return new MsgReportStartStop(startStop);
+ }
+
+ protected:
+ bool m_startStop;
+
+ MsgReportStartStop(bool startStop) :
+ Message(),
+ m_startStop(startStop)
+ { }
+ };
+
+ /**
+ * Push meta data information
+ */
+ class MsgReportMetaData : public Message {
+ MESSAGE_CLASS_DECLARATION
+
+ public:
+ const SigMFFileMetaInfo& getMetaInfo() const { return m_metaInfo; }
+ const QList& getCaptures() { return m_captures; }
+
+ static MsgReportMetaData* create(const SigMFFileMetaInfo& metaInfo, const QList