1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-17 23:28:50 -05:00

Deep redesign: phase #1

This commit is contained in:
f4exb 2015-08-13 08:51:33 +02:00
parent 7433cdd91e
commit 1799cd816f
8 changed files with 33 additions and 50 deletions

View File

@ -9,8 +9,7 @@
#include "dsp/samplesink.h"
#include "util/export.h"
#include "util/message.h"
class MessageQueue;
#include "util/messagequeue.h"
class SDRANGELOVE_API FileSink : public SampleSink {
public:
@ -23,44 +22,41 @@ public:
};
FileSink();
~FileSink();
virtual ~FileSink();
quint64 getByteCount() const { return m_byteCount; }
void configure(MessageQueue* msgQueue, const std::string& filename, int sampleRate, quint64 centerFrequency);
void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly);
void start();
void stop();
virtual bool init(Message* cmd);
virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly);
virtual void start();
virtual void stop();
virtual bool handleMessage(Message* message);
void startRecording();
void stopRecording();
bool handleMessage(Message* message);
static void readHeader(std::ifstream& samplefile, Header& header);
MessageQueue *getMessageQueue() { return m_messageQueue; }
private:
class MsgConfigureFileSink : public Message {
MESSAGE_CLASS_DECLARATION
public:
const std::string& getFileName() const { return m_fileName; }
int getSampleRate() const { return m_sampleRate; }
quint64 getCenterFrequency() const { return m_centerFrequency; }
static MsgConfigureFileSink* create(const std::string& fileName, int sampleRate, quint64 centerFrequency)
static MsgConfigureFileSink* create(const std::string& fileName)
{
return new MsgConfigureFileSink(fileName, sampleRate, centerFrequency);
return new MsgConfigureFileSink(fileName);
}
private:
std::string m_fileName;
int m_sampleRate;
quint64 m_centerFrequency;
MsgConfigureFileSink(const std::string& fileName, int sampleRate, quint64 centerFrequency) :
MsgConfigureFileSink(const std::string& fileName) :
Message(),
m_fileName(fileName),
m_sampleRate(sampleRate),
m_centerFrequency(centerFrequency)
m_fileName(fileName)
{ }
};
@ -71,6 +67,7 @@ private:
bool m_recordStart;
std::ofstream m_sampleFile;
quint64 m_byteCount;
MessageQueue m_messageQueue;
void handleConfigure(const std::string& fileName, int sampleRate, quint64 centerFrequency);
void writeHeader();

View File

@ -12,11 +12,11 @@ public:
SampleSink();
virtual ~SampleSink();
virtual bool init(Message* cmd) = 0;
virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) = 0;
virtual void start() = 0;
virtual void stop() = 0;
virtual bool handleMessage(Message* cmd) = 0; //!< Handle message immediately or submit it to a queue
virtual bool executeMessage(Message* cmd); //!< Handle message immediately FIXME: shall we keep it or fix behaviour of ThreadedSampleSink?
};
#endif // INCLUDE_SAMPLESINK_H

View File

@ -40,6 +40,7 @@ public:
SampleSource(MessageQueue* guiMessageQueue);
virtual ~SampleSource();
virtual void init(Message* cmd) = 0;
virtual bool startInput(int device) = 0;
virtual void stopInput() = 0;

View File

@ -23,7 +23,6 @@ public:
void start();
void stop();
bool handleMessage(Message* cmd);
virtual bool executeMessage(Message* cmd);
protected:
QMutex m_mutex;

View File

@ -363,7 +363,7 @@ DSPEngine::State DSPEngine::gotoInit()
{
qDebug() << " - initializing " << (*it)->objectName().toStdString().c_str();
DSPSignalNotification* notif = DSPSignalNotification::create(m_sampleRate, m_centerFrequency);
(*it)->executeMessage(notif); // this one does not use queuing and thus waits for completion
(*it)->init(notif);
}
// pass sample rate to main window
@ -542,15 +542,6 @@ void DSPEngine::handleInputMessages()
else if (DSPAddSink::match(message))
{
SampleSink* sink = ((DSPAddSink*)message)->getSampleSink();
/*
if(m_state == StRunning) // FIXME: fix this mess once init phase is coded
{
DSPSignalNotification* signal = DSPSignalNotification::create(m_sampleRate, 0);
signal->submit(&m_outputMessageQueue, sink);
sink->start();
}*/
m_sampleSinks.push_back(sink);
message->completed();
}

View File

@ -29,6 +29,19 @@ void FileSink::configure(MessageQueue* msgQueue, const std::string& filename, in
cmd->submit(msgQueue, this);
}
bool FileSink::init(Message* cmd)
{
if (DSPSignalNotification::match(cmd))
{
DSPSignalNotification* notif = (DSPSignalNotification*) cmd;
m_sampleRate = notif->getSampleRate();
m_centerFrequency = notif->getFrequencyOffset();
qDebug() << "FileSink::init: DSPSignalNotification: m_inputSampleRate: " << m_sampleRate;
cmd->completed();
return true;
}
}
void FileSink::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly)
{
// if no recording is active, send the samples to /dev/null

View File

@ -57,26 +57,6 @@ bool ThreadedSampleSink::handleMessage(Message* cmd)
return true;
}
bool ThreadedSampleSink::executeMessage(Message* cmd)
{
qDebug() << "ThreadedSampleSink::executeMessage: "
<< m_sampleSink->objectName().toStdString().c_str()
<< ": " << cmd->getIdentifier();
if (m_sampleSink != NULL)
{
if (!m_sampleSink->handleMessage(cmd)) {
cmd->completed();
}
}
else
{
cmd->completed();
}
return true;
}
void ThreadedSampleSink::handleData()
{
bool positiveOnly = false;

View File

@ -335,7 +335,7 @@ void MainWindow::handleDSPMessages()
updateSampleRate();
message->completed();
qDebug() << "MainWindow::handleMessages: m_fileSink->configure";
m_fileSink->configure(m_dspEngine->getInputMessageQueue(), m_sampleFileName, m_sampleRate, m_centerFrequency);
m_fileSink->configure(m_fileSink->getMessageQueue(), m_sampleFileName, m_sampleRate, m_centerFrequency);
}
}
}
@ -486,6 +486,8 @@ void MainWindow::on_presetUpdate_clicked()
void MainWindow::on_presetLoad_clicked()
{
qDebug() << "MainWindow::on_presetLoad_clicked";
QTreeWidgetItem* item = ui->presetTree->currentItem();
if(item == 0) {
updatePresets();