fixed linux bugs

This commit is contained in:
AlexandreRouma 2020-10-24 14:51:55 +02:00
parent 0d45217dfd
commit edbc0c149d
9 changed files with 165 additions and 75 deletions

View File

@ -75,3 +75,36 @@ void ConfigManager::autoSaveWorker(ConfigManager* _this) {
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 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;
// }

View File

@ -8,6 +8,11 @@ using nlohmann::json;
#define DEV_BUILD #define DEV_BUILD
#define SDRPP_RESOURCE_DIR "/usr/local/"
#ifndef ROOT_DIR #ifndef ROOT_DIR
#ifdef DEV_BUILD #ifdef DEV_BUILD
#define ROOT_DIR "../root_dev" #define ROOT_DIR "../root_dev"
@ -29,11 +34,20 @@ public:
void aquire(); void aquire();
void release(bool changed = false); 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; json conf;
private: private:
static void autoSaveWorker(ConfigManager* _this); static void autoSaveWorker(ConfigManager* _this);
//static std::string resDir;
//static std::string configDir;
std::string path = ""; std::string path = "";
bool changed = false; bool changed = false;
bool autoSaveEnabled = false; bool autoSaveEnabled = false;

View File

@ -62,46 +62,11 @@ duk_ret_t test_func(duk_context *ctx) {
int sdrpp_main() { int sdrpp_main() {
#ifdef _WIN32 #ifdef _WIN32
//FreeConsole(); //FreeConsole();
// ConfigManager::setResourceDir("./res");
// ConfigManager::setConfigDir(".");
#endif #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); spdlog::info("SDR++ v" VERSION_STR);
// Load config // Load config

View File

@ -176,4 +176,76 @@ namespace dsp {
} }
}; };
template <class T>
class Reshaper {
public:
Reshaper() {
}
void init(int outBlockSize, dsp::stream<T>* 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<T>* 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<T> 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<T>* in;
};
}; };

View File

@ -3,6 +3,8 @@
#include <dsp/stream.h> #include <dsp/stream.h>
#include <dsp/types.h> #include <dsp/types.h>
#include <vector> #include <vector>
#include <spdlog/spdlog.h>
namespace dsp { namespace dsp {
class HandlerSink { class HandlerSink {
@ -61,18 +63,19 @@ namespace dsp {
bool running = false; bool running = false;
}; };
template <class T>
class NullSink { class NullSink {
public: public:
NullSink() { NullSink() {
} }
NullSink(stream<complex_t>* input, int bufferSize) { NullSink(stream<T>* input, int bufferSize) {
_in = input; _in = input;
_bufferSize = bufferSize; _bufferSize = bufferSize;
} }
void init(stream<complex_t>* input, int bufferSize) { void init(stream<T>* input, int bufferSize) {
_in = input; _in = input;
_bufferSize = bufferSize; _bufferSize = bufferSize;
} }
@ -85,13 +88,14 @@ namespace dsp {
private: private:
static void _worker(NullSink* _this) { static void _worker(NullSink* _this) {
complex_t* buf = new complex_t[_this->_bufferSize]; T* buf = new T[_this->_bufferSize];
while (true) { while (true) {
//spdlog::info("NS: Reading...");
_this->_in->read(buf, _this->_bufferSize); _this->_in->read(buf, _this->_bufferSize);
} }
} }
stream<complex_t>* _in; stream<T>* _in;
int _bufferSize; int _bufferSize;
std::thread _workerThread; std::thread _workerThread;
}; };
@ -113,6 +117,7 @@ namespace dsp {
} }
void start() { void start() {
spdlog::info("NS: Starting...");
_workerThread = std::thread(_worker, this); _workerThread = std::thread(_worker, this);
} }
@ -120,8 +125,10 @@ namespace dsp {
private: private:
static void _worker(FloatNullSink* _this) { static void _worker(FloatNullSink* _this) {
spdlog::info("NS: Started!");
float* buf = new float[_this->_bufferSize]; float* buf = new float[_this->_bufferSize];
while (true) { while (true) {
spdlog::info("NS: Reading...");
_this->_in->read(buf, _this->_bufferSize); _this->_in->read(buf, _this->_bufferSize);
} }
} }

View File

@ -66,7 +66,6 @@ void fftHandler(dsp::complex_t* samples) {
_data.clear(); _data.clear();
} }
dsp::NullSink sink;
watcher<uint64_t> freq((uint64_t)90500000); watcher<uint64_t> freq((uint64_t)90500000);
watcher<double> vfoFreq(92000000.0); watcher<double> vfoFreq(92000000.0);
float dummyVolume = 1.0; float dummyVolume = 1.0;

View File

@ -11,7 +11,7 @@ namespace audio {
astr->audio->init(1); astr->audio->init(1);
astr->deviceId = astr->audio->getDeviceId(); astr->deviceId = astr->audio->getDeviceId();
double sampleRate = astr->audio->devices[astr->deviceId].sampleRates[0]; 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<float>(blockSize * 2); astr->monoAudioStream = new dsp::stream<float>(blockSize * 2);
astr->audio->setBlockSize(blockSize); astr->audio->setBlockSize(blockSize);
astr->audio->setStreamType(io::AudioSink::MONO); astr->audio->setStreamType(io::AudioSink::MONO);
@ -38,7 +38,7 @@ namespace audio {
astr->audio = new io::AudioSink; astr->audio = new io::AudioSink;
astr->audio->init(1); astr->audio->init(1);
double sampleRate = astr->audio->devices[astr->audio->getDeviceId()].sampleRates[0]; 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<dsp::StereoFloat_t>(blockSize * 2); astr->stereoAudioStream = new dsp::stream<dsp::StereoFloat_t>(blockSize * 2);
astr->audio->setBlockSize(blockSize); astr->audio->setBlockSize(blockSize);
astr->audio->setStreamType(io::AudioSink::STEREO); astr->audio->setStreamType(io::AudioSink::STEREO);

View File

@ -1,9 +1,9 @@
{ {
"audio": { "audio": {
"Radio": { "Radio": {
"device": "Speakers (Realtek High Definiti", "device": "default",
"sampleRate": 48000.0, "sampleRate": 48000.0,
"volume": 0.60546875 "volume": 0.5148147940635681
}, },
"Radio 1": { "Radio 1": {
"device": "Speakers (Realtek High Definition Audio)", "device": "Speakers (Realtek High Definition Audio)",
@ -19,7 +19,7 @@
"bandPlan": "General", "bandPlan": "General",
"bandPlanEnabled": true, "bandPlanEnabled": true,
"fftHeight": 298, "fftHeight": 298,
"frequency": 100100000, "frequency": 99000000,
"max": 0.0, "max": 0.0,
"maximized": true, "maximized": true,
"menuOrder": [ "menuOrder": [

View File

@ -1,5 +1,5 @@
{ {
"device": "Generic RTL2832U OEM :: 00000001", "device": "HackRF One #0 901868dc282c8f8b",
"devices": { "devices": {
"AirSpy HF+ [c852435de0224af7]": { "AirSpy HF+ [c852435de0224af7]": {
"gains": { "gains": {
@ -16,7 +16,7 @@
}, },
"HackRF One #0 901868dc282c8f8b": { "HackRF One #0 901868dc282c8f8b": {
"gains": { "gains": {
"AMP": 0.0, "AMP": 13.86299991607666,
"LNA": 24.711999893188477, "LNA": 24.711999893188477,
"VGA": 14.282999992370605 "VGA": 14.282999992370605
}, },