2020-10-01 13:46:12 +02:00
|
|
|
#include <imgui.h>
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include <module.h>
|
|
|
|
#include <gui/gui.h>
|
|
|
|
#include <signal_path/signal_path.h>
|
2020-10-04 02:56:02 +02:00
|
|
|
#include <wavreader.h>
|
|
|
|
#include <core.h>
|
2020-10-01 13:46:12 +02:00
|
|
|
|
|
|
|
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
|
|
|
|
|
|
|
MOD_INFO {
|
|
|
|
/* Name: */ "fike_source",
|
|
|
|
/* Description: */ "File input module for SDR++",
|
|
|
|
/* Author: */ "Ryzerth",
|
|
|
|
/* Version: */ "0.1.0"
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileSourceModule {
|
|
|
|
public:
|
|
|
|
FileSourceModule(std::string name) {
|
|
|
|
this->name = name;
|
|
|
|
|
|
|
|
handler.ctx = this;
|
|
|
|
handler.selectHandler = menuSelected;
|
|
|
|
handler.deselectHandler = menuDeselected;
|
|
|
|
handler.menuHandler = menuHandler;
|
|
|
|
handler.startHandler = start;
|
|
|
|
handler.stopHandler = stop;
|
|
|
|
handler.tuneHandler = tune;
|
|
|
|
handler.stream = &stream;
|
|
|
|
sigpath::sourceManager.registerSource("File", &handler);
|
2020-10-04 02:56:02 +02:00
|
|
|
|
2020-10-20 00:32:17 +02:00
|
|
|
reader = new WavReader("D:/Downloads/20120416_glv_594_2.wav");
|
2020-10-04 02:56:02 +02:00
|
|
|
|
|
|
|
spdlog::info("Samplerate: {0}, Bit depth: {1}, Channel count: {2}", reader->getSampleRate(), reader->getBitDepth(), reader->getChannelCount());
|
|
|
|
|
2020-10-01 13:46:12 +02:00
|
|
|
spdlog::info("FileSourceModule '{0}': Instance created!", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
~FileSourceModule() {
|
|
|
|
spdlog::info("FileSourceModule '{0}': Instance deleted!", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void menuSelected(void* ctx) {
|
|
|
|
FileSourceModule* _this = (FileSourceModule*)ctx;
|
2020-10-04 02:56:02 +02:00
|
|
|
core::setInputSampleRate(_this->reader->getSampleRate());
|
2020-10-01 13:46:12 +02:00
|
|
|
spdlog::info("FileSourceModule '{0}': Menu Select!", _this->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menuDeselected(void* ctx) {
|
|
|
|
FileSourceModule* _this = (FileSourceModule*)ctx;
|
|
|
|
spdlog::info("FileSourceModule '{0}': Menu Deselect!", _this->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void start(void* ctx) {
|
|
|
|
FileSourceModule* _this = (FileSourceModule*)ctx;
|
2020-10-04 02:56:02 +02:00
|
|
|
_this->workerThread = std::thread(worker, _this);
|
2020-10-01 13:46:12 +02:00
|
|
|
spdlog::info("FileSourceModule '{0}': Start!", _this->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stop(void* ctx) {
|
|
|
|
FileSourceModule* _this = (FileSourceModule*)ctx;
|
2020-10-04 02:56:02 +02:00
|
|
|
_this->stream.stopWriter();
|
|
|
|
_this->workerThread.join();
|
|
|
|
_this->stream.clearWriteStop();
|
2020-10-01 13:46:12 +02:00
|
|
|
spdlog::info("FileSourceModule '{0}': Stop!", _this->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tune(double freq, void* ctx) {
|
|
|
|
FileSourceModule* _this = (FileSourceModule*)ctx;
|
|
|
|
spdlog::info("FileSourceModule '{0}': Tune: {1}!", _this->name, freq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menuHandler(void* ctx) {
|
|
|
|
FileSourceModule* _this = (FileSourceModule*)ctx;
|
|
|
|
ImGui::Text("Hi from %s!", _this->name.c_str());
|
|
|
|
}
|
|
|
|
|
2020-10-04 02:56:02 +02:00
|
|
|
static void worker(void* ctx) {
|
|
|
|
FileSourceModule* _this = (FileSourceModule*)ctx;
|
|
|
|
double sampleRate = _this->reader->getSampleRate();
|
|
|
|
int blockSize = sampleRate / 200.0;
|
|
|
|
int16_t* inBuf = new int16_t[blockSize * 2];
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
_this->reader->readSamples(inBuf, blockSize * 2 * sizeof(int16_t));
|
2020-11-02 03:57:44 +01:00
|
|
|
if (_this->stream.aquire() < 0) { break; };
|
2020-10-04 02:56:02 +02:00
|
|
|
for (int i = 0; i < blockSize; i++) {
|
2020-11-02 03:57:44 +01:00
|
|
|
_this->stream.data[i].q = (float)inBuf[i * 2] / (float)0x7FFF;
|
|
|
|
_this->stream.data[i].i = (float)inBuf[(i * 2) + 1] / (float)0x7FFF;
|
2020-10-04 02:56:02 +02:00
|
|
|
}
|
2020-11-02 03:57:44 +01:00
|
|
|
_this->stream.write(blockSize);
|
2020-10-04 02:56:02 +02:00
|
|
|
//std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] inBuf;
|
|
|
|
}
|
|
|
|
|
2020-10-01 13:46:12 +02:00
|
|
|
std::string name;
|
|
|
|
dsp::stream<dsp::complex_t> stream;
|
|
|
|
SourceManager::SourceHandler handler;
|
2020-10-04 02:56:02 +02:00
|
|
|
WavReader* reader;
|
|
|
|
std::thread workerThread;
|
2020-10-01 13:46:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
MOD_EXPORT void _INIT_() {
|
|
|
|
// Do your one time init here
|
|
|
|
}
|
|
|
|
|
|
|
|
MOD_EXPORT void* _CREATE_INSTANCE_(std::string name) {
|
|
|
|
return new FileSourceModule(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOD_EXPORT void _DELETE_INSTANCE_(void* instance) {
|
|
|
|
delete (FileSourceModule*)instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOD_EXPORT void _STOP_() {
|
|
|
|
// Do your one shutdown here
|
|
|
|
}
|