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

Side by Side Diff: webrtc/modules/audio_processing/aec3/echo_remover_unittest.cc

Issue 2678423005: Finalization of the first version of EchoCanceller 3 (Closed)
Patch Set: Created 3 years, 10 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
1 /* 1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2017 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 "webrtc/modules/audio_processing/aec3/echo_remover.h" 11 #include "webrtc/modules/audio_processing/aec3/echo_remover.h"
12 12
13 #include <algorithm>
13 #include <memory> 14 #include <memory>
15 #include <numeric>
14 #include <sstream> 16 #include <sstream>
15 #include <string> 17 #include <string>
16 18
19 #include "webrtc/base/random.h"
17 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h" 20 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h"
18 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" 21 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
22 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h"
19 #include "webrtc/test/gtest.h" 23 #include "webrtc/test/gtest.h"
20 24
21 namespace webrtc { 25 namespace webrtc {
22 namespace { 26 namespace {
23 27
24 std::string ProduceDebugText(int sample_rate_hz) { 28 std::string ProduceDebugText(int sample_rate_hz) {
25 std::ostringstream ss; 29 std::ostringstream ss;
26 ss << "Sample rate: " << sample_rate_hz; 30 ss << "Sample rate: " << sample_rate_hz;
27 return ss.str(); 31 return ss.str();
28 } 32 }
29 33
34 std::string ProduceDebugText(int sample_rate_hz, int delay) {
35 std::ostringstream ss(ProduceDebugText(sample_rate_hz));
36 ss << ", Delay: " << delay;
37 return ss.str();
38 }
39
30 } // namespace 40 } // namespace
31 41
32 // Verifies the basic API call sequence 42 // Verifies the basic API call sequence
33 TEST(EchoRemover, BasicApiCalls) { 43 TEST(EchoRemover, BasicApiCalls) {
34 for (auto rate : {8000, 16000, 32000, 48000}) { 44 for (auto rate : {8000, 16000, 32000, 48000}) {
35 ProduceDebugText(rate); 45 ProduceDebugText(rate);
36 std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate)); 46 std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate));
37 47
38 std::vector<std::vector<float>> render(NumBandsForRate(rate), 48 std::vector<std::vector<float>> render(NumBandsForRate(rate),
39 std::vector<float>(kBlockSize, 0.f)); 49 std::vector<float>(kBlockSize, 0.f));
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 EchoPathVariability echo_path_variability(false, false); 158 EchoPathVariability echo_path_variability(false, false);
149 rtc::Optional<size_t> echo_path_delay_samples; 159 rtc::Optional<size_t> echo_path_delay_samples;
150 EXPECT_DEATH( 160 EXPECT_DEATH(
151 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, 161 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability,
152 false, render, nullptr), 162 false, render, nullptr),
153 ""); 163 "");
154 } 164 }
155 165
156 #endif 166 #endif
157 167
168 // Performs a sanity check that the echo_remover is being able to properly
169 // remove echoes.
170 TEST(EchoRemover, BasicEchoRemoval) {
aleloi 2017/02/09 17:02:59 In this test, the near-end signal is comprised ent
peah-webrtc 2017/02/20 07:37:16 Absolutely, but I'm not sure if we should have tha
aleloi 2017/02/23 10:56:45 Acknowledged.
171 constexpr int kNumBlocksToProcess = 500;
172 Random random_generator(42U);
173 for (auto rate : {8000, 16000, 32000, 48000}) {
174 std::vector<std::vector<float>> x(NumBandsForRate(rate),
175 std::vector<float>(kBlockSize, 0.f));
176 std::vector<std::vector<float>> y(NumBandsForRate(rate),
177 std::vector<float>(kBlockSize, 0.f));
178 EchoPathVariability echo_path_variability(false, false);
179 for (size_t delay_samples : {0, 64, 150, 200, 301}) {
180 ProduceDebugText(rate, delay_samples);
aleloi 2017/02/09 17:02:59 This doesn't do anything: ProduceDebugText is a fu
peah-webrtc 2017/02/20 07:37:16 Done.
181 std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate));
182 std::vector<std::unique_ptr<DelayBuffer<float>>> delay_buffers(x.size());
183 for (size_t j = 0; j < x.size(); ++j) {
184 delay_buffers[j].reset(new DelayBuffer<float>(delay_samples));
185 }
186
187 bool silence = false;
188 float input_energy = 0.f;
189 float output_energy = 0.f;
190 for (int k = 0; k < kNumBlocksToProcess; ++k) {
191 if (silence) {
192 silence = (k % 100) != 0;
193 } else {
194 silence = (k % 10) == 0;
195 }
aleloi 2017/02/09 17:02:59 The 'silence' updating construct seems a little st
peah-webrtc 2017/02/20 07:37:16 I changed to your proposed one-linear. The purpos
196
197 for (size_t j = 0; j < x.size(); ++j) {
198 if (silence) {
199 std::fill(x[j].begin(), x[j].end(), 0.f);
200 } else {
201 RandomizeSampleVector(&random_generator, x[j]);
202 }
203 delay_buffers[j]->Delay(x[j], y[j]);
204 }
205
206 if (k > kNumBlocksToProcess / 2) {
207 for (size_t j = 0; j < x.size(); ++j) {
208 input_energy = std::inner_product(y[j].begin(), y[j].end(),
209 y[j].begin(), input_energy);
210 }
211
212 remover->ProcessBlock(rtc::Optional<size_t>(delay_samples),
213 echo_path_variability, false, x, &y);
aleloi 2017/02/09 17:02:59 The remover only sees the last 250 of the samples.
peah-webrtc 2017/02/20 07:37:16 Good find! Done.
214
215 for (size_t j = 0; j < x.size(); ++j) {
216 output_energy = std::inner_product(y[j].begin(), y[j].end(),
217 y[j].begin(), output_energy);
218 }
219 }
220 }
221 EXPECT_GT(input_energy, 10.f * output_energy);
222 }
223 }
224 }
225
158 } // namespace webrtc 226 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698