diff --git a/core/src/config.cpp b/core/src/config.cpp index 896fd78f..6c7c2b36 100644 --- a/core/src/config.cpp +++ b/core/src/config.cpp @@ -75,3 +75,36 @@ void ConfigManager::autoSaveWorker(ConfigManager* _this) { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } } + +// void ConfigManager::setResourceDir(std::string path) { +// if (!std::filesystem::exists(path)) { +// spdlog::error("Resource directory '{0}' does not exist", path); +// return; +// } +// if (!std::filesystem::is_regular_file(path)) { +// spdlog::error("Resource directory '{0}' is not a directory", path); +// return; +// } +// resDir = path; +// } + +// std::string ConfigManager::getResourceDir() { +// return resDir; +// } + +// void ConfigManager::setConfigDir(std::string path) { +// if (!std::filesystem::exists(path)) { +// spdlog::error("Resource directory '{0}' does not exist", path); +// return; +// } +// if (!std::filesystem::is_regular_file(path)) { +// spdlog::error("Resource directory '{0}' is not a directory", path); +// return; +// } +// resDir = path; +// } + +// std::string ConfigManager::getConfigDir() { +// return configDir; +// } + diff --git a/core/src/config.h b/core/src/config.h index e5cb96fe..337ea484 100644 --- a/core/src/config.h +++ b/core/src/config.h @@ -8,6 +8,11 @@ using nlohmann::json; #define DEV_BUILD + +#define SDRPP_RESOURCE_DIR "/usr/local/" + + + #ifndef ROOT_DIR #ifdef DEV_BUILD #define ROOT_DIR "../root_dev" @@ -29,11 +34,20 @@ public: void aquire(); void release(bool changed = false); + // static void setResourceDir(std::string path); + // static std::string getResourceDir(); + + // static void setConfigDir(std::string path); + // static std::string getConfigDir(); + json conf; private: static void autoSaveWorker(ConfigManager* _this); + //static std::string resDir; + //static std::string configDir; + std::string path = ""; bool changed = false; bool autoSaveEnabled = false; diff --git a/core/src/core.cpp b/core/src/core.cpp index 0e472955..6b3c4073 100644 --- a/core/src/core.cpp +++ b/core/src/core.cpp @@ -62,46 +62,11 @@ duk_ret_t test_func(duk_context *ctx) { int sdrpp_main() { #ifdef _WIN32 //FreeConsole(); + // ConfigManager::setResourceDir("./res"); + // ConfigManager::setConfigDir("."); #endif - // TESTING - - - // duk_context* ctx = duk_create_heap_default(); - // duk_console_init(ctx, DUK_CONSOLE_PROXY_WRAPPER); - - // std::ifstream file("test.js", std::ios::in); - // std::stringstream ss; - // ss << file.rdbuf(); - // std::string code = ss.str(); - - // duk_idx_t baseObj = duk_push_object(ctx); - - // duk_push_int(ctx, 42); - // duk_put_prop_string(ctx, baseObj, "my_property"); - - // duk_push_c_function(ctx, test_func, 0); - // duk_put_prop_string(ctx, baseObj, "my_func"); - - // duk_put_global_string(ctx, "my_object"); - // duk_push_object(ctx); - - - - // if (duk_peval_string(ctx, code.c_str()) != 0) { - // printf("Error: %s\n", duk_safe_to_string(ctx, -1)); - // return -1; - // } - // duk_pop(ctx); - - core::scriptManager.createScript("TestScript 1", "test.js"); - //core::scriptManager.createScript("TestScript 2", "test.js"); - //core::scriptManager.createScript("TestScript 3", "test.js"); - //core::scriptManager.createScript("TestScript 4", "test.js"); - - // TESTING - spdlog::info("SDR++ v" VERSION_STR); // Load config diff --git a/core/src/dsp/block.h b/core/src/dsp/block.h index e4fdfa53..4a301f71 100644 --- a/core/src/dsp/block.h +++ b/core/src/dsp/block.h @@ -176,4 +176,76 @@ namespace dsp { } }; + + + + + + template + class Reshaper { + public: + Reshaper() { + + } + + void init(int outBlockSize, dsp::stream* input) { + outputBlockSize = outBlockSize; + in = input; + out.init(outputBlockSize * 2); + } + + void setOutputBlockSize(int blockSize) { + if (running) { + return; + } + outputBlockSize = blockSize; + out.setMaxLatency(outputBlockSize * 2); + } + + void setInput(dsp::stream* input) { + if (running) { + return; + } + in = input; + } + + void start() { + if (running) { + return; + } + workerThread = std::thread(_worker, this); + running = true; + } + + void stop() { + if (!running) { + return; + } + in->stopReader(); + out.stopWriter(); + workerThread.join(); + in->clearReadStop(); + out.clearWriteStop(); + running = false; + } + + dsp::stream out; + + private: + static void _worker(Reshaper* _this) { + T* buf = new T[_this->outputBlockSize]; + while (true) { + if (_this->in->read(buf, _this->outputBlockSize) < 0) { break; } + if (_this->out.write(buf, _this->outputBlockSize) < 0) { break; } + } + delete[] buf; + } + + int outputBlockSize; + bool running = false; + std::thread workerThread; + + dsp::stream* in; + + }; }; \ No newline at end of file diff --git a/core/src/dsp/sink.h b/core/src/dsp/sink.h index 6661d63e..55d8cd40 100644 --- a/core/src/dsp/sink.h +++ b/core/src/dsp/sink.h @@ -3,6 +3,8 @@ #include #include #include +#include + namespace dsp { class HandlerSink { @@ -61,18 +63,19 @@ namespace dsp { bool running = false; }; + template class NullSink { public: NullSink() { } - NullSink(stream* input, int bufferSize) { + NullSink(stream* input, int bufferSize) { _in = input; _bufferSize = bufferSize; } - void init(stream* input, int bufferSize) { + void init(stream* input, int bufferSize) { _in = input; _bufferSize = bufferSize; } @@ -85,13 +88,14 @@ namespace dsp { private: static void _worker(NullSink* _this) { - complex_t* buf = new complex_t[_this->_bufferSize]; + T* buf = new T[_this->_bufferSize]; while (true) { + //spdlog::info("NS: Reading..."); _this->_in->read(buf, _this->_bufferSize); } } - stream* _in; + stream* _in; int _bufferSize; std::thread _workerThread; }; @@ -113,6 +117,7 @@ namespace dsp { } void start() { + spdlog::info("NS: Starting..."); _workerThread = std::thread(_worker, this); } @@ -120,8 +125,10 @@ namespace dsp { private: static void _worker(FloatNullSink* _this) { + spdlog::info("NS: Started!"); float* buf = new float[_this->_bufferSize]; while (true) { + spdlog::info("NS: Reading..."); _this->_in->read(buf, _this->_bufferSize); } } diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp index 6cf486ee..057519bd 100644 --- a/core/src/gui/main_window.cpp +++ b/core/src/gui/main_window.cpp @@ -66,7 +66,6 @@ void fftHandler(dsp::complex_t* samples) { _data.clear(); } -dsp::NullSink sink; watcher freq((uint64_t)90500000); watcher vfoFreq(92000000.0); float dummyVolume = 1.0; diff --git a/core/src/signal_path/audio.cpp b/core/src/signal_path/audio.cpp index 0528994d..d99fb7e5 100644 --- a/core/src/signal_path/audio.cpp +++ b/core/src/signal_path/audio.cpp @@ -11,7 +11,7 @@ namespace audio { astr->audio->init(1); astr->deviceId = astr->audio->getDeviceId(); double sampleRate = astr->audio->devices[astr->deviceId].sampleRates[0]; - int blockSize = sampleRate / 200; // default block size + int blockSize = sampleRate / 200.0; // default block size astr->monoAudioStream = new dsp::stream(blockSize * 2); astr->audio->setBlockSize(blockSize); astr->audio->setStreamType(io::AudioSink::MONO); @@ -38,7 +38,7 @@ namespace audio { astr->audio = new io::AudioSink; astr->audio->init(1); double sampleRate = astr->audio->devices[astr->audio->getDeviceId()].sampleRates[0]; - int blockSize = sampleRate / 200; // default block size + int blockSize = sampleRate / 200.0; // default block size astr->stereoAudioStream = new dsp::stream(blockSize * 2); astr->audio->setBlockSize(blockSize); astr->audio->setStreamType(io::AudioSink::STEREO); diff --git a/root_dev/config.json b/root_dev/config.json index 5256a56d..3723970d 100644 --- a/root_dev/config.json +++ b/root_dev/config.json @@ -1,9 +1,9 @@ { "audio": { "Radio": { - "device": "Speakers (Realtek High Definiti", + "device": "default", "sampleRate": 48000.0, - "volume": 0.60546875 + "volume": 0.5148147940635681 }, "Radio 1": { "device": "Speakers (Realtek High Definition Audio)", @@ -19,7 +19,7 @@ "bandPlan": "General", "bandPlanEnabled": true, "fftHeight": 298, - "frequency": 100100000, + "frequency": 99000000, "max": 0.0, "maximized": true, "menuOrder": [ diff --git a/root_dev/soapy_source_config.json b/root_dev/soapy_source_config.json index 47627fd8..757b6a37 100644 --- a/root_dev/soapy_source_config.json +++ b/root_dev/soapy_source_config.json @@ -1,29 +1,29 @@ -{ - "device": "Generic RTL2832U OEM :: 00000001", - "devices": { - "AirSpy HF+ [c852435de0224af7]": { - "gains": { - "LNA": 6.0, - "RF": 0.0 - }, - "sampleRate": 768000.0 - }, - "Generic RTL2832U OEM :: 00000001": { - "gains": { - "TUNER": 49.599998474121094 - }, - "sampleRate": 2560000.0 - }, - "HackRF One #0 901868dc282c8f8b": { - "gains": { - "AMP": 0.0, - "LNA": 24.711999893188477, - "VGA": 14.282999992370605 - }, - "sampleRate": 8000000.0 - }, - "PulseAudio": { - "sampleRate": 96000.0 - } - } +{ + "device": "HackRF One #0 901868dc282c8f8b", + "devices": { + "AirSpy HF+ [c852435de0224af7]": { + "gains": { + "LNA": 6.0, + "RF": 0.0 + }, + "sampleRate": 768000.0 + }, + "Generic RTL2832U OEM :: 00000001": { + "gains": { + "TUNER": 49.599998474121094 + }, + "sampleRate": 2560000.0 + }, + "HackRF One #0 901868dc282c8f8b": { + "gains": { + "AMP": 13.86299991607666, + "LNA": 24.711999893188477, + "VGA": 14.282999992370605 + }, + "sampleRate": 8000000.0 + }, + "PulseAudio": { + "sampleRate": 96000.0 + } + } } \ No newline at end of file