Index: webrtc/modules/audio_processing/aec3/echo_remover_unittest.cc |
diff --git a/webrtc/modules/audio_processing/aec3/echo_remover_unittest.cc b/webrtc/modules/audio_processing/aec3/echo_remover_unittest.cc |
index 1c019937e5086ddd3ffe6ab4f7242dc9d2ce1dd9..29d3410a1e703ecf555e6f27970d2db32442a0f0 100644 |
--- a/webrtc/modules/audio_processing/aec3/echo_remover_unittest.cc |
+++ b/webrtc/modules/audio_processing/aec3/echo_remover_unittest.cc |
@@ -10,12 +10,16 @@ |
#include "webrtc/modules/audio_processing/aec3/echo_remover.h" |
+#include <algorithm> |
#include <memory> |
+#include <numeric> |
#include <sstream> |
#include <string> |
-#include "webrtc/modules/audio_processing/aec3/aec3_constants.h" |
+#include "webrtc/base/random.h" |
+#include "webrtc/modules/audio_processing/aec3/aec3_common.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 { |
@@ -27,12 +31,18 @@ std::string ProduceDebugText(int sample_rate_hz) { |
return ss.str(); |
} |
+std::string ProduceDebugText(int sample_rate_hz, int delay) { |
+ std::ostringstream ss(ProduceDebugText(sample_rate_hz)); |
+ ss << ", Delay: " << delay; |
+ return ss.str(); |
+} |
+ |
} // namespace |
// Verifies the basic API call sequence |
TEST(EchoRemover, BasicApiCalls) { |
for (auto rate : {8000, 16000, 32000, 48000}) { |
- ProduceDebugText(rate); |
+ SCOPED_TRACE(ProduceDebugText(rate)); |
std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate)); |
std::vector<std::vector<float>> render(NumBandsForRate(rate), |
@@ -64,7 +74,7 @@ TEST(EchoRemover, DISABLED_WrongSampleRate) { |
// Verifies the check for the render block size. |
TEST(EchoRemover, WrongRenderBlockSize) { |
for (auto rate : {8000, 16000, 32000, 48000}) { |
- ProduceDebugText(rate); |
+ SCOPED_TRACE(ProduceDebugText(rate)); |
std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate)); |
std::vector<std::vector<float>> render( |
@@ -83,7 +93,7 @@ TEST(EchoRemover, WrongRenderBlockSize) { |
// Verifies the check for the capture block size. |
TEST(EchoRemover, WrongCaptureBlockSize) { |
for (auto rate : {8000, 16000, 32000, 48000}) { |
- ProduceDebugText(rate); |
+ SCOPED_TRACE(ProduceDebugText(rate)); |
std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate)); |
std::vector<std::vector<float>> render(NumBandsForRate(rate), |
@@ -102,7 +112,7 @@ TEST(EchoRemover, WrongCaptureBlockSize) { |
// Verifies the check for the number of render bands. |
TEST(EchoRemover, WrongRenderNumBands) { |
for (auto rate : {16000, 32000, 48000}) { |
- ProduceDebugText(rate); |
+ SCOPED_TRACE(ProduceDebugText(rate)); |
std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate)); |
std::vector<std::vector<float>> render( |
@@ -120,9 +130,11 @@ TEST(EchoRemover, WrongRenderNumBands) { |
} |
// Verifies the check for the number of capture bands. |
-TEST(EchoRemover, WrongCaptureNumBands) { |
+// TODO(peah): Re-enable the test once the issue with memory leaks during DEATH |
+// tests on test bots has been fixed.c |
+TEST(EchoRemover, DISABLED_WrongCaptureNumBands) { |
for (auto rate : {16000, 32000, 48000}) { |
- ProduceDebugText(rate); |
+ SCOPED_TRACE(ProduceDebugText(rate)); |
std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate)); |
std::vector<std::vector<float>> render(NumBandsForRate(rate), |
@@ -155,4 +167,59 @@ TEST(EchoRemover, NullCapture) { |
#endif |
+// Performs a sanity check that the echo_remover is able to properly |
+// remove echoes. |
+TEST(EchoRemover, BasicEchoRemoval) { |
+ constexpr int kNumBlocksToProcess = 500; |
+ Random random_generator(42U); |
+ for (auto rate : {8000, 16000, 32000, 48000}) { |
+ std::vector<std::vector<float>> x(NumBandsForRate(rate), |
+ std::vector<float>(kBlockSize, 0.f)); |
+ std::vector<std::vector<float>> y(NumBandsForRate(rate), |
+ std::vector<float>(kBlockSize, 0.f)); |
+ EchoPathVariability echo_path_variability(false, false); |
+ for (size_t delay_samples : {0, 64, 150, 200, 301}) { |
+ SCOPED_TRACE(ProduceDebugText(rate, delay_samples)); |
+ std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate)); |
+ std::vector<std::unique_ptr<DelayBuffer<float>>> delay_buffers(x.size()); |
+ for (size_t j = 0; j < x.size(); ++j) { |
+ delay_buffers[j].reset(new DelayBuffer<float>(delay_samples)); |
+ } |
+ |
+ float input_energy = 0.f; |
+ float output_energy = 0.f; |
+ for (int k = 0; k < kNumBlocksToProcess; ++k) { |
+ const bool silence = k < 100 || (k % 100 >= 10); |
+ |
+ for (size_t j = 0; j < x.size(); ++j) { |
+ if (silence) { |
+ std::fill(x[j].begin(), x[j].end(), 0.f); |
+ } else { |
+ RandomizeSampleVector(&random_generator, x[j]); |
+ } |
+ delay_buffers[j]->Delay(x[j], y[j]); |
+ } |
+ |
+ if (k > kNumBlocksToProcess / 2) { |
+ for (size_t j = 0; j < x.size(); ++j) { |
+ input_energy = std::inner_product(y[j].begin(), y[j].end(), |
+ y[j].begin(), input_energy); |
+ } |
+ } |
+ |
+ remover->ProcessBlock(rtc::Optional<size_t>(delay_samples), |
+ echo_path_variability, false, x, &y); |
+ |
+ if (k > kNumBlocksToProcess / 2) { |
+ for (size_t j = 0; j < x.size(); ++j) { |
+ output_energy = std::inner_product(y[j].begin(), y[j].end(), |
+ y[j].begin(), output_energy); |
+ } |
+ } |
+ } |
+ EXPECT_GT(input_energy, 10.f * output_energy); |
+ } |
+ } |
+} |
+ |
} // namespace webrtc |