* Copyright (c) 2016 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 "modules/audio_processing/residual_echo_detector.h"
#include <vector>
#include "api/make_ref_counted.h"
#include "test/gtest.h"
namespace webrtc {
TEST(ResidualEchoDetectorTests, Echo) {
auto echo_detector = rtc::make_ref_counted<ResidualEchoDetector>();
echo_detector->SetReliabilityForTest(1.0f);
std::vector<float> ones(160, 1.f);
std::vector<float> zeros(160, 0.f);
for (int i = 0; i < 1000; i++) {
if (i % 20 == 0) {
echo_detector->AnalyzeRenderAudio(ones);
echo_detector->AnalyzeCaptureAudio(zeros);
} else if (i % 20 == 10) {
echo_detector->AnalyzeRenderAudio(zeros);
echo_detector->AnalyzeCaptureAudio(ones);
} else {
echo_detector->AnalyzeRenderAudio(zeros);
echo_detector->AnalyzeCaptureAudio(zeros);
}
}
auto ed_metrics = echo_detector->GetMetrics();
ASSERT_TRUE(ed_metrics.echo_likelihood);
EXPECT_NEAR(1.f, ed_metrics.echo_likelihood.value(), 0.01f);
}
TEST(ResidualEchoDetectorTests, NoEcho) {
auto echo_detector = rtc::make_ref_counted<ResidualEchoDetector>();
echo_detector->SetReliabilityForTest(1.0f);
std::vector<float> ones(160, 1.f);
std::vector<float> zeros(160, 0.f);
for (int i = 0; i < 1000; i++) {
if (i % 20 == 0) {
echo_detector->AnalyzeRenderAudio(ones);
} else {
echo_detector->AnalyzeRenderAudio(zeros);
}
echo_detector->AnalyzeCaptureAudio(zeros);
}
auto ed_metrics = echo_detector->GetMetrics();
ASSERT_TRUE(ed_metrics.echo_likelihood);
EXPECT_NEAR(0.f, ed_metrics.echo_likelihood.value(), 0.01f);
}
TEST(ResidualEchoDetectorTests, EchoWithRenderClockDrift) {
auto echo_detector = rtc::make_ref_counted<ResidualEchoDetector>();
echo_detector->SetReliabilityForTest(1.0f);
std::vector<float> ones(160, 1.f);
std::vector<float> zeros(160, 0.f);
for (int i = 0; i < 1000; i++) {
if (i % 20 == 0) {
echo_detector->AnalyzeRenderAudio(ones);
echo_detector->AnalyzeCaptureAudio(zeros);
} else if (i % 20 == 10) {
echo_detector->AnalyzeRenderAudio(zeros);
echo_detector->AnalyzeCaptureAudio(ones);
} else {
echo_detector->AnalyzeRenderAudio(zeros);
echo_detector->AnalyzeCaptureAudio(zeros);
}
if (i % 100 == 0) {
echo_detector->AnalyzeRenderAudio(zeros);
}
}
auto ed_metrics = echo_detector->GetMetrics();
ASSERT_TRUE(ed_metrics.echo_likelihood);
EXPECT_GT(ed_metrics.echo_likelihood.value(), 0.75f);
}
TEST(ResidualEchoDetectorTests, EchoWithCaptureClockDrift) {
auto echo_detector = rtc::make_ref_counted<ResidualEchoDetector>();
echo_detector->SetReliabilityForTest(1.0f);
std::vector<float> ones(160, 1.f);
std::vector<float> zeros(160, 0.f);
for (int i = 0; i < 1000; i++) {
if (i % 20 == 0) {
echo_detector->AnalyzeRenderAudio(ones);
echo_detector->AnalyzeCaptureAudio(zeros);
} else if (i % 20 == 10) {
echo_detector->AnalyzeRenderAudio(zeros);
echo_detector->AnalyzeCaptureAudio(ones);
} else {
echo_detector->AnalyzeRenderAudio(zeros);
echo_detector->AnalyzeCaptureAudio(zeros);
}
if (i % 100 == 0) {
echo_detector->AnalyzeCaptureAudio(zeros);
}
}
auto ed_metrics = echo_detector->GetMetrics();
ASSERT_TRUE(ed_metrics.echo_likelihood);
EXPECT_NEAR(1.f, ed_metrics.echo_likelihood.value(), 0.01f);
}
}