2015-07-28 17:54:17 -04:00
|
|
|
#ifndef INCLUDE_FILESINK_H
|
|
|
|
#define INCLUDE_FILESINK_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include "dsp/samplesink.h"
|
|
|
|
#include "util/export.h"
|
|
|
|
#include "util/message.h"
|
2015-08-13 02:51:33 -04:00
|
|
|
#include "util/messagequeue.h"
|
2015-07-28 17:54:17 -04:00
|
|
|
|
|
|
|
class SDRANGELOVE_API FileSink : public SampleSink {
|
|
|
|
public:
|
|
|
|
|
|
|
|
struct Header
|
|
|
|
{
|
|
|
|
int sampleRate;
|
|
|
|
quint64 centerFrequency;
|
|
|
|
std::time_t startTimeStamp;
|
|
|
|
};
|
|
|
|
|
|
|
|
FileSink();
|
2015-08-13 02:51:33 -04:00
|
|
|
virtual ~FileSink();
|
2015-07-28 17:54:17 -04:00
|
|
|
|
|
|
|
quint64 getByteCount() const { return m_byteCount; }
|
|
|
|
|
|
|
|
void configure(MessageQueue* msgQueue, const std::string& filename, int sampleRate, quint64 centerFrequency);
|
|
|
|
|
2015-08-13 02:51:33 -04:00
|
|
|
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);
|
2015-07-28 17:54:17 -04:00
|
|
|
void startRecording();
|
|
|
|
void stopRecording();
|
|
|
|
static void readHeader(std::ifstream& samplefile, Header& header);
|
|
|
|
|
2015-08-13 02:51:33 -04:00
|
|
|
MessageQueue *getMessageQueue() { return m_messageQueue; }
|
|
|
|
|
2015-07-28 17:54:17 -04:00
|
|
|
private:
|
|
|
|
class MsgConfigureFileSink : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
const std::string& getFileName() const { return m_fileName; }
|
|
|
|
|
2015-08-13 02:51:33 -04:00
|
|
|
static MsgConfigureFileSink* create(const std::string& fileName)
|
2015-07-28 17:54:17 -04:00
|
|
|
{
|
2015-08-13 02:51:33 -04:00
|
|
|
return new MsgConfigureFileSink(fileName);
|
2015-07-28 17:54:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string m_fileName;
|
|
|
|
|
2015-08-13 02:51:33 -04:00
|
|
|
MsgConfigureFileSink(const std::string& fileName) :
|
2015-07-28 17:54:17 -04:00
|
|
|
Message(),
|
2015-08-13 02:51:33 -04:00
|
|
|
m_fileName(fileName)
|
2015-07-28 17:54:17 -04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string m_fileName;
|
|
|
|
int m_sampleRate;
|
|
|
|
quint64 m_centerFrequency;
|
|
|
|
bool m_recordOn;
|
|
|
|
bool m_recordStart;
|
|
|
|
std::ofstream m_sampleFile;
|
|
|
|
quint64 m_byteCount;
|
2015-08-13 02:51:33 -04:00
|
|
|
MessageQueue m_messageQueue;
|
2015-07-28 17:54:17 -04:00
|
|
|
|
|
|
|
void handleConfigure(const std::string& fileName, int sampleRate, quint64 centerFrequency);
|
|
|
|
void writeHeader();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDE_FILESINK_H
|