Index: webrtc/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc |
diff --git a/webrtc/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc b/webrtc/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f5eda74438c42d285d5ebcc6a192f6c8a4cab4e8 |
--- /dev/null |
+++ b/webrtc/modules/audio_processing/aec3/adaptive_fir_filter_unittest.cc |
@@ -0,0 +1,148 @@ |
+/* |
+ * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include "webrtc/modules/audio_processing/aec3/adaptive_fir_filter.h" |
+ |
+#include <algorithm> |
+#include <numeric> |
+#include <string> |
+ |
+#include "webrtc/base/arraysize.h" |
+#include "webrtc/base/random.h" |
+#include "webrtc/modules/audio_processing/aec3/aec3_fft.h" |
+#include "webrtc/modules/audio_processing/aec3/delay_handler.h" |
+#include "webrtc/modules/audio_processing/aec3/render_signal_analyzer.h" |
+#include "webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.h" |
+#include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" |
+#include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" |
+#include "webrtc/test/gtest.h" |
+ |
+namespace webrtc { |
+namespace { |
+ |
+std::string ProduceDebugText(size_t delay) { |
+ std::ostringstream ss; |
+ ss << ", Delay: " << delay; |
+ return ss.str(); |
+} |
+ |
+} // namespace |
+ |
+#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
+// Verifies that the check for non-null data dumper works. |
+TEST(AdaptiveFirFilter, NullDataDumper) { |
+ EXPECT_DEATH(AdaptiveFirFilter(9, true, nullptr), ""); |
+} |
+ |
+// Verifies that the check for non-null data dumper works. |
hlundin-webrtc
2017/02/13 21:37:00
Copy-paste error in comment.
peah-webrtc
2017/02/20 07:37:14
Done.
|
+TEST(AdaptiveFirFilter, NullFilterOutput) { |
+ ApmDataDumper data_dumper(42); |
+ AdaptiveFirFilter filter(9, true, &data_dumper); |
+ FftBuffer X_buffer(filter.SizePartitions(), |
+ std::vector<size_t>(1, filter.SizePartitions())); |
+ EXPECT_DEATH(filter.Filter(X_buffer, nullptr), ""); |
+} |
+ |
+// Verifies that the check for whether filter statistics are being generated |
+// works when retrieving the ERL. |
+TEST(AdaptiveFirFilter, ErlAccessWhenNoFilterStatistics) { |
+ ApmDataDumper data_dumper(42); |
+ AdaptiveFirFilter filter(9, false, &data_dumper); |
+ EXPECT_DEATH(filter.Erl(), ""); |
+} |
+ |
+// Verifies that the check for whether filter statistics are being generated |
+// works when retrieving the filter frequencyResponse. |
+TEST(AdaptiveFirFilter, FilterFrequencyResponseAccessWhenNoFilterStatistics) { |
+ ApmDataDumper data_dumper(42); |
+ AdaptiveFirFilter filter(9, false, &data_dumper); |
+ EXPECT_DEATH(filter.FilterFrequencyResponse(), ""); |
+} |
+ |
+#endif |
+ |
+// Verifies that the filter statistics can be accessed when filter statistics |
+// are turned on. |
+TEST(AdaptiveFirFilter, FilterStatisticsAccess) { |
+ ApmDataDumper data_dumper(42); |
+ AdaptiveFirFilter filter(9, true, &data_dumper); |
+ filter.Erl(); |
+ filter.FilterFrequencyResponse(); |
+} |
+ |
+// Verifies that the filter size if correctly repported., |
hlundin-webrtc
2017/02/13 21:37:00
.,
peah-webrtc
2017/02/20 07:37:14
Done.
|
+TEST(AdaptiveFirFilter, FilterSize) { |
+ ApmDataDumper data_dumper(42); |
+ for (size_t k = 1; k < 30; ++k) { |
hlundin-webrtc
2017/02/13 21:37:00
Rename k -> filter_size?
hlundin-webrtc
2017/02/13 21:37:00
Why test so many sizes? And, is there something ma
peah-webrtc
2017/02/20 07:37:14
Done.
peah-webrtc
2017/02/20 07:37:15
Done.
|
+ AdaptiveFirFilter filter(k, false, &data_dumper); |
+ EXPECT_EQ(k, filter.SizePartitions()); |
+ } |
+} |
+ |
+// Verifies that the filter is being able to properly filter a signal and to |
+// adapt its coefficients1. |
hlundin-webrtc
2017/02/13 21:37:00
Sure, you are checking coefficients1, but what abo
peah-webrtc
2017/02/20 07:37:15
:-D
Done.
|
+TEST(AdaptiveFirFilter, FilterAndAdapt) { |
+ constexpr size_t kNumBlocksToProcess = 500; |
+ ApmDataDumper data_dumper(42); |
+ AdaptiveFirFilter filter(9, true, &data_dumper); |
+ Aec3Fft fft; |
+ FftBuffer X_buffer(filter.SizePartitions(), |
+ std::vector<size_t>(1, filter.SizePartitions())); |
+ std::array<float, kBlockSize> x_old; |
+ x_old.fill(0.f); |
+ ShadowFilterUpdateGain gain; |
+ Random random_generator(42U); |
+ std::vector<float> x(kBlockSize, 0.f); |
+ std::vector<float> y(kBlockSize, 0.f); |
+ DelayHandler delay_handler; |
+ RenderSignalAnalyzer render_signal_analyzer; |
+ FftData X; |
+ std::vector<float> e(kBlockSize, 0.f); |
+ std::array<float, kFftLength> s; |
+ FftData S; |
+ FftData G; |
+ FftData E; |
+ constexpr float kScale = 1.0f / kFftLengthBy2; |
+ |
+ for (size_t delay_samples : {0, 64, 150, 200, 301}) { |
+ DelayBuffer<float> delay_buffer(delay_samples); |
+ SCOPED_TRACE(ProduceDebugText(delay_samples)); |
+ for (size_t k = 0; k < kNumBlocksToProcess; ++k) { |
+ RandomizeSampleVector(&random_generator, x); |
+ delay_buffer.Delay(x, y); |
+ |
+ fft.PaddedFft(x, x_old, &X); |
+ X_buffer.Insert(X); |
+ render_signal_analyzer.Update(X_buffer, delay_handler.FilterDelay()); |
+ |
+ filter.Filter(X_buffer, &S); |
+ fft.Ifft(S, &s); |
+ std::transform(y.begin(), y.end(), s.begin() + kFftLengthBy2, e.begin(), |
+ [&](float a, float b) { return a - b * kScale; }); |
+ std::for_each(e.begin(), e.end(), [](float& a) { |
+ a = std::max(std::min(a, 32767.0f), -32768.0f); |
+ }); |
+ fft.ZeroPaddedFft(e, &E); |
+ |
+ gain.Compute(X_buffer, render_signal_analyzer, E, filter.SizePartitions(), |
+ false, &G); |
+ filter.Adapt(X_buffer, G); |
+ delay_handler.UpdateDelays(filter.FilterFrequencyResponse(), |
+ rtc::Optional<size_t>()); |
+ } |
+ // Verify that the filter is able to perform well. |
+ EXPECT_LT(1000 * std::inner_product(e.begin(), e.end(), e.begin(), 0.f), |
+ std::inner_product(y.begin(), y.end(), y.begin(), 0.f)); |
+ EXPECT_TRUE(delay_handler.FilterDelay()); |
hlundin-webrtc
2017/02/13 21:37:00
ASSERT_TRUE
peah-webrtc
2017/02/20 07:37:14
Done.
|
+ EXPECT_EQ(delay_samples / kBlockSize, *delay_handler.FilterDelay()); |
+ } |
+} |
+ |
+} // namespace webrtc |