1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-16 05:11:49 -05:00

File Input: acceleration and loop handling phase 1

This commit is contained in:
f4exb 2018-10-14 01:16:39 +02:00
parent 1674ab0e29
commit bb1e3f3933
9 changed files with 255 additions and 42 deletions

View File

@ -51,7 +51,8 @@ FileSourceGui::FileSourceGui(DeviceUISet *deviceUISet, QWidget* parent) :
m_samplesCount(0), m_samplesCount(0),
m_tickCount(0), m_tickCount(0),
m_enableNavTime(false), m_enableNavTime(false),
m_lastEngineState(DSPDeviceSourceEngine::StNotStarted) m_lastEngineState(DSPDeviceSourceEngine::StNotStarted),
m_accelerationMaxScale(1)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
@ -64,8 +65,10 @@ FileSourceGui::FileSourceGui(DeviceUISet *deviceUISet, QWidget* parent) :
m_statusTimer.start(500); m_statusTimer.start(500);
displaySettings(); displaySettings();
setAccelerationCombo();
ui->navTimeSlider->setEnabled(false); ui->navTimeSlider->setEnabled(false);
ui->acceleration->setEnabled(false);
ui->playLoop->setChecked(true); // FIXME: always play in a loop ui->playLoop->setChecked(true); // FIXME: always play in a loop
ui->playLoop->setEnabled(false); ui->playLoop->setEnabled(false);
@ -279,6 +282,7 @@ void FileSourceGui::on_play_toggled(bool checked)
FileSourceInput::MsgConfigureFileSourceWork* message = FileSourceInput::MsgConfigureFileSourceWork::create(checked); FileSourceInput::MsgConfigureFileSourceWork* message = FileSourceInput::MsgConfigureFileSourceWork::create(checked);
m_sampleSource->getInputMessageQueue()->push(message); m_sampleSource->getInputMessageQueue()->push(message);
ui->navTimeSlider->setEnabled(!checked); ui->navTimeSlider->setEnabled(!checked);
ui->acceleration->setEnabled(!checked);
m_enableNavTime = !checked; m_enableNavTime = !checked;
} }
@ -305,6 +309,13 @@ void FileSourceGui::on_showFileDialog_clicked(bool checked __attribute__((unused
} }
} }
void FileSourceGui::on_acceleration_currentIndexChanged(int index)
{
m_settings.m_accelerationFactor = FileSourceSettings::getAccelerationValue(index);
FileSourceInput::MsgConfigureFileSource *message = FileSourceInput::MsgConfigureFileSource::create(m_settings);
m_sampleSource->getInputMessageQueue()->push(message);
}
void FileSourceGui::configureFileName() void FileSourceGui::configureFileName()
{ {
qDebug() << "FileSourceGui::configureFileName: " << m_fileName.toStdString().c_str(); qDebug() << "FileSourceGui::configureFileName: " << m_fileName.toStdString().c_str();
@ -369,3 +380,42 @@ void FileSourceGui::tick()
m_sampleSource->getInputMessageQueue()->push(message); m_sampleSource->getInputMessageQueue()->push(message);
} }
} }
void FileSourceGui::setAccelerationCombo()
{
ui->acceleration->blockSignals(true);
ui->acceleration->clear();
ui->acceleration->addItem(QString("1"));
for (unsigned int i = 0; i <= m_accelerationMaxScale; i++)
{
QString s;
int m = pow(10.0, i);
int x = 2*m;
setNumberStr(x, s);
ui->acceleration->addItem(s);
x = 5*m;
setNumberStr(x, s);
ui->acceleration->addItem(s);
x = 10*m;
setNumberStr(x, s);
ui->acceleration->addItem(s);
}
ui->acceleration->blockSignals(false);
}
void FileSourceGui::setNumberStr(int n, QString& s)
{
if (n < 1000) {
s = tr("%1").arg(n);
} else if (n < 100000) {
s = tr("%1k").arg(n/1000);
} else if (n < 1000000) {
s = tr("%1e5").arg(n/100000);
} else if (n < 1000000000) {
s = tr("%1M").arg(n/1000000);
} else {
s = tr("%1G").arg(n/1000000000);
}
}

View File

