Removed the AEC3 namespace This CL removes the AEC3 namespace to reduce the number of nested namespaces. As part of this removal, one of the functions (ComputeFrequencyResponse(..), and one class (MovingAverage), had to be renamed to avoid naming clashes. Bug: webrtc:42233815 Change-Id: I0f4dfac095f557cf1d6ee7d170c2f405eb0f7a9e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/454360 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Per Åhgren <peah@webrtc.org> Cr-Commit-Position: refs/heads/main@{#47130}
diff --git a/modules/audio_processing/aec3/BUILD.gn b/modules/audio_processing/aec3/BUILD.gn index 10b055f..6b5279b 100644 --- a/modules/audio_processing/aec3/BUILD.gn +++ b/modules/audio_processing/aec3/BUILD.gn
@@ -75,8 +75,8 @@ "matched_filter.cc", "matched_filter_lag_aggregator.cc", "matched_filter_lag_aggregator.h", - "moving_average.cc", - "moving_average.h", + "moving_average_spectrum.cc", + "moving_average_spectrum.h", "multi_channel_content_detector.cc", "multi_channel_content_detector.h", "nearend_detector.h", @@ -369,7 +369,7 @@ "frame_blocker_unittest.cc", "matched_filter_lag_aggregator_unittest.cc", "matched_filter_unittest.cc", - "moving_average_unittest.cc", + "moving_average_spectrum_unittest.cc", "multi_channel_content_detector_unittest.cc", "refined_filter_update_gain_unittest.cc", "render_buffer_unittest.cc",
diff --git a/modules/audio_processing/aec3/adaptive_fir_filter.cc b/modules/audio_processing/aec3/adaptive_fir_filter.cc index 52718c0..142f786 100644 --- a/modules/audio_processing/aec3/adaptive_fir_filter.cc +++ b/modules/audio_processing/aec3/adaptive_fir_filter.cc
@@ -34,10 +34,8 @@ namespace webrtc { -namespace aec3 { - // Computes and stores the frequency response of the filter. -void ComputeFrequencyResponse( +void ComputeFrequencyResponse_C( size_t num_partitions, const std::vector<std::vector<FftData>>& H, std::vector<std::array<float, kFftLengthBy2Plus1>>* H2) { @@ -455,8 +453,6 @@ } #endif -} // namespace aec3 - namespace { // Ensures that the newly added filter partitions after a size increase are set @@ -563,19 +559,19 @@ switch (optimization_) { #if defined(WEBRTC_ARCH_X86_FAMILY) case Aec3Optimization::kSse2: - aec3::ApplyFilter_Sse2(render_buffer, current_size_partitions_, H_, S); + ApplyFilter_Sse2(render_buffer, current_size_partitions_, H_, S); break; case Aec3Optimization::kAvx2: - aec3::ApplyFilter_Avx2(render_buffer, current_size_partitions_, H_, S); + ApplyFilter_Avx2(render_buffer, current_size_partitions_, H_, S); break; #endif #if defined(WEBRTC_HAS_NEON) case Aec3Optimization::kNeon: - aec3::ApplyFilter_Neon(render_buffer, current_size_partitions_, H_, S); + ApplyFilter_Neon(render_buffer, current_size_partitions_, H_, S); break; #endif default: - aec3::ApplyFilter(render_buffer, current_size_partitions_, H_, S); + ApplyFilter(render_buffer, current_size_partitions_, H_, S); } } @@ -607,19 +603,19 @@ switch (optimization_) { #if defined(WEBRTC_ARCH_X86_FAMILY) case Aec3Optimization::kSse2: - aec3::ComputeFrequencyResponse_Sse2(current_size_partitions_, H_, H2); + ComputeFrequencyResponse_Sse2(current_size_partitions_, H_, H2); break; case Aec3Optimization::kAvx2: - aec3::ComputeFrequencyResponse_Avx2(current_size_partitions_, H_, H2); + ComputeFrequencyResponse_Avx2(current_size_partitions_, H_, H2); break; #endif #if defined(WEBRTC_HAS_NEON) case Aec3Optimization::kNeon: - aec3::ComputeFrequencyResponse_Neon(current_size_partitions_, H_, H2); + ComputeFrequencyResponse_Neon(current_size_partitions_, H_, H2); break; #endif default: - aec3::ComputeFrequencyResponse(current_size_partitions_, H_, H2); + ComputeFrequencyResponse_C(current_size_partitions_, H_, H2); } } @@ -632,22 +628,19 @@ switch (optimization_) { #if defined(WEBRTC_ARCH_X86_FAMILY) case Aec3Optimization::kSse2: - aec3::AdaptPartitions_Sse2(render_buffer, G, current_size_partitions_, - &H_); + AdaptPartitions_Sse2(render_buffer, G, current_size_partitions_, &H_); break; case Aec3Optimization::kAvx2: - aec3::AdaptPartitions_Avx2(render_buffer, G, current_size_partitions_, - &H_); + AdaptPartitions_Avx2(render_buffer, G, current_size_partitions_, &H_); break; #endif #if defined(WEBRTC_HAS_NEON) case Aec3Optimization::kNeon: - aec3::AdaptPartitions_Neon(render_buffer, G, current_size_partitions_, - &H_); + AdaptPartitions_Neon(render_buffer, G, current_size_partitions_, &H_); break; #endif default: - aec3::AdaptPartitions(render_buffer, G, current_size_partitions_, &H_); + AdaptPartitions(render_buffer, G, current_size_partitions_, &H_); } }
diff --git a/modules/audio_processing/aec3/adaptive_fir_filter.h b/modules/audio_processing/aec3/adaptive_fir_filter.h index 681cd23..d960a2a 100644 --- a/modules/audio_processing/aec3/adaptive_fir_filter.h +++ b/modules/audio_processing/aec3/adaptive_fir_filter.h
@@ -25,9 +25,8 @@ #include "rtc_base/system/arch.h" namespace webrtc { -namespace aec3 { // Computes and stores the frequency response of the filter. -void ComputeFrequencyResponse( +void ComputeFrequencyResponse_C( size_t num_partitions, const std::vector<std::vector<FftData>>& H, std::vector<std::array<float, kFftLengthBy2Plus1>>* H2); @@ -95,8 +94,6 @@ FftData* S); #endif -} // namespace aec3 - // Provides a frequency domain adaptive filter functionality. class AdaptiveFirFilter { public:
diff --git a/modules/audio_processing/aec3/adaptive_fir_filter_avx2.cc b/modules/audio_processing/aec3/adaptive_fir_filter_avx2.cc index f250f84..327f0fb 100644 --- a/modules/audio_processing/aec3/adaptive_fir_filter_avx2.cc +++ b/modules/audio_processing/aec3/adaptive_fir_filter_avx2.cc
@@ -24,8 +24,6 @@ namespace webrtc { -namespace aec3 { - // Computes and stores the frequency response of the filter. void ComputeFrequencyResponse_Avx2( size_t num_partitions, @@ -193,5 +191,4 @@ } while (p < lim2); } -} // namespace aec3 } // namespace webrtc
diff --git a/modules/audio_processing/aec3/adaptive_fir_filter_erl.cc b/modules/audio_processing/aec3/adaptive_fir_filter_erl.cc index 77d1487..19ffe86 100644 --- a/modules/audio_processing/aec3/adaptive_fir_filter_erl.cc +++ b/modules/audio_processing/aec3/adaptive_fir_filter_erl.cc
@@ -31,8 +31,6 @@ namespace webrtc { -namespace aec3 { - // Computes and stores the echo return loss estimate of the filter, which is the // sum of the partition frequency responses. void ErlComputer(const std::vector<std::array<float, kFftLengthBy2Plus1>>& H2, @@ -82,8 +80,6 @@ } #endif -} // namespace aec3 - void ComputeErl(const Aec3Optimization& optimization, const std::vector<std::array<float, kFftLengthBy2Plus1>>& H2, std::span<float> erl) { @@ -92,19 +88,19 @@ switch (optimization) { #if defined(WEBRTC_ARCH_X86_FAMILY) case Aec3Optimization::kSse2: - aec3::ErlComputer_SSE2(H2, erl); + ErlComputer_SSE2(H2, erl); break; case Aec3Optimization::kAvx2: - aec3::ErlComputer_AVX2(H2, erl); + ErlComputer_AVX2(H2, erl); break; #endif #if defined(WEBRTC_HAS_NEON) case Aec3Optimization::kNeon: - aec3::ErlComputer_NEON(H2, erl); + ErlComputer_NEON(H2, erl); break; #endif default: - aec3::ErlComputer(H2, erl); + ErlComputer(H2, erl); } }
diff --git a/modules/audio_processing/aec3/adaptive_fir_filter_erl.h b/modules/audio_processing/aec3/adaptive_fir_filter_erl.h index d504d27..60a5c1e 100644 --- a/modules/audio_processing/aec3/adaptive_fir_filter_erl.h +++ b/modules/audio_processing/aec3/adaptive_fir_filter_erl.h
@@ -21,7 +21,6 @@ #include "rtc_base/system/arch.h" namespace webrtc { -namespace aec3 { // Computes and stores the echo return loss estimate of the filter, which is the // sum of the partition frequency responses. @@ -42,8 +41,6 @@ std::span<float> erl); #endif -} // namespace aec3 - // Computes the echo return loss based on a frequency response. void ComputeErl(const Aec3Optimization& optimization, const std::vector<std::array<float, kFftLengthBy2Plus1>>& H2,
diff --git a/modules/audio_processing/aec3/adaptive_fir_filter_erl_avx2.cc b/modules/audio_processing/aec3/adaptive_fir_filter_erl_avx2.cc index c3606aa..3b67f02 100644 --- a/modules/audio_processing/aec3/adaptive_fir_filter_erl_avx2.cc +++ b/modules/audio_processing/aec3/adaptive_fir_filter_erl_avx2.cc
@@ -21,8 +21,6 @@ namespace webrtc { -namespace aec3 { - // Computes and stores the echo return loss estimate of the filter, which is the // sum of the partition frequency responses. void ErlComputer_AVX2( @@ -40,5 +38,4 @@ } } -} // namespace aec3 } // namespace webrtc
diff --git a/modules/audio_processing/aec3/adaptive_fir_filter_erl_unittest.cc b/modules/audio_processing/aec3/adaptive_fir_filter_erl_unittest.cc index d95aad1..64d4f04 100644 --- a/modules/audio_processing/aec3/adaptive_fir_filter_erl_unittest.cc +++ b/modules/audio_processing/aec3/adaptive_fir_filter_erl_unittest.cc
@@ -25,7 +25,6 @@ #endif namespace webrtc { -namespace aec3 { #if defined(WEBRTC_HAS_NEON) // Verifies that the optimized method for echo return loss computation is @@ -105,5 +104,4 @@ #endif -} // namespace aec3 } // namespace webrtc
diff --git a/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc b/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc index 60e9628..e4c5481 100644 --- a/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc +++ b/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc
@@ -52,7 +52,6 @@ #endif namespace webrtc { -namespace aec3 { namespace { std::string ProduceDebugText(size_t num_render_channels, size_t delay) { @@ -168,7 +167,7 @@ } } - ComputeFrequencyResponse(num_partitions, H, &H2); + ComputeFrequencyResponse_C(num_partitions, H, &H2); ComputeFrequencyResponse_Neon(num_partitions, H, &H2_Neon); for (size_t p = 0; p < num_partitions; ++p) { @@ -348,7 +347,7 @@ } } - ComputeFrequencyResponse(num_partitions, H, &H2); + ComputeFrequencyResponse_C(num_partitions, H, &H2); ComputeFrequencyResponse_Sse2(num_partitions, H, &H2_Sse2); for (size_t p = 0; p < num_partitions; ++p) { @@ -383,7 +382,7 @@ } } - ComputeFrequencyResponse(num_partitions, H, &H2); + ComputeFrequencyResponse_C(num_partitions, H, &H2); ComputeFrequencyResponse_Avx2(num_partitions, H, &H2_Avx2); for (size_t p = 0; p < num_partitions; ++p) { @@ -620,5 +619,4 @@ } } -} // namespace aec3 } // namespace webrtc
diff --git a/modules/audio_processing/aec3/comfort_noise_generator.cc b/modules/audio_processing/aec3/comfort_noise_generator.cc index b7f30de..58b2323 100644 --- a/modules/audio_processing/aec3/comfort_noise_generator.cc +++ b/modules/audio_processing/aec3/comfort_noise_generator.cc
@@ -94,7 +94,7 @@ // Compute square root spectrum. std::array<float, kFftLengthBy2Plus1> N; std::copy(N2.begin(), N2.end(), N.begin()); - aec3::VectorMath(optimization).Sqrt(N); + VectorMath(optimization).Sqrt(N); // Compute the noise level for the upper bands. constexpr float kOneByNumBands = 1.f / (kFftLengthBy2Plus1 / 2 + 1);
diff --git a/modules/audio_processing/aec3/comfort_noise_generator.h b/modules/audio_processing/aec3/comfort_noise_generator.h index c28e269..05cd43e 100644 --- a/modules/audio_processing/aec3/comfort_noise_generator.h +++ b/modules/audio_processing/aec3/comfort_noise_generator.h
@@ -25,7 +25,6 @@ #include "rtc_base/system/arch.h" namespace webrtc { -namespace aec3 { #if defined(WEBRTC_ARCH_X86_FAMILY) void EstimateComfortNoise_SSE2(const std::array<float, kFftLengthBy2Plus1>& N2, @@ -38,8 +37,6 @@ FftData* lower_band_noise, FftData* upper_band_noise); -} // namespace aec3 - // Generates the comfort noise. class ComfortNoiseGenerator { public:
diff --git a/modules/audio_processing/aec3/comfort_noise_generator_unittest.cc b/modules/audio_processing/aec3/comfort_noise_generator_unittest.cc index 17ce047..e985023 100644 --- a/modules/audio_processing/aec3/comfort_noise_generator_unittest.cc +++ b/modules/audio_processing/aec3/comfort_noise_generator_unittest.cc
@@ -23,7 +23,6 @@ #include "test/gtest.h" namespace webrtc { -namespace aec3 { namespace { float Power(const FftData& N) { @@ -70,5 +69,4 @@ } } -} // namespace aec3 } // namespace webrtc
diff --git a/modules/audio_processing/aec3/echo_remover_metrics.cc b/modules/audio_processing/aec3/echo_remover_metrics.cc index fce3964..a3f3167 100644 --- a/modules/audio_processing/aec3/echo_remover_metrics.cc +++ b/modules/audio_processing/aec3/echo_remover_metrics.cc
@@ -78,35 +78,35 @@ case kMetricsCollectionBlocks + 2: RTC_HISTOGRAM_COUNTS_LINEAR( "WebRTC.Audio.EchoCanceller.Erl.Value", - aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 30.f, 1.f, - erl_time_domain_.sum_value), + TransformDbMetricForReporting(true, 0.f, 59.f, 30.f, 1.f, + erl_time_domain_.sum_value), 0, 59, 30); RTC_HISTOGRAM_COUNTS_LINEAR( "WebRTC.Audio.EchoCanceller.Erl.Max", - aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 30.f, 1.f, - erl_time_domain_.ceil_value), + TransformDbMetricForReporting(true, 0.f, 59.f, 30.f, 1.f, + erl_time_domain_.ceil_value), 0, 59, 30); RTC_HISTOGRAM_COUNTS_LINEAR( "WebRTC.Audio.EchoCanceller.Erl.Min", - aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 30.f, 1.f, - erl_time_domain_.floor_value), + TransformDbMetricForReporting(true, 0.f, 59.f, 30.f, 1.f, + erl_time_domain_.floor_value), 0, 59, 30); break; case kMetricsCollectionBlocks + 3: RTC_HISTOGRAM_COUNTS_LINEAR( "WebRTC.Audio.EchoCanceller.Erle.Value", - aec3::TransformDbMetricForReporting(false, 0.f, 19.f, 0.f, 1.f, - erle_time_domain_.sum_value), + TransformDbMetricForReporting(false, 0.f, 19.f, 0.f, 1.f, + erle_time_domain_.sum_value), 0, 19, 20); RTC_HISTOGRAM_COUNTS_LINEAR( "WebRTC.Audio.EchoCanceller.Erle.Max", - aec3::TransformDbMetricForReporting(false, 0.f, 19.f, 0.f, 1.f, - erle_time_domain_.ceil_value), + TransformDbMetricForReporting(false, 0.f, 19.f, 0.f, 1.f, + erle_time_domain_.ceil_value), 0, 19, 20); RTC_HISTOGRAM_COUNTS_LINEAR( "WebRTC.Audio.EchoCanceller.Erle.Min", - aec3::TransformDbMetricForReporting(false, 0.f, 19.f, 0.f, 1.f, - erle_time_domain_.floor_value), + TransformDbMetricForReporting(false, 0.f, 19.f, 0.f, 1.f, + erle_time_domain_.floor_value), 0, 19, 20); metrics_reported_ = true; RTC_DCHECK_EQ(kMetricsReportingIntervalBlocks, block_counter_); @@ -120,8 +120,6 @@ } } -namespace aec3 { - void UpdateDbMetric(const std::array<float, kFftLengthBy2Plus1>& value, std::array<EchoRemoverMetrics::DbMetric, 2>* statistic) { RTC_DCHECK(statistic); @@ -153,6 +151,4 @@ return static_cast<int>(SafeClamp(new_value, min_value, max_value)); } -} // namespace aec3 - } // namespace webrtc
diff --git a/modules/audio_processing/aec3/echo_remover_metrics.h b/modules/audio_processing/aec3/echo_remover_metrics.h index aec8084..ebcd277 100644 --- a/modules/audio_processing/aec3/echo_remover_metrics.h +++ b/modules/audio_processing/aec3/echo_remover_metrics.h
@@ -56,8 +56,6 @@ bool metrics_reported_ = false; }; -namespace aec3 { - // Updates a banded metric of type DbMetric with the values in the supplied // array. void UpdateDbMetric(const std::array<float, kFftLengthBy2Plus1>& value, @@ -71,8 +69,6 @@ float scaling, float value); -} // namespace aec3 - } // namespace webrtc #endif // MODULES_AUDIO_PROCESSING_AEC3_ECHO_REMOVER_METRICS_H_
diff --git a/modules/audio_processing/aec3/echo_remover_metrics_unittest.cc b/modules/audio_processing/aec3/echo_remover_metrics_unittest.cc index 85b04b7..b087ad1 100644 --- a/modules/audio_processing/aec3/echo_remover_metrics_unittest.cc +++ b/modules/audio_processing/aec3/echo_remover_metrics_unittest.cc
@@ -31,7 +31,7 @@ TEST(UpdateDbMetricDeathTest, NullValue) { std::array<float, kFftLengthBy2Plus1> value; value.fill(0.f); - EXPECT_DEATH(aec3::UpdateDbMetric(value, nullptr), ""); + EXPECT_DEATH(UpdateDbMetric(value, nullptr), ""); } #endif @@ -46,7 +46,7 @@ std::fill(value.begin(), value.begin() + 32, kValue0); std::fill(value.begin() + 32, value.begin() + 64, kValue1); - aec3::UpdateDbMetric(value, &statistic); + UpdateDbMetric(value, &statistic); EXPECT_FLOAT_EQ(kValue0, statistic[0].sum_value); EXPECT_FLOAT_EQ(kValue0, statistic[0].ceil_value); EXPECT_FLOAT_EQ(kValue0, statistic[0].floor_value); @@ -54,7 +54,7 @@ EXPECT_FLOAT_EQ(kValue1, statistic[1].ceil_value); EXPECT_FLOAT_EQ(kValue1, statistic[1].floor_value); - aec3::UpdateDbMetric(value, &statistic); + UpdateDbMetric(value, &statistic); EXPECT_FLOAT_EQ(2.f * kValue0, statistic[0].sum_value); EXPECT_FLOAT_EQ(kValue0, statistic[0].ceil_value); EXPECT_FLOAT_EQ(kValue0, statistic[0].floor_value); @@ -78,26 +78,26 @@ EXPECT_NEAR(offset, -90.3f, 0.1f); EXPECT_EQ( static_cast<int>(30.3f), - aec3::TransformDbMetricForReporting( - true, 0.f, 90.f, offset, 1.f / (kBlockSize * kBlockSize), X2[0])); + TransformDbMetricForReporting(true, 0.f, 90.f, offset, + 1.f / (kBlockSize * kBlockSize), X2[0])); } // Verifies that the TransformDbMetricForReporting method is able to properly // limit the output. TEST(TransformDbMetricForReporting, Limits) { - EXPECT_EQ(0, aec3::TransformDbMetricForReporting(false, 0.f, 10.f, 0.f, 1.f, - 0.001f)); - EXPECT_EQ(10, aec3::TransformDbMetricForReporting(false, 0.f, 10.f, 0.f, 1.f, - 100.f)); + EXPECT_EQ(0, + TransformDbMetricForReporting(false, 0.f, 10.f, 0.f, 1.f, 0.001f)); + EXPECT_EQ(10, + TransformDbMetricForReporting(false, 0.f, 10.f, 0.f, 1.f, 100.f)); } // Verifies that the TransformDbMetricForReporting method is able to properly // negate output. TEST(TransformDbMetricForReporting, Negate) { - EXPECT_EQ(10, aec3::TransformDbMetricForReporting(true, -20.f, 20.f, 0.f, 1.f, - 0.1f)); - EXPECT_EQ(-10, aec3::TransformDbMetricForReporting(true, -20.f, 20.f, 0.f, - 1.f, 10.f)); + EXPECT_EQ(10, + TransformDbMetricForReporting(true, -20.f, 20.f, 0.f, 1.f, 0.1f)); + EXPECT_EQ(-10, + TransformDbMetricForReporting(true, -20.f, 20.f, 0.f, 1.f, 10.f)); } // Verify the Update functionality of DbMetric.
diff --git a/modules/audio_processing/aec3/matched_filter.cc b/modules/audio_processing/aec3/matched_filter.cc index 961d8a8..69962e9 100644 --- a/modules/audio_processing/aec3/matched_filter.cc +++ b/modules/audio_processing/aec3/matched_filter.cc
@@ -79,8 +79,6 @@ } // namespace -namespace aec3 { - #if defined(WEBRTC_HAS_NEON) inline float SumAllElements(float32x4_t elements) { @@ -591,8 +589,6 @@ return lag_estimate1; } -} // namespace aec3 - MatchedFilter::MatchedFilter(ApmDataDumper* data_dumper, Aec3Optimization optimization, size_t sub_block_size, @@ -694,13 +690,13 @@ switch (optimization_) { #if defined(WEBRTC_ARCH_X86_FAMILY) case Aec3Optimization::kSse2: - aec3::MatchedFilterCore_SSE2( + MatchedFilterCore_SSE2( x_start_index, x2_sum_threshold, smoothing, render_buffer.buffer, y, filters_[n], &filters_updated, &error_sum, compute_pre_echo, instantaneous_accumulated_error_, scratch_memory_); break; case Aec3Optimization::kAvx2: - aec3::MatchedFilterCore_AVX2( + MatchedFilterCore_AVX2( x_start_index, x2_sum_threshold, smoothing, render_buffer.buffer, y, filters_[n], &filters_updated, &error_sum, compute_pre_echo, instantaneous_accumulated_error_, scratch_memory_); @@ -708,23 +704,23 @@ #endif #if defined(WEBRTC_HAS_NEON) case Aec3Optimization::kNeon: - aec3::MatchedFilterCore_NEON( + MatchedFilterCore_NEON( x_start_index, x2_sum_threshold, smoothing, render_buffer.buffer, y, filters_[n], &filters_updated, &error_sum, compute_pre_echo, instantaneous_accumulated_error_, scratch_memory_); break; #endif default: - aec3::MatchedFilterCore(x_start_index, x2_sum_threshold, smoothing, - render_buffer.buffer, y, filters_[n], - &filters_updated, &error_sum, compute_pre_echo, - instantaneous_accumulated_error_); + MatchedFilterCore(x_start_index, x2_sum_threshold, smoothing, + render_buffer.buffer, y, filters_[n], + &filters_updated, &error_sum, compute_pre_echo, + instantaneous_accumulated_error_); } // Estimate the lag in the matched filter as the distance to the portion in // the filter that contributes the most to the matched filter output. This // is detected as the peak of the matched filter. - const size_t lag_estimate = aec3::MaxSquarePeakIndex(filters_[n]); + const size_t lag_estimate = MaxSquarePeakIndex(filters_[n]); const bool reliable = lag_estimate > 2 && lag_estimate < (filters_[n].size() - 10) && error_sum < matching_filter_threshold_ * error_sum_anchor; @@ -798,7 +794,7 @@ void MatchedFilter::Dump() { for (size_t n = 0; n < filters_.size(); ++n) { - const size_t lag_estimate = aec3::MaxSquarePeakIndex(filters_[n]); + const size_t lag_estimate = MaxSquarePeakIndex(filters_[n]); std::string dumper_filter = "aec3_correlator_" + std::to_string(n) + "_h"; data_dumper_->DumpRaw(dumper_filter.c_str(), filters_[n]); std::string dumper_lag = "aec3_correlator_lag_" + std::to_string(n);
diff --git a/modules/audio_processing/aec3/matched_filter.h b/modules/audio_processing/aec3/matched_filter.h index 993670e..b0b7a0d 100644 --- a/modules/audio_processing/aec3/matched_filter.h +++ b/modules/audio_processing/aec3/matched_filter.h
@@ -25,8 +25,6 @@ class ApmDataDumper; struct DownsampledRenderBuffer; -namespace aec3 { - #if defined(WEBRTC_HAS_NEON) // Filter core for the matched filter that is optimized for NEON. @@ -89,8 +87,6 @@ // Find largest peak of squared values in array. size_t MaxSquarePeakIndex(std::span<const float> h); -} // namespace aec3 - // Produces recursively updated cross-correlation estimates for several signal // shifts where the intra-shift spacing is uniform. class MatchedFilter {
diff --git a/modules/audio_processing/aec3/matched_filter_avx2.cc b/modules/audio_processing/aec3/matched_filter_avx2.cc index 0b9360c..eacd648 100644 --- a/modules/audio_processing/aec3/matched_filter_avx2.cc +++ b/modules/audio_processing/aec3/matched_filter_avx2.cc
@@ -18,7 +18,6 @@ #include "rtc_base/checks.h" namespace webrtc { -namespace aec3 { // Let ha denote the horizontal of a, and hb the horizontal sum of b // returns [ha, hb, ha, hb] @@ -259,5 +258,4 @@ } } -} // namespace aec3 } // namespace webrtc
diff --git a/modules/audio_processing/aec3/matched_filter_unittest.cc b/modules/audio_processing/aec3/matched_filter_unittest.cc index 7369ec2..d7f6f5e 100644 --- a/modules/audio_processing/aec3/matched_filter_unittest.cc +++ b/modules/audio_processing/aec3/matched_filter_unittest.cc
@@ -41,7 +41,6 @@ #endif namespace webrtc { -namespace aec3 { namespace { std::string ProduceDebugText(size_t delay, size_t down_sampling_factor) { @@ -565,5 +564,4 @@ #endif -} // namespace aec3 } // namespace webrtc
diff --git a/modules/audio_processing/aec3/moving_average.cc b/modules/audio_processing/aec3/moving_average_spectrum.cc similarity index 80% rename from modules/audio_processing/aec3/moving_average.cc rename to modules/audio_processing/aec3/moving_average_spectrum.cc index 503b86b..3884c4a 100644 --- a/modules/audio_processing/aec3/moving_average.cc +++ b/modules/audio_processing/aec3/moving_average_spectrum.cc
@@ -9,7 +9,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "modules/audio_processing/aec3/moving_average.h" +#include "modules/audio_processing/aec3/moving_average_spectrum.h" #include <algorithm> #include <cstddef> @@ -19,9 +19,8 @@ #include "rtc_base/checks.h" namespace webrtc { -namespace aec3 { -MovingAverage::MovingAverage(size_t num_elem, size_t mem_len) +MovingAverageSpectrum::MovingAverageSpectrum(size_t num_elem, size_t mem_len) : num_elem_(num_elem), mem_len_(mem_len - 1), scaling_(1.0f / static_cast<float>(mem_len)), @@ -31,10 +30,10 @@ RTC_DCHECK(mem_len > 0); } -MovingAverage::~MovingAverage() = default; +MovingAverageSpectrum::~MovingAverageSpectrum() = default; -void MovingAverage::Average(std::span<const float> input, - std::span<float> output) { +void MovingAverageSpectrum::Average(std::span<const float> input, + std::span<float> output) { RTC_DCHECK(input.size() == num_elem_); RTC_DCHECK(output.size() == num_elem_); @@ -58,5 +57,4 @@ } } -} // namespace aec3 } // namespace webrtc
diff --git a/modules/audio_processing/aec3/moving_average.h b/modules/audio_processing/aec3/moving_average_spectrum.h similarity index 65% rename from modules/audio_processing/aec3/moving_average.h rename to modules/audio_processing/aec3/moving_average_spectrum.h index 77e2a59..b4a3763 100644 --- a/modules/audio_processing/aec3/moving_average.h +++ b/modules/audio_processing/aec3/moving_average_spectrum.h
@@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef MODULES_AUDIO_PROCESSING_AEC3_MOVING_AVERAGE_H_ -#define MODULES_AUDIO_PROCESSING_AEC3_MOVING_AVERAGE_H_ +#ifndef MODULES_AUDIO_PROCESSING_AEC3_MOVING_AVERAGE_SPECTRUM_H_ +#define MODULES_AUDIO_PROCESSING_AEC3_MOVING_AVERAGE_SPECTRUM_H_ #include <stddef.h> @@ -17,14 +17,13 @@ #include <vector> namespace webrtc { -namespace aec3 { -class MovingAverage { +class MovingAverageSpectrum { public: - // Creates an instance of MovingAverage that accepts inputs of length num_elem - // and averages over mem_len inputs. - MovingAverage(size_t num_elem, size_t mem_len); - ~MovingAverage(); + // Creates an instance of MovingAverageSpectrum that accepts inputs of length + // num_elem and averages over mem_len inputs. + MovingAverageSpectrum(size_t num_elem, size_t mem_len); + ~MovingAverageSpectrum(); // Computes the average of input and mem_len-1 previous inputs and stores the // result in output. @@ -38,7 +37,6 @@ size_t mem_index_; }; -} // namespace aec3 } // namespace webrtc -#endif // MODULES_AUDIO_PROCESSING_AEC3_MOVING_AVERAGE_H_ +#endif // MODULES_AUDIO_PROCESSING_AEC3_MOVING_AVERAGE_SPECTRUM_H_
diff --git a/modules/audio_processing/aec3/moving_average_unittest.cc b/modules/audio_processing/aec3/moving_average_spectrum_unittest.cc similarity index 92% rename from modules/audio_processing/aec3/moving_average_unittest.cc rename to modules/audio_processing/aec3/moving_average_spectrum_unittest.cc index ca98517..718069b 100644 --- a/modules/audio_processing/aec3/moving_average_unittest.cc +++ b/modules/audio_processing/aec3/moving_average_spectrum_unittest.cc
@@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "modules/audio_processing/aec3/moving_average.h" +#include "modules/audio_processing/aec3/moving_average_spectrum.h" #include <array> #include <cstddef> @@ -17,11 +17,11 @@ namespace webrtc { -TEST(MovingAverage, Average) { +TEST(MovingAverageSpectrum, Average) { constexpr size_t num_elem = 4; constexpr size_t mem_len = 3; constexpr float e = 1e-6f; - aec3::MovingAverage ma(num_elem, mem_len); + MovingAverageSpectrum ma(num_elem, mem_len); std::array<float, num_elem> data1 = {1, 2, 3, 4}; std::array<float, num_elem> data2 = {5, 1, 9, 7}; std::array<float, num_elem> data3 = {3, 3, 5, 6}; @@ -53,11 +53,11 @@ EXPECT_NEAR(output[3], (data2[3] + data3[3] + data4[3]) / 3.0f, e); } -TEST(MovingAverage, PassThrough) { +TEST(MovingAverageSpectrum, PassThrough) { constexpr size_t num_elem = 4; constexpr size_t mem_len = 1; constexpr float e = 1e-6f; - aec3::MovingAverage ma(num_elem, mem_len); + MovingAverageSpectrum ma(num_elem, mem_len); std::array<float, num_elem> data1 = {1, 2, 3, 4}; std::array<float, num_elem> data2 = {5, 1, 9, 7}; std::array<float, num_elem> data3 = {3, 3, 5, 6};
diff --git a/modules/audio_processing/aec3/subband_nearend_detector.cc b/modules/audio_processing/aec3/subband_nearend_detector.cc index e569a3f..39908ac 100644 --- a/modules/audio_processing/aec3/subband_nearend_detector.cc +++ b/modules/audio_processing/aec3/subband_nearend_detector.cc
@@ -17,7 +17,7 @@ #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/aec3_common.h" -#include "modules/audio_processing/aec3/moving_average.h" +#include "modules/audio_processing/aec3/moving_average_spectrum.h" namespace webrtc { SubbandNearendDetector::SubbandNearendDetector( @@ -26,8 +26,8 @@ : config_(config), num_capture_channels_(num_capture_channels), nearend_smoothers_(num_capture_channels_, - aec3::MovingAverage(kFftLengthBy2Plus1, - config_.nearend_average_blocks)), + MovingAverageSpectrum(kFftLengthBy2Plus1, + config_.nearend_average_blocks)), one_over_subband_length1_( 1.f / (config_.subband1.high - config_.subband1.low + 1)), one_over_subband_length2_(
diff --git a/modules/audio_processing/aec3/subband_nearend_detector.h b/modules/audio_processing/aec3/subband_nearend_detector.h index 635e063..5b43331 100644 --- a/modules/audio_processing/aec3/subband_nearend_detector.h +++ b/modules/audio_processing/aec3/subband_nearend_detector.h
@@ -18,7 +18,7 @@ #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/aec3_common.h" -#include "modules/audio_processing/aec3/moving_average.h" +#include "modules/audio_processing/aec3/moving_average_spectrum.h" #include "modules/audio_processing/aec3/nearend_detector.h" namespace webrtc { @@ -44,7 +44,7 @@ private: const EchoCanceller3Config::Suppressor::SubbandNearendDetection config_; const size_t num_capture_channels_; - std::vector<aec3::MovingAverage> nearend_smoothers_; + std::vector<MovingAverageSpectrum> nearend_smoothers_; const float one_over_subband_length1_; const float one_over_subband_length2_; bool nearend_state_ = false;
diff --git a/modules/audio_processing/aec3/suppression_filter.cc b/modules/audio_processing/aec3/suppression_filter.cc index b5a6f79..bd895e8 100644 --- a/modules/audio_processing/aec3/suppression_filter.cc +++ b/modules/audio_processing/aec3/suppression_filter.cc
@@ -100,7 +100,7 @@ for (size_t i = 0; i < kFftLengthBy2Plus1; ++i) { noise_gain[i] = 1.f - suppression_gain[i] * suppression_gain[i]; } - aec3::VectorMath(optimization_).Sqrt(noise_gain); + VectorMath(optimization_).Sqrt(noise_gain); const float high_bands_noise_scaling = 0.4f * std::sqrt(1.f - high_bands_gain * high_bands_gain);
diff --git a/modules/audio_processing/aec3/suppression_gain.cc b/modules/audio_processing/aec3/suppression_gain.cc index bd92aff..aab8a32 100644 --- a/modules/audio_processing/aec3/suppression_gain.cc +++ b/modules/audio_processing/aec3/suppression_gain.cc
@@ -25,7 +25,7 @@ #include "modules/audio_processing/aec3/aec_state.h" #include "modules/audio_processing/aec3/block.h" #include "modules/audio_processing/aec3/dominant_nearend_detector.h" -#include "modules/audio_processing/aec3/moving_average.h" +#include "modules/audio_processing/aec3/moving_average_spectrum.h" #include "modules/audio_processing/aec3/render_signal_analyzer.h" #include "modules/audio_processing/aec3/subband_nearend_detector.h" #include "modules/audio_processing/aec3/vector_math.h" @@ -333,7 +333,7 @@ std::copy(gain->begin(), gain->end(), last_gain_.begin()); // Transform gains to amplitude domain. - aec3::VectorMath(optimization_).Sqrt(*gain); + VectorMath(optimization_).Sqrt(*gain); } SuppressionGain::SuppressionGain(const EchoCanceller3Config& config, @@ -350,8 +350,8 @@ last_echo_(num_capture_channels_, {0}), nearend_smoothers_( num_capture_channels_, - aec3::MovingAverage(kFftLengthBy2Plus1, - config.suppressor.nearend_average_blocks)), + MovingAverageSpectrum(kFftLengthBy2Plus1, + config.suppressor.nearend_average_blocks)), nearend_params_(config_.suppressor.last_lf_band, config_.suppressor.first_hf_band, config_.suppressor.nearend_tuning),
diff --git a/modules/audio_processing/aec3/suppression_gain.h b/modules/audio_processing/aec3/suppression_gain.h index 550b533..4bcd0d2 100644 --- a/modules/audio_processing/aec3/suppression_gain.h +++ b/modules/audio_processing/aec3/suppression_gain.h
@@ -23,7 +23,7 @@ #include "modules/audio_processing/aec3/aec3_common.h" #include "modules/audio_processing/aec3/aec_state.h" #include "modules/audio_processing/aec3/block.h" -#include "modules/audio_processing/aec3/moving_average.h" +#include "modules/audio_processing/aec3/moving_average_spectrum.h" #include "modules/audio_processing/aec3/nearend_detector.h" #include "modules/audio_processing/aec3/render_signal_analyzer.h" #include "modules/audio_processing/logging/apm_data_dumper.h" @@ -130,7 +130,7 @@ LowNoiseRenderDetector low_render_detector_; bool initial_state_ = true; int initial_state_change_counter_ = 0; - std::vector<aec3::MovingAverage> nearend_smoothers_; + std::vector<MovingAverageSpectrum> nearend_smoothers_; const GainParameters nearend_params_; const GainParameters normal_params_; // Determines if the dominant nearend detector uses the unbounded residual
diff --git a/modules/audio_processing/aec3/suppression_gain_unittest.cc b/modules/audio_processing/aec3/suppression_gain_unittest.cc index 2da9589..60d290d 100644 --- a/modules/audio_processing/aec3/suppression_gain_unittest.cc +++ b/modules/audio_processing/aec3/suppression_gain_unittest.cc
@@ -34,7 +34,6 @@ #include "test/gtest.h" namespace webrtc { -namespace aec3 { #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) @@ -160,5 +159,4 @@ [](float a) { EXPECT_NEAR(0.0f, a, 0.001f); }); } -} // namespace aec3 } // namespace webrtc
diff --git a/modules/audio_processing/aec3/vector_math.h b/modules/audio_processing/aec3/vector_math.h index d8b5ecf..c733aa0 100644 --- a/modules/audio_processing/aec3/vector_math.h +++ b/modules/audio_processing/aec3/vector_math.h
@@ -29,7 +29,6 @@ #endif namespace webrtc { -namespace aec3 { // Provides optimizations for mathematical operations based on vectors. class VectorMath { @@ -220,8 +219,6 @@ Aec3Optimization optimization_; }; -} // namespace aec3 - } // namespace webrtc #endif // MODULES_AUDIO_PROCESSING_AEC3_VECTOR_MATH_H_
diff --git a/modules/audio_processing/aec3/vector_math_avx2.cc b/modules/audio_processing/aec3/vector_math_avx2.cc index 2288420..ec25104 100644 --- a/modules/audio_processing/aec3/vector_math_avx2.cc +++ b/modules/audio_processing/aec3/vector_math_avx2.cc
@@ -17,7 +17,6 @@ #include "rtc_base/checks.h" namespace webrtc { -namespace aec3 { // Elementwise square root. void VectorMath::SqrtAVX2(std::span<float> x) { @@ -77,5 +76,4 @@ } } -} // namespace aec3 } // namespace webrtc
diff --git a/modules/audio_processing/aec3/vector_math_unittest.cc b/modules/audio_processing/aec3/vector_math_unittest.cc index a47263b..1f3525b 100644 --- a/modules/audio_processing/aec3/vector_math_unittest.cc +++ b/modules/audio_processing/aec3/vector_math_unittest.cc
@@ -34,9 +34,9 @@ } std::copy(x.begin(), x.end(), z.begin()); - aec3::VectorMath(Aec3Optimization::kNone).Sqrt(z); + VectorMath(Aec3Optimization::kNone).Sqrt(z); std::copy(x.begin(), x.end(), z_neon.begin()); - aec3::VectorMath(Aec3Optimization::kNeon).Sqrt(z_neon); + VectorMath(Aec3Optimization::kNeon).Sqrt(z_neon); for (size_t k = 0; k < z.size(); ++k) { EXPECT_NEAR(z[k], z_neon[k], 0.0001f); EXPECT_NEAR(sqrtf(x[k]), z_neon[k], 0.0001f); @@ -54,8 +54,8 @@ y[k] = (2.f / 3.f) * k; } - aec3::VectorMath(Aec3Optimization::kNone).Multiply(x, y, z); - aec3::VectorMath(Aec3Optimization::kNeon).Multiply(x, y, z_neon); + VectorMath(Aec3Optimization::kNone).Multiply(x, y, z); + VectorMath(Aec3Optimization::kNeon).Multiply(x, y, z_neon); for (size_t k = 0; k < z.size(); ++k) { EXPECT_FLOAT_EQ(z[k], z_neon[k]); EXPECT_FLOAT_EQ(x[k] * y[k], z_neon[k]); @@ -72,8 +72,8 @@ z[k] = z_neon[k] = 2.f * k; } - aec3::VectorMath(Aec3Optimization::kNone).Accumulate(x, z); - aec3::VectorMath(Aec3Optimization::kNeon).Accumulate(x, z_neon); + VectorMath(Aec3Optimization::kNone).Accumulate(x, z); + VectorMath(Aec3Optimization::kNeon).Accumulate(x, z_neon); for (size_t k = 0; k < z.size(); ++k) { EXPECT_FLOAT_EQ(z[k], z_neon[k]); EXPECT_FLOAT_EQ(x[k] + 2.f * x[k], z_neon[k]); @@ -94,9 +94,9 @@ } std::copy(x.begin(), x.end(), z.begin()); - aec3::VectorMath(Aec3Optimization::kNone).Sqrt(z); + VectorMath(Aec3Optimization::kNone).Sqrt(z); std::copy(x.begin(), x.end(), z_sse2.begin()); - aec3::VectorMath(Aec3Optimization::kSse2).Sqrt(z_sse2); + VectorMath(Aec3Optimization::kSse2).Sqrt(z_sse2); EXPECT_EQ(z, z_sse2); for (size_t k = 0; k < z.size(); ++k) { EXPECT_FLOAT_EQ(z[k], z_sse2[k]); @@ -116,9 +116,9 @@ } std::copy(x.begin(), x.end(), z.begin()); - aec3::VectorMath(Aec3Optimization::kNone).Sqrt(z); + VectorMath(Aec3Optimization::kNone).Sqrt(z); std::copy(x.begin(), x.end(), z_avx2.begin()); - aec3::VectorMath(Aec3Optimization::kAvx2).Sqrt(z_avx2); + VectorMath(Aec3Optimization::kAvx2).Sqrt(z_avx2); EXPECT_EQ(z, z_avx2); for (size_t k = 0; k < z.size(); ++k) { EXPECT_FLOAT_EQ(z[k], z_avx2[k]); @@ -139,8 +139,8 @@ y[k] = (2.f / 3.f) * k; } - aec3::VectorMath(Aec3Optimization::kNone).Multiply(x, y, z); - aec3::VectorMath(Aec3Optimization::kSse2).Multiply(x, y, z_sse2); + VectorMath(Aec3Optimization::kNone).Multiply(x, y, z); + VectorMath(Aec3Optimization::kSse2).Multiply(x, y, z_sse2); for (size_t k = 0; k < z.size(); ++k) { EXPECT_FLOAT_EQ(z[k], z_sse2[k]); EXPECT_FLOAT_EQ(x[k] * y[k], z_sse2[k]); @@ -160,8 +160,8 @@ y[k] = (2.f / 3.f) * k; } - aec3::VectorMath(Aec3Optimization::kNone).Multiply(x, y, z); - aec3::VectorMath(Aec3Optimization::kAvx2).Multiply(x, y, z_avx2); + VectorMath(Aec3Optimization::kNone).Multiply(x, y, z); + VectorMath(Aec3Optimization::kAvx2).Multiply(x, y, z_avx2); for (size_t k = 0; k < z.size(); ++k) { EXPECT_FLOAT_EQ(z[k], z_avx2[k]); EXPECT_FLOAT_EQ(x[k] * y[k], z_avx2[k]); @@ -180,8 +180,8 @@ z[k] = z_sse2[k] = 2.f * k; } - aec3::VectorMath(Aec3Optimization::kNone).Accumulate(x, z); - aec3::VectorMath(Aec3Optimization::kSse2).Accumulate(x, z_sse2); + VectorMath(Aec3Optimization::kNone).Accumulate(x, z); + VectorMath(Aec3Optimization::kSse2).Accumulate(x, z_sse2); for (size_t k = 0; k < z.size(); ++k) { EXPECT_FLOAT_EQ(z[k], z_sse2[k]); EXPECT_FLOAT_EQ(x[k] + 2.f * x[k], z_sse2[k]); @@ -200,8 +200,8 @@ z[k] = z_avx2[k] = 2.f * k; } - aec3::VectorMath(Aec3Optimization::kNone).Accumulate(x, z); - aec3::VectorMath(Aec3Optimization::kAvx2).Accumulate(x, z_avx2); + VectorMath(Aec3Optimization::kNone).Accumulate(x, z); + VectorMath(Aec3Optimization::kAvx2).Accumulate(x, z_avx2); for (size_t k = 0; k < z.size(); ++k) { EXPECT_FLOAT_EQ(z[k], z_avx2[k]); EXPECT_FLOAT_EQ(x[k] + 2.f * x[k], z_avx2[k]);