Added back 'ignore silence' option in the recorder

This commit is contained in:
AlexandreRouma 2023-03-02 14:47:02 +01:00
parent 5b47f900a6
commit 6f9dacdd53

View File

@ -23,7 +23,8 @@
#include <utils/wav.h>
#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<float>(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<float>(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<dsp::complex_t>* basebandStream;