@ -74,6 +74,7 @@ private:
quint64 m_deviceCenterFrequency; //!< Center frequency in device quint64 m_deviceCenterFrequency; //!< Center frequency in device
int m_lastEngineState; int m_lastEngineState;
MessageQueue m_inputMessageQueue; MessageQueue m_inputMessageQueue;
unsigned int m_accelerationMaxScale;
void blockApplySettings(bool block) { m_doApplySettings = !block; } void blockApplySettings(bool block) { m_doApplySettings = !block; }
void displaySettings(); void displaySettings();
@ -84,6 +85,8 @@ private:
void updateWithAcquisition(); void updateWithAcquisition();
void updateWithStreamData(); void updateWithStreamData();
void updateWithStreamTime(); void updateWithStreamTime();
void setAccelerationCombo();
void setNumberStr(int n, QString& s);
private slots: private slots:
void handleInputMessages(); void handleInputMessages();
@ -92,6 +95,7 @@ private slots:
void on_play_toggled(bool checked); void on_play_toggled(bool checked);
void on_navTimeSlider_valueChanged(int value); void on_navTimeSlider_valueChanged(int value);
void on_showFileDialog_clicked(bool checked); void on_showFileDialog_clicked(bool checked);
void on_acceleration_currentIndexChanged(int index);
void updateStatus(); void updateStatus();
void tick(); void tick();
}; };

View File

@ -418,6 +418,65 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QComboBox" name="acceleration">
<property name="minimumSize">
<size>
<width>45</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>45</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="toolTip">
<string>Acceleration factor</string>
</property>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
<item>
<property name="text">
<string>10</string>
</property>
</item>
<item>
<property name="text">
<string>20</string>
</property>
</item>
<item>
<property name="text">
<string>50</string>
</property>
</item>
<item>
<property name="text">
<string>100</string>
</property>
</item>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
@ -528,20 +587,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="Line" name="line_rate2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_nav">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>

View File

@ -86,7 +86,6 @@ void FileSourceInput::openFileStream()
if (fileSize > sizeof(FileRecord::Header)) if (fileSize > sizeof(FileRecord::Header))
{ {
// TODO: add CRC
FileRecord::Header header; FileRecord::Header header;
m_ifstream.seekg(0,std::ios_base::beg); m_ifstream.seekg(0,std::ios_base::beg);
bool crcOK = FileRecord::readHeader(m_ifstream, header); bool crcOK = FileRecord::readHeader(m_ifstream, header);
@ -181,9 +180,8 @@ bool FileSourceInput::start()
//openFileStream(); //openFileStream();
m_fileSourceThread = new FileSourceThread(&m_ifstream, &m_sampleFifo); m_fileSourceThread = new FileSourceThread(&m_ifstream, &m_sampleFifo, m_masterTimer, &m_inputMessageQueue);
m_fileSourceThread->setSampleRateAndSize(m_sampleRate, m_sampleSize); m_fileSourceThread->setSampleRateAndSize(m_settings.m_accelerationFactor * m_sampleRate, m_sampleSize); // Fast Forward: 1 corresponds to live. 1/2 is half speed, 2 is double speed
m_fileSourceThread->connectTimer(m_masterTimer);
m_fileSourceThread->startWork(); m_fileSourceThread->startWork();
m_deviceDescription = "FileSource"; m_deviceDescription = "FileSource";
@ -361,6 +359,19 @@ bool FileSourceInput::handleMessage(const Message& message)
return true; return true;
} }
else if (FileSourceThread::MsgReportEOF::match(message))
{
qDebug() << "FileSourceInput::handleMessage: MsgReportEOF";
m_fileSourceThread->stopWork();
if (m_settings.m_loop)
{
seekFileStream(0);
m_fileSourceThread->startWork();
}
return true;
}
else else
{ {
return false; return false;
@ -373,6 +384,12 @@ bool FileSourceInput::applySettings(const FileSourceSettings& settings, bool for
m_centerFrequency = settings.m_centerFrequency; m_centerFrequency = settings.m_centerFrequency;
} }
if ((m_settings.m_accelerationFactor != settings.m_accelerationFactor) || force)
{
QMutexLocker mutexLocker(&m_mutex);
m_fileSourceThread->setSampleRateAndSize(settings.m_accelerationFactor * m_sampleRate, m_sampleSize); // Fast Forward: 1 corresponds to live. 1/2 is half speed, 2 is double speed
}
m_settings = settings; m_settings = settings;
return true; return true;
} }

View File

