Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(632)

Side by Side Diff: webrtc/modules/audio_processing/echo_detector/echo_detector_unittest.cc

Issue 2419563003: Add algorithm for Residual Echo Detector. (Closed)
Patch Set: Added better handling of clock drift on render side. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <vector>
12
13 #include "webrtc/modules/audio_processing/echo_detector/echo_detector.h"
14 #include "webrtc/test/gtest.h"
15
16 namespace webrtc {
17
18 TEST(EchoDetectorTests, Echo) {
19 EchoDetector echo_detector;
20 std::vector<float> ones(160, 1.f);
21 std::vector<float> zeros(160, 0.f);
22
23 // In this test the capture signal has a delay of 10 frames w.r.t. the render
24 // signal, but is otherwise identical. Both signals are periodic with a 20
25 // frame interval.
26 for (int i = 0; i < 1000; i++) {
27 if (i % 20 == 0) {
28 echo_detector.BufferRender(ones);
29 echo_detector.Process(zeros);
30 } else if (i % 20 == 10) {
31 echo_detector.BufferRender(zeros);
32 echo_detector.Process(ones);
33 } else {
34 echo_detector.BufferRender(zeros);
35 echo_detector.Process(zeros);
36 }
37 }
38 // We expect to detect echo with near certain likelihood.
39 EXPECT_NEAR(1.f, echo_detector.echo_likelihood(), 0.01f);
40 }
41
42 TEST(EchoDetectorTests, NoEcho) {
43 EchoDetector echo_detector;
44 std::vector<float> ones(160, 1.f);
45 std::vector<float> zeros(160, 0.f);
46
47 // In this test the capture signal is always zero, so no echo should be
48 // detected.
49 for (int i = 0; i < 1000; i++) {
50 if (i % 20 == 0) {
51 echo_detector.BufferRender(ones);
52 } else {
53 echo_detector.BufferRender(zeros);
54 }
55 echo_detector.Process(zeros);
56 }
57 // We expect to not detect any echo.
58 EXPECT_NEAR(0.f, echo_detector.echo_likelihood(), 0.01f);
59 }
60
61 TEST(EchoDetectorTests, EchoWithRenderClockDrift) {
62 EchoDetector echo_detector;
63 std::vector<float> ones(160, 1.f);
64 std::vector<float> zeros(160, 0.f);
65
66 // In this test the capture signal has a delay of 10 frames w.r.t. the render
67 // signal, but is otherwise identical. Both signals are periodic with a 20
68 // frame interval. There is a simulated clock drift of 1% in this test, with
69 // the render side producing data slightly faster.
70 for (int i = 0; i < 1000; i++) {
71 if (i % 20 == 0) {
72 echo_detector.BufferRender(ones);
73 echo_detector.Process(zeros);
74 } else if (i % 20 == 10) {
75 echo_detector.BufferRender(zeros);
76 echo_detector.Process(ones);
77 } else {
78 echo_detector.BufferRender(zeros);
79 echo_detector.Process(zeros);
80 }
81 if (i % 100 == 0) {
82 // This is causing the simulated clock drift.
83 echo_detector.BufferRender(zeros);
84 }
85 }
86 // We expect to detect echo with high likelihood.
87 EXPECT_GT(echo_detector.echo_likelihood(), 0.8f);
88 }
89
90 TEST(EchoDetectorTests, EchoWithCaptureClockDrift) {
91 EchoDetector echo_detector;
92 std::vector<float> ones(160, 1.f);
93 std::vector<float> zeros(160, 0.f);
94
95 // In this test the capture signal has a delay of 10 frames w.r.t. the render
96 // signal, but is otherwise identical. Both signals are periodic with a 20
97 // frame interval. There is a simulated clock drift of 1% in this test, with
98 // the capture side producing data slightly faster.
99 for (int i = 0; i < 1000; i++) {
100 if (i % 20 == 0) {
101 echo_detector.BufferRender(ones);
102 echo_detector.Process(zeros);
103 } else if (i % 20 == 10) {
104 echo_detector.BufferRender(zeros);
105 echo_detector.Process(ones);
106 } else {
107 echo_detector.BufferRender(zeros);
108 echo_detector.Process(zeros);
109 }
110 if (i % 100 == 0) {
111 // This is causing the simulated clock drift.
112 echo_detector.Process(zeros);
113 }
114 }
115 // We expect to detect echo with near certain likelihood.
116 EXPECT_NEAR(1.f, echo_detector.echo_likelihood(), 0.01f);
117 }
118
119 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698