diff --git a/plugins/samplesource/filesource/filesourcegui.cpp b/plugins/samplesource/filesource/filesourcegui.cpp index ca22e6b0d..f70c244ac 100644 --- a/plugins/samplesource/filesource/filesourcegui.cpp +++ b/plugins/samplesource/filesource/filesourcegui.cpp @@ -16,6 +16,9 @@ #include +#include +#include +#include #include "ui_filesourcegui.h" #include "plugin/pluginapi.h" #include "gui/colormapper.h" @@ -28,7 +31,12 @@ FileSourceGui::FileSourceGui(PluginAPI* pluginAPI, QWidget* parent) : ui(new Ui::FileSourceGui), m_pluginAPI(pluginAPI), m_settings(), - m_sampleSource(NULL) + m_sampleSource(NULL), + m_acquisition(false), + m_sampleRate(0), + m_centerFrequency(0), + m_startingTimeStamp(0), + m_samplesCount(0) { ui->setupUi(this); ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold)); @@ -109,17 +117,53 @@ bool FileSourceGui::deserialize(const QByteArray& data) bool FileSourceGui::handleMessage(Message* message) { - if(FileSourceInput::MsgReportFileSource::match(message)) { + if(FileSourceInput::MsgReportFileSource::match(message)) + { + m_acquisition = ((FileSourceInput::MsgReportFileSource*)message)->getAcquisition(); + m_sampleRate = ((FileSourceInput::MsgReportFileSource*)message)->getSampleRate(); + m_centerFrequency = ((FileSourceInput::MsgReportFileSource*)message)->getCenterFrequency(); + m_startingTimeStamp = ((FileSourceInput::MsgReportFileSource*)message)->getStartingTimeStamp(); displaySettings(); message->completed(); return true; - } else { + } + else + { return false; } } void FileSourceGui::displaySettings() { + ui->centerFrequency->setValue(m_centerFrequency/1000); + QString s = QString::number(m_sampleRate/1000.0, 'f', 0); + ui->sampleRateText->setText(tr("%1k").arg(s)); + ui->play->setEnabled(m_acquisition); + displayTime(); +} + +void FileSourceGui::displayTime() +{ + int t_sec = 0; + int t_msec = 0; + + if (m_sampleRate > 0){ + t_msec = ((m_samplesCount * 1000) / m_sampleRate) % 1000; + t_sec = m_samplesCount / m_sampleRate; + } + + QTime t(0, 0, 0, 0); + t.addSecs(t_sec); + t.addMSecs(t_msec); + QString s_time = t.toString("hh:mm:ss.zzz"); + ui->relTimeText->setText(s_time); + + quint64 startingTimeStampMsec = m_startingTimeStamp * 1000; + QDateTime dt = QDateTime::fromMSecsSinceEpoch(startingTimeStampMsec); + dt.addSecs(t_sec); + dt.addMSecs(t_msec); + QString s_date = dt.toString("yyyyMMdd hh.mm.ss.zzz"); + ui->absTimeText->setText(s_date); } void FileSourceGui::sendSettings() @@ -134,3 +178,8 @@ void FileSourceGui::updateHardware() message->submit(m_pluginAPI->getDSPEngineMessageQueue()); m_updateTimer.stop(); } + +void FileSourceGui::on_play_toggled(bool checked) +{ + +} diff --git a/plugins/samplesource/filesource/filesourcegui.h b/plugins/samplesource/filesource/filesourcegui.h index 630b67b68..a763bd246 100644 --- a/plugins/samplesource/filesource/filesourcegui.h +++ b/plugins/samplesource/filesource/filesourcegui.h @@ -56,8 +56,14 @@ private: QTimer m_updateTimer; std::vector m_gains; SampleSource* m_sampleSource; + bool m_acquisition; + int m_sampleRate; + quint64 m_centerFrequency; + std::time_t m_startingTimeStamp; + int m_samplesCount; void displaySettings(); + void displayTime(); void sendSettings(); void updateHardware(); diff --git a/plugins/samplesource/filesource/filesourcegui.ui b/plugins/samplesource/filesource/filesourcegui.ui index e3b1c512e..938e6147a 100644 --- a/plugins/samplesource/filesource/filesourcegui.ui +++ b/plugins/samplesource/filesource/filesourcegui.ui @@ -80,7 +80,7 @@ Qt::StrongFocus - Tuner center frequency in kHz + Record center frequency in kHz @@ -109,14 +109,14 @@ - + 8 - Rate + Record sample rate 0k @@ -153,6 +153,9 @@ 8 + + Record absolute time + 20150101 00:00:00.000 @@ -171,11 +174,14 @@ + + Play in a loop + - + :/playloop.png:/playloop.png @@ -191,12 +197,22 @@ + + Stopped / Play / Pause + - - :/play.png:/play.png + + :/pause.png + :/play.png + :/stop.png + :/stop.png + :/pause.png + :/play.png + :/pause.png + :/play.png:/pause.png @@ -242,6 +258,9 @@ 8 + + Record time from start + 00:00:00.000 @@ -264,6 +283,8 @@
gui/buttonswitch.h
- + + + diff --git a/plugins/samplesource/filesource/filesourceinput.cpp b/plugins/samplesource/filesource/filesourceinput.cpp index 0dd66cb78..b8229f03b 100644 --- a/plugins/samplesource/filesource/filesourceinput.cpp +++ b/plugins/samplesource/filesource/filesourceinput.cpp @@ -84,6 +84,10 @@ FileSourceInput::~FileSourceInput() void FileSourceInput::openFileStream() { + if (m_ifstream.is_open()) { + m_ifstream.close(); + } + m_ifstream.open(m_settings.m_fileName.toStdString().c_str(), std::ios::binary); FileSink::Header header; FileSink::readHeader(m_ifstream, header); @@ -95,6 +99,7 @@ void FileSourceInput::openFileStream() bool FileSourceInput::startInput(int device) { + std::cerr << "FileSourceInput::startInput" << std::endl; QMutexLocker mutexLocker(&m_mutex); openFileStream(); @@ -111,8 +116,7 @@ bool FileSourceInput::startInput(int device) mutexLocker.unlock(); applySettings(m_generalSettings, m_settings, true); - qDebug("bladerfInput: start"); - //MsgReportBladerf::create(m_gains)->submit(m_guiMessageQueue); Pass anything here + MsgReportFileSource::create(true, m_sampleRate, m_centerFrequency, m_startingTimeStamp)->submit(m_guiMessageQueue); // acquisition on return true; @@ -123,6 +127,7 @@ failed: void FileSourceInput::stopInput() { + std::cerr << "FileSourceInput::stopInput()" << std::endl; QMutexLocker mutexLocker(&m_mutex); if(m_fileSourceThread != NULL) { @@ -132,6 +137,8 @@ void FileSourceInput::stopInput() } m_deviceDescription.clear(); + + MsgReportFileSource::create(false, m_sampleRate, m_centerFrequency, m_startingTimeStamp)->submit(m_guiMessageQueue); // acquisition off } const QString& FileSourceInput::getDeviceDescription() const diff --git a/plugins/samplesource/filesource/filesourceinput.h b/plugins/samplesource/filesource/filesourceinput.h index 2f16f462a..ba4dc3e99 100644 --- a/plugins/samplesource/filesource/filesourceinput.h +++ b/plugins/samplesource/filesource/filesourceinput.h @@ -64,16 +64,29 @@ public: MESSAGE_CLASS_DECLARATION public: + bool getAcquisition() const { return m_acquisition; } + int getSampleRate() const { return m_sampleRate; } + quint64 getCenterFrequency() const { return m_centerFrequency; } + std::time_t getStartingTimeStamp() const { return m_startingTimeStamp; } - static MsgReportFileSource* create() + static MsgReportFileSource* create(bool acquisition, int sampleRate, quint64 centerFrequency, std::time_t startingTimeStamp) { - return new MsgReportFileSource(); + return new MsgReportFileSource(acquisition, sampleRate, centerFrequency, startingTimeStamp); } protected: + bool m_acquisition; + int m_sampleRate; + quint64 m_centerFrequency; + std::time_t m_startingTimeStamp; - MsgReportFileSource() : - Message() + + MsgReportFileSource(bool acquisition, int sampleRate, quint64 centerFrequency, std::time_t startingTimeStamp) : + Message(), + m_acquisition(acquisition), + m_sampleRate(sampleRate), + m_centerFrequency(centerFrequency), + m_startingTimeStamp(startingTimeStamp) { } }; diff --git a/plugins/samplesource/filesource/filesourcethread.cpp b/plugins/samplesource/filesource/filesourcethread.cpp index 4bd40df6c..e312ac635 100644 --- a/plugins/samplesource/filesource/filesourcethread.cpp +++ b/plugins/samplesource/filesource/filesourcethread.cpp @@ -16,6 +16,7 @@ #include #include +#include #include "dsp/samplefifo.h" #include "filesourcethread.h" @@ -32,6 +33,7 @@ FileSourceThread::FileSourceThread(std::ifstream *samplesStream, SampleFifo* sam m_sampleFifo(sampleFifo), m_samplerate(0) { + assert(m_ifstream != 0); } FileSourceThread::~FileSourceThread() @@ -47,12 +49,21 @@ FileSourceThread::~FileSourceThread() void FileSourceThread::startWork() { - std::cerr << "FileSourceThread::startWork" << std::endl; - m_startWaitMutex.lock(); - start(); - while(!m_running) - m_startWaiter.wait(&m_startWaitMutex, 100); - m_startWaitMutex.unlock(); + std::cerr << "FileSourceThread::startWork: "; + + if (m_ifstream->is_open()) + { + std::cerr << " file stream open, starting..." << std::endl; + m_startWaitMutex.lock(); + start(); + while(!m_running) + m_startWaiter.wait(&m_startWaitMutex, 100); + m_startWaitMutex.unlock(); + } + else + { + std::cerr << " file stream closed, not starting." << std::endl; + } } void FileSourceThread::stopWork() @@ -64,19 +75,33 @@ void FileSourceThread::stopWork() void FileSourceThread::setSamplerate(int samplerate) { + std::cerr << "FileSourceThread::setSamplerate:" + << " new:" << samplerate + << " old:" << m_samplerate; + if (samplerate != m_samplerate) { if (m_running) { stopWork(); } + m_samplerate = samplerate; m_bufsize = (m_samplerate / m_rateDivider)*4; if (m_buf == 0) { + std::cerr << " Allocate buffer"; m_buf = (quint8*) malloc(m_bufsize); } else { + std::cerr << " Re-allocate buffer"; m_buf = (quint8*) realloc((void*) m_buf, m_bufsize); } + + std::cerr << " size: " << m_bufsize + << " #samples: " << (m_bufsize/4) << std::endl; + } + else + { + std::cerr << std::endl; } m_samplerate = samplerate; @@ -90,7 +115,7 @@ void FileSourceThread::run() m_running = true; m_startWaiter.wakeAll(); - while(m_running) + while(m_running) // actual work is in the tick() function { sleep(1); } @@ -110,7 +135,18 @@ void FileSourceThread::tick() { // read samples directly feeding the SampleFifo (no callback) m_ifstream->read(reinterpret_cast(m_buf), m_chunksize); - m_sampleFifo->write(m_buf, m_chunksize); + + if (m_ifstream->eof()) + { + m_sampleFifo->write(m_buf, m_ifstream->gcount()); + // TODO: handle loop playback situation + stopWork(); + m_ifstream->close(); + } + else + { + m_sampleFifo->write(m_buf, m_chunksize); + } } } diff --git a/sdrbase/resources/pause.png b/sdrbase/resources/pause.png new file mode 100644 index 000000000..ba7d624bb Binary files /dev/null and b/sdrbase/resources/pause.png differ diff --git a/sdrbase/resources/res.qrc b/sdrbase/resources/res.qrc index 829f8d9a0..d81718cd2 100644 --- a/sdrbase/resources/res.qrc +++ b/sdrbase/resources/res.qrc @@ -27,5 +27,7 @@ clear.png playloop.png play.png + pause.png + stop.png diff --git a/sdrbase/resources/stop.png b/sdrbase/resources/stop.png new file mode 100644 index 000000000..b8a677a66 Binary files /dev/null and b/sdrbase/resources/stop.png differ