@ -18,6 +18,8 @@
#include "filesourcesettings.h" #include "filesourcesettings.h"
const unsigned int FileSourceSettings::m_accelerationMaxScale = 1;
FileSourceSettings::FileSourceSettings() FileSourceSettings::FileSourceSettings()
{ {
resetToDefaults(); resetToDefaults();
@ -28,12 +30,16 @@ void FileSourceSettings::resetToDefaults()
m_centerFrequency = 435000000; m_centerFrequency = 435000000;
m_sampleRate = 48000; m_sampleRate = 48000;
m_fileName = "./test.sdriq"; m_fileName = "./test.sdriq";
m_accelerationFactor = 1;
m_loop = true;
} }
QByteArray FileSourceSettings::serialize() const QByteArray FileSourceSettings::serialize() const
{ {
SimpleSerializer s(1); SimpleSerializer s(1);
s.writeString(1, m_fileName); s.writeString(1, m_fileName);
s.writeU32(2, m_accelerationFactor);
s.writeBool(3, m_loop);
return s.final(); return s.final();
} }
@ -48,6 +54,8 @@ bool FileSourceSettings::deserialize(const QByteArray& data)
if(d.getVersion() == 1) { if(d.getVersion() == 1) {
d.readString(1, &m_fileName, "./test.sdriq"); d.readString(1, &m_fileName, "./test.sdriq");
d.readU32(2, &m_accelerationFactor, 1);
d.readBool(3, &m_loop, true);
return true; return true;
} else { } else {
resetToDefaults(); resetToDefaults();
@ -55,6 +63,60 @@ bool FileSourceSettings::deserialize(const QByteArray& data)
} }
} }
int FileSourceSettings::getAccelerationIndex(int accelerationValue)
{
if (accelerationValue <= 1) {
return 0;
}
int v = accelerationValue;
int j = 0;
for (int i = 0; i <= accelerationValue; i++)
{
if (v < 20)
{
if (v < 2) {
j = 0;
} else if (v < 5) {
j = 1;
} else if (v < 10) {
j = 2;
} else {
j = 3;
}
return 3*i + j;
}
v /= 10;
}
return 3*m_accelerationMaxScale + 3;
}
int FileSourceSettings::getAccelerationValue(int accelerationIndex)
{
if (accelerationIndex <= 0) {
return 1;
}
unsigned int v = accelerationIndex - 1;
int m = pow(10.0, v/3 > m_accelerationMaxScale ? m_accelerationMaxScale : v/3);
int x;
if (v % 3 == 0) {
x = 2;
} else if (v % 3 == 1) {
x = 5;
} else if (v % 3 == 2) {
x = 10;
}
return x * m;
}

View File

@ -24,6 +24,9 @@ struct FileSourceSettings {
quint64 m_centerFrequency; quint64 m_centerFrequency;
qint32 m_sampleRate; qint32 m_sampleRate;
QString m_fileName; QString m_fileName;
quint32 m_accelerationFactor;
bool m_loop;
static const unsigned int m_accelerationMaxScale; //!< Max power of 10 multiplier to 2,5,10 base ex: 2 -> 2,5,10,20,50,100,200,500,1000
FileSourceSettings(); FileSourceSettings();
~FileSourceSettings() {} ~FileSourceSettings() {}
@ -31,6 +34,8 @@ struct FileSourceSettings {
void resetToDefaults(); void resetToDefaults();
QByteArray serialize() const; QByteArray serialize() const;
bool deserialize(const QByteArray& data); bool deserialize(const QByteArray& data);
static int getAccelerationIndex(int averaging);
static int getAccelerationValue(int averagingIndex);
}; };
#endif /* PLUGINS_SAMPLESOURCE_FILESOURCE_FILESOURCESETTINGS_H_ */ #endif /* PLUGINS_SAMPLESOURCE_FILESOURCE_FILESOURCESETTINGS_H_ */

View File

@ -22,8 +22,15 @@
#include "dsp/filerecord.h" #include "dsp/filerecord.h"
#include "filesourcethread.h" #include "filesourcethread.h"
#include "dsp/samplesinkfifo.h" #include "dsp/samplesinkfifo.h"
#include "util/messagequeue.h"
FileSourceThread::FileSourceThread(std::ifstream *samplesStream, SampleSinkFifo* sampleFifo, QObject* parent) : MESSAGE_CLASS_DEFINITION(FileSourceThread::MsgReportEOF, Message)
FileSourceThread::FileSourceThread(std::ifstream *samplesStream,
SampleSinkFifo* sampleFifo,
const QTimer& timer,
MessageQueue *fileInputMessageQueue,
QObject* parent) :
QThread(parent), QThread(parent),
m_running(false), m_running(false),
m_ifstream(samplesStream), m_ifstream(samplesStream),
@ -33,6 +40,8 @@ FileSourceThread::FileSourceThread(std::ifstream *samplesStream, SampleSinkFifo*
m_chunksize(0), m_chunksize(0),
m_sampleFifo(sampleFifo), m_sampleFifo(sampleFifo),
m_samplesCount(0), m_samplesCount(0),
m_timer(timer),
m_fileInputMessageQueue(fileInputMessageQueue),
m_samplerate(0), m_samplerate(0),
m_samplesize(0), m_samplesize(0),
m_samplebytes(0), m_samplebytes(0),
@ -70,6 +79,7 @@ void FileSourceThread::startWork()
while(!m_running) while(!m_running)
m_startWaiter.wait(&m_startWaitMutex, 100); m_startWaiter.wait(&m_startWaitMutex, 100);
m_startWaitMutex.unlock(); m_startWaitMutex.unlock();
connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
} }
else else
{ {
@ -80,6 +90,7 @@ void FileSourceThread::startWork()
void FileSourceThread::stopWork() void FileSourceThread::stopWork()
{ {
qDebug() << "FileSourceThread::stopWork"; qDebug() << "FileSourceThread::stopWork";
disconnect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
m_running = false; m_running = false;
wait(); wait();
} }
@ -101,7 +112,6 @@ void FileSourceThread::setSampleRateAndSize(int samplerate, quint32 samplesize)
m_samplerate = samplerate; m_samplerate = samplerate;
m_samplesize = samplesize; m_samplesize = samplesize;
m_samplebytes = m_samplesize > 16 ? sizeof(int32_t) : sizeof(int16_t); m_samplebytes = m_samplesize > 16 ? sizeof(int32_t) : sizeof(int16_t);
// TODO: implement FF and slow motion here. 2 corresponds to live. 1 is half speed, 4 is double speed
m_chunksize = (m_samplerate * 2 * m_samplebytes * m_throttlems) / 1000; m_chunksize = (m_samplerate * 2 * m_samplebytes * m_throttlems) / 1000;
setBuffers(m_chunksize); setBuffers(m_chunksize);
@ -161,12 +171,6 @@ void FileSourceThread::run()
m_running = false; m_running = false;
} }
void FileSourceThread::connectTimer(const QTimer& timer)
{
qDebug() << "FileSourceThread::connectTimer";
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
}
void FileSourceThread::tick() void FileSourceThread::tick()
{ {
if (m_running) if (m_running)
@ -187,11 +191,15 @@ void FileSourceThread::tick()
if (m_ifstream->eof()) if (m_ifstream->eof())
{ {
writeToSampleFifo(m_fileBuf, (qint32) m_ifstream->gcount()); writeToSampleFifo(m_fileBuf, (qint32) m_ifstream->gcount());
MsgReportEOF *message = MsgReportEOF::create();
m_fileInputMessageQueue->push(message);
//m_sampleFifo->write(m_buf, m_ifstream->gcount()); //m_sampleFifo->write(m_buf, m_ifstream->gcount());
// TODO: handle loop playback situation // TODO: handle loop playback situation
m_ifstream->clear();
m_ifstream->seekg(sizeof(FileRecord::Header), std::ios::beg); // m_ifstream->clear();
m_samplesCount = 0; // m_ifstream->seekg(sizeof(FileRecord::Header), std::ios::beg);
// m_samplesCount = 0;
//stopWork(); //stopWork();
//m_ifstream->close(); //m_ifstream->close();
} }

View File

@ -27,16 +27,39 @@
#include <cstdlib> #include <cstdlib>
#include "dsp/inthalfbandfilter.h" #include "dsp/inthalfbandfilter.h"
#include "util/message.h"
#define FILESOURCE_THROTTLE_MS 50 #define FILESOURCE_THROTTLE_MS 50
class SampleSinkFifo; class SampleSinkFifo;
class MessageQueue;
class FileSourceThread : public QThread { class FileSourceThread : public QThread {
Q_OBJECT Q_OBJECT
public: public:
FileSourceThread(std::ifstream *samplesStream, SampleSinkFifo* sampleFifo, QObject* parent = NULL); class MsgReportEOF : public Message {
MESSAGE_CLASS_DECLARATION
public:
static MsgReportEOF* create()
{
return new MsgReportEOF();
}
private:
MsgReportEOF() :
Message()
{ }
};
FileSourceThread(std::ifstream *samplesStream,
SampleSinkFifo* sampleFifo,
const QTimer& timer,
MessageQueue *fileInputMessageQueue,
QObject* parent = NULL);
~FileSourceThread(); ~FileSourceThread();
void startWork(); void startWork();
@ -44,14 +67,9 @@ public:
void setSampleRateAndSize(int samplerate, quint32 samplesize); void setSampleRateAndSize(int samplerate, quint32 samplesize);
void setBuffers(std::size_t chunksize); void setBuffers(std::size_t chunksize);
bool isRunning() const { return m_running; } bool isRunning() const { return m_running; }
quint64 getSamplesCount() const { quint64 getSamplesCount() const { return m_samplesCount; }
qDebug("FileSourceThread::getSamplesCount: m_samplesCount: %llu", m_samplesCount);
return m_samplesCount;
}
void setSamplesCount(quint64 samplesCount) { m_samplesCount = samplesCount; } void setSamplesCount(quint64 samplesCount) { m_samplesCount = samplesCount; }
void connectTimer(const QTimer& timer);
private: private:
QMutex m_startWaitMutex; QMutex m_startWaitMutex;
QWaitCondition m_startWaiter; QWaitCondition m_startWaiter;
@ -64,6 +82,8 @@ private:
qint64 m_chunksize; qint64 m_chunksize;
SampleSinkFifo* m_sampleFifo; SampleSinkFifo* m_sampleFifo;
quint64 m_samplesCount; quint64 m_samplesCount;
const QTimer& m_timer;
MessageQueue *m_fileInputMessageQueue;
int m_samplerate; //!< File I/Q stream original sample rate int m_samplerate; //!< File I/Q stream original sample rate
quint64 m_samplesize; //!< File effective sample size in bits (I or Q). Ex: 16, 24. quint64 m_samplesize; //!< File effective sample size in bits (I or Q). Ex: 16, 24.

View File

@ -454,7 +454,7 @@ void GLSpectrumGUI::on_clearSpectrum_clicked(bool checked __attribute__((unused)
int GLSpectrumGUI::getAveragingIndex(int averagingValue) const int GLSpectrumGUI::getAveragingIndex(int averagingValue) const
{ {
if (averagingValue <= 0) { if (averagingValue <= 1) {
return 0; return 0;
} }
@ -487,7 +487,7 @@ int GLSpectrumGUI::getAveragingIndex(int averagingValue) const
int GLSpectrumGUI::getAveragingValue(int averagingIndex) const int GLSpectrumGUI::getAveragingValue(int averagingIndex) const
{ {
if (averagingIndex <= 0) { if (averagingIndex <= 0) {
return 0; return 1;
} }
int v = averagingIndex - 1; int v = averagingIndex - 1;
@ -508,7 +508,7 @@ int GLSpectrumGUI::getAveragingValue(int averagingIndex) const
void GLSpectrumGUI::setAveragingCombo() void GLSpectrumGUI::setAveragingCombo()
{ {
ui->averaging->clear(); ui->averaging->clear();
ui->averaging->addItem(QString("0")); ui->averaging->addItem(QString("1"));
for (int i = 0; i <= m_averagingMaxScale; i++) for (int i = 0; i <= m_averagingMaxScale; i++)
{ {
@ -530,8 +530,10 @@ void GLSpectrumGUI::setNumberStr(int n, QString& s)
{ {
if (n < 1000) { if (n < 1000) {
s = tr("%1").arg(n); s = tr("%1").arg(n);
} else if (n < 1000000) { } else if (n < 100000) {
s = tr("%1k").arg(n/1000); s = tr("%1k").arg(n/1000);
} else if (n < 1000000) {
s = tr("%1e5").arg(n/100000);
} else if (n < 1000000000) { } else if (n < 1000000000) {
s = tr("%1M").arg(n/1000000); s = tr("%1M").arg(n/1000000);
} else { } else {