mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-06 07:07:48 -04:00
Refactor common code into WavFileRecord class
This commit is contained in:
parent
b036dbfd7d
commit
631b9c256f
@ -27,7 +27,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QRegExp>
|
|
||||||
|
|
||||||
#include "dsp/dspcommands.h"
|
#include "dsp/dspcommands.h"
|
||||||
#include "dsp/devicesamplesink.h"
|
#include "dsp/devicesamplesink.h"
|
||||||
@ -175,7 +174,7 @@ void FileSourceSource::openFileStream(const QString& fileName)
|
|||||||
quint64 fileSize = m_ifstream.tellg();
|
quint64 fileSize = m_ifstream.tellg();
|
||||||
m_samplesCount = 0;
|
m_samplesCount = 0;
|
||||||
|
|
||||||
if (m_settings.m_fileName.endsWith(".wav"))
|
if (m_fileName.endsWith(".wav"))
|
||||||
{
|
{
|
||||||
WavFileRecord::Header header;
|
WavFileRecord::Header header;
|
||||||
m_ifstream.seekg(0, std::ios_base::beg);
|
m_ifstream.seekg(0, std::ios_base::beg);
|
||||||
@ -185,44 +184,16 @@ void FileSourceSource::openFileStream(const QString& fileName)
|
|||||||
{
|
{
|
||||||
// Some WAV files written by SDR tools have auxi header
|
// Some WAV files written by SDR tools have auxi header
|
||||||
m_centerFrequency = header.m_auxi.m_centerFreq;
|
m_centerFrequency = header.m_auxi.m_centerFreq;
|
||||||
m_startingTimeStamp = QDateTime(QDate(
|
m_startingTimeStamp = header.getStartTime().toMSecsSinceEpoch() / 1000;
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
// Attempt to extract time and frequency from filename
|
// Attempt to extract start 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])");
|
QDateTime startTime;
|
||||||
if (dateTimeRE.indexIn(m_settings.m_fileName) != -1)
|
if (WavFileRecord::getStartTime(m_fileName, startTime)) {
|
||||||
{
|
m_startingTimeStamp = startTime.toMSecsSinceEpoch() / 1000;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
WavFileRecord::getCenterFrequency(m_fileName, m_centerFrequency);
|
||||||
}
|
}
|
||||||
m_sampleSize = header.m_bitsPerSample;
|
m_sampleSize = header.m_bitsPerSample;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QRegExp>
|
|
||||||
|
|
||||||
#include "SWGDeviceSettings.h"
|
#include "SWGDeviceSettings.h"
|
||||||
#include "SWGFileInputSettings.h"
|
#include "SWGFileInputSettings.h"
|
||||||
@ -111,44 +110,16 @@ void FileInput::openFileStream()
|
|||||||
{
|
{
|
||||||
// Some WAV files written by SDR tools have auxi header
|
// Some WAV files written by SDR tools have auxi header
|
||||||
m_centerFrequency = header.m_auxi.m_centerFreq;
|
m_centerFrequency = header.m_auxi.m_centerFreq;
|
||||||
m_startingTimeStamp = QDateTime(QDate(
|
m_startingTimeStamp = header.getStartTime().toMSecsSinceEpoch() / 1000;
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
// Attempt to extract time and frequency from filename
|
// Attempt to extract start 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])");
|
QDateTime startTime;
|
||||||
if (dateTimeRE.indexIn(m_settings.m_fileName) != -1)
|
if (WavFileRecord::getStartTime(m_settings.m_fileName, startTime)) {
|
||||||
{
|
m_startingTimeStamp = startTime.toMSecsSinceEpoch() / 1000;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
WavFileRecord::getCenterFrequency(m_settings.m_fileName, m_centerFrequency);
|
||||||
}
|
}
|
||||||
m_sampleSize = header.m_bitsPerSample;
|
m_sampleSize = header.m_bitsPerSample;
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
#include "dsp/dspcommands.h"
|
#include "dsp/dspcommands.h"
|
||||||
#include "util/simpleserializer.h"
|
#include "util/simpleserializer.h"
|
||||||
@ -340,3 +341,51 @@ void WavFileRecord::writeHeader(std::ofstream& sampleFile, Header& header)
|
|||||||
{
|
{
|
||||||
sampleFile.write((const char *) &header, sizeof(Header));
|
sampleFile.write((const char *) &header, sizeof(Header));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WavFileRecord::getCenterFrequency(QString fileName, quint64& centerFrequency)
|
||||||
|
{
|
||||||
|
// Attempt to extract center frequency from filename
|
||||||
|
QRegExp freqkRE("(([0-9]+)kHz)");
|
||||||
|
QRegExp freqRE("(([0-9]+)Hz)");
|
||||||
|
if (freqkRE.indexIn(fileName))
|
||||||
|
{
|
||||||
|
centerFrequency = freqkRE.capturedTexts()[2].toLongLong() * 1000LL;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (freqRE.indexIn(fileName))
|
||||||
|
{
|
||||||
|
centerFrequency = freqRE.capturedTexts()[2].toLongLong();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WavFileRecord::getStartTime(QString fileName, QDateTime& startTime)
|
||||||
|
{
|
||||||
|
// Attempt to extract start time 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(fileName) != -1)
|
||||||
|
{
|
||||||
|
startTime = 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()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDateTime WavFileRecord::Header::getStartTime() const
|
||||||
|
{
|
||||||
|
return QDateTime(QDate(m_auxi.m_startTime.m_year,
|
||||||
|
m_auxi.m_startTime.m_month,
|
||||||
|
m_auxi.m_startTime.m_day),
|
||||||
|
QTime(m_auxi.m_startTime.m_hour,
|
||||||
|
m_auxi.m_startTime.m_minute,
|
||||||
|
m_auxi.m_startTime.m_second,
|
||||||
|
m_auxi.m_startTime.m_milliseconds));
|
||||||
|
}
|
||||||
|
@ -66,7 +66,7 @@ public:
|
|||||||
quint32 m_unused5;
|
quint32 m_unused5;
|
||||||
char m_nextFilename[96];
|
char m_nextFilename[96];
|
||||||
};
|
};
|
||||||
struct Header
|
struct SDRBASE_API Header
|
||||||
{
|
{
|
||||||
Chunk m_riffHeader;
|
Chunk m_riffHeader;
|
||||||
char m_type[4]; // "WAVE"
|
char m_type[4]; // "WAVE"
|
||||||
@ -80,6 +80,8 @@ public:
|
|||||||
Chunk m_auxiHeader;
|
Chunk m_auxiHeader;
|
||||||
Auxi m_auxi;
|
Auxi m_auxi;
|
||||||
Chunk m_dataHeader;
|
Chunk m_dataHeader;
|
||||||
|
|
||||||
|
QDateTime getStartTime() const;
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
@ -107,6 +109,10 @@ public:
|
|||||||
static bool readHeader(std::ifstream& samplefile, Header& header);
|
static bool readHeader(std::ifstream& samplefile, Header& header);
|
||||||
static void writeHeader(std::ofstream& samplefile, Header& header);
|
static void writeHeader(std::ofstream& samplefile, Header& header);
|
||||||
|
|
||||||
|
// These functions guess from the filename, not contents
|
||||||
|
static bool getCenterFrequency(QString fileName, quint64& centerFrequency);
|
||||||
|
static bool getStartTime(QString fileName, QDateTime& startTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_fileBase;
|
QString m_fileBase;
|
||||||
quint32 m_sampleRate;
|
quint32 m_sampleRate;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user