Move AGC2 config ToString to the right place and update Validate()
The APM config to string mapping must be in one place (namely, in `audio_processing.cc`). This CL moves the AGC2 config to string impl to the right place. This CL also updates `GainController2::Validate()` and adds the missing unit tests for the parameters that have recently been added. Stack buffer size in `AudioProcessing::Config::ToString()` increased because of the extra params. Syntax near `multi_channel_capture` fixed. Output string format verified with a JS linter. Bug: webrtc:7494 Change-Id: I692e1549b7d40c970d88a14c8e83da16325fb54c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/187080 Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Minyue Li <minyue@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32400}
This commit is contained in:
committed by
Commit Bot
parent
47156e27c0
commit
0c83e15c6b
@ -65,8 +65,7 @@ void GainController2::NotifyAnalogLevel(int level) {
|
||||
|
||||
void GainController2::ApplyConfig(
|
||||
const AudioProcessing::Config::GainController2& config) {
|
||||
RTC_DCHECK(Validate(config))
|
||||
<< " the invalid config was " << ToString(config);
|
||||
RTC_DCHECK(Validate(config));
|
||||
|
||||
config_ = config;
|
||||
if (config.fixed_digital.gain_db != config_.fixed_digital.gain_db) {
|
||||
@ -84,55 +83,19 @@ void GainController2::ApplyConfig(
|
||||
|
||||
bool GainController2::Validate(
|
||||
const AudioProcessing::Config::GainController2& config) {
|
||||
return config.fixed_digital.gain_db >= 0.f &&
|
||||
config.fixed_digital.gain_db < 50.f &&
|
||||
config.adaptive_digital.extra_saturation_margin_db >= 0.f &&
|
||||
config.adaptive_digital.extra_saturation_margin_db <= 100.f;
|
||||
}
|
||||
|
||||
std::string GainController2::ToString(
|
||||
const AudioProcessing::Config::GainController2& config) {
|
||||
rtc::StringBuilder ss;
|
||||
std::string adaptive_digital_level_estimator;
|
||||
using LevelEstimatorType =
|
||||
AudioProcessing::Config::GainController2::LevelEstimator;
|
||||
switch (config.adaptive_digital.level_estimator) {
|
||||
case LevelEstimatorType::kRms:
|
||||
adaptive_digital_level_estimator = "RMS";
|
||||
break;
|
||||
case LevelEstimatorType::kPeak:
|
||||
adaptive_digital_level_estimator = "peak";
|
||||
break;
|
||||
}
|
||||
// clang-format off
|
||||
// clang formatting doesn't respect custom nested style.
|
||||
ss << "{"
|
||||
"enabled: " << (config.enabled ? "true" : "false") << ", "
|
||||
"fixed_digital: {gain_db: " << config.fixed_digital.gain_db << "}, "
|
||||
"adaptive_digital: {"
|
||||
"enabled: "
|
||||
<< (config.adaptive_digital.enabled ? "true" : "false") << ", "
|
||||
"level_estimator: {"
|
||||
"type: " << adaptive_digital_level_estimator << ", "
|
||||
"adjacent_speech_frames_threshold: "
|
||||
<< config.adaptive_digital
|
||||
.level_estimator_adjacent_speech_frames_threshold << ", "
|
||||
"initial_saturation_margin_db: "
|
||||
<< config.adaptive_digital.initial_saturation_margin_db << ", "
|
||||
"extra_saturation_margin_db: "
|
||||
<< config.adaptive_digital.extra_saturation_margin_db << "}, "
|
||||
"gain_applier: {"
|
||||
"adjacent_speech_frames_threshold: "
|
||||
<< config.adaptive_digital
|
||||
.gain_applier_adjacent_speech_frames_threshold << ", "
|
||||
"max_gain_change_db_per_second: "
|
||||
<< config.adaptive_digital.max_gain_change_db_per_second << ", "
|
||||
"max_output_noise_level_dbfs: "
|
||||
<< config.adaptive_digital.max_output_noise_level_dbfs << "}"
|
||||
"}"
|
||||
"}";
|
||||
// clang-format on
|
||||
return ss.Release();
|
||||
const auto& fixed = config.fixed_digital;
|
||||
const auto& adaptive = config.adaptive_digital;
|
||||
return fixed.gain_db >= 0.f && fixed.gain_db < 50.f &&
|
||||
adaptive.vad_probability_attack > 0.f &&
|
||||
adaptive.vad_probability_attack <= 1.f &&
|
||||
adaptive.level_estimator_adjacent_speech_frames_threshold >= 1 &&
|
||||
adaptive.initial_saturation_margin_db >= 0.f &&
|
||||
adaptive.initial_saturation_margin_db <= 100.f &&
|
||||
adaptive.extra_saturation_margin_db >= 0.f &&
|
||||
adaptive.extra_saturation_margin_db <= 100.f &&
|
||||
adaptive.gain_applier_adjacent_speech_frames_threshold >= 1 &&
|
||||
adaptive.max_gain_change_db_per_second > 0.f &&
|
||||
adaptive.max_output_noise_level_dbfs <= 0.f;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user