blob: 4e2943395e495171e51981048881f6fc470941c7 [file] [log] [blame]
minyue275d2552015-11-04 06:23:54 -08001/*
2 * Copyright (c) 2015 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 <stddef.h> // size_t
kwiberg62eaacf2016-02-17 06:39:05 -080012
kwiberg84be5112016-04-27 01:19:58 -070013#include <memory>
minyue275d2552015-11-04 06:23:54 -080014#include <string>
15#include <vector>
16
Gustaf Ullberg0efa9412018-02-27 13:58:45 +010017#include "api/audio/echo_canceller3_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
19#include "modules/audio_processing/aec_dump/aec_dump_factory.h"
20#include "modules/audio_processing/test/debug_dump_replayer.h"
21#include "modules/audio_processing/test/test_utils.h"
22#include "rtc_base/task_queue.h"
23#include "test/gtest.h"
24#include "test/testsupport/fileutils.h"
minyue275d2552015-11-04 06:23:54 -080025
26namespace webrtc {
27namespace test {
28
29namespace {
30
kwiberg62eaacf2016-02-17 06:39:05 -080031void MaybeResetBuffer(std::unique_ptr<ChannelBuffer<float>>* buffer,
minyue275d2552015-11-04 06:23:54 -080032 const StreamConfig& config) {
33 auto& buffer_ref = *buffer;
34 if (!buffer_ref.get() || buffer_ref->num_frames() != config.num_frames() ||
35 buffer_ref->num_channels() != config.num_channels()) {
Yves Gerey665174f2018-06-19 15:03:05 +020036 buffer_ref.reset(
37 new ChannelBuffer<float>(config.num_frames(), config.num_channels()));
minyue275d2552015-11-04 06:23:54 -080038 }
39}
40
41class DebugDumpGenerator {
42 public:
43 DebugDumpGenerator(const std::string& input_file_name,
Alex Loiko890988c2017-08-31 10:25:48 +020044 int input_rate_hz,
minyue275d2552015-11-04 06:23:54 -080045 int input_channels,
46 const std::string& reverse_file_name,
Alex Loiko890988c2017-08-31 10:25:48 +020047 int reverse_rate_hz,
minyue275d2552015-11-04 06:23:54 -080048 int reverse_channels,
49 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +020050 const std::string& dump_file_name,
51 bool enable_aec3);
minyue275d2552015-11-04 06:23:54 -080052
53 // Constructor that uses default input files.
peah88ac8532016-09-12 16:47:25 -070054 explicit DebugDumpGenerator(const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +020055 const AudioProcessing::Config& apm_config,
56 bool enable_aec3);
57
58 explicit DebugDumpGenerator(const Config& config,
peah88ac8532016-09-12 16:47:25 -070059 const AudioProcessing::Config& apm_config);
minyue275d2552015-11-04 06:23:54 -080060
61 ~DebugDumpGenerator();
62
63 // Changes the sample rate of the input audio to the APM.
64 void SetInputRate(int rate_hz);
65
66 // Sets if converts stereo input signal to mono by discarding other channels.
67 void ForceInputMono(bool mono);
68
69 // Changes the sample rate of the reverse audio to the APM.
70 void SetReverseRate(int rate_hz);
71
72 // Sets if converts stereo reverse signal to mono by discarding other
73 // channels.
74 void ForceReverseMono(bool mono);
75
76 // Sets the required sample rate of the APM output.
77 void SetOutputRate(int rate_hz);
78
79 // Sets the required channels of the APM output.
80 void SetOutputChannels(int channels);
81
82 std::string dump_file_name() const { return dump_file_name_; }
83
84 void StartRecording();
85 void Process(size_t num_blocks);
86 void StopRecording();
87 AudioProcessing* apm() const { return apm_.get(); }
88
89 private:
Yves Gerey665174f2018-06-19 15:03:05 +020090 static void ReadAndDeinterleave(ResampleInputAudioFile* audio,
91 int channels,
minyue275d2552015-11-04 06:23:54 -080092 const StreamConfig& config,
93 float* const* buffer);
94
95 // APM input/output settings.
96 StreamConfig input_config_;
97 StreamConfig reverse_config_;
98 StreamConfig output_config_;
99
100 // Input file format.
101 const std::string input_file_name_;
102 ResampleInputAudioFile input_audio_;
103 const int input_file_channels_;
104
105 // Reverse file format.
106 const std::string reverse_file_name_;
107 ResampleInputAudioFile reverse_audio_;
108 const int reverse_file_channels_;
109
110 // Buffer for APM input/output.
kwiberg62eaacf2016-02-17 06:39:05 -0800111 std::unique_ptr<ChannelBuffer<float>> input_;
112 std::unique_ptr<ChannelBuffer<float>> reverse_;
113 std::unique_ptr<ChannelBuffer<float>> output_;
minyue275d2552015-11-04 06:23:54 -0800114
aleloif4dd1912017-06-15 01:55:38 -0700115 rtc::TaskQueue worker_queue_;
kwiberg62eaacf2016-02-17 06:39:05 -0800116 std::unique_ptr<AudioProcessing> apm_;
minyue275d2552015-11-04 06:23:54 -0800117
118 const std::string dump_file_name_;
119};
120
121DebugDumpGenerator::DebugDumpGenerator(const std::string& input_file_name,
122 int input_rate_hz,
123 int input_channels,
124 const std::string& reverse_file_name,
125 int reverse_rate_hz,
126 int reverse_channels,
127 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200128 const std::string& dump_file_name,
129 bool enable_aec3)
minyue275d2552015-11-04 06:23:54 -0800130 : input_config_(input_rate_hz, input_channels),
131 reverse_config_(reverse_rate_hz, reverse_channels),
132 output_config_(input_rate_hz, input_channels),
133 input_audio_(input_file_name, input_rate_hz, input_rate_hz),
134 input_file_channels_(input_channels),
135 reverse_audio_(reverse_file_name, reverse_rate_hz, reverse_rate_hz),
136 reverse_file_channels_(reverse_channels),
137 input_(new ChannelBuffer<float>(input_config_.num_frames(),
138 input_config_.num_channels())),
139 reverse_(new ChannelBuffer<float>(reverse_config_.num_frames(),
140 reverse_config_.num_channels())),
141 output_(new ChannelBuffer<float>(output_config_.num_frames(),
142 output_config_.num_channels())),
aleloif4dd1912017-06-15 01:55:38 -0700143 worker_queue_("debug_dump_generator_worker_queue"),
Ivo Creusen62337e52018-01-09 14:17:33 +0100144 dump_file_name_(dump_file_name) {
145 AudioProcessingBuilder apm_builder;
146 if (enable_aec3) {
147 apm_builder.SetEchoControlFactory(
148 std::unique_ptr<EchoControlFactory>(new EchoCanceller3Factory()));
149 }
150 apm_.reset(apm_builder.Create(config));
151}
minyue275d2552015-11-04 06:23:54 -0800152
peah88ac8532016-09-12 16:47:25 -0700153DebugDumpGenerator::DebugDumpGenerator(
154 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200155 const AudioProcessing::Config& apm_config,
156 bool enable_aec3)
peah88ac8532016-09-12 16:47:25 -0700157 : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"),
158 32000,
159 2,
160 ResourcePath("far32_stereo", "pcm"),
161 32000,
162 2,
163 config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200164 TempFilename(OutputPath(), "debug_aec"),
165 enable_aec3) {
166 apm_->ApplyConfig(apm_config);
167}
168
169DebugDumpGenerator::DebugDumpGenerator(
170 const Config& config,
171 const AudioProcessing::Config& apm_config)
172 : DebugDumpGenerator(config, apm_config, false) {
peah88ac8532016-09-12 16:47:25 -0700173 apm_->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800174}
175
176DebugDumpGenerator::~DebugDumpGenerator() {
177 remove(dump_file_name_.c_str());
178}
179
180void DebugDumpGenerator::SetInputRate(int rate_hz) {
181 input_audio_.set_output_rate_hz(rate_hz);
182 input_config_.set_sample_rate_hz(rate_hz);
183 MaybeResetBuffer(&input_, input_config_);
184}
185
186void DebugDumpGenerator::ForceInputMono(bool mono) {
187 const int channels = mono ? 1 : input_file_channels_;
188 input_config_.set_num_channels(channels);
189 MaybeResetBuffer(&input_, input_config_);
190}
191
192void DebugDumpGenerator::SetReverseRate(int rate_hz) {
193 reverse_audio_.set_output_rate_hz(rate_hz);
194 reverse_config_.set_sample_rate_hz(rate_hz);
195 MaybeResetBuffer(&reverse_, reverse_config_);
196}
197
198void DebugDumpGenerator::ForceReverseMono(bool mono) {
199 const int channels = mono ? 1 : reverse_file_channels_;
200 reverse_config_.set_num_channels(channels);
201 MaybeResetBuffer(&reverse_, reverse_config_);
202}
203
204void DebugDumpGenerator::SetOutputRate(int rate_hz) {
205 output_config_.set_sample_rate_hz(rate_hz);
206 MaybeResetBuffer(&output_, output_config_);
207}
208
209void DebugDumpGenerator::SetOutputChannels(int channels) {
210 output_config_.set_num_channels(channels);
211 MaybeResetBuffer(&output_, output_config_);
212}
213
214void DebugDumpGenerator::StartRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700215 apm_->AttachAecDump(
216 AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_));
minyue275d2552015-11-04 06:23:54 -0800217}
218
219void DebugDumpGenerator::Process(size_t num_blocks) {
220 for (size_t i = 0; i < num_blocks; ++i) {
221 ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_,
222 reverse_config_, reverse_->channels());
223 ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_,
224 input_->channels());
225 RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100));
226 apm_->set_stream_key_pressed(i % 10 == 9);
227 RTC_CHECK_EQ(AudioProcessing::kNoError,
228 apm_->ProcessStream(input_->channels(), input_config_,
229 output_config_, output_->channels()));
230
Yves Gerey665174f2018-06-19 15:03:05 +0200231 RTC_CHECK_EQ(
232 AudioProcessing::kNoError,
233 apm_->ProcessReverseStream(reverse_->channels(), reverse_config_,
234 reverse_config_, reverse_->channels()));
minyue275d2552015-11-04 06:23:54 -0800235 }
236}
237
238void DebugDumpGenerator::StopRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700239 apm_->DetachAecDump();
minyue275d2552015-11-04 06:23:54 -0800240}
241
242void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio,
243 int channels,
244 const StreamConfig& config,
245 float* const* buffer) {
246 const size_t num_frames = config.num_frames();
247 const int out_channels = config.num_channels();
248
249 std::vector<int16_t> signal(channels * num_frames);
250
251 audio->Read(num_frames * channels, &signal[0]);
252
253 // We only allow reducing number of channels by discarding some channels.
254 RTC_CHECK_LE(out_channels, channels);
255 for (int channel = 0; channel < out_channels; ++channel) {
256 for (size_t i = 0; i < num_frames; ++i) {
257 buffer[channel][i] = S16ToFloat(signal[i * channels + channel]);
258 }
259 }
260}
261
262} // namespace
263
264class DebugDumpTest : public ::testing::Test {
265 public:
minyue275d2552015-11-04 06:23:54 -0800266 // VerifyDebugDump replays a debug dump using APM and verifies that the result
267 // is bit-exact-identical to the output channel in the dump. This is only
268 // guaranteed if the debug dump is started on the first frame.
Alex Loiko890988c2017-08-31 10:25:48 +0200269 void VerifyDebugDump(const std::string& in_filename);
minyue275d2552015-11-04 06:23:54 -0800270
271 private:
minyue0de1c132016-03-17 02:39:30 -0700272 DebugDumpReplayer debug_dump_replayer_;
minyue275d2552015-11-04 06:23:54 -0800273};
274
minyue275d2552015-11-04 06:23:54 -0800275void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) {
minyue0de1c132016-03-17 02:39:30 -0700276 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename));
minyue275d2552015-11-04 06:23:54 -0800277
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200278 while (const absl::optional<audioproc::Event> event =
279 debug_dump_replayer_.GetNextEvent()) {
minyue0de1c132016-03-17 02:39:30 -0700280 debug_dump_replayer_.RunNextEvent();
281 if (event->type() == audioproc::Event::STREAM) {
282 const audioproc::Stream* msg = &event->stream();
283 const StreamConfig output_config = debug_dump_replayer_.GetOutputConfig();
284 const ChannelBuffer<float>* output = debug_dump_replayer_.GetOutput();
285 // Check that output of APM is bit-exact to the output in the dump.
286 ASSERT_EQ(output_config.num_channels(),
287 static_cast<size_t>(msg->output_channel_size()));
288 ASSERT_EQ(output_config.num_frames() * sizeof(float),
289 msg->output_channel(0).size());
290 for (int i = 0; i < msg->output_channel_size(); ++i) {
Yves Gerey665174f2018-06-19 15:03:05 +0200291 ASSERT_EQ(0,
292 memcmp(output->channels()[i], msg->output_channel(i).data(),
293 msg->output_channel(i).size()));
minyue0de1c132016-03-17 02:39:30 -0700294 }
minyue275d2552015-11-04 06:23:54 -0800295 }
296 }
minyue275d2552015-11-04 06:23:54 -0800297}
298
299TEST_F(DebugDumpTest, SimpleCase) {
300 Config config;
peah88ac8532016-09-12 16:47:25 -0700301 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800302 generator.StartRecording();
303 generator.Process(100);
304 generator.StopRecording();
305 VerifyDebugDump(generator.dump_file_name());
306}
307
308TEST_F(DebugDumpTest, ChangeInputFormat) {
309 Config config;
peah88ac8532016-09-12 16:47:25 -0700310 DebugDumpGenerator generator(config, AudioProcessing::Config());
311
minyue275d2552015-11-04 06:23:54 -0800312 generator.StartRecording();
313 generator.Process(100);
314 generator.SetInputRate(48000);
315
316 generator.ForceInputMono(true);
317 // Number of output channel should not be larger than that of input. APM will
318 // fail otherwise.
319 generator.SetOutputChannels(1);
320
321 generator.Process(100);
322 generator.StopRecording();
323 VerifyDebugDump(generator.dump_file_name());
324}
325
326TEST_F(DebugDumpTest, ChangeReverseFormat) {
327 Config config;
peah88ac8532016-09-12 16:47:25 -0700328 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800329 generator.StartRecording();
330 generator.Process(100);
331 generator.SetReverseRate(48000);
332 generator.ForceReverseMono(true);
333 generator.Process(100);
334 generator.StopRecording();
335 VerifyDebugDump(generator.dump_file_name());
336}
337
338TEST_F(DebugDumpTest, ChangeOutputFormat) {
339 Config config;
peah88ac8532016-09-12 16:47:25 -0700340 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800341 generator.StartRecording();
342 generator.Process(100);
343 generator.SetOutputRate(48000);
344 generator.SetOutputChannels(1);
345 generator.Process(100);
346 generator.StopRecording();
347 VerifyDebugDump(generator.dump_file_name());
348}
349
350TEST_F(DebugDumpTest, ToggleAec) {
351 Config config;
peah88ac8532016-09-12 16:47:25 -0700352 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800353 generator.StartRecording();
354 generator.Process(100);
355
356 EchoCancellation* aec = generator.apm()->echo_cancellation();
357 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled()));
358
359 generator.Process(100);
360 generator.StopRecording();
361 VerifyDebugDump(generator.dump_file_name());
362}
363
364TEST_F(DebugDumpTest, ToggleDelayAgnosticAec) {
365 Config config;
366 config.Set<DelayAgnostic>(new DelayAgnostic(true));
peah88ac8532016-09-12 16:47:25 -0700367 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800368 generator.StartRecording();
369 generator.Process(100);
370
Sam Zackrisson2a959d92018-07-23 14:48:07 +0000371 EchoCancellation* aec = generator.apm()->echo_cancellation();
372 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled()));
minyue275d2552015-11-04 06:23:54 -0800373
374 generator.Process(100);
375 generator.StopRecording();
376 VerifyDebugDump(generator.dump_file_name());
377}
378
peah0332c2d2016-04-15 11:23:33 -0700379TEST_F(DebugDumpTest, VerifyRefinedAdaptiveFilterExperimentalString) {
380 Config config;
381 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
peah88ac8532016-09-12 16:47:25 -0700382 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah0332c2d2016-04-15 11:23:33 -0700383 generator.StartRecording();
384 generator.Process(100);
385 generator.StopRecording();
386
387 DebugDumpReplayer debug_dump_replayer_;
388
389 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
390
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200391 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700392 debug_dump_replayer_.GetNextEvent()) {
393 debug_dump_replayer_.RunNextEvent();
394 if (event->type() == audioproc::Event::CONFIG) {
395 const audioproc::Config* msg = &event->config();
396 ASSERT_TRUE(msg->has_experiments_description());
397 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
398 msg->experiments_description().c_str());
399 }
400 }
401}
402
403TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) {
404 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800405 AudioProcessing::Config apm_config;
peah0332c2d2016-04-15 11:23:33 -0700406 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
henrik.lundinbd681b92016-12-05 09:08:42 -0800407 // Arbitrarily set clipping gain to 17, which will never be the default.
408 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200409 bool enable_aec3 = true;
410 DebugDumpGenerator generator(config, apm_config, enable_aec3);
peah0332c2d2016-04-15 11:23:33 -0700411 generator.StartRecording();
412 generator.Process(100);
413 generator.StopRecording();
414
415 DebugDumpReplayer debug_dump_replayer_;
416
417 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
418
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200419 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700420 debug_dump_replayer_.GetNextEvent()) {
421 debug_dump_replayer_.RunNextEvent();
422 if (event->type() == audioproc::Event::CONFIG) {
423 const audioproc::Config* msg = &event->config();
424 ASSERT_TRUE(msg->has_experiments_description());
425 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
426 msg->experiments_description().c_str());
Gustaf Ullbergce045ac2017-10-16 13:49:04 +0200427 EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700428 msg->experiments_description().c_str());
henrik.lundinbd681b92016-12-05 09:08:42 -0800429 EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment",
430 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700431 }
432 }
433}
434
435TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) {
436 Config config;
437 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
peah88ac8532016-09-12 16:47:25 -0700438 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah0332c2d2016-04-15 11:23:33 -0700439 generator.StartRecording();
440 generator.Process(100);
441 generator.StopRecording();
442
443 DebugDumpReplayer debug_dump_replayer_;
444
445 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
446
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200447 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700448 debug_dump_replayer_.GetNextEvent()) {
449 debug_dump_replayer_.RunNextEvent();
450 if (event->type() == audioproc::Event::CONFIG) {
451 const audioproc::Config* msg = &event->config();
452 ASSERT_TRUE(msg->has_experiments_description());
453 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
454 msg->experiments_description().c_str());
455 EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AEC3",
456 msg->experiments_description().c_str());
henrik.lundinbd681b92016-12-05 09:08:42 -0800457 EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AgcClippingLevelExperiment",
458 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700459 }
460 }
461}
462
peah7789fe72016-04-15 01:19:44 -0700463TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) {
464 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800465 AudioProcessing::Config apm_config;
Sam Zackrisson2a959d92018-07-23 14:48:07 +0000466 DebugDumpGenerator generator(config, apm_config, true);
peah7789fe72016-04-15 01:19:44 -0700467 generator.StartRecording();
468 generator.Process(100);
469 generator.StopRecording();
470
471 DebugDumpReplayer debug_dump_replayer_;
472
473 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
474
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200475 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700476 debug_dump_replayer_.GetNextEvent()) {
477 debug_dump_replayer_.RunNextEvent();
478 if (event->type() == audioproc::Event::CONFIG) {
479 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700480 ASSERT_TRUE(msg->has_experiments_description());
Gustaf Ullbergce045ac2017-10-16 13:49:04 +0200481 EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700482 msg->experiments_description().c_str());
peah7789fe72016-04-15 01:19:44 -0700483 }
484 }
485}
486
henrik.lundinbd681b92016-12-05 09:08:42 -0800487TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) {
488 Config config;
489 // Arbitrarily set clipping gain to 17, which will never be the default.
490 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
491 DebugDumpGenerator generator(config, AudioProcessing::Config());
492 generator.StartRecording();
493 generator.Process(100);
494 generator.StopRecording();
495
496 DebugDumpReplayer debug_dump_replayer_;
497
498 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
499
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200500 while (const absl::optional<audioproc::Event> event =
henrik.lundinbd681b92016-12-05 09:08:42 -0800501 debug_dump_replayer_.GetNextEvent()) {
502 debug_dump_replayer_.RunNextEvent();
503 if (event->type() == audioproc::Event::CONFIG) {
504 const audioproc::Config* msg = &event->config();
505 ASSERT_TRUE(msg->has_experiments_description());
506 EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment",
507 msg->experiments_description().c_str());
508 }
509 }
510}
511
peah7789fe72016-04-15 01:19:44 -0700512TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) {
513 Config config;
peah88ac8532016-09-12 16:47:25 -0700514 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah7789fe72016-04-15 01:19:44 -0700515 generator.StartRecording();
516 generator.Process(100);
517 generator.StopRecording();
518
519 DebugDumpReplayer debug_dump_replayer_;
520
521 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
522
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200523 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700524 debug_dump_replayer_.GetNextEvent()) {
525 debug_dump_replayer_.RunNextEvent();
526 if (event->type() == audioproc::Event::CONFIG) {
527 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700528 ASSERT_TRUE(msg->has_experiments_description());
peah7789fe72016-04-15 01:19:44 -0700529 EXPECT_EQ(0u, msg->experiments_description().size());
530 }
531 }
532}
533
minyue275d2552015-11-04 06:23:54 -0800534TEST_F(DebugDumpTest, ToggleAecLevel) {
535 Config config;
peah88ac8532016-09-12 16:47:25 -0700536 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800537 EchoCancellation* aec = generator.apm()->echo_cancellation();
538 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(true));
539 EXPECT_EQ(AudioProcessing::kNoError,
540 aec->set_suppression_level(EchoCancellation::kLowSuppression));
541 generator.StartRecording();
542 generator.Process(100);
543
544 EXPECT_EQ(AudioProcessing::kNoError,
545 aec->set_suppression_level(EchoCancellation::kHighSuppression));
546 generator.Process(100);
547 generator.StopRecording();
548 VerifyDebugDump(generator.dump_file_name());
549}
550
Kári Tristan Helgason470c0882016-10-03 13:13:29 +0200551// AGC is not supported on Android or iOS.
552#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
minyue275d2552015-11-04 06:23:54 -0800553#define MAYBE_ToggleAgc DISABLED_ToggleAgc
554#else
555#define MAYBE_ToggleAgc ToggleAgc
556#endif
557TEST_F(DebugDumpTest, MAYBE_ToggleAgc) {
558 Config config;
peah88ac8532016-09-12 16:47:25 -0700559 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800560 generator.StartRecording();
561 generator.Process(100);
562
563 GainControl* agc = generator.apm()->gain_control();
564 EXPECT_EQ(AudioProcessing::kNoError, agc->Enable(!agc->is_enabled()));
565
566 generator.Process(100);
567 generator.StopRecording();
568 VerifyDebugDump(generator.dump_file_name());
569}
570
571TEST_F(DebugDumpTest, ToggleNs) {
572 Config config;
peah88ac8532016-09-12 16:47:25 -0700573 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800574 generator.StartRecording();
575 generator.Process(100);
576
577 NoiseSuppression* ns = generator.apm()->noise_suppression();
578 EXPECT_EQ(AudioProcessing::kNoError, ns->Enable(!ns->is_enabled()));
579
580 generator.Process(100);
581 generator.StopRecording();
582 VerifyDebugDump(generator.dump_file_name());
583}
584
585TEST_F(DebugDumpTest, TransientSuppressionOn) {
586 Config config;
587 config.Set<ExperimentalNs>(new ExperimentalNs(true));
peah88ac8532016-09-12 16:47:25 -0700588 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800589 generator.StartRecording();
590 generator.Process(100);
591 generator.StopRecording();
592 VerifyDebugDump(generator.dump_file_name());
593}
594
minyue275d2552015-11-04 06:23:54 -0800595} // namespace test
596} // namespace webrtc