Remove expired WebRTC-Aec3PreEchoConfiguration
This hard-codes the behavior to mode 3 with a threshold of 0.5 like was already done by FetchPreEchoConfiguration. Bug: webrtc:14205 Change-Id: I48d47a77c9df0001460788b504524203417f9647 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/345483 Commit-Queue: Emil Lundmark <lndmrk@webrtc.org> Reviewed-by: Jesus de Vicente Pena <devicentepena@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42015}
This commit is contained in:
parent
a909424577
commit
3fc8422993
@ -41,9 +41,6 @@ ACTIVE_FIELD_TRIALS: FrozenSet[FieldTrial] = frozenset([
|
||||
FieldTrial('WebRTC-Aec3PenalyzeHighDelaysInitialPhase',
|
||||
'webrtc:14919',
|
||||
date(2024, 4, 1)),
|
||||
FieldTrial('WebRTC-Aec3PreEchoConfiguration',
|
||||
'webrtc:14205',
|
||||
date(2024, 4, 1)),
|
||||
FieldTrial('WebRTC-Audio-GainController2',
|
||||
'webrtc:7494',
|
||||
date(2024, 4, 1)),
|
||||
|
||||
@ -43,8 +43,8 @@ constexpr int kAccumulatedErrorSubSampleRate = 4;
|
||||
void UpdateAccumulatedError(
|
||||
const rtc::ArrayView<const float> instantaneous_accumulated_error,
|
||||
const rtc::ArrayView<float> accumulated_error,
|
||||
float one_over_error_sum_anchor,
|
||||
float smooth_constant_increases) {
|
||||
float one_over_error_sum_anchor) {
|
||||
static constexpr float kSmoothConstantIncreases = 0.015f;
|
||||
for (size_t k = 0; k < instantaneous_accumulated_error.size(); ++k) {
|
||||
float error_norm =
|
||||
instantaneous_accumulated_error[k] * one_over_error_sum_anchor;
|
||||
@ -52,97 +52,30 @@ void UpdateAccumulatedError(
|
||||
accumulated_error[k] = error_norm;
|
||||
} else {
|
||||
accumulated_error[k] +=
|
||||
smooth_constant_increases * (error_norm - accumulated_error[k]);
|
||||
kSmoothConstantIncreases * (error_norm - accumulated_error[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t ComputePreEchoLag(
|
||||
const webrtc::MatchedFilter::PreEchoConfiguration& pre_echo_configuration,
|
||||
const rtc::ArrayView<const float> accumulated_error,
|
||||
size_t lag,
|
||||
size_t alignment_shift_winner) {
|
||||
static constexpr float kPreEchoThreshold = 0.5f;
|
||||
RTC_DCHECK_GE(lag, alignment_shift_winner);
|
||||
size_t pre_echo_lag_estimate = lag - alignment_shift_winner;
|
||||
size_t maximum_pre_echo_lag =
|
||||
std::min(pre_echo_lag_estimate / kAccumulatedErrorSubSampleRate,
|
||||
accumulated_error.size());
|
||||
switch (pre_echo_configuration.mode) {
|
||||
case 0:
|
||||
// Mode 0: Pre echo lag is defined as the first coefficient with an error
|
||||
// lower than a threshold with a certain decrease slope.
|
||||
for (size_t k = 1; k < maximum_pre_echo_lag; ++k) {
|
||||
if (accumulated_error[k] <
|
||||
pre_echo_configuration.threshold * accumulated_error[k - 1] &&
|
||||
accumulated_error[k] < pre_echo_configuration.threshold) {
|
||||
pre_echo_lag_estimate = (k + 1) * kAccumulatedErrorSubSampleRate - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
// Mode 1: Pre echo lag is defined as the first coefficient with an error
|
||||
// lower than a certain threshold.
|
||||
for (size_t k = 0; k < maximum_pre_echo_lag; ++k) {
|
||||
if (accumulated_error[k] < pre_echo_configuration.threshold) {
|
||||
pre_echo_lag_estimate = (k + 1) * kAccumulatedErrorSubSampleRate - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
// Mode 2,3: Pre echo lag is defined as the closest coefficient to the lag
|
||||
// with an error lower than a certain threshold.
|
||||
for (int k = static_cast<int>(maximum_pre_echo_lag) - 1; k >= 0; --k) {
|
||||
if (accumulated_error[k] > pre_echo_configuration.threshold) {
|
||||
break;
|
||||
}
|
||||
pre_echo_lag_estimate = (k + 1) * kAccumulatedErrorSubSampleRate - 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
RTC_DCHECK_NOTREACHED();
|
||||
for (int k = static_cast<int>(maximum_pre_echo_lag) - 1; k >= 0; --k) {
|
||||
if (accumulated_error[k] > kPreEchoThreshold) {
|
||||
break;
|
||||
}
|
||||
pre_echo_lag_estimate = (k + 1) * kAccumulatedErrorSubSampleRate - 1;
|
||||
}
|
||||
return pre_echo_lag_estimate + alignment_shift_winner;
|
||||
}
|
||||
|
||||
webrtc::MatchedFilter::PreEchoConfiguration FetchPreEchoConfiguration() {
|
||||
constexpr float kDefaultThreshold = 0.5f;
|
||||
constexpr int kDefaultMode = 3;
|
||||
float threshold = kDefaultThreshold;
|
||||
int mode = kDefaultMode;
|
||||
const std::string pre_echo_configuration_field_trial =
|
||||
webrtc::field_trial::FindFullName("WebRTC-Aec3PreEchoConfiguration");
|
||||
webrtc::FieldTrialParameter<double> threshold_field_trial_parameter(
|
||||
/*key=*/"threshold", /*default_value=*/kDefaultThreshold);
|
||||
webrtc::FieldTrialParameter<int> mode_field_trial_parameter(
|
||||
/*key=*/"mode", /*default_value=*/kDefaultMode);
|
||||
webrtc::ParseFieldTrial(
|
||||
{&threshold_field_trial_parameter, &mode_field_trial_parameter},
|
||||
pre_echo_configuration_field_trial);
|
||||
float threshold_read =
|
||||
static_cast<float>(threshold_field_trial_parameter.Get());
|
||||
int mode_read = mode_field_trial_parameter.Get();
|
||||
if (threshold_read < 1.0f && threshold_read > 0.0f) {
|
||||
threshold = threshold_read;
|
||||
} else {
|
||||
RTC_LOG(LS_ERROR)
|
||||
<< "AEC3: Pre echo configuration: wrong input, threshold = "
|
||||
<< threshold_read << ".";
|
||||
}
|
||||
if (mode_read >= 0 && mode_read <= 3) {
|
||||
mode = mode_read;
|
||||
} else {
|
||||
RTC_LOG(LS_ERROR) << "AEC3: Pre echo configuration: wrong input, mode = "
|
||||
<< mode_read << ".";
|
||||
}
|
||||
RTC_LOG(LS_INFO) << "AEC3: Pre echo configuration: threshold = " << threshold
|
||||
<< ", mode = " << mode << ".";
|
||||
return {.threshold = threshold, .mode = mode};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace webrtc {
|
||||
@ -685,8 +618,7 @@ MatchedFilter::MatchedFilter(ApmDataDumper* data_dumper,
|
||||
smoothing_fast_(smoothing_fast),
|
||||
smoothing_slow_(smoothing_slow),
|
||||
matching_filter_threshold_(matching_filter_threshold),
|
||||
detect_pre_echo_(detect_pre_echo),
|
||||
pre_echo_config_(FetchPreEchoConfiguration()) {
|
||||
detect_pre_echo_(detect_pre_echo) {
|
||||
RTC_DCHECK(data_dumper);
|
||||
RTC_DCHECK_LT(0, window_size_sub_blocks);
|
||||
RTC_DCHECK((kBlockSize % sub_block_size) == 0);
|
||||
@ -717,7 +649,7 @@ void MatchedFilter::Reset(bool full_reset) {
|
||||
|
||||
winner_lag_ = absl::nullopt;
|
||||
reported_lag_estimate_ = absl::nullopt;
|
||||
if (pre_echo_config_.mode != 3 || full_reset) {
|
||||
if (full_reset) {
|
||||
for (auto& e : accumulated_error_) {
|
||||
std::fill(e.begin(), e.end(), 1.0f);
|
||||
}
|
||||
@ -823,22 +755,16 @@ void MatchedFilter::Update(const DownsampledRenderBuffer& render_buffer,
|
||||
reported_lag_estimate_ =
|
||||
LagEstimate(winner_lag_.value(), /*pre_echo_lag=*/winner_lag_.value());
|
||||
if (detect_pre_echo_ && last_detected_best_lag_filter_ == winner_index) {
|
||||
const float energy_threshold =
|
||||
pre_echo_config_.mode == 3 ? 1.0f : 30.0f * 30.0f * y.size();
|
||||
|
||||
if (error_sum_anchor > energy_threshold) {
|
||||
const float smooth_constant_increases =
|
||||
pre_echo_config_.mode != 3 ? 0.01f : 0.015f;
|
||||
|
||||
UpdateAccumulatedError(
|
||||
instantaneous_accumulated_error_, accumulated_error_[winner_index],
|
||||
1.0f / error_sum_anchor, smooth_constant_increases);
|
||||
static constexpr float kEnergyThreshold = 1.0f;
|
||||
if (error_sum_anchor > kEnergyThreshold) {
|
||||
UpdateAccumulatedError(instantaneous_accumulated_error_,
|
||||
accumulated_error_[winner_index],
|
||||
1.0f / error_sum_anchor);
|
||||
number_pre_echo_updates_++;
|
||||
}
|
||||
if (pre_echo_config_.mode != 3 || number_pre_echo_updates_ >= 50) {
|
||||
if (number_pre_echo_updates_ >= 50) {
|
||||
reported_lag_estimate_->pre_echo_lag = ComputePreEchoLag(
|
||||
pre_echo_config_, accumulated_error_[winner_index],
|
||||
winner_lag_.value(),
|
||||
accumulated_error_[winner_index], winner_lag_.value(),
|
||||
winner_index * filter_intra_lag_shift_ /*alignment_shift_winner*/);
|
||||
} else {
|
||||
reported_lag_estimate_->pre_echo_lag = winner_lag_.value();
|
||||
@ -885,10 +811,9 @@ void MatchedFilter::Dump() {
|
||||
"aec3_correlator_error_" + std::to_string(n) + "_h";
|
||||
data_dumper_->DumpRaw(dumper_error.c_str(), accumulated_error_[n]);
|
||||
|
||||
size_t pre_echo_lag =
|
||||
ComputePreEchoLag(pre_echo_config_, accumulated_error_[n],
|
||||
lag_estimate + n * filter_intra_lag_shift_,
|
||||
n * filter_intra_lag_shift_);
|
||||
size_t pre_echo_lag = ComputePreEchoLag(
|
||||
accumulated_error_[n], lag_estimate + n * filter_intra_lag_shift_,
|
||||
n * filter_intra_lag_shift_);
|
||||
std::string dumper_pre_lag =
|
||||
"aec3_correlator_pre_echo_lag_" + std::to_string(n);
|
||||
data_dumper_->DumpRaw(dumper_pre_lag.c_str(), pre_echo_lag);
|
||||
|
||||
@ -106,11 +106,6 @@ class MatchedFilter {
|
||||
size_t pre_echo_lag = 0;
|
||||
};
|
||||
|
||||
struct PreEchoConfiguration {
|
||||
const float threshold;
|
||||
const int mode;
|
||||
};
|
||||
|
||||
MatchedFilter(ApmDataDumper* data_dumper,
|
||||
Aec3Optimization optimization,
|
||||
size_t sub_block_size,
|
||||
@ -153,15 +148,6 @@ class MatchedFilter {
|
||||
size_t downsampling_factor) const;
|
||||
|
||||
private:
|
||||
FRIEND_TEST_ALL_PREFIXES(MatchedFilterFieldTrialTest,
|
||||
PreEchoConfigurationTest);
|
||||
FRIEND_TEST_ALL_PREFIXES(MatchedFilterFieldTrialTest,
|
||||
WrongPreEchoConfigurationTest);
|
||||
|
||||
// Only for testing. Gets the pre echo detection configuration.
|
||||
const PreEchoConfiguration& GetPreEchoConfiguration() const {
|
||||
return pre_echo_config_;
|
||||
}
|
||||
void Dump();
|
||||
|
||||
ApmDataDumper* const data_dumper_;
|
||||
@ -182,7 +168,6 @@ class MatchedFilter {
|
||||
const float smoothing_slow_;
|
||||
const float matching_filter_threshold_;
|
||||
const bool detect_pre_echo_;
|
||||
const PreEchoConfiguration pre_echo_config_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -556,57 +556,4 @@ INSTANTIATE_TEST_SUITE_P(_,
|
||||
#endif
|
||||
|
||||
} // namespace aec3
|
||||
|
||||
TEST(MatchedFilterFieldTrialTest, PreEchoConfigurationTest) {
|
||||
float threshold_in = 0.1f;
|
||||
int mode_in = 2;
|
||||
rtc::StringBuilder field_trial_name;
|
||||
field_trial_name << "WebRTC-Aec3PreEchoConfiguration/threshold:"
|
||||
<< threshold_in << ",mode:" << mode_in << "/";
|
||||
webrtc::test::ScopedFieldTrials field_trials(field_trial_name.str());
|
||||
ApmDataDumper data_dumper(0);
|
||||
EchoCanceller3Config config;
|
||||
MatchedFilter matched_filter(
|
||||
&data_dumper, DetectOptimization(),
|
||||
kBlockSize / config.delay.down_sampling_factor,
|
||||
aec3::kWindowSizeSubBlocks, aec3::kNumMatchedFilters,
|
||||
aec3::kAlignmentShiftSubBlocks,
|
||||
config.render_levels.poor_excitation_render_limit,
|
||||
config.delay.delay_estimate_smoothing,
|
||||
config.delay.delay_estimate_smoothing_delay_found,
|
||||
config.delay.delay_candidate_detection_threshold,
|
||||
config.delay.detect_pre_echo);
|
||||
|
||||
auto& pre_echo_config = matched_filter.GetPreEchoConfiguration();
|
||||
EXPECT_EQ(pre_echo_config.threshold, threshold_in);
|
||||
EXPECT_EQ(pre_echo_config.mode, mode_in);
|
||||
}
|
||||
|
||||
TEST(MatchedFilterFieldTrialTest, WrongPreEchoConfigurationTest) {
|
||||
constexpr float kDefaultThreshold = 0.5f;
|
||||
constexpr int kDefaultMode = 3;
|
||||
float threshold_in = -0.1f;
|
||||
int mode_in = 5;
|
||||
rtc::StringBuilder field_trial_name;
|
||||
field_trial_name << "WebRTC-Aec3PreEchoConfiguration/threshold:"
|
||||
<< threshold_in << ",mode:" << mode_in << "/";
|
||||
webrtc::test::ScopedFieldTrials field_trials(field_trial_name.str());
|
||||
ApmDataDumper data_dumper(0);
|
||||
EchoCanceller3Config config;
|
||||
MatchedFilter matched_filter(
|
||||
&data_dumper, DetectOptimization(),
|
||||
kBlockSize / config.delay.down_sampling_factor,
|
||||
aec3::kWindowSizeSubBlocks, aec3::kNumMatchedFilters,
|
||||
aec3::kAlignmentShiftSubBlocks,
|
||||
config.render_levels.poor_excitation_render_limit,
|
||||
config.delay.delay_estimate_smoothing,
|
||||
config.delay.delay_estimate_smoothing_delay_found,
|
||||
config.delay.delay_candidate_detection_threshold,
|
||||
config.delay.detect_pre_echo);
|
||||
|
||||
auto& pre_echo_config = matched_filter.GetPreEchoConfiguration();
|
||||
EXPECT_EQ(pre_echo_config.threshold, kDefaultThreshold);
|
||||
EXPECT_EQ(pre_echo_config.mode, kDefaultMode);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user