OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "webrtc/modules/audio_processing/residual_echo_detector.h" | 13 #include "webrtc/modules/audio_processing/residual_echo_detector.h" |
14 #include "webrtc/test/gtest.h" | 14 #include "webrtc/test/gtest.h" |
15 | 15 |
16 namespace webrtc { | 16 namespace webrtc { |
17 | 17 |
18 TEST(ResidualEchoDetectorTests, Echo) { | 18 TEST(ResidualEchoDetectorTests, Echo) { |
19 ResidualEchoDetector echo_detector; | 19 ResidualEchoDetector echo_detector; |
| 20 echo_detector.SetReliabilityForTest(1.0f); |
20 std::vector<float> ones(160, 1.f); | 21 std::vector<float> ones(160, 1.f); |
21 std::vector<float> zeros(160, 0.f); | 22 std::vector<float> zeros(160, 0.f); |
22 | 23 |
23 // In this test the capture signal has a delay of 10 frames w.r.t. the render | 24 // 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 // signal, but is otherwise identical. Both signals are periodic with a 20 |
25 // frame interval. | 26 // frame interval. |
26 for (int i = 0; i < 1000; i++) { | 27 for (int i = 0; i < 1000; i++) { |
27 if (i % 20 == 0) { | 28 if (i % 20 == 0) { |
28 echo_detector.AnalyzeRenderAudio(ones); | 29 echo_detector.AnalyzeRenderAudio(ones); |
29 echo_detector.AnalyzeCaptureAudio(zeros); | 30 echo_detector.AnalyzeCaptureAudio(zeros); |
30 } else if (i % 20 == 10) { | 31 } else if (i % 20 == 10) { |
31 echo_detector.AnalyzeRenderAudio(zeros); | 32 echo_detector.AnalyzeRenderAudio(zeros); |
32 echo_detector.AnalyzeCaptureAudio(ones); | 33 echo_detector.AnalyzeCaptureAudio(ones); |
33 } else { | 34 } else { |
34 echo_detector.AnalyzeRenderAudio(zeros); | 35 echo_detector.AnalyzeRenderAudio(zeros); |
35 echo_detector.AnalyzeCaptureAudio(zeros); | 36 echo_detector.AnalyzeCaptureAudio(zeros); |
36 } | 37 } |
37 } | 38 } |
38 // We expect to detect echo with near certain likelihood. | 39 // We expect to detect echo with near certain likelihood. |
39 EXPECT_NEAR(1.f, echo_detector.echo_likelihood(), 0.01f); | 40 EXPECT_NEAR(1.f, echo_detector.echo_likelihood(), 0.01f); |
40 } | 41 } |
41 | 42 |
42 TEST(ResidualEchoDetectorTests, NoEcho) { | 43 TEST(ResidualEchoDetectorTests, NoEcho) { |
43 ResidualEchoDetector echo_detector; | 44 ResidualEchoDetector echo_detector; |
| 45 echo_detector.SetReliabilityForTest(1.0f); |
44 std::vector<float> ones(160, 1.f); | 46 std::vector<float> ones(160, 1.f); |
45 std::vector<float> zeros(160, 0.f); | 47 std::vector<float> zeros(160, 0.f); |
46 | 48 |
47 // In this test the capture signal is always zero, so no echo should be | 49 // In this test the capture signal is always zero, so no echo should be |
48 // detected. | 50 // detected. |
49 for (int i = 0; i < 1000; i++) { | 51 for (int i = 0; i < 1000; i++) { |
50 if (i % 20 == 0) { | 52 if (i % 20 == 0) { |
51 echo_detector.AnalyzeRenderAudio(ones); | 53 echo_detector.AnalyzeRenderAudio(ones); |
52 } else { | 54 } else { |
53 echo_detector.AnalyzeRenderAudio(zeros); | 55 echo_detector.AnalyzeRenderAudio(zeros); |
54 } | 56 } |
55 echo_detector.AnalyzeCaptureAudio(zeros); | 57 echo_detector.AnalyzeCaptureAudio(zeros); |
56 } | 58 } |
57 // We expect to not detect any echo. | 59 // We expect to not detect any echo. |
58 EXPECT_NEAR(0.f, echo_detector.echo_likelihood(), 0.01f); | 60 EXPECT_NEAR(0.f, echo_detector.echo_likelihood(), 0.01f); |
59 } | 61 } |
60 | 62 |
61 TEST(ResidualEchoDetectorTests, EchoWithRenderClockDrift) { | 63 TEST(ResidualEchoDetectorTests, EchoWithRenderClockDrift) { |
62 ResidualEchoDetector echo_detector; | 64 ResidualEchoDetector echo_detector; |
| 65 echo_detector.SetReliabilityForTest(1.0f); |
63 std::vector<float> ones(160, 1.f); | 66 std::vector<float> ones(160, 1.f); |
64 std::vector<float> zeros(160, 0.f); | 67 std::vector<float> zeros(160, 0.f); |
65 | 68 |
66 // In this test the capture signal has a delay of 10 frames w.r.t. the render | 69 // 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 | 70 // 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 | 71 // frame interval. There is a simulated clock drift of 1% in this test, with |
69 // the render side producing data slightly faster. | 72 // the render side producing data slightly faster. |
70 for (int i = 0; i < 1000; i++) { | 73 for (int i = 0; i < 1000; i++) { |
71 if (i % 20 == 0) { | 74 if (i % 20 == 0) { |
72 echo_detector.AnalyzeRenderAudio(ones); | 75 echo_detector.AnalyzeRenderAudio(ones); |
(...skipping 14 matching lines...) Expand all Loading... |
87 // correct on the render side than on the capture side. This is due to the | 90 // 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. | 91 // 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 | 92 // 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 | 93 // possible to make this decision right away. For this reason we only expect |
91 // an echo likelihood of 80% in this test. | 94 // an echo likelihood of 80% in this test. |
92 EXPECT_GT(echo_detector.echo_likelihood(), 0.8f); | 95 EXPECT_GT(echo_detector.echo_likelihood(), 0.8f); |
93 } | 96 } |
94 | 97 |
95 TEST(ResidualEchoDetectorTests, EchoWithCaptureClockDrift) { | 98 TEST(ResidualEchoDetectorTests, EchoWithCaptureClockDrift) { |
96 ResidualEchoDetector echo_detector; | 99 ResidualEchoDetector echo_detector; |
| 100 echo_detector.SetReliabilityForTest(1.0f); |
97 std::vector<float> ones(160, 1.f); | 101 std::vector<float> ones(160, 1.f); |
98 std::vector<float> zeros(160, 0.f); | 102 std::vector<float> zeros(160, 0.f); |
99 | 103 |
100 // In this test the capture signal has a delay of 10 frames w.r.t. the render | 104 // 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 | 105 // 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 | 106 // frame interval. There is a simulated clock drift of 1% in this test, with |
103 // the capture side producing data slightly faster. | 107 // the capture side producing data slightly faster. |
104 for (int i = 0; i < 1000; i++) { | 108 for (int i = 0; i < 1000; i++) { |
105 if (i % 20 == 0) { | 109 if (i % 20 == 0) { |
106 echo_detector.AnalyzeRenderAudio(ones); | 110 echo_detector.AnalyzeRenderAudio(ones); |
107 echo_detector.AnalyzeCaptureAudio(zeros); | 111 echo_detector.AnalyzeCaptureAudio(zeros); |
108 } else if (i % 20 == 10) { | 112 } else if (i % 20 == 10) { |
109 echo_detector.AnalyzeRenderAudio(zeros); | 113 echo_detector.AnalyzeRenderAudio(zeros); |
110 echo_detector.AnalyzeCaptureAudio(ones); | 114 echo_detector.AnalyzeCaptureAudio(ones); |
111 } else { | 115 } else { |
112 echo_detector.AnalyzeRenderAudio(zeros); | 116 echo_detector.AnalyzeRenderAudio(zeros); |
113 echo_detector.AnalyzeCaptureAudio(zeros); | 117 echo_detector.AnalyzeCaptureAudio(zeros); |
114 } | 118 } |
115 if (i % 100 == 0) { | 119 if (i % 100 == 0) { |
116 // This is causing the simulated clock drift. | 120 // This is causing the simulated clock drift. |
117 echo_detector.AnalyzeCaptureAudio(zeros); | 121 echo_detector.AnalyzeCaptureAudio(zeros); |
118 } | 122 } |
119 } | 123 } |
120 // We expect to detect echo with near certain likelihood. | 124 // We expect to detect echo with near certain likelihood. |
121 EXPECT_NEAR(1.f, echo_detector.echo_likelihood(), 0.01f); | 125 EXPECT_NEAR(1.f, echo_detector.echo_likelihood(), 0.01f); |
122 } | 126 } |
123 | 127 |
124 } // namespace webrtc | 128 } // namespace webrtc |
OLD | NEW |