From 8946b4b4b6e5200ec09e83302f95d3b208cbbf2f Mon Sep 17 00:00:00 2001 From: zakrent Date: Sat, 26 Dec 2020 01:01:19 +0100 Subject: [PATCH 1/3] Added recorder volume meter --- core/src/imgui/imgui_custom.cpp | 57 +++++++++++++++++++++++++++++++++ core/src/imgui/imgui_custom.h | 6 ++++ recorder/src/main.cpp | 50 +++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 core/src/imgui/imgui_custom.cpp create mode 100644 core/src/imgui/imgui_custom.h diff --git a/core/src/imgui/imgui_custom.cpp b/core/src/imgui/imgui_custom.cpp new file mode 100644 index 00000000..99ad6921 --- /dev/null +++ b/core/src/imgui/imgui_custom.cpp @@ -0,0 +1,57 @@ +#include "imgui_custom.h" +#include "imgui.h" + +#ifndef IMGUI_DEFINE_MATH_OPERATORS +#define IMGUI_DEFINE_MATH_OPERATORS +#endif +#include "imgui_internal.h" + +namespace ImGui{ + void VolumeBar(float volumeL, float volumeR, float *holdL, float *holdR, const ImVec2& size_arg){ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + + ImVec2 pos = window->DC.CursorPos; + ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), g.FontSize + style.FramePadding.y * 2.0f); + ImRect bb(pos, pos + size); + ItemSize(size, style.FramePadding.y); + if (!ItemAdd(bb, 0)) + return; + + float fractionU = ImSaturate(1.0f+20*std::log10(volumeL)/60.0f); + float fractionD = ImSaturate(1.0f+20*std::log10(volumeR)/60.0f); + + *holdL = std::max(*holdL-0.005f,fractionU); + *holdR = std::max(*holdR-0.005f,fractionD); + + //Background + ImRect upbb(bb.Min, ImVec2(bb.Max.x, ImLerp(bb.Min.y, bb.Max.y, 0.4f))); + RenderRectFilledRangeH(window->DrawList, upbb, 0xff005500, 0.0f, 0.6f, 0.0f); + RenderRectFilledRangeH(window->DrawList, upbb, 0xff005555, 0.6f, 0.85f, 0.0f); + RenderRectFilledRangeH(window->DrawList, upbb, 0xff000055, 0.85f, 1.0f, 0.0f); + + ImRect dwbb(ImVec2(bb.Min.x, ImLerp(bb.Min.y, bb.Max.y, 0.6f)), bb.Max); + RenderRectFilledRangeH(window->DrawList, dwbb, 0xff005500, 0.00f, 0.6f, 0.0f); + RenderRectFilledRangeH(window->DrawList, dwbb, 0xff005555, 0.60f, 0.85f, 0.0f); + RenderRectFilledRangeH(window->DrawList, dwbb, 0xff000055, 0.85f, 1.0f, 0.0f); + + //Bar + RenderRectFilledRangeH(window->DrawList, upbb, 0xff00ff00, 0.00f, 0.60f*ImSaturate(fractionU/0.6f), 0.0f); + RenderRectFilledRangeH(window->DrawList, upbb, 0xff00ffff, 0.60f, 0.60f+0.25f*ImSaturate((fractionU-0.6f)/0.25f), 0.0f); + RenderRectFilledRangeH(window->DrawList, upbb, 0xff0000ff, 0.85f, 0.85f+0.15f*ImSaturate((fractionU-0.85f)/0.15f), 0.0f); + + RenderRectFilledRangeH(window->DrawList, dwbb, 0xff00ff00, 0.00f, 0.60f*ImSaturate(fractionD/0.6f), 0.0f); + RenderRectFilledRangeH(window->DrawList, dwbb, 0xff00ffff, 0.60f, 0.60f+0.25f*ImSaturate((fractionD-0.6f)/0.25f), 0.0f); + RenderRectFilledRangeH(window->DrawList, dwbb, 0xff0000ff, 0.85f, 0.85f+0.15f*ImSaturate((fractionD-0.85f)/0.15f), 0.0f); + + //Holders + RenderRectFilledRangeH(window->DrawList, upbb, GetColorU32(ImGuiCol_SliderGrab), *holdL, *holdL+0.01f, 0.0f); + + RenderRectFilledRangeH(window->DrawList, dwbb, GetColorU32(ImGuiCol_SliderGrab), *holdR, *holdR+0.01f, 0.0f); + + } +} diff --git a/core/src/imgui/imgui_custom.h b/core/src/imgui/imgui_custom.h new file mode 100644 index 00000000..47d4bb34 --- /dev/null +++ b/core/src/imgui/imgui_custom.h @@ -0,0 +1,6 @@ +#pragma once +#include "imgui.h" + +namespace ImGui{ + IMGUI_API void VolumeBar(float volumeL, float volumeR, float *holdL, float *holdR, const ImVec2& size_arg); +}; diff --git a/recorder/src/main.cpp b/recorder/src/main.cpp index efff67b7..26c05a4c 100644 --- a/recorder/src/main.cpp +++ b/recorder/src/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -58,6 +59,9 @@ public: selectedStreamId = 0; lastNameList = ""; + volumeHold = {0}; + currentVolumePeak = {0}; + config.aquire(); if (!config.conf.contains(name)) { config.conf[name]["recMode"] = 1; @@ -144,6 +148,12 @@ private: ImGui::PopStyleColor(); } + { + std::lock_guard lck(_this->volumeMtx); + ImGui::VolumeBar(_this->currentVolumePeak.l, _this->currentVolumePeak.r, &_this->volumeHold.l, &_this->volumeHold.r, ImVec2(-1.0f, 0.0f)); + _this->volumePeakShouldReset = true; + } + // TODO: Change VFO ref in signal path // TODO: Add VFO record ImGui::Columns(2, CONCAT("RecordModeColumns##_", _this->name), false); @@ -191,6 +201,7 @@ private: sigpath::signalPath.unbindIQStream(_this->iqStream); _this->writer->close(); delete _this->writer; + _this->currentVolumePeak = {0}; _this->recording = false; } uint64_t seconds = _this->samplesWritten / (uint64_t)_this->sampleRate; @@ -238,6 +249,7 @@ private: sigpath::sinkManager.unbindStream(_this->selectedStreamName, _this->audioStream); _this->writer->close(); delete _this->writer; + _this->currentVolumePeak = {0}; _this->recording = false; } uint64_t seconds = _this->samplesWritten / (uint64_t)_this->sampleRate; @@ -253,6 +265,23 @@ private: while (true) { int count = _this->audioStream->read(); if (count < 0) { break; } + + { + std::lock_guard lck(_this->volumeMtx); + if (_this->volumePeakShouldReset) { + _this->currentVolumePeak.l = 0.0f; + _this->currentVolumePeak.r = 0.0f; + _this->volumePeakShouldReset = false; + } + + for (int i = 0; i < count; i++) { + _this->currentVolumePeak.l = std::max(_this->currentVolumePeak.l, + std::abs(_this->audioStream->readBuf[i].l)); + _this->currentVolumePeak.r = std::max(_this->currentVolumePeak.r, + std::abs(_this->audioStream->readBuf[i].r)); + } + } + for (int i = 0; i < count; i++) { sampleBuf[(i * 2) + 0] = _this->audioStream->readBuf[i].l * 0x7FFF; sampleBuf[(i * 2) + 1] = _this->audioStream->readBuf[i].r * 0x7FFF; @@ -269,6 +298,23 @@ private: while (true) { int count = _this->iqStream->read(); if (count < 0) { break; } + + { + std::lock_guard lck(_this->volumeMtx); + if (_this->volumePeakShouldReset) { + _this->currentVolumePeak.l = 0.0f; + _this->currentVolumePeak.r = 0.0f; + _this->volumePeakShouldReset = false; + } + + for (int i = 0; i < count; i++) { + _this->currentVolumePeak.l = std::max(_this->currentVolumePeak.l, + std::abs(_this->iqStream->readBuf[i].q)); + _this->currentVolumePeak.r = std::max(_this->currentVolumePeak.r, + std::abs(_this->iqStream->readBuf[i].i)); + } + } + for (int i = 0; i < count; i++) { sampleBuf[(i * 2) + 0] = _this->iqStream->readBuf[i].q * 0x7FFF; sampleBuf[(i * 2) + 1] = _this->iqStream->readBuf[i].i * 0x7FFF; @@ -284,6 +330,10 @@ private: bool enabled = true; char path[4096]; bool pathValid = true; + std::mutex volumeMtx; + dsp::stereo_t currentVolumePeak; + dsp::stereo_t volumeHold; + bool volumePeakShouldReset; dsp::stream* audioStream; dsp::stream* iqStream; WavWriter* writer; From bb919d0f32176000d500abbeda10527f65819061 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Sat, 26 Dec 2020 00:46:52 +0100 Subject: [PATCH 2/3] Revert " Added recorder volume meter " --- core/src/imgui/imgui_custom.cpp | 57 --------------------------------- core/src/imgui/imgui_custom.h | 6 ---- recorder/src/main.cpp | 50 ----------------------------- 3 files changed, 113 deletions(-) delete mode 100644 core/src/imgui/imgui_custom.cpp delete mode 100644 core/src/imgui/imgui_custom.h diff --git a/core/src/imgui/imgui_custom.cpp b/core/src/imgui/imgui_custom.cpp deleted file mode 100644 index 99ad6921..00000000 --- a/core/src/imgui/imgui_custom.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "imgui_custom.h" -#include "imgui.h" - -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif -#include "imgui_internal.h" - -namespace ImGui{ - void VolumeBar(float volumeL, float volumeR, float *holdL, float *holdR, const ImVec2& size_arg){ - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; - - ImGuiContext& g = *GImGui; - const ImGuiStyle& style = g.Style; - - ImVec2 pos = window->DC.CursorPos; - ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), g.FontSize + style.FramePadding.y * 2.0f); - ImRect bb(pos, pos + size); - ItemSize(size, style.FramePadding.y); - if (!ItemAdd(bb, 0)) - return; - - float fractionU = ImSaturate(1.0f+20*std::log10(volumeL)/60.0f); - float fractionD = ImSaturate(1.0f+20*std::log10(volumeR)/60.0f); - - *holdL = std::max(*holdL-0.005f,fractionU); - *holdR = std::max(*holdR-0.005f,fractionD); - - //Background - ImRect upbb(bb.Min, ImVec2(bb.Max.x, ImLerp(bb.Min.y, bb.Max.y, 0.4f))); - RenderRectFilledRangeH(window->DrawList, upbb, 0xff005500, 0.0f, 0.6f, 0.0f); - RenderRectFilledRangeH(window->DrawList, upbb, 0xff005555, 0.6f, 0.85f, 0.0f); - RenderRectFilledRangeH(window->DrawList, upbb, 0xff000055, 0.85f, 1.0f, 0.0f); - - ImRect dwbb(ImVec2(bb.Min.x, ImLerp(bb.Min.y, bb.Max.y, 0.6f)), bb.Max); - RenderRectFilledRangeH(window->DrawList, dwbb, 0xff005500, 0.00f, 0.6f, 0.0f); - RenderRectFilledRangeH(window->DrawList, dwbb, 0xff005555, 0.60f, 0.85f, 0.0f); - RenderRectFilledRangeH(window->DrawList, dwbb, 0xff000055, 0.85f, 1.0f, 0.0f); - - //Bar - RenderRectFilledRangeH(window->DrawList, upbb, 0xff00ff00, 0.00f, 0.60f*ImSaturate(fractionU/0.6f), 0.0f); - RenderRectFilledRangeH(window->DrawList, upbb, 0xff00ffff, 0.60f, 0.60f+0.25f*ImSaturate((fractionU-0.6f)/0.25f), 0.0f); - RenderRectFilledRangeH(window->DrawList, upbb, 0xff0000ff, 0.85f, 0.85f+0.15f*ImSaturate((fractionU-0.85f)/0.15f), 0.0f); - - RenderRectFilledRangeH(window->DrawList, dwbb, 0xff00ff00, 0.00f, 0.60f*ImSaturate(fractionD/0.6f), 0.0f); - RenderRectFilledRangeH(window->DrawList, dwbb, 0xff00ffff, 0.60f, 0.60f+0.25f*ImSaturate((fractionD-0.6f)/0.25f), 0.0f); - RenderRectFilledRangeH(window->DrawList, dwbb, 0xff0000ff, 0.85f, 0.85f+0.15f*ImSaturate((fractionD-0.85f)/0.15f), 0.0f); - - //Holders - RenderRectFilledRangeH(window->DrawList, upbb, GetColorU32(ImGuiCol_SliderGrab), *holdL, *holdL+0.01f, 0.0f); - - RenderRectFilledRangeH(window->DrawList, dwbb, GetColorU32(ImGuiCol_SliderGrab), *holdR, *holdR+0.01f, 0.0f); - - } -} diff --git a/core/src/imgui/imgui_custom.h b/core/src/imgui/imgui_custom.h deleted file mode 100644 index 47d4bb34..00000000 --- a/core/src/imgui/imgui_custom.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once -#include "imgui.h" - -namespace ImGui{ - IMGUI_API void VolumeBar(float volumeL, float volumeR, float *holdL, float *holdR, const ImVec2& size_arg); -}; diff --git a/recorder/src/main.cpp b/recorder/src/main.cpp index 26c05a4c..efff67b7 100644 --- a/recorder/src/main.cpp +++ b/recorder/src/main.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -59,9 +58,6 @@ public: selectedStreamId = 0; lastNameList = ""; - volumeHold = {0}; - currentVolumePeak = {0}; - config.aquire(); if (!config.conf.contains(name)) { config.conf[name]["recMode"] = 1; @@ -148,12 +144,6 @@ private: ImGui::PopStyleColor(); } - { - std::lock_guard lck(_this->volumeMtx); - ImGui::VolumeBar(_this->currentVolumePeak.l, _this->currentVolumePeak.r, &_this->volumeHold.l, &_this->volumeHold.r, ImVec2(-1.0f, 0.0f)); - _this->volumePeakShouldReset = true; - } - // TODO: Change VFO ref in signal path // TODO: Add VFO record ImGui::Columns(2, CONCAT("RecordModeColumns##_", _this->name), false); @@ -201,7 +191,6 @@ private: sigpath::signalPath.unbindIQStream(_this->iqStream); _this->writer->close(); delete _this->writer; - _this->currentVolumePeak = {0}; _this->recording = false; } uint64_t seconds = _this->samplesWritten / (uint64_t)_this->sampleRate; @@ -249,7 +238,6 @@ private: sigpath::sinkManager.unbindStream(_this->selectedStreamName, _this->audioStream); _this->writer->close(); delete _this->writer; - _this->currentVolumePeak = {0}; _this->recording = false; } uint64_t seconds = _this->samplesWritten / (uint64_t)_this->sampleRate; @@ -265,23 +253,6 @@ private: while (true) { int count = _this->audioStream->read(); if (count < 0) { break; } - - { - std::lock_guard lck(_this->volumeMtx); - if (_this->volumePeakShouldReset) { - _this->currentVolumePeak.l = 0.0f; - _this->currentVolumePeak.r = 0.0f; - _this->volumePeakShouldReset = false; - } - - for (int i = 0; i < count; i++) { - _this->currentVolumePeak.l = std::max(_this->currentVolumePeak.l, - std::abs(_this->audioStream->readBuf[i].l)); - _this->currentVolumePeak.r = std::max(_this->currentVolumePeak.r, - std::abs(_this->audioStream->readBuf[i].r)); - } - } - for (int i = 0; i < count; i++) { sampleBuf[(i * 2) + 0] = _this->audioStream->readBuf[i].l * 0x7FFF; sampleBuf[(i * 2) + 1] = _this->audioStream->readBuf[i].r * 0x7FFF; @@ -298,23 +269,6 @@ private: while (true) { int count = _this->iqStream->read(); if (count < 0) { break; } - - { - std::lock_guard lck(_this->volumeMtx); - if (_this->volumePeakShouldReset) { - _this->currentVolumePeak.l = 0.0f; - _this->currentVolumePeak.r = 0.0f; - _this->volumePeakShouldReset = false; - } - - for (int i = 0; i < count; i++) { - _this->currentVolumePeak.l = std::max(_this->currentVolumePeak.l, - std::abs(_this->iqStream->readBuf[i].q)); - _this->currentVolumePeak.r = std::max(_this->currentVolumePeak.r, - std::abs(_this->iqStream->readBuf[i].i)); - } - } - for (int i = 0; i < count; i++) { sampleBuf[(i * 2) + 0] = _this->iqStream->readBuf[i].q * 0x7FFF; sampleBuf[(i * 2) + 1] = _this->iqStream->readBuf[i].i * 0x7FFF; @@ -330,10 +284,6 @@ private: bool enabled = true; char path[4096]; bool pathValid = true; - std::mutex volumeMtx; - dsp::stereo_t currentVolumePeak; - dsp::stereo_t volumeHold; - bool volumePeakShouldReset; dsp::stream* audioStream; dsp::stream* iqStream; WavWriter* writer; From 149af55e61c8018af1b4615fbb3d2b2c40c6eaaf Mon Sep 17 00:00:00 2001 From: cropinghigh <38228168+cropinghigh@users.noreply.github.com> Date: Sat, 26 Dec 2020 11:47:37 +0300 Subject: [PATCH 3/3] Addition to linux guide --- readme.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index 1a7e2365..6e1a220e 100644 --- a/readme.md +++ b/readme.md @@ -186,9 +186,9 @@ Then, you need to edit the `root_dev/config` file to point to the modules that w You also need to change the location of the resource and module directories, for development, I recommend: ```json ... -"modulesDirectory": "../root_dev/modules", +"modulesDirectory": "./root_dev/modules", ... -"resourcesDirectory": "../root_dev/res", +"resourcesDirectory": "./root_dev/res", ... ``` @@ -198,12 +198,12 @@ Off cours, remember to add entries for all modules that were built and that you Next, from the top directory, you can simply run: ``` -./build/Release/sdrpp.exe -r root_dev +./build/sdrpp -r root_dev ``` -Or, if you wish to run from the build directory: +Or, if you wish to run from the build directory, you need to correct directories in config.json, and: ``` -./Release/sdrpp.exe -r ../root_dev +./sdrpp -r ../root_dev ``` ## Installing SDR++ @@ -234,4 +234,4 @@ I will soon publish a contributing.md listing the code style to use. * [Dear ImGui (ocornut)](https://github.com/ocornut/imgui) * [spdlog (gabime)](https://github.com/gabime/spdlog) * [json (nlohmann)](https://github.com/nlohmann/json) -* [portaudio (PortAudio community)](http://www.portaudio.com/) \ No newline at end of file +* [portaudio (PortAudio community)](http://www.portaudio.com/)