From 2a6c742a51bbc7c487c876f9aeaa29a4788ea88d Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Wed, 4 Aug 2021 00:14:55 +0200 Subject: [PATCH] Bugfix --- .gitignore | 1 + core/src/config.cpp | 13 ++++++++++--- core/src/dsp/clock_recovery.h | 4 ++-- core/src/dsp/deframing.h | 6 ++++-- core/src/dsp/demodulator.h | 5 +++++ core/src/gui/widgets/symbol_diagram.cpp | 16 ++++++++++++---- core/src/gui/widgets/symbol_diagram.h | 6 ++++-- core/src/gui/widgets/waterfall.cpp | 1 + 8 files changed, 39 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 09dbda94..baeaf4bc 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ build/ root_dev/ Folder.DotSettings.user CMakeSettings.json +poggers_decoder \ No newline at end of file diff --git a/core/src/config.cpp b/core/src/config.cpp index a638dbdc..bf2e3100 100644 --- a/core/src/config.cpp +++ b/core/src/config.cpp @@ -32,9 +32,16 @@ void ConfigManager::load(json def, bool lock) { return; } - std::ifstream file(path.c_str()); - file >> conf; - file.close(); + try { + std::ifstream file(path.c_str()); + file >> conf; + file.close(); + } + catch (std::exception e) { + spdlog::error("Config file '{0}' is corrupted, resetting it", path); + conf = def; + save(false); + } if (lock) { mtx.unlock(); } } diff --git a/core/src/dsp/clock_recovery.h b/core/src/dsp/clock_recovery.h index 5189ec7e..515bb0d7 100644 --- a/core/src/dsp/clock_recovery.h +++ b/core/src/dsp/clock_recovery.h @@ -53,7 +53,7 @@ namespace dsp { } _in->flush(); - if (!out.swap(outCount)) { return -1; } + if (outCount > 0 && !out.swap(outCount)) { return -1; } return count; } @@ -217,7 +217,7 @@ namespace dsp { memcpy(delay, &_in->readBuf[count - 7], 7 * sizeof(T)); _in->flush(); - if (!out.swap(outCount)) { return -1; } + if (outCount > 0 && !out.swap(outCount)) { return -1; } return count; } diff --git a/core/src/dsp/deframing.h b/core/src/dsp/deframing.h index 1a6f9362..4b8df54a 100644 --- a/core/src/dsp/deframing.h +++ b/core/src/dsp/deframing.h @@ -64,7 +64,7 @@ namespace dsp { if (bitsRead >= _frameLen) { if (!out.swap((bitsRead / 8) + ((bitsRead % 8) > 0))) { return -1; } bitsRead = -1; - nextBitIsStartOfFrame = true; + if (allowSequential) { nextBitIsStartOfFrame = true; } } continue; @@ -100,12 +100,14 @@ namespace dsp { memcpy(buffer, &_in->readBuf[count - _syncLen], _syncLen); //printf("Block processed\n"); - callcount++; + callcount++; _in->flush(); return count; } + bool allowSequential = true; + stream out; private: diff --git a/core/src/dsp/demodulator.h b/core/src/dsp/demodulator.h index 756e6542..99e73b49 100644 --- a/core/src/dsp/demodulator.h +++ b/core/src/dsp/demodulator.h @@ -396,6 +396,11 @@ namespace dsp { generic_hier_block::_block_init = true; } + void setInput(stream* input) { + assert((generic_hier_block::_block_init)); + demod.setInput(input); + } + void setSampleRate(float sampleRate) { assert(generic_hier_block::_block_init); generic_hier_block::tempStop(); diff --git a/core/src/gui/widgets/symbol_diagram.cpp b/core/src/gui/widgets/symbol_diagram.cpp index a934174e..bbef51e1 100644 --- a/core/src/gui/widgets/symbol_diagram.cpp +++ b/core/src/gui/widgets/symbol_diagram.cpp @@ -1,9 +1,17 @@ #include namespace ImGui { - SymbolDiagram::SymbolDiagram(float scale) { + SymbolDiagram::SymbolDiagram(float scale, int count) { _scale = scale; - memset(buffer, 0, 1024 * sizeof(float)); + sampleCount = count; + + buffer = new float[count]; + + memset(buffer, 0, sampleCount * sizeof(float)); + } + + SymbolDiagram::~SymbolDiagram() { + delete[] buffer; } void SymbolDiagram::draw(const ImVec2& size_arg) { @@ -23,9 +31,9 @@ namespace ImGui { window->DrawList->AddRectFilled(min, ImVec2(min.x+size.x, min.y+size.y), IM_COL32(0,0,0,255)); ImU32 col = ImGui::GetColorU32(ImGuiCol_CheckMark, 0.7f); - float increment = size.x / 1024.0f; + float increment = size.x / (float)sampleCount; float val; - for (int i = 0; i < 1024; i++) { + for (int i = 0; i < sampleCount; i++) { val = buffer[i] * _scale; if (val > 1.0f || val < -1.0f) { continue; } window->DrawList->AddCircleFilled(ImVec2(((float)i * increment) + min.x, ((val + 1) * (size.y*0.5f)) + min.y), 2, col); diff --git a/core/src/gui/widgets/symbol_diagram.h b/core/src/gui/widgets/symbol_diagram.h index 358fa177..43a9cc17 100644 --- a/core/src/gui/widgets/symbol_diagram.h +++ b/core/src/gui/widgets/symbol_diagram.h @@ -8,7 +8,8 @@ namespace ImGui { class SymbolDiagram { public: - SymbolDiagram(float _scale = 1.0f); + SymbolDiagram(float _scale = 1.0f, int count = 1024); + ~SymbolDiagram(); void draw(const ImVec2& size_arg = ImVec2(0, 0)); @@ -18,8 +19,9 @@ namespace ImGui { private: std::mutex bufferMtx; - float buffer[1024]; + float* buffer; float _scale; + int sampleCount = 0; }; } \ No newline at end of file diff --git a/core/src/gui/widgets/waterfall.cpp b/core/src/gui/widgets/waterfall.cpp index 3df810d6..aba95566 100644 --- a/core/src/gui/widgets/waterfall.cpp +++ b/core/src/gui/widgets/waterfall.cpp @@ -682,6 +682,7 @@ namespace ImGui { if (waterfallVisible) { FFTAreaHeight = std::min(FFTAreaHeight, widgetSize.y - 50); + newFFTAreaHeight = FFTAreaHeight; fftHeight = FFTAreaHeight - 50; waterfallHeight = widgetSize.y - fftHeight - 52; }