Index: webrtc/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc |
diff --git a/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc b/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc |
index 4146c3ff8b83f12e63353e1c39f559971f5bb914..75e59720d62319ea238a7ce1a10c5a48e91754eb 100644 |
--- a/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc |
+++ b/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc |
@@ -10,11 +10,14 @@ |
#include "webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h" |
+#include <algorithm> |
#include <sstream> |
#include <string> |
+#include "webrtc/base/random.h" |
#include "webrtc/modules/audio_processing/aec3/aec3_constants.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 { |
@@ -26,6 +29,12 @@ std::string ProduceDebugText(int sample_rate_hz) { |
return ss.str(); |
} |
+std::string ProduceDebugText(int sample_rate_hz, size_t delay) { |
+ std::ostringstream ss(ProduceDebugText(sample_rate_hz)); |
+ ss << ", Delay: " << delay; |
+ return ss.str(); |
+} |
+ |
} // namespace |
// Verifies that the basic API calls work. |
@@ -42,12 +51,97 @@ TEST(EchoPathDelayEstimator, BasicApiCalls) { |
} |
} |
+// Verifies that the delay estimator produces correct delay for artificially |
+// delayed signals. |
+TEST(EchoPathDelayEstimator, DelayEstimation) { |
+ Random random_generator(42U); |
+ std::vector<float> render(kBlockSize, 0.f); |
+ std::vector<float> capture(kBlockSize, 0.f); |
+ ApmDataDumper data_dumper(0); |
+ for (auto rate : {8000, 16000, 32000, 48000}) { |
+ for (size_t delay_samples : {0, 64, 150, 200, 800, 4000}) { |
+ SCOPED_TRACE(ProduceDebugText(rate, delay_samples)); |
+ DelayBuffer<float> signal_delay_buffer(delay_samples); |
+ EchoPathDelayEstimator estimator(&data_dumper, rate); |
+ |
+ rtc::Optional<size_t> estimated_delay_samples; |
+ for (size_t k = 0; k < (100 + delay_samples / kBlockSize); ++k) { |
+ RandomizeSampleVector(&random_generator, render); |
+ signal_delay_buffer.Delay(render, capture); |
+ estimated_delay_samples = estimator.EstimateDelay(render, capture); |
+ } |
+ if (estimated_delay_samples) { |
+ EXPECT_NEAR(delay_samples, *estimated_delay_samples, 4); |
aleloi
2017/02/03 15:46:48
Is the 4 here because of the down sampling factor?
peah-webrtc
2017/02/06 11:25:39
Yes, that is the reason.
I added a comment to cla
|
+ } else { |
+ ADD_FAILURE(); |
+ } |
+ } |
+ } |
+} |
+ |
+// Verifies that the delay estimator does not produce delay estimates too |
+// quickly. |
+TEST(EchoPathDelayEstimator, NoInitialDelayestimates) { |
+ Random random_generator(42U); |
+ std::vector<float> render(kBlockSize, 0.f); |
+ std::vector<float> capture(kBlockSize, 0.f); |
+ ApmDataDumper data_dumper(0); |
+ for (auto rate : {8000, 16000, 32000, 48000}) { |
+ SCOPED_TRACE(ProduceDebugText(rate)); |
+ EchoPathDelayEstimator estimator(&data_dumper, rate); |
+ for (size_t k = 0; k < 19; ++k) { |
+ RandomizeSampleVector(&random_generator, render); |
+ std::copy(render.begin(), render.end(), capture.begin()); |
+ EXPECT_FALSE(estimator.EstimateDelay(render, capture)); |
+ } |
+ } |
+} |
+ |
+// Verifies that the delay estimator does not produce delay estimates for render |
+// signals of low level. |
+TEST(EchoPathDelayEstimator, NoDelayEstimatesForLowLevelRenderSignals) { |
+ Random random_generator(42U); |
+ std::vector<float> render(kBlockSize, 0.f); |
+ std::vector<float> capture(kBlockSize, 0.f); |
+ ApmDataDumper data_dumper(0); |
+ for (auto rate : {8000, 16000, 32000, 48000}) { |
+ SCOPED_TRACE(ProduceDebugText(rate)); |
+ EchoPathDelayEstimator estimator(&data_dumper, rate); |
+ for (size_t k = 0; k < 100; ++k) { |
+ RandomizeSampleVector(&random_generator, render); |
+ for (auto& render_k : render) { |
+ render_k *= 100.f / 32767.f; |
+ } |
+ std::copy(render.begin(), render.end(), capture.begin()); |
+ EXPECT_FALSE(estimator.EstimateDelay(render, capture)); |
+ } |
+ } |
+} |
+ |
+// Verifies that the delay estimator does not produce delay estimates for |
+// uncorrelated signals. |
+TEST(EchoPathDelayEstimator, NoDelayEstimatesForUncorrelatedSignals) { |
+ Random random_generator(42U); |
+ std::vector<float> render(kBlockSize, 0.f); |
+ std::vector<float> capture(kBlockSize, 0.f); |
+ ApmDataDumper data_dumper(0); |
+ for (auto rate : {8000, 16000, 32000, 48000}) { |
+ SCOPED_TRACE(ProduceDebugText(rate)); |
+ EchoPathDelayEstimator estimator(&data_dumper, rate); |
+ for (size_t k = 0; k < 100; ++k) { |
+ RandomizeSampleVector(&random_generator, render); |
+ RandomizeSampleVector(&random_generator, capture); |
+ EXPECT_FALSE(estimator.EstimateDelay(render, capture)); |
+ } |
+ } |
+} |
+ |
#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
// Verifies the check for correct sample rate. |
TEST(EchoPathDelayEstimator, WrongSampleRate) { |
ApmDataDumper data_dumper(0); |
- EXPECT_DEATH(EchoPathDelayEstimator remover(&data_dumper, 8001), ""); |
+ EXPECT_DEATH(EchoPathDelayEstimator(&data_dumper, 8001), ""); |
} |
// Verifies the check for the render blocksize. |