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

Side by Side Diff: webrtc/modules/audio_processing/residual_echo_detector_unittest.cc

Issue 2419563003: Add algorithm for Residual Echo Detector. (Closed)
Patch Set: Merged residual_echo_detector and echo_detector. Created 4 years, 1 month 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
« no previous file with comments | « webrtc/modules/audio_processing/residual_echo_detector.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/residual_echo_detector.h"
14 #include "webrtc/test/gtest.h"
15
16 namespace webrtc {
17
18 TEST(ResidualEchoDetectorTests, Echo) {
19 ResidualEchoDetector 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.AnalyzeRenderAudio(ones);
29 echo_detector.AnalyzeCaptureAudio(zeros);
30 } else if (i % 20 == 10) {
31 echo_detector.AnalyzeRenderAudio(zeros);
32 echo_detector.AnalyzeCaptureAudio(ones);
33 } else {
34 echo_detector.AnalyzeRenderAudio(zeros);
35 echo_detector.AnalyzeCaptureAudio(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(ResidualEchoDetectorTests, NoEcho) {
43 ResidualEchoDetector 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.AnalyzeRenderAudio(ones);
52 } else {
53 echo_detector.AnalyzeRenderAudio(zeros);
54 }
55 echo_detector.AnalyzeCaptureAudio(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(ResidualEchoDetectorTests, EchoWithRenderClockDrift) {
62 ResidualEchoDetector 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.AnalyzeRenderAudio(ones);
73 echo_detector.AnalyzeCaptureAudio(zeros);
74 } else if (i % 20 == 10) {
75 echo_detector.AnalyzeRenderAudio(zeros);
76 echo_detector.AnalyzeCaptureAudio(ones);
77 } else {
78 echo_detector.AnalyzeRenderAudio(zeros);
79 echo_detector.AnalyzeCaptureAudio(zeros);
80 }
81 if (i % 100 == 0) {
82 // This is causing the simulated clock drift.
83 echo_detector.AnalyzeRenderAudio(zeros);
84 }
85 }
86 // We expect to detect echo with high likelihood. Clock drift is harder to
87 // correct on the render side than on the capture side. This is due to the
88 // render buffer, clock drift can only be discovered after a certain delay.
89 // A growing buffer can be caused by jitter or clock drift and it's not
90 // possible to make this decision right away. For this reason we only expect
91 // an echo likelihood of 80% in this test.
92 EXPECT_GT(echo_detector.echo_likelihood(), 0.8f);
93 }
94
95 TEST(ResidualEchoDetectorTests, EchoWithCaptureClockDrift) {
96 ResidualEchoDetector echo_detector;
97 std::vector<float> ones(160, 1.f);
98 std::vector<float> zeros(160, 0.f);
99
100 // In this test the capture signal has a delay of 10 frames w.r.t. the render
101 // signal, but is otherwise identical. Both signals are periodic with a 20
102 // frame interval. There is a simulated clock drift of 1% in this test, with
103 // the capture side producing data slightly faster.
104 for (int i = 0; i < 1000; i++) {
105 if (i % 20 == 0) {
106 echo_detector.AnalyzeRenderAudio(ones);
107 echo_detector.AnalyzeCaptureAudio(zeros);
108 } else if (i % 20 == 10) {
109 echo_detector.AnalyzeRenderAudio(zeros);
110 echo_detector.AnalyzeCaptureAudio(ones);
111 } else {
112 echo_detector.AnalyzeRenderAudio(zeros);
113 echo_detector.AnalyzeCaptureAudio(zeros);
114 }
115 if (i % 100 == 0) {
116 // This is causing the simulated clock drift.
117 echo_detector.AnalyzeCaptureAudio(zeros);
118 }
119 }
120 // We expect to detect echo with near certain likelihood.
121 EXPECT_NEAR(1.f, echo_detector.echo_likelihood(), 0.01f);
122 }
123
124 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/residual_echo_detector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698