1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

FileInput: calculate file record length down to the microsecond. Implements #614

This commit is contained in:
f4exb 2020-08-26 00:12:30 +02:00
parent b644e7fe92
commit 47a1eeaedc
5 changed files with 27 additions and 25 deletions

View File

@ -58,7 +58,7 @@ FileInput::FileInput(DeviceAPI *deviceAPI) :
m_sampleRate(48000),
m_sampleSize(0),
m_centerFrequency(435000000),
m_recordLength(0),
m_recordLengthMuSec(0),
m_startingTimeStamp(0)
{
m_deviceAPI->setNbSourceStreams(1);
@ -114,12 +114,12 @@ void FileInput::openFileStream()
if (crcOK)
{
qDebug("FileInput::openFileStream: CRC32 OK for header: %s", qPrintable(crcHex));
m_recordLength = (fileSize - sizeof(FileRecord::Header)) / ((m_sampleSize == 24 ? 8 : 4) * m_sampleRate);
m_recordLengthMuSec = ((fileSize - sizeof(FileRecord::Header)) * 1000000UL) / ((m_sampleSize == 24 ? 8 : 4) * m_sampleRate);
}
else
{
qCritical("FileInput::openFileStream: bad CRC32 for header: %s", qPrintable(crcHex));
m_recordLength = 0;
m_recordLengthMuSec = 0;
}
if (getMessageQueueToGUI())
@ -130,12 +130,12 @@ void FileInput::openFileStream()
}
else
{
m_recordLength = 0;
m_recordLengthMuSec = 0;
}
qDebug() << "FileInput::openFileStream: " << m_fileName.toStdString().c_str()
<< " fileSize: " << fileSize << " bytes"
<< " length: " << m_recordLength << " seconds"
<< " length: " << m_recordLengthMuSec << " microseconds"
<< " sample rate: " << m_sampleRate << " S/s"
<< " center frequency: " << m_centerFrequency << " Hz"
<< " sample size: " << m_sampleSize << " bits";
@ -148,11 +148,11 @@ void FileInput::openFileStream()
m_sampleSize,
m_centerFrequency,
m_startingTimeStamp,
m_recordLength); // file stream data
m_recordLengthMuSec); // file stream data
getMessageQueueToGUI()->push(report);
}
if (m_recordLength == 0) {
if (m_recordLengthMuSec == 0) {
m_ifstream.close();
}
}
@ -163,7 +163,8 @@ void FileInput::seekFileStream(int seekMillis)
if ((m_ifstream.is_open()) && m_fileInputWorker && !m_fileInputWorker->isRunning())
{
quint64 seekPoint = ((m_recordLength * seekMillis) / 1000) * m_sampleRate;
quint64 seekPoint = ((m_recordLengthMuSec * seekMillis) / 1000) * m_sampleRate;
seekPoint /= 1000000UL;
m_fileInputWorker->setSamplesCount(seekPoint);
seekPoint *= (m_sampleSize == 24 ? 8 : 4); // + sizeof(FileRecord::Header)
m_ifstream.clear();
@ -612,8 +613,8 @@ void FileInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response)
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")));
recordLength = recordLength.addMSecs(m_recordLengthMuSec / 1000UL);
response.getFileInputReport()->setDurationTime(new QString(recordLength.toString("HH:mm:ss.zzz")));
response.getFileInputReport()->setFileName(new QString(m_fileName));
response.getFileInputReport()->setSampleRate(m_sampleRate);

View File

@ -206,7 +206,7 @@ public:
quint32 getSampleSize() const { return m_sampleSize; }
quint64 getCenterFrequency() const { return m_centerFrequency; }
quint64 getStartingTimeStamp() const { return m_startingTimeStamp; }
quint64 getRecordLength() const { return m_recordLength; }
quint64 getRecordLengthMuSec() const { return m_recordLengthMuSec; }
static MsgReportFileInputStreamData* create(int sampleRate,
quint32 sampleSize,
@ -222,19 +222,19 @@ public:
quint32 m_sampleSize;
quint64 m_centerFrequency;
quint64 m_startingTimeStamp;
quint64 m_recordLength;
quint64 m_recordLengthMuSec;
MsgReportFileInputStreamData(int sampleRate,
quint32 sampleSize,
quint64 centerFrequency,
quint64 startingTimeStamp,
quint64 recordLength) :
quint64 recordLengthMuSec) :
Message(),
m_sampleRate(sampleRate),
m_sampleSize(sampleSize),
m_centerFrequency(centerFrequency),
m_startingTimeStamp(startingTimeStamp),
m_recordLength(recordLength)
m_recordLengthMuSec(recordLengthMuSec)
{ }
};
@ -342,7 +342,7 @@ public:
int m_sampleRate;
quint32 m_sampleSize;
quint64 m_centerFrequency;
quint64 m_recordLength; //!< record length in seconds computed from file size
quint64 m_recordLengthMuSec; //!< record length in microseconds computed from file size
quint64 m_startingTimeStamp;
QTimer m_masterTimer;
QNetworkAccessManager *m_networkManager;

View File

@ -49,7 +49,7 @@ FileInputGUI::FileInputGUI(DeviceUISet *deviceUISet, QWidget* parent) :
m_fileName("..."),
m_sampleRate(0),
m_centerFrequency(0),
m_recordLength(0),
m_recordLengthMuSec(0),
m_startingTimeStamp(0),
m_samplesCount(0),
m_tickCount(0),
@ -184,7 +184,7 @@ bool FileInputGUI::handleMessage(const Message& message)
m_sampleSize = ((FileInput::MsgReportFileInputStreamData&)message).getSampleSize();
m_centerFrequency = ((FileInput::MsgReportFileInputStreamData&)message).getCenterFrequency();
m_startingTimeStamp = ((FileInput::MsgReportFileInputStreamData&)message).getStartingTimeStamp();
m_recordLength = ((FileInput::MsgReportFileInputStreamData&)message).getRecordLength();
m_recordLengthMuSec = ((FileInput::MsgReportFileInputStreamData&)message).getRecordLengthMuSec();
updateWithStreamData();
return true;
}
@ -362,8 +362,8 @@ void FileInputGUI::updateWithStreamData()
ui->sampleSizeText->setText(tr("%1b").arg(m_sampleSize));
ui->play->setEnabled(m_acquisition);
QTime recordLength(0, 0, 0, 0);
recordLength = recordLength.addSecs(m_recordLength);
QString s_time = recordLength.toString("HH:mm:ss");
recordLength = recordLength.addMSecs(m_recordLengthMuSec/1000UL);
QString s_time = recordLength.toString("HH:mm:ss.zzz");
ui->recordLengthText->setText(s_time);
updateWithStreamTime();
}
@ -373,7 +373,8 @@ void FileInputGUI::updateWithStreamTime()
qint64 t_sec = 0;
qint64 t_msec = 0;
if (m_sampleRate > 0){
if (m_sampleRate > 0)
{
t_sec = m_samplesCount / m_sampleRate;
t_msec = (m_samplesCount - (t_sec * m_sampleRate)) * 1000LL / m_sampleRate;
}
@ -393,7 +394,7 @@ void FileInputGUI::updateWithStreamTime()
if (!m_enableNavTime)
{
float posRatio = (float) t_sec / (float) m_recordLength;
float posRatio = (float) (t_sec*1000000L + t_msec*1000L) / (float) m_recordLengthMuSec;
ui->navTimeSlider->setValue((int) (posRatio * 1000.0));
}
}

View File

@ -66,7 +66,7 @@ private:
int m_sampleRate;
quint32 m_sampleSize;
quint64 m_centerFrequency;
quint64 m_recordLength;
quint64 m_recordLengthMuSec;
quint64 m_startingTimeStamp;
quint64 m_samplesCount;
std::size_t m_tickCount;

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<width>377</width>
<height>190</height>
</rect>
</property>
@ -548,7 +548,7 @@
</property>
<property name="minimumSize">
<size>
<width>60</width>
<width>90</width>
<height>0</height>
</size>
</property>
@ -556,7 +556,7 @@
<string>Total record time</string>
</property>
<property name="text">
<string>00:00:00</string>
<string>00:00:00.000</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>