From 41057110401bf42f438190c29f3cc11d65e79914 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Mon, 3 May 2021 11:09:35 +0200 Subject: [PATCH] Some minor changes to the native code --- native/serverconnection/exports/exports.d.ts | 3 ++- .../src/audio/js/AudioProcessor.cpp | 2 ++ .../src/audio/processing/AudioProcessor.cpp | 15 ++++++++++++--- .../src/audio/processing/AudioProcessor.h | 2 ++ native/updater/util.cpp | 3 ++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/native/serverconnection/exports/exports.d.ts b/native/serverconnection/exports/exports.d.ts index 93720f1..30edcd1 100644 --- a/native/serverconnection/exports/exports.d.ts +++ b/native/serverconnection/exports/exports.d.ts @@ -296,7 +296,8 @@ export namespace audio { "residual_echo_detector.enabled": boolean, "level_estimation.enabled": boolean, - "rnnoise.enabled": boolean + "rnnoise.enabled": boolean, + "artificial_stream_delay": number } export interface AudioProcessorStatistics { diff --git a/native/serverconnection/src/audio/js/AudioProcessor.cpp b/native/serverconnection/src/audio/js/AudioProcessor.cpp index 8294c3e..4223ca4 100644 --- a/native/serverconnection/src/audio/js/AudioProcessor.cpp +++ b/native/serverconnection/src/audio/js/AudioProcessor.cpp @@ -177,6 +177,7 @@ NAN_METHOD(AudioProcessorWrapper::get_config) { PUT_CONFIG(residual_echo_detector.enabled); PUT_CONFIG(level_estimation.enabled); PUT_CONFIG(rnnoise.enabled); + PUT_CONFIG(artificial_stream_delay); info.GetReturnValue().Set(result); } @@ -351,6 +352,7 @@ NAN_METHOD(AudioProcessorWrapper::apply_config) { LOAD_CONFIG(residual_echo_detector.enabled); LOAD_CONFIG(level_estimation.enabled); LOAD_CONFIG(rnnoise.enabled); + LOAD_CONFIG(artificial_stream_delay); processor->apply_config(config); } diff --git a/native/serverconnection/src/audio/processing/AudioProcessor.cpp b/native/serverconnection/src/audio/processing/AudioProcessor.cpp index bfa033b..4bfdb2a 100644 --- a/native/serverconnection/src/audio/processing/AudioProcessor.cpp +++ b/native/serverconnection/src/audio/processing/AudioProcessor.cpp @@ -118,6 +118,11 @@ void AudioProcessor::apply_config(const AudioProcessor::Config &config) { void AudioProcessor::apply_config_unlocked(const Config &config) { this->current_config = config; + + /* These are internal bounds and should not be changed */ + this->current_config.gain_controller1.analog_level_minimum = 0; + this->current_config.gain_controller1.analog_level_maximum = 255; + if(this->processor) { this->processor->ApplyConfig(config); } @@ -125,7 +130,7 @@ void AudioProcessor::apply_config_unlocked(const Config &config) { if(!this->current_config.rnnoise.enabled) { this->rnnoise_volume = absl::nullopt; } - log_trace(category::audio, tr("Applying process config:\n{}\nRNNoise: "), config.ToString(), this->current_config.rnnoise.enabled); + log_trace(category::audio, tr("Applying process config:\n{}\nRNNoise: {}\nArtificial stream delay: {}"), config.ToString(), this->current_config.rnnoise.enabled, this->current_config.artificial_stream_delay); } AudioProcessor::Stats AudioProcessor::get_statistics() const { @@ -217,8 +222,12 @@ std::optional AudioProcessor::process_stream(const webrtc } } - this->processor->set_stream_delay_ms(2); /* TODO: Measure it and not just guess it! */ - this->processor->set_stream_analog_level(0); + /* TODO: Measure it and not just guess it! */ + this->processor->set_stream_delay_ms(this->current_config.artificial_stream_delay); + if(this->current_config.gain_controller1.enabled) { + /* TODO: Calculate the actual audio volume */ + this->processor->set_stream_analog_level(0); + } auto result = this->processor->ProcessStream(buffer, config, config, buffer); if(result != webrtc::AudioProcessing::kNoError) { diff --git a/native/serverconnection/src/audio/processing/AudioProcessor.h b/native/serverconnection/src/audio/processing/AudioProcessor.h index d0dcb5d..fa0e279 100644 --- a/native/serverconnection/src/audio/processing/AudioProcessor.h +++ b/native/serverconnection/src/audio/processing/AudioProcessor.h @@ -12,6 +12,8 @@ namespace tc::audio { struct { bool enabled{false}; } rnnoise; + + int artificial_stream_delay{0}; }; struct Stats : public webrtc::AudioProcessingStats { diff --git a/native/updater/util.cpp b/native/updater/util.cpp index e380809..7ed090c 100644 --- a/native/updater/util.cpp +++ b/native/updater/util.cpp @@ -51,6 +51,8 @@ using namespace std; bool is_executable(const std::string& file) { chmod(file.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + /* We chmod above but for some reasons access still fails. This should be fixed but I want to finish the linux client... */ + return true; return access(file.c_str(), F_OK | X_OK) == 0; } @@ -89,7 +91,6 @@ inline std::string build_callback_info(const std::string& error_id, const std::s void execute_callback_fail_exit(const std::string& error, const std::string& error_message) { file::rollback(); - //int chmod(const char *path, mode_t mode); if(!is_executable(config::callback_file)) { logger::fatal("callback file (%s) is not executable! Ignoring fail callback", config::callback_file.c_str()); logger::flush();