mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-02-02 21:04:45 +01:00
New module system
This commit is contained in:
parent
524f20bc2f
commit
1507e6ec31
@ -3,8 +3,9 @@ project(sdrpp_core)
|
|||||||
|
|
||||||
add_subdirectory("core")
|
add_subdirectory("core")
|
||||||
add_subdirectory("radio")
|
add_subdirectory("radio")
|
||||||
# Add back recorder when module new system is ready
|
add_subdirectory("recorder")
|
||||||
#add_subdirectory("recorder")
|
add_subdirectory("soapy")
|
||||||
|
add_subdirectory("file_source")
|
||||||
add_subdirectory("demo")
|
add_subdirectory("demo")
|
||||||
|
|
||||||
add_executable(sdrpp "src/main.cpp" "win32/resources.rc")
|
add_executable(sdrpp "src/main.cpp" "win32/resources.rc")
|
||||||
|
@ -72,7 +72,6 @@ void windowInit() {
|
|||||||
sigpath::signalPath.start();
|
sigpath::signalPath.start();
|
||||||
|
|
||||||
spdlog::info("Loading modules");
|
spdlog::info("Loading modules");
|
||||||
mod::initAPI(&gui::waterfall);
|
|
||||||
mod::loadFromList(ROOT_DIR "/module_list.json");
|
mod::loadFromList(ROOT_DIR "/module_list.json");
|
||||||
|
|
||||||
sourecmenu::init();
|
sourecmenu::init();
|
||||||
@ -231,7 +230,6 @@ void drawWindow() {
|
|||||||
gui::waterfall.selectedVFOChanged = false;
|
gui::waterfall.selectedVFOChanged = false;
|
||||||
gui::freqSelect.setFrequency(vfo->generalOffset + gui::waterfall.getCenterFrequency());
|
gui::freqSelect.setFrequency(vfo->generalOffset + gui::waterfall.getCenterFrequency());
|
||||||
gui::freqSelect.frequencyChanged = false;
|
gui::freqSelect.frequencyChanged = false;
|
||||||
mod::broadcastEvent(mod::EVENT_SELECTED_VFO_CHANGED);
|
|
||||||
audioStreamName = audio::getNameFromVFO(gui::waterfall.selectedVFO);
|
audioStreamName = audio::getNameFromVFO(gui::waterfall.selectedVFO);
|
||||||
if (audioStreamName != "") {
|
if (audioStreamName != "") {
|
||||||
volume = &audio::streams[audioStreamName]->volume;
|
volume = &audio::streams[audioStreamName]->volume;
|
||||||
@ -279,13 +277,6 @@ void drawWindow() {
|
|||||||
int width = vMax.x - vMin.x;
|
int width = vMax.x - vMin.x;
|
||||||
int height = vMax.y - vMin.y;
|
int height = vMax.y - vMin.y;
|
||||||
|
|
||||||
int modCount = mod::moduleNames.size();
|
|
||||||
mod::Module_t mod;
|
|
||||||
for (int i = 0; i < modCount; i++) {
|
|
||||||
mod = mod::modules[mod::moduleNames[i]];
|
|
||||||
mod._NEW_FRAME_(mod.ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
// To Bar
|
// To Bar
|
||||||
if (ImGui::ImageButton(icons::MENU, ImVec2(40, 40), ImVec2(0, 0), ImVec2(1, 1), 0)) {
|
if (ImGui::ImageButton(icons::MENU, ImVec2(40, 40), ImVec2(0, 0), ImVec2(1, 1), 0)) {
|
||||||
showMenu = !showMenu;
|
showMenu = !showMenu;
|
||||||
@ -384,14 +375,6 @@ void drawWindow() {
|
|||||||
|
|
||||||
gui::menu.draw();
|
gui::menu.draw();
|
||||||
|
|
||||||
for (int i = 0; i < modCount; i++) {
|
|
||||||
if (ImGui::CollapsingHeader(mod::moduleNames[i].c_str(), ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
||||||
mod = mod::modules[mod::moduleNames[i]];
|
|
||||||
mod._DRAW_MENU_(mod.ctx);
|
|
||||||
ImGui::Spacing();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ImGui::CollapsingHeader("Debug")) {
|
if(ImGui::CollapsingHeader("Debug")) {
|
||||||
ImGui::Text("Frame time: %.3f ms/frame", 1000.0f / ImGui::GetIO().Framerate);
|
ImGui::Text("Frame time: %.3f ms/frame", 1000.0f / ImGui::GetIO().Framerate);
|
||||||
ImGui::Text("Framerate: %.1f FPS", ImGui::GetIO().Framerate);
|
ImGui::Text("Framerate: %.1f FPS", ImGui::GetIO().Framerate);
|
||||||
|
@ -4,37 +4,10 @@
|
|||||||
#include <signal_path/audio.h>
|
#include <signal_path/audio.h>
|
||||||
|
|
||||||
namespace mod {
|
namespace mod {
|
||||||
API_t API;
|
|
||||||
std::map<std::string, Module_t> modules;
|
std::map<std::string, Module_t> modules;
|
||||||
std::vector<std::string> moduleNames;
|
std::vector<std::string> moduleNames;
|
||||||
ImGui::WaterFall* _wtf;
|
ImGui::WaterFall* _wtf;
|
||||||
|
|
||||||
std::string api_getSelectedVFOName() {
|
|
||||||
return _wtf->selectedVFO;
|
|
||||||
}
|
|
||||||
|
|
||||||
void initAPI(ImGui::WaterFall* wtf) {
|
|
||||||
_wtf = wtf;
|
|
||||||
|
|
||||||
// GUI
|
|
||||||
API.getSelectedVFOName = api_getSelectedVFOName;
|
|
||||||
API.bindVolumeVariable = bindVolumeVariable;
|
|
||||||
API.unbindVolumeVariable = unbindVolumeVariable;
|
|
||||||
|
|
||||||
// Audio
|
|
||||||
API.registerMonoStream = audio::registerMonoStream;
|
|
||||||
API.registerStereoStream = audio::registerStereoStream;
|
|
||||||
API.startStream = audio::startStream;
|
|
||||||
API.stopStream = audio::stopStream;
|
|
||||||
API.removeStream = audio::removeStream;
|
|
||||||
API.bindToStreamMono = audio::bindToStreamMono;
|
|
||||||
API.bindToStreamStereo = audio::bindToStreamStereo;
|
|
||||||
API.setBlockSize = audio::setBlockSize;
|
|
||||||
API.unbindFromStreamMono = audio::unbindFromStreamMono;
|
|
||||||
API.unbindFromStreamStereo = audio::unbindFromStreamStereo;
|
|
||||||
API.getStreamNameList = audio::getStreamNameList;
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadModule(std::string path, std::string name) {
|
void loadModule(std::string path, std::string name) {
|
||||||
if (!std::filesystem::exists(path)) {
|
if (!std::filesystem::exists(path)) {
|
||||||
spdlog::error("{0} does not exist", path);
|
spdlog::error("{0} does not exist", path);
|
||||||
@ -51,10 +24,10 @@ namespace mod {
|
|||||||
spdlog::error("Couldn't load {0}.", name);
|
spdlog::error("Couldn't load {0}.", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mod._INIT_ = (void*(*)(mod::API_t*,ImGuiContext*,std::string))GetProcAddress(mod.inst, "_INIT_");
|
|
||||||
mod._NEW_FRAME_ = (void(*)(void*))GetProcAddress(mod.inst, "_NEW_FRAME_");
|
mod._INIT_ = (void(*)())GetProcAddress(mod.inst, "_INIT_");
|
||||||
mod._DRAW_MENU_ = (void(*)(void*))GetProcAddress(mod.inst, "_DRAW_MENU_");
|
mod._CREATE_INSTANCE_ = (void*(*)(std::string))GetProcAddress(mod.inst, "_CREATE_INSTANCE_");
|
||||||
mod._HANDLE_EVENT_ = (void(*)(void*, int))GetProcAddress(mod.inst, "_HANDLE_EVENT_");
|
mod._DELETE_INSTANCE_ = (void(*)(void*))GetProcAddress(mod.inst, "_DELETE_INSTANCE_");
|
||||||
mod._STOP_ = (void(*)(void*))GetProcAddress(mod.inst, "_STOP_");
|
mod._STOP_ = (void(*)(void*))GetProcAddress(mod.inst, "_STOP_");
|
||||||
#else
|
#else
|
||||||
mod.inst = dlopen(path.c_str(), RTLD_LAZY);
|
mod.inst = dlopen(path.c_str(), RTLD_LAZY);
|
||||||
@ -62,49 +35,41 @@ namespace mod {
|
|||||||
spdlog::error("Couldn't load {0}.", name);
|
spdlog::error("Couldn't load {0}.", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mod._INIT_ = (void*(*)(mod::API_t*,ImGuiContext*,std::string))dlsym(mod.inst, "_INIT_");
|
mod._INIT_ = (void(*)())dlsym(mod.inst, "_INIT_");
|
||||||
mod._NEW_FRAME_ = (void(*)(void*))dlsym(mod.inst, "_NEW_FRAME_");
|
mod._CREATE_INSTANCE_ = (void*(*)(std::string))dlsym(mod.inst, "_CREATE_INSTANCE_");
|
||||||
mod._DRAW_MENU_ = (void(*)(void*))dlsym(mod.inst, "_DRAW_MENU_");
|
mod._DELETE_INSTANCE_ = (void(*)(void*))dlsym(mod.inst, "_DELETE_INSTANCE_");
|
||||||
mod._HANDLE_EVENT_ = (void(*)(void*, int))dlsym(mod.inst, "_HANDLE_EVENT_");
|
mod._STOP_ = (void(*)())dlsym(mod.inst, "_STOP_");
|
||||||
mod._STOP_ = (void(*)(void*))dlsym(mod.inst, "_STOP_");
|
|
||||||
#endif
|
#endif
|
||||||
if (mod._INIT_ == NULL) {
|
if (mod._INIT_ == NULL) {
|
||||||
spdlog::error("Couldn't load {0} because it's missing _INIT_.", name);
|
spdlog::error("Couldn't load {0} because it's missing _INIT_.", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mod._NEW_FRAME_ == NULL) {
|
if (mod._CREATE_INSTANCE_ == NULL) {
|
||||||
spdlog::error("Couldn't load {0} because it's missing _NEW_FRAME_.", name);
|
spdlog::error("Couldn't load {0} because it's missing _CREATE_INSTANCE_.", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mod._DRAW_MENU_ == NULL) {
|
if (mod._DELETE_INSTANCE_ == NULL) {
|
||||||
spdlog::error("Couldn't load {0} because it's missing _DRAW_MENU_.", name);
|
spdlog::error("Couldn't load {0} because it's missing _DELETE_INSTANCE_.", name);
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mod._HANDLE_EVENT_ == NULL) {
|
|
||||||
spdlog::error("Couldn't load {0} because it's missing _HANDLE_EVENT_.", name);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mod._STOP_ == NULL) {
|
if (mod._STOP_ == NULL) {
|
||||||
spdlog::error("Couldn't load {0} because it's missing _STOP_.", name);
|
spdlog::error("Couldn't load {0} because it's missing _STOP_.", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mod.ctx = mod._INIT_(&API, ImGui::GetCurrentContext(), name);
|
|
||||||
|
if (!isLoaded(mod.inst)) {
|
||||||
|
mod._INIT_();
|
||||||
|
}
|
||||||
|
|
||||||
|
mod.ctx = mod._CREATE_INSTANCE_(name);
|
||||||
if (mod.ctx == NULL) {
|
if (mod.ctx == NULL) {
|
||||||
spdlog::error("{0} Failed to initialize.", name);
|
spdlog::error("{0} Failed to initialize.", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
modules[name] = mod;
|
modules[name] = mod;
|
||||||
moduleNames.push_back(name);
|
moduleNames.push_back(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void broadcastEvent(int eventId) {
|
|
||||||
if (eventId < 0 || eventId >= _EVENT_COUNT) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (auto const& [name, mod] : modules) {
|
|
||||||
mod._HANDLE_EVENT_(mod.ctx, eventId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadFromList(std::string path) {
|
void loadFromList(std::string path) {
|
||||||
if (!std::filesystem::exists(path)) {
|
if (!std::filesystem::exists(path)) {
|
||||||
spdlog::error("Module list file does not exist");
|
spdlog::error("Module list file does not exist");
|
||||||
@ -125,5 +90,14 @@ namespace mod {
|
|||||||
loadModule(file, name);
|
loadModule(file, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isLoaded(void* handle) {
|
||||||
|
for (auto const& [name, module] : modules) {
|
||||||
|
if (module.inst == handle) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -37,23 +37,22 @@ namespace mod {
|
|||||||
void* inst;
|
void* inst;
|
||||||
#endif
|
#endif
|
||||||
void (*_INIT_)();
|
void (*_INIT_)();
|
||||||
void* (*_CREATE_INSTANCE)(std::string);
|
void* (*_CREATE_INSTANCE_)(std::string name);
|
||||||
void (*_DELETE_INSTANCE)();
|
void (*_DELETE_INSTANCE_)(void* instance);
|
||||||
void (*_STOP_)();
|
void (*_STOP_)();
|
||||||
void* ctx;
|
void* ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModuleInfo_t {
|
struct ModuleInfo_t {
|
||||||
char* name;
|
const char* name;
|
||||||
char* description;
|
const char* description;
|
||||||
char* author;
|
const char* author;
|
||||||
char* version;
|
const char* version;
|
||||||
};
|
};
|
||||||
|
|
||||||
void initAPI(ImGui::WaterFall* wtf);
|
|
||||||
void loadModule(std::string path, std::string name);
|
void loadModule(std::string path, std::string name);
|
||||||
void broadcastEvent(int eventId);
|
|
||||||
void loadFromList(std::string path);
|
void loadFromList(std::string path);
|
||||||
|
bool isLoaded(void* handle);
|
||||||
|
|
||||||
extern std::map<std::string, Module_t> modules;
|
extern std::map<std::string, Module_t> modules;
|
||||||
extern std::vector<std::string> moduleNames;
|
extern std::vector<std::string> moduleNames;
|
||||||
|
14
file_source/CMakeLists.txt
Normal file
14
file_source/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
project(file_source)
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
set(CMAKE_CXX_FLAGS "-O2 /std:c++17")
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_FLAGS "-O3 -std=c++17 -fpermissive")
|
||||||
|
endif (MSVC)
|
||||||
|
|
||||||
|
file(GLOB SRC "src/*.cpp")
|
||||||
|
|
||||||
|
add_library(file_source SHARED ${SRC})
|
||||||
|
target_link_libraries(file_source PRIVATE sdrpp_core)
|
||||||
|
set_target_properties(file_source PROPERTIES PREFIX "")
|
90
file_source/src/main.cpp
Normal file
90
file_source/src/main.cpp
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#include <imgui.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <module.h>
|
||||||
|
#include <gui/gui.h>
|
||||||
|
#include <signal_path/signal_path.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
|
stream.init(100);
|
||||||
|
|
||||||
|
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);
|
||||||
|
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;
|
||||||
|
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;
|
||||||
|
spdlog::info("FileSourceModule '{0}': Start!", _this->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stop(void* ctx) {
|
||||||
|
FileSourceModule* _this = (FileSourceModule*)ctx;
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
dsp::stream<dsp::complex_t> stream;
|
||||||
|
SourceManager::SourceHandler handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
@ -25,6 +25,7 @@ public:
|
|||||||
sigPath.init(name, 200000, 1000);
|
sigPath.init(name, 200000, 1000);
|
||||||
sigPath.start();
|
sigPath.start();
|
||||||
sigPath.setDemodulator(SigPath::DEMOD_FM, bandWidth);
|
sigPath.setDemodulator(SigPath::DEMOD_FM, bandWidth);
|
||||||
|
gui::menu.registerEntry(name, menuHandler, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
~RadioModule() {
|
~RadioModule() {
|
||||||
|
@ -7,40 +7,11 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <signal_path/audio.h>
|
#include <signal_path/audio.h>
|
||||||
|
#include <gui/gui.h>
|
||||||
|
|
||||||
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||||
|
|
||||||
struct RecorderContext_t {
|
// TODO: Fix this and finish module
|
||||||
std::string name;
|
|
||||||
dsp::stream<dsp::StereoFloat_t>* stream;
|
|
||||||
WavWriter* writer;
|
|
||||||
std::thread workerThread;
|
|
||||||
bool recording;
|
|
||||||
time_t startTime;
|
|
||||||
std::string lastNameList;
|
|
||||||
std::string selectedStreamName;
|
|
||||||
int selectedStreamId;
|
|
||||||
uint64_t samplesWritten;
|
|
||||||
float sampleRate;
|
|
||||||
};
|
|
||||||
|
|
||||||
void _writeWorker(RecorderContext_t* ctx) {
|
|
||||||
dsp::StereoFloat_t* floatBuf = new dsp::StereoFloat_t[1024];
|
|
||||||
int16_t* sampleBuf = new int16_t[2048];
|
|
||||||
while (true) {
|
|
||||||
if (ctx->stream->read(floatBuf, 1024) < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < 1024; i++) {
|
|
||||||
sampleBuf[(i * 2) + 0] = floatBuf[i].l * 0x7FFF;
|
|
||||||
sampleBuf[(i * 2) + 1] = floatBuf[i].r * 0x7FFF;
|
|
||||||
}
|
|
||||||
ctx->samplesWritten += 1024;
|
|
||||||
ctx->writer->writeSamples(sampleBuf, 2048 * sizeof(int16_t));
|
|
||||||
}
|
|
||||||
delete[] floatBuf;
|
|
||||||
delete[] sampleBuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string genFileName(std::string prefix) {
|
std::string genFileName(std::string prefix) {
|
||||||
time_t now = time(0);
|
time_t now = time(0);
|
||||||
@ -58,21 +29,24 @@ void sampleRateChanged(void* ctx, float sampleRate, int blockSize) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MOD_EXPORT void* _INIT_(mod::API_t* _API, ImGuiContext* imctx, std::string _name) {
|
class RecorderModule {
|
||||||
RecorderContext_t* ctx = new RecorderContext_t;
|
public:
|
||||||
ctx->recording = false;
|
RecorderModule(std::string name) {
|
||||||
ctx->selectedStreamName = "";
|
this->name = name;
|
||||||
ctx->selectedStreamId = 0;
|
recording = false;
|
||||||
ctx->lastNameList = "";
|
selectedStreamName = "";
|
||||||
ImGui::SetCurrentContext(imctx);
|
selectedStreamId = 0;
|
||||||
return ctx;
|
lastNameList = "";
|
||||||
}
|
gui::menu.registerEntry(name, menuHandler, this);
|
||||||
|
}
|
||||||
|
|
||||||
MOD_EXPORT void _NEW_FRAME_(RecorderContext_t* ctx) {
|
~RecorderModule() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MOD_EXPORT void _DRAW_MENU_(RecorderContext_t* ctx) {
|
private:
|
||||||
|
static void menuHandler(void* ctx) {
|
||||||
|
RecorderModule* _this = (RecorderModule*)ctx;
|
||||||
float menuColumnWidth = ImGui::GetContentRegionAvailWidth();
|
float menuColumnWidth = ImGui::GetContentRegionAvailWidth();
|
||||||
|
|
||||||
std::vector<std::string> streamNames = audio::getStreamNameList();
|
std::vector<std::string> streamNames = audio::getStreamNameList();
|
||||||
@ -87,24 +61,24 @@ MOD_EXPORT void _DRAW_MENU_(RecorderContext_t* ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->lastNameList != nameList) {
|
if (_this->lastNameList != nameList) {
|
||||||
ctx->lastNameList = nameList;
|
_this->lastNameList = nameList;
|
||||||
auto _nameIt = std::find(streamNames.begin(), streamNames.end(), ctx->selectedStreamName);
|
auto _nameIt = std::find(streamNames.begin(), streamNames.end(), _this->selectedStreamName);
|
||||||
if (_nameIt == streamNames.end()) {
|
if (_nameIt == streamNames.end()) {
|
||||||
// TODO: verify if there even is a stream
|
// TODO: verify if there even is a stream
|
||||||
ctx->selectedStreamId = 0;
|
_this->selectedStreamId = 0;
|
||||||
ctx->selectedStreamName = streamNames[ctx->selectedStreamId];
|
_this->selectedStreamName = streamNames[_this->selectedStreamId];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ctx->selectedStreamId = std::distance(streamNames.begin(), _nameIt);
|
_this->selectedStreamId = std::distance(streamNames.begin(), _nameIt);
|
||||||
ctx->selectedStreamName = streamNames[ctx->selectedStreamId];
|
_this->selectedStreamName = streamNames[_this->selectedStreamId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::PushItemWidth(menuColumnWidth);
|
ImGui::PushItemWidth(menuColumnWidth);
|
||||||
if (!ctx->recording) {
|
if (!_this->recording) {
|
||||||
if (ImGui::Combo(CONCAT("##_strea_select_", ctx->name), &ctx->selectedStreamId, nameList.c_str())) {
|
if (ImGui::Combo(CONCAT("##_strea_select_", _this->name), &_this->selectedStreamId, nameList.c_str())) {
|
||||||
ctx->selectedStreamName = streamNames[ctx->selectedStreamId];
|
_this->selectedStreamName = streamNames[_this->selectedStreamId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -112,48 +86,87 @@ MOD_EXPORT void _DRAW_MENU_(RecorderContext_t* ctx) {
|
|||||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.44f, 0.44f, 0.44f, 0.15f));
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.44f, 0.44f, 0.44f, 0.15f));
|
||||||
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.20f, 0.21f, 0.22f, 0.30f));
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.20f, 0.21f, 0.22f, 0.30f));
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.00f, 1.00f, 1.00f, 0.65f));
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.00f, 1.00f, 1.00f, 0.65f));
|
||||||
ImGui::Combo(CONCAT("##_strea_select_", ctx->name), &ctx->selectedStreamId, nameList.c_str());
|
ImGui::Combo(CONCAT("##_strea_select_", _this->name), &_this->selectedStreamId, nameList.c_str());
|
||||||
ImGui::PopItemFlag();
|
ImGui::PopItemFlag();
|
||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx->recording) {
|
if (!_this->recording) {
|
||||||
if (ImGui::Button("Record", ImVec2(menuColumnWidth, 0))) {
|
if (ImGui::Button("Record", ImVec2(menuColumnWidth, 0))) {
|
||||||
ctx->samplesWritten = 0;
|
_this->samplesWritten = 0;
|
||||||
ctx->sampleRate = 48000;
|
_this->sampleRate = 48000;
|
||||||
ctx->writer = new WavWriter("recordings/" + genFileName("audio_"), 16, 2, 48000);
|
_this->writer = new WavWriter("recordings/" + genFileName("audio_"), 16, 2, 48000);
|
||||||
ctx->stream = audio::bindToStreamStereo(ctx->selectedStreamName, streamRemovedHandler, sampleRateChanged, ctx);
|
_this->stream = audio::bindToStreamStereo(_this->selectedStreamName, streamRemovedHandler, sampleRateChanged, _this);
|
||||||
ctx->workerThread = std::thread(_writeWorker, ctx);
|
_this->workerThread = std::thread(_writeWorker, _this);
|
||||||
ctx->recording = true;
|
_this->recording = true;
|
||||||
ctx->startTime = time(0);
|
_this->startTime = time(0);
|
||||||
}
|
}
|
||||||
ImGui::TextColored(ImGui::GetStyleColorVec4(ImGuiCol_Text), "Idle --:--:--");
|
ImGui::TextColored(ImGui::GetStyleColorVec4(ImGuiCol_Text), "Idle --:--:--");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (ImGui::Button("Stop", ImVec2(menuColumnWidth, 0))) {
|
if (ImGui::Button("Stop", ImVec2(menuColumnWidth, 0))) {
|
||||||
ctx->stream->stopReader();
|
_this->stream->stopReader();
|
||||||
ctx->workerThread.join();
|
_this->workerThread.join();
|
||||||
ctx->stream->clearReadStop();
|
_this->stream->clearReadStop();
|
||||||
audio::unbindFromStreamStereo(ctx->selectedStreamName, ctx->stream);
|
audio::unbindFromStreamStereo(_this->selectedStreamName, _this->stream);
|
||||||
ctx->writer->close();
|
_this->writer->close();
|
||||||
delete ctx->writer;
|
delete _this->writer;
|
||||||
ctx->recording = false;
|
_this->recording = false;
|
||||||
}
|
}
|
||||||
uint64_t seconds = ctx->samplesWritten / (uint64_t)ctx->sampleRate;
|
uint64_t seconds = _this->samplesWritten / (uint64_t)_this->sampleRate;
|
||||||
time_t diff = seconds;
|
time_t diff = seconds;
|
||||||
tm *dtm = gmtime(&diff);
|
tm *dtm = gmtime(&diff);
|
||||||
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Recording %02d:%02d:%02d", dtm->tm_hour, dtm->tm_min, dtm->tm_sec);
|
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Recording %02d:%02d:%02d", dtm->tm_hour, dtm->tm_min, dtm->tm_sec);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _writeWorker(RecorderModule* _this) {
|
||||||
|
dsp::StereoFloat_t* floatBuf = new dsp::StereoFloat_t[1024];
|
||||||
|
int16_t* sampleBuf = new int16_t[2048];
|
||||||
|
while (true) {
|
||||||
|
if (_this->stream->read(floatBuf, 1024) < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 1024; i++) {
|
||||||
|
sampleBuf[(i * 2) + 0] = floatBuf[i].l * 0x7FFF;
|
||||||
|
sampleBuf[(i * 2) + 1] = floatBuf[i].r * 0x7FFF;
|
||||||
|
}
|
||||||
|
_this->samplesWritten += 1024;
|
||||||
|
_this->writer->writeSamples(sampleBuf, 2048 * sizeof(int16_t));
|
||||||
|
}
|
||||||
|
delete[] floatBuf;
|
||||||
|
delete[] sampleBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
dsp::stream<dsp::StereoFloat_t>* stream;
|
||||||
|
WavWriter* writer;
|
||||||
|
std::thread workerThread;
|
||||||
|
bool recording;
|
||||||
|
time_t startTime;
|
||||||
|
std::string lastNameList;
|
||||||
|
std::string selectedStreamName;
|
||||||
|
int selectedStreamId;
|
||||||
|
uint64_t samplesWritten;
|
||||||
|
float sampleRate;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RecorderContext_t {
|
||||||
|
std::string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
MOD_EXPORT void _INIT_() {
|
||||||
|
// Nothing here
|
||||||
}
|
}
|
||||||
|
|
||||||
MOD_EXPORT void _HANDLE_EVENT_(RecorderContext_t* ctx, int eventId) {
|
MOD_EXPORT void* _CREATE_INSTANCE_(std::string name) {
|
||||||
// INSTEAD OF EVENTS, REGISTER HANDLER WHEN CREATING VFO
|
RecorderModule* instance = new RecorderModule(name);
|
||||||
if (eventId == mod::EVENT_STREAM_PARAM_CHANGED) {
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
MOD_EXPORT void _DELETE_INSTANCE_() {
|
||||||
else if (eventId == mod::EVENT_SELECTED_VFO_CHANGED) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MOD_EXPORT void _STOP_(RecorderContext_t* ctx) {
|
MOD_EXPORT void _STOP_(RecorderContext_t* ctx) {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"bandPlan": "General",
|
"bandPlan": "General",
|
||||||
"bandPlanEnabled": true,
|
"bandPlanEnabled": true,
|
||||||
"fftHeight": 300,
|
"fftHeight": 300,
|
||||||
"frequency": 99000000,
|
"frequency": 96570096,
|
||||||
"max": 0.0,
|
"max": 0.0,
|
||||||
"maximized": false,
|
"maximized": false,
|
||||||
"menuWidth": 300,
|
"menuWidth": 300,
|
||||||
@ -46,7 +46,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"windowSize": {
|
"windowSize": {
|
||||||
"h": 784,
|
"h": 1053,
|
||||||
"w": 1460
|
"w": 959
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
"Radio 1": "./radio/Release/radio.dll",
|
"Radio": "./radio/radio.so",
|
||||||
"Recorder 1": "./recorder/Release/recorder.dll"
|
"Recorder": "./recorder/recorder.so",
|
||||||
|
"Soapy": "./soapy/soapy.so",
|
||||||
|
"FileSource": "./file_source/file_source.so"
|
||||||
}
|
}
|
14
soapy/CMakeLists.txt
Normal file
14
soapy/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
project(soapy)
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
set(CMAKE_CXX_FLAGS "-O2 /std:c++17")
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_FLAGS "-O3 -std=c++17 -fpermissive")
|
||||||
|
endif (MSVC)
|
||||||
|
|
||||||
|
file(GLOB SRC "src/*.cpp")
|
||||||
|
|
||||||
|
add_library(soapy SHARED ${SRC})
|
||||||
|
target_link_libraries(soapy PRIVATE sdrpp_core)
|
||||||
|
set_target_properties(soapy PROPERTIES PREFIX "")
|
92
soapy/src/main.cpp
Normal file
92
soapy/src/main.cpp
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#include <imgui.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <module.h>
|
||||||
|
#include <gui/gui.h>
|
||||||
|
#include <signal_path/signal_path.h>
|
||||||
|
|
||||||
|
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||||
|
|
||||||
|
MOD_INFO {
|
||||||
|
/* Name: */ "soapy",
|
||||||
|
/* Description: */ "SoapySDR input module for SDR++",
|
||||||
|
/* Author: */ "Ryzerth",
|
||||||
|
/* Version: */ "0.1.0"
|
||||||
|
};
|
||||||
|
|
||||||
|
class SoapyModule {
|
||||||
|
public:
|
||||||
|
SoapyModule(std::string name) {
|
||||||
|
this->name = name;
|
||||||
|
|
||||||
|
//TODO: Make module tune on source select change (in sdrpp_core)
|
||||||
|
|
||||||
|
stream.init(100);
|
||||||
|
|
||||||
|
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("SoapySDR", &handler);
|
||||||
|
spdlog::info("SoapyModule '{0}': Instance created!", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
~SoapyModule() {
|
||||||
|
spdlog::info("SoapyModule '{0}': Instance deleted!", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void menuSelected(void* ctx) {
|
||||||
|
SoapyModule* _this = (SoapyModule*)ctx;
|
||||||
|
spdlog::info("SoapyModule '{0}': Menu Select!", _this->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void menuDeselected(void* ctx) {
|
||||||
|
SoapyModule* _this = (SoapyModule*)ctx;
|
||||||
|
spdlog::info("SoapyModule '{0}': Menu Deselect!", _this->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void start(void* ctx) {
|
||||||
|
SoapyModule* _this = (SoapyModule*)ctx;
|
||||||
|
spdlog::info("SoapyModule '{0}': Start!", _this->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stop(void* ctx) {
|
||||||
|
SoapyModule* _this = (SoapyModule*)ctx;
|
||||||
|
spdlog::info("SoapyModule '{0}': Stop!", _this->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tune(double freq, void* ctx) {
|
||||||
|
SoapyModule* _this = (SoapyModule*)ctx;
|
||||||
|
spdlog::info("SoapyModule '{0}': Tune: {1}!", _this->name, freq);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void menuHandler(void* ctx) {
|
||||||
|
SoapyModule* _this = (SoapyModule*)ctx;
|
||||||
|
ImGui::Text("Hi from %s!", _this->name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
dsp::stream<dsp::complex_t> stream;
|
||||||
|
SourceManager::SourceHandler handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
MOD_EXPORT void _INIT_() {
|
||||||
|
// Do your one time init here
|
||||||
|
}
|
||||||
|
|
||||||
|
MOD_EXPORT void* _CREATE_INSTANCE_(std::string name) {
|
||||||
|
return new SoapyModule(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
MOD_EXPORT void _DELETE_INSTANCE_(void* instance) {
|
||||||
|
delete (SoapyModule*)instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
MOD_EXPORT void _STOP_() {
|
||||||
|
// Do your one shutdown here
|
||||||
|
}
|
14
source_demo/CMakeLists.txt
Normal file
14
source_demo/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
project(soapy)
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
set(CMAKE_CXX_FLAGS "-O2 /std:c++17")
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_FLAGS "-O3 -std=c++17 -fpermissive")
|
||||||
|
endif (MSVC)
|
||||||
|
|
||||||
|
file(GLOB SRC "src/*.cpp")
|
||||||
|
|
||||||
|
add_library(soapy SHARED ${SRC})
|
||||||
|
target_link_libraries(soapy PRIVATE sdrpp_core)
|
||||||
|
set_target_properties(soapy PROPERTIES PREFIX "")
|
87
source_demo/src/main.cpp
Normal file
87
source_demo/src/main.cpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#include <imgui.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <module.h>
|
||||||
|
#include <gui/gui.h>
|
||||||
|
#include <signal_path/signal_path.h>
|
||||||
|
|
||||||
|
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||||
|
|
||||||
|
MOD_INFO {
|
||||||
|
/* Name: */ "soapy",
|
||||||
|
/* Description: */ "SoapySDR input module for SDR++",
|
||||||
|
/* Author: */ "Ryzerth",
|
||||||
|
/* Version: */ "0.1.0"
|
||||||
|
};
|
||||||
|
|
||||||
|
class SoapyModule {
|
||||||
|
public:
|
||||||
|
SoapyModule(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;
|
||||||
|
sigpath::sourceManager.registerSource("SoapySDR", &handler);
|
||||||
|
spdlog::info("SoapyModule '{0}': Instance created!", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
~SoapyModule() {
|
||||||
|
spdlog::info("SoapyModule '{0}': Instance deleted!", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void menuSelected(void* ctx) {
|
||||||
|
SoapyModule* _this = (SoapyModule*)ctx;
|
||||||
|
spdlog::info("SoapyModule '{0}': Menu Select!", _this->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void menuDeselected(void* ctx) {
|
||||||
|
SoapyModule* _this = (SoapyModule*)ctx;
|
||||||
|
spdlog::info("SoapyModule '{0}': Menu Deselect!", _this->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void start(void* ctx) {
|
||||||
|
SoapyModule* _this = (SoapyModule*)ctx;
|
||||||
|
spdlog::info("SoapyModule '{0}': Start!", _this->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void stop(void* ctx) {
|
||||||
|
SoapyModule* _this = (SoapyModule*)ctx;
|
||||||
|
spdlog::info("SoapyModule '{0}': Stop!", _this->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tune(double freq, void* ctx) {
|
||||||
|
SoapyModule* _this = (SoapyModule*)ctx;
|
||||||
|
spdlog::info("SoapyModule '{0}': Tune: {1}!", _this->name, freq);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void menuHandler(void* ctx) {
|
||||||
|
SoapyModule* _this = (SoapyModule*)ctx;
|
||||||
|
ImGui::Text("Hi from %s!", _this->name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
dsp::stream<dsp::complex_t> stream;
|
||||||
|
SourceManager::SourceHandler handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
MOD_EXPORT void _INIT_() {
|
||||||
|
// Do your one time init here
|
||||||
|
}
|
||||||
|
|
||||||
|
MOD_EXPORT void* _CREATE_INSTANCE_(std::string name) {
|
||||||
|
return new SoapyModule(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
MOD_EXPORT void _DELETE_INSTANCE_(void* instance) {
|
||||||
|
delete (SoapyModule*)instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
MOD_EXPORT void _STOP_() {
|
||||||
|
// Do your one shutdown here
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user