From f4bd483410003a96eaaa84742211e9bc9dd89d72 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Mon, 26 Sep 2022 17:04:24 +0200 Subject: [PATCH] more work --- misc_modules/recorder/src/main.cpp | 36 +++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/misc_modules/recorder/src/main.cpp b/misc_modules/recorder/src/main.cpp index a0a30988..04dcf1c5 100644 --- a/misc_modules/recorder/src/main.cpp +++ b/misc_modules/recorder/src/main.cpp @@ -77,10 +77,10 @@ public: config.release(); // Init audio path - splitter.init(NULL); + volume.init(NULL, audioVolume, false); + splitter.init(&volume.out); splitter.bindStream(&meterStream); meter.init(&meterStream); - meter.start(); // Init sinks basebandSink.init(NULL, complexHandler, this); @@ -98,7 +98,7 @@ public: } void postInit() { - + selectStream("Radio"); } void enable() { @@ -184,15 +184,16 @@ public: deselectStream(); audioStream = sigpath::sinkManager.bindStream(name); if (!audioStream) { return; } - splitter.setInput(audioStream); - splitter.start(); + selectedStreamName = name; + volume.setInput(audioStream); + startAudioPath(); } void deselectStream() { std::lock_guard lck(recMtx); if (selectedStreamName.empty() || !audioStream) { return; } if (recording && recMode == RECORDER_MODE_AUDIO) { stop(); } - splitter.stop(); + stopAudioPath(); sigpath::sinkManager.unbindStream(selectedStreamName, audioStream); selectedStreamName = ""; audioStream = NULL; @@ -260,16 +261,16 @@ private: ImGui::FillWidth(); if (ImGui::SliderFloat(CONCAT("##_recorder_vol_", _this->name), &_this->audioVolume, 0, 1, "")) { // TODO: ADD VOLUME CONTROL - //_this->vol.setVolume(_this->audioVolume); + _this->volume.setVolume(_this->audioVolume); config.acquire(); config.conf[_this->name]["audioVolume"] = _this->audioVolume; config.release(true); } - ImGui::PopItemWidth(); + //ImGui::PopItemWidth(); if (_this->recording) { style::beginDisabled(); } if (ImGui::Checkbox(CONCAT("Stereo##_recorder_stereo_", _this->name), &_this->stereo)) { - config.acquire();audioStream + config.acquire(); config.conf[_this->name]["stereo"] = _this->stereo; config.release(true); } @@ -302,14 +303,26 @@ private: } } + void startAudioPath() { + volume.start(); + splitter.start(); + meter.start(); + } + + void stopAudioPath() { + volume.stop(); + splitter.stop(); + meter.stop(); + } + void updateAudioMeter(dsp::stereo_t& lvl) { // Note: Yes, using the natural log is on purpose, it just gives a more beautiful result. double frameTime = 1.0 / ImGui::GetIO().Framerate; lvl.l = std::clamp(lvl.l - (frameTime * 50.0), -90.0f, 10.0f); lvl.r = std::clamp(lvl.r - (frameTime * 50.0), -90.0f, 10.0f); // TODO: FINISH METER - dsp::stereo_t rawLvl = {0.0f,0.0f};//meter.getLevel(); - //meter.resetLevel(); + dsp::stereo_t rawLvl = meter.getLevel(); + meter.resetLevel(); dsp::stereo_t dbLvl = { 10.0f * logf(rawLvl.l), 10.0f * logf(rawLvl.r) }; if (dbLvl.l > lvl.l) { lvl.l = dbLvl.l; } if (dbLvl.r > lvl.r) { lvl.r = dbLvl.r; } @@ -373,6 +386,7 @@ private: dsp::sink::Handler monoSink; dsp::stream* audioStream = NULL; + dsp::audio::Volume volume; dsp::routing::Splitter splitter; dsp::stream meterStream; dsp::bench::PeakLevelMeter meter;