1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-02 14:04:46 -04:00

Add signed 16-bit PCM 2 channel .wav file support to File Input and File Record plugins

This commit is contained in:
Jon Beniston
2021-05-21 10:06:10 +01:00
parent cd3434c871
commit 80fe6cb096
15 changed files with 611 additions and 48 deletions
+70 -1
View File
@@ -21,6 +21,7 @@
#include <QDebug>
#include <QNetworkReply>
#include <QBuffer>
#include <QRegExp>
#include "SWGDeviceSettings.h"
#include "SWGFileInputSettings.h"
@@ -32,6 +33,7 @@
#include "dsp/dspdevicesourceengine.h"
#include "dsp/dspengine.h"
#include "dsp/filerecord.h"
#include "dsp/wavfilerecord.h"
#include "device/deviceapi.h"
#include "fileinput.h"
@@ -99,7 +101,74 @@ void FileInput::openFileStream()
#endif
quint64 fileSize = m_ifstream.tellg();
if (fileSize > sizeof(FileRecord::Header))
if (m_settings.m_fileName.endsWith(".wav"))
{
WavFileRecord::Header header;
m_ifstream.seekg(0, std::ios_base::beg);
bool headerOK = WavFileRecord::readHeader(m_ifstream, header);
m_sampleRate = header.m_sampleRate;
if (header.m_auxiHeader.m_size > 0)
{
// Some WAV files written by SDR tools have auxi header
m_centerFrequency = header.m_auxi.m_centerFreq;
m_startingTimeStamp = QDateTime(QDate(
header.m_auxi.m_startTime.m_year,
header.m_auxi.m_startTime.m_month,
header.m_auxi.m_startTime.m_day
), QTime(
header.m_auxi.m_startTime.m_hour,
header.m_auxi.m_startTime.m_minute,
header.m_auxi.m_startTime.m_second,
header.m_auxi.m_startTime.m_milliseconds
)).toMSecsSinceEpoch() / 1000;
}
else
{
// Attempt to extract time and frequency from filename
QRegExp dateTimeRE("([12][0-9][0-9][0-9]).?([01][0-9]).?([0-3][0-9]).?([0-2][0-9]).?([0-5][0-9]).?([0-5][0-9])");
if (dateTimeRE.indexIn(m_settings.m_fileName) != -1)
{
m_startingTimeStamp = QDateTime(QDate(
dateTimeRE.capturedTexts()[1].toInt(),
dateTimeRE.capturedTexts()[2].toInt(),
dateTimeRE.capturedTexts()[3].toInt()
), QTime(
dateTimeRE.capturedTexts()[4].toInt(),
dateTimeRE.capturedTexts()[5].toInt(),
dateTimeRE.capturedTexts()[6].toInt()
)).toMSecsSinceEpoch() / 1000;
}
// Attempt to extract centre frequency from filename
QRegExp freqkRE("(([0-9]+)kHz)");
QRegExp freqRE("(([0-9]+)Hz)");
if (freqkRE.indexIn(m_settings.m_fileName))
{
m_centerFrequency = freqkRE.capturedTexts()[2].toLongLong() * 1000LL;
}
else if (freqRE.indexIn(m_settings.m_fileName))
{
m_centerFrequency = freqRE.capturedTexts()[2].toLongLong();
}
}
m_sampleSize = header.m_bitsPerSample;
if (headerOK && (m_sampleRate > 0) && (m_sampleSize > 0))
{
m_recordLengthMuSec = ((fileSize - m_ifstream.tellg()) * 1000000UL) / ((m_sampleSize == 24 ? 8 : 4) * m_sampleRate);
}
else
{
qCritical("FileInput::openFileStream: invalid .wav file");
m_recordLengthMuSec = 0;
}
if (getMessageQueueToGUI())
{
MsgReportHeaderCRC *report = MsgReportHeaderCRC::create(headerOK);
getMessageQueueToGUI()->push(report);
}
}
else if (fileSize > sizeof(FileRecord::Header))
{
FileRecord::Header header;
m_ifstream.seekg(0,std::ios_base::beg);
@@ -302,7 +302,7 @@ void FileInputGUI::on_showFileDialog_clicked(bool checked)
{
(void) checked;
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open I/Q record file"), ".", tr("SDR I/Q Files (*.sdriq)"), 0, QFileDialog::DontUseNativeDialog);
tr("Open I/Q record file"), ".", tr("SDR I/Q Files (*.sdriq *.wav)"), 0, QFileDialog::DontUseNativeDialog);
if (fileName != "")
{
+4 -2
View File
@@ -2,7 +2,9 @@
<h2>Introduction</h2>
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:
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 plugin supports SDRangel's own .sdriq file format as well as signed 16-bit PCM, 2 channel .wav files (including support for optional auxi headers, containing centre frequency).
An .sdriq file starts with a 32 byte header of all unsigned integer of various sizes containing meta data:
<table>
<tr>
@@ -66,7 +68,7 @@ This is the center frequency of reception in kHz when the record was taken and w
<h3>4: Open file</h3>
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.
Opens a file dialog to select the input file. It expects an extension of `.sdriq` or `.wav`. 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.
<h3>5: File path</h3>