mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-29 05:22:25 -04:00
Add .wav file support to File Source plugin
This commit is contained in:
parent
14710596be
commit
b036dbfd7d
@ -427,7 +427,7 @@ void FileSourceGUI::on_showFileDialog_clicked(bool checked)
|
|||||||
{
|
{
|
||||||
(void) checked;
|
(void) checked;
|
||||||
QString fileName = QFileDialog::getOpenFileName(this,
|
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 != "")
|
if (fileName != "")
|
||||||
{
|
{
|
||||||
|
@ -27,11 +27,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
#include "dsp/dspcommands.h"
|
#include "dsp/dspcommands.h"
|
||||||
#include "dsp/devicesamplesink.h"
|
#include "dsp/devicesamplesink.h"
|
||||||
#include "dsp/hbfilterchainconverter.h"
|
#include "dsp/hbfilterchainconverter.h"
|
||||||
#include "dsp/filerecord.h"
|
#include "dsp/filerecord.h"
|
||||||
|
#include "dsp/wavfilerecord.h"
|
||||||
#include "util/db.h"
|
#include "util/db.h"
|
||||||
|
|
||||||
FileSourceSource::FileSourceSource() :
|
FileSourceSource::FileSourceSource() :
|
||||||
@ -173,7 +175,74 @@ void FileSourceSource::openFileStream(const QString& fileName)
|
|||||||
quint64 fileSize = m_ifstream.tellg();
|
quint64 fileSize = m_ifstream.tellg();
|
||||||
m_samplesCount = 0;
|
m_samplesCount = 0;
|
||||||
|
|
||||||
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_fileSampleRate = 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_fileSampleRate > 0) && (m_sampleSize > 0))
|
||||||
|
{
|
||||||
|
m_recordLengthMuSec = ((fileSize - m_ifstream.tellg()) * 1000000UL) / ((m_sampleSize == 24 ? 8 : 4) * m_fileSampleRate);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCritical("FileSourceSource::openFileStream: invalid .wav file");
|
||||||
|
m_recordLengthMuSec = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getMessageQueueToGUI())
|
||||||
|
{
|
||||||
|
FileSourceReport::MsgReportHeaderCRC *report = FileSourceReport::MsgReportHeaderCRC::create(headerOK);
|
||||||
|
getMessageQueueToGUI()->push(report);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (fileSize > sizeof(FileRecord::Header))
|
||||||
{
|
{
|
||||||
FileRecord::Header header;
|
FileRecord::Header header;
|
||||||
m_ifstream.seekg(0,std::ios_base::beg);
|
m_ifstream.seekg(0,std::ios_base::beg);
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
<h2>Introduction</h2>
|
<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. File formats supported include SDRangel's `.sdriq` and signed 16-bit PCM `.wav` files.
|
||||||
|
|
||||||
|
`.sqriq` files start with a 32 byte header of all unsigned integer of various sizes containing meta data:
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user