From 6f9dacdd532e118f4aecb1e273cf2eb9a9b5c1f9 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Thu, 2 Mar 2023 14:47:02 +0100 Subject: [PATCH] Added back 'ignore silence' option in the recorder --- misc_modules/recorder/src/main.cpp | 40 +++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/misc_modules/recorder/src/main.cpp b/misc_modules/recorder/src/main.cpp index 1a8a3b84..79849c54 100644 --- a/misc_modules/recorder/src/main.cpp +++ b/misc_modules/recorder/src/main.cpp @@ -23,7 +23,8 @@ #include #define CONCAT(a, b) ((std::string(a) + b).c_str()) -#define SILENCE_LVL 10e-20 + +#define SILENCE_LVL 10e-6 SDRPP_MOD_INFO{ /* Name: */ "recorder", @@ -315,11 +316,11 @@ private: } if (_this->recording) { style::endDisabled(); } - // if (ImGui::Checkbox(CONCAT("Ignore silence##_recorder_ignore_silence_", _this->name), &_this->ignoreSilence)) { - // config.acquire(); - // config.conf[_this->name]["ignoreSilence"] = _this->ignoreSilence; - // config.release(true); - // } + if (ImGui::Checkbox(CONCAT("Ignore silence##_recorder_ignore_silence_", _this->name), &_this->ignoreSilence)) { + config.acquire(); + config.conf[_this->name]["ignoreSilence"] = _this->ignoreSilence; + config.release(true); + } } // Record button @@ -338,7 +339,13 @@ private: uint64_t seconds = _this->writer.getSamplesWritten() / _this->samplerate; time_t diff = seconds; 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); + + if (_this->ignoreSilence && _this->ignoringSilence) { + ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "Paused %02d:%02d:%02d", dtm->tm_hour, dtm->tm_min, dtm->tm_sec); + } + else { + ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Recording %02d:%02d:%02d", dtm->tm_hour, dtm->tm_min, dtm->tm_sec); + } } } @@ -480,13 +487,27 @@ private: static void stereoHandler(dsp::stereo_t* data, int count, void* ctx) { RecorderModule* _this = (RecorderModule*)ctx; - // TODO: Ignore silence + if (_this->ignoreSilence) { + uint32_t minId = 0; + uint32_t maxId = 0; + volk_32f_index_min_32u(&minId, (float*)data, count * 2); + volk_32f_index_max_32u(&maxId, (float*)data, count * 2); + _this->ignoringSilence = (std::max(fabsf(((float*)data)[minId]), fabsf(((float*)data)[maxId])) < SILENCE_LVL); + if (_this->ignoringSilence) { return; } + } _this->writer.write((float*)data, count); } static void monoHandler(float* data, int count, void* ctx) { RecorderModule* _this = (RecorderModule*)ctx; - // TODO: Ignore silence + if (_this->ignoreSilence) { + uint32_t minId = 0; + uint32_t maxId = 0; + volk_32f_index_min_32u(&minId, data, count); + volk_32f_index_max_32u(&maxId, data, count); + _this->ignoringSilence = (std::max(fabsf(data[minId]), fabsf(data[maxId])) < SILENCE_LVL); + if (_this->ignoringSilence) { return; } + } _this->writer.write(data, count); } @@ -529,6 +550,7 @@ private: dsp::stereo_t audioLvl = { -100.0f, -100.0f }; bool recording = false; + bool ignoringSilence = false; wav::Writer writer; std::recursive_mutex recMtx; dsp::stream* basebandStream;