blob: 8b83c0f63e93c965f6644fa56b3684c17d33e16f [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,
Alex Loiko62347222018-09-10 10:18:07 +020051 bool enable_aec3,
52 bool enable_pre_amplifier);
minyue275d2552015-11-04 06:23:54 -080053
54 // Constructor that uses default input files.
peah88ac8532016-09-12 16:47:25 -070055 explicit DebugDumpGenerator(const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +020056 const AudioProcessing::Config& apm_config,
57 bool enable_aec3);
58
59 explicit DebugDumpGenerator(const Config& config,
peah88ac8532016-09-12 16:47:25 -070060 const AudioProcessing::Config& apm_config);
minyue275d2552015-11-04 06:23:54 -080061
62 ~DebugDumpGenerator();
63
64 // Changes the sample rate of the input audio to the APM.
65 void SetInputRate(int rate_hz);
66
67 // Sets if converts stereo input signal to mono by discarding other channels.
68 void ForceInputMono(bool mono);
69
70 // Changes the sample rate of the reverse audio to the APM.
71 void SetReverseRate(int rate_hz);
72
73 // Sets if converts stereo reverse signal to mono by discarding other
74 // channels.
75 void ForceReverseMono(bool mono);
76
77 // Sets the required sample rate of the APM output.
78 void SetOutputRate(int rate_hz);
79
80 // Sets the required channels of the APM output.
81 void SetOutputChannels(int channels);
82
83 std::string dump_file_name() const { return dump_file_name_; }
84
85 void StartRecording();
86 void Process(size_t num_blocks);
87 void StopRecording();
88 AudioProcessing* apm() const { return apm_.get(); }
89
90 private:
Yves Gerey665174f2018-06-19 15:03:05 +020091 static void ReadAndDeinterleave(ResampleInputAudioFile* audio,
92 int channels,
minyue275d2552015-11-04 06:23:54 -080093 const StreamConfig& config,
94 float* const* buffer);
95
96 // APM input/output settings.
97 StreamConfig input_config_;
98 StreamConfig reverse_config_;
99 StreamConfig output_config_;
100
101 // Input file format.
102 const std::string input_file_name_;
103 ResampleInputAudioFile input_audio_;
104 const int input_file_channels_;
105
106 // Reverse file format.
107 const std::string reverse_file_name_;
108 ResampleInputAudioFile reverse_audio_;
109 const int reverse_file_channels_;
110
111 // Buffer for APM input/output.
kwiberg62eaacf2016-02-17 06:39:05 -0800112 std::unique_ptr<ChannelBuffer<float>> input_;
113 std::unique_ptr<ChannelBuffer<float>> reverse_;
114 std::unique_ptr<ChannelBuffer<float>> output_;
minyue275d2552015-11-04 06:23:54 -0800115
Alex Loiko62347222018-09-10 10:18:07 +0200116 bool enable_pre_amplifier_;
117
aleloif4dd1912017-06-15 01:55:38 -0700118 rtc::TaskQueue worker_queue_;
kwiberg62eaacf2016-02-17 06:39:05 -0800119 std::unique_ptr<AudioProcessing> apm_;
minyue275d2552015-11-04 06:23:54 -0800120
121 const std::string dump_file_name_;
122};
123
124DebugDumpGenerator::DebugDumpGenerator(const std::string& input_file_name,
125 int input_rate_hz,
126 int input_channels,
127 const std::string& reverse_file_name,
128 int reverse_rate_hz,
129 int reverse_channels,
130 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200131 const std::string& dump_file_name,
Alex Loiko62347222018-09-10 10:18:07 +0200132 bool enable_aec3,
133 bool enable_pre_amplifier)
minyue275d2552015-11-04 06:23:54 -0800134 : input_config_(input_rate_hz, input_channels),
135 reverse_config_(reverse_rate_hz, reverse_channels),
136 output_config_(input_rate_hz, input_channels),
137 input_audio_(input_file_name, input_rate_hz, input_rate_hz),
138 input_file_channels_(input_channels),
139 reverse_audio_(reverse_file_name, reverse_rate_hz, reverse_rate_hz),
140 reverse_file_channels_(reverse_channels),
141 input_(new ChannelBuffer<float>(input_config_.num_frames(),
142 input_config_.num_channels())),
143 reverse_(new ChannelBuffer<float>(reverse_config_.num_frames(),
144 reverse_config_.num_channels())),
145 output_(new ChannelBuffer<float>(output_config_.num_frames(),
146 output_config_.num_channels())),
Alex Loiko62347222018-09-10 10:18:07 +0200147 enable_pre_amplifier_(enable_pre_amplifier),
aleloif4dd1912017-06-15 01:55:38 -0700148 worker_queue_("debug_dump_generator_worker_queue"),
Ivo Creusen62337e52018-01-09 14:17:33 +0100149 dump_file_name_(dump_file_name) {
150 AudioProcessingBuilder apm_builder;
151 if (enable_aec3) {
152 apm_builder.SetEchoControlFactory(
153 std::unique_ptr<EchoControlFactory>(new EchoCanceller3Factory()));
154 }
155 apm_.reset(apm_builder.Create(config));
156}
minyue275d2552015-11-04 06:23:54 -0800157
peah88ac8532016-09-12 16:47:25 -0700158DebugDumpGenerator::DebugDumpGenerator(
159 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200160 const AudioProcessing::Config& apm_config,
161 bool enable_aec3)
peah88ac8532016-09-12 16:47:25 -0700162 : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"),
163 32000,
164 2,
165 ResourcePath("far32_stereo", "pcm"),
166 32000,
167 2,
168 config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200169 TempFilename(OutputPath(), "debug_aec"),
Alex Loiko62347222018-09-10 10:18:07 +0200170 enable_aec3,
171 apm_config.pre_amplifier.enabled) {
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200172 apm_->ApplyConfig(apm_config);
173}
174
175DebugDumpGenerator::DebugDumpGenerator(
176 const Config& config,
177 const AudioProcessing::Config& apm_config)
178 : DebugDumpGenerator(config, apm_config, false) {
peah88ac8532016-09-12 16:47:25 -0700179 apm_->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800180}
181
182DebugDumpGenerator::~DebugDumpGenerator() {
183 remove(dump_file_name_.c_str());
184}
185
186void DebugDumpGenerator::SetInputRate(int rate_hz) {
187 input_audio_.set_output_rate_hz(rate_hz);
188 input_config_.set_sample_rate_hz(rate_hz);
189 MaybeResetBuffer(&input_, input_config_);
190}
191
192void DebugDumpGenerator::ForceInputMono(bool mono) {
193 const int channels = mono ? 1 : input_file_channels_;
194 input_config_.set_num_channels(channels);
195 MaybeResetBuffer(&input_, input_config_);
196}
197
198void DebugDumpGenerator::SetReverseRate(int rate_hz) {
199 reverse_audio_.set_output_rate_hz(rate_hz);
200 reverse_config_.set_sample_rate_hz(rate_hz);
201 MaybeResetBuffer(&reverse_, reverse_config_);
202}
203
204void DebugDumpGenerator::ForceReverseMono(bool mono) {
205 const int channels = mono ? 1 : reverse_file_channels_;
206 reverse_config_.set_num_channels(channels);
207 MaybeResetBuffer(&reverse_, reverse_config_);
208}
209
210void DebugDumpGenerator::SetOutputRate(int rate_hz) {
211 output_config_.set_sample_rate_hz(rate_hz);
212 MaybeResetBuffer(&output_, output_config_);
213}
214
215void DebugDumpGenerator::SetOutputChannels(int channels) {
216 output_config_.set_num_channels(channels);
217 MaybeResetBuffer(&output_, output_config_);
218}
219
220void DebugDumpGenerator::StartRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700221 apm_->AttachAecDump(
222 AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_));
minyue275d2552015-11-04 06:23:54 -0800223}
224
225void DebugDumpGenerator::Process(size_t num_blocks) {
226 for (size_t i = 0; i < num_blocks; ++i) {
227 ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_,
228 reverse_config_, reverse_->channels());
229 ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_,
230 input_->channels());
231 RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100));
Alex Loiko62347222018-09-10 10:18:07 +0200232 if (enable_pre_amplifier_) {
233 apm_->SetRuntimeSetting(
234 AudioProcessing::RuntimeSetting::CreateCapturePreGain(1 + i % 10));
235 }
minyue275d2552015-11-04 06:23:54 -0800236 apm_->set_stream_key_pressed(i % 10 == 9);
237 RTC_CHECK_EQ(AudioProcessing::kNoError,
238 apm_->ProcessStream(input_->channels(), input_config_,
239 output_config_, output_->channels()));
240
Yves Gerey665174f2018-06-19 15:03:05 +0200241 RTC_CHECK_EQ(
242 AudioProcessing::kNoError,
243 apm_->ProcessReverseStream(reverse_->channels(), reverse_config_,
244 reverse_config_, reverse_->channels()));
minyue275d2552015-11-04 06:23:54 -0800245 }
246}
247
248void DebugDumpGenerator::StopRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700249 apm_->DetachAecDump();
minyue275d2552015-11-04 06:23:54 -0800250}
251
252void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio,
253 int channels,
254 const StreamConfig& config,
255 float* const* buffer) {
256 const size_t num_frames = config.num_frames();
257 const int out_channels = config.num_channels();
258
259 std::vector<int16_t> signal(channels * num_frames);
260
261 audio->Read(num_frames * channels, &signal[0]);
262
263 // We only allow reducing number of channels by discarding some channels.
264 RTC_CHECK_LE(out_channels, channels);
265 for (int channel = 0; channel < out_channels; ++channel) {
266 for (size_t i = 0; i < num_frames; ++i) {
267 buffer[channel][i] = S16ToFloat(signal[i * channels + channel]);
268 }
269 }
270}
271
272} // namespace
273
274class DebugDumpTest : public ::testing::Test {
275 public:
minyue275d2552015-11-04 06:23:54 -0800276 // VerifyDebugDump replays a debug dump using APM and verifies that the result
277 // is bit-exact-identical to the output channel in the dump. This is only
278 // guaranteed if the debug dump is started on the first frame.
Alex Loiko890988c2017-08-31 10:25:48 +0200279 void VerifyDebugDump(const std::string& in_filename);
minyue275d2552015-11-04 06:23:54 -0800280
281 private:
minyue0de1c132016-03-17 02:39:30 -0700282 DebugDumpReplayer debug_dump_replayer_;
minyue275d2552015-11-04 06:23:54 -0800283};
284
minyue275d2552015-11-04 06:23:54 -0800285void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) {
minyue0de1c132016-03-17 02:39:30 -0700286 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename));
minyue275d2552015-11-04 06:23:54 -0800287
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200288 while (const absl::optional<audioproc::Event> event =
289 debug_dump_replayer_.GetNextEvent()) {
minyue0de1c132016-03-17 02:39:30 -0700290 debug_dump_replayer_.RunNextEvent();
291 if (event->type() == audioproc::Event::STREAM) {
292 const audioproc::Stream* msg = &event->stream();
293 const StreamConfig output_config = debug_dump_replayer_.GetOutputConfig();
294 const ChannelBuffer<float>* output = debug_dump_replayer_.GetOutput();
295 // Check that output of APM is bit-exact to the output in the dump.
296 ASSERT_EQ(output_config.num_channels(),
297 static_cast<size_t>(msg->output_channel_size()));
298 ASSERT_EQ(output_config.num_frames() * sizeof(float),
299 msg->output_channel(0).size());
300 for (int i = 0; i < msg->output_channel_size(); ++i) {
Yves Gerey665174f2018-06-19 15:03:05 +0200301 ASSERT_EQ(0,
302 memcmp(output->channels()[i], msg->output_channel(i).data(),
303 msg->output_channel(i).size()));
minyue0de1c132016-03-17 02:39:30 -0700304 }
minyue275d2552015-11-04 06:23:54 -0800305 }
306 }
minyue275d2552015-11-04 06:23:54 -0800307}
308
309TEST_F(DebugDumpTest, SimpleCase) {
310 Config config;
peah88ac8532016-09-12 16:47:25 -0700311 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800312 generator.StartRecording();
313 generator.Process(100);
314 generator.StopRecording();
315 VerifyDebugDump(generator.dump_file_name());
316}
317
318TEST_F(DebugDumpTest, ChangeInputFormat) {
319 Config config;
peah88ac8532016-09-12 16:47:25 -0700320 DebugDumpGenerator generator(config, AudioProcessing::Config());
321
minyue275d2552015-11-04 06:23:54 -0800322 generator.StartRecording();
323 generator.Process(100);
324 generator.SetInputRate(48000);
325
326 generator.ForceInputMono(true);
327 // Number of output channel should not be larger than that of input. APM will
328 // fail otherwise.
329 generator.SetOutputChannels(1);
330
331 generator.Process(100);
332 generator.StopRecording();
333 VerifyDebugDump(generator.dump_file_name());
334}
335
336TEST_F(DebugDumpTest, ChangeReverseFormat) {
337 Config config;
peah88ac8532016-09-12 16:47:25 -0700338 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800339 generator.StartRecording();
340 generator.Process(100);
341 generator.SetReverseRate(48000);
342 generator.ForceReverseMono(true);
343 generator.Process(100);
344 generator.StopRecording();
345 VerifyDebugDump(generator.dump_file_name());
346}
347
348TEST_F(DebugDumpTest, ChangeOutputFormat) {
349 Config config;
peah88ac8532016-09-12 16:47:25 -0700350 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800351 generator.StartRecording();
352 generator.Process(100);
353 generator.SetOutputRate(48000);
354 generator.SetOutputChannels(1);
355 generator.Process(100);
356 generator.StopRecording();
357 VerifyDebugDump(generator.dump_file_name());
358}
359
360TEST_F(DebugDumpTest, ToggleAec) {
361 Config config;
peah88ac8532016-09-12 16:47:25 -0700362 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800363 generator.StartRecording();
364 generator.Process(100);
365
366 EchoCancellation* aec = generator.apm()->echo_cancellation();
367 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled()));
368
369 generator.Process(100);
370 generator.StopRecording();
371 VerifyDebugDump(generator.dump_file_name());
372}
373
374TEST_F(DebugDumpTest, ToggleDelayAgnosticAec) {
375 Config config;
376 config.Set<DelayAgnostic>(new DelayAgnostic(true));
peah88ac8532016-09-12 16:47:25 -0700377 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800378 generator.StartRecording();
379 generator.Process(100);
380
Sam Zackrisson2a959d92018-07-23 14:48:07 +0000381 EchoCancellation* aec = generator.apm()->echo_cancellation();
382 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled()));
minyue275d2552015-11-04 06:23:54 -0800383
384 generator.Process(100);
385 generator.StopRecording();
386 VerifyDebugDump(generator.dump_file_name());
387}
388
peah0332c2d2016-04-15 11:23:33 -0700389TEST_F(DebugDumpTest, VerifyRefinedAdaptiveFilterExperimentalString) {
390 Config config;
391 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
peah88ac8532016-09-12 16:47:25 -0700392 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah0332c2d2016-04-15 11:23:33 -0700393 generator.StartRecording();
394 generator.Process(100);
395 generator.StopRecording();
396
397 DebugDumpReplayer debug_dump_replayer_;
398
399 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
400
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200401 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700402 debug_dump_replayer_.GetNextEvent()) {
403 debug_dump_replayer_.RunNextEvent();
404 if (event->type() == audioproc::Event::CONFIG) {
405 const audioproc::Config* msg = &event->config();
406 ASSERT_TRUE(msg->has_experiments_description());
407 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
408 msg->experiments_description().c_str());
409 }
410 }
411}
412
413TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) {
414 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800415 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200416 apm_config.echo_canceller.enabled = true;
peah0332c2d2016-04-15 11:23:33 -0700417 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
henrik.lundinbd681b92016-12-05 09:08:42 -0800418 // Arbitrarily set clipping gain to 17, which will never be the default.
419 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200420 bool enable_aec3 = true;
421 DebugDumpGenerator generator(config, apm_config, enable_aec3);
peah0332c2d2016-04-15 11:23:33 -0700422 generator.StartRecording();
423 generator.Process(100);
424 generator.StopRecording();
425
426 DebugDumpReplayer debug_dump_replayer_;
427
428 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
429
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200430 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700431 debug_dump_replayer_.GetNextEvent()) {
432 debug_dump_replayer_.RunNextEvent();
433 if (event->type() == audioproc::Event::CONFIG) {
434 const audioproc::Config* msg = &event->config();
435 ASSERT_TRUE(msg->has_experiments_description());
436 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
437 msg->experiments_description().c_str());
Gustaf Ullbergce045ac2017-10-16 13:49:04 +0200438 EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700439 msg->experiments_description().c_str());
henrik.lundinbd681b92016-12-05 09:08:42 -0800440 EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment",
441 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700442 }
443 }
444}
445
446TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) {
447 Config config;
448 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
peah88ac8532016-09-12 16:47:25 -0700449 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah0332c2d2016-04-15 11:23:33 -0700450 generator.StartRecording();
451 generator.Process(100);
452 generator.StopRecording();
453
454 DebugDumpReplayer debug_dump_replayer_;
455
456 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
457
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200458 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700459 debug_dump_replayer_.GetNextEvent()) {
460 debug_dump_replayer_.RunNextEvent();
461 if (event->type() == audioproc::Event::CONFIG) {
462 const audioproc::Config* msg = &event->config();
463 ASSERT_TRUE(msg->has_experiments_description());
464 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
465 msg->experiments_description().c_str());
466 EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AEC3",
467 msg->experiments_description().c_str());
henrik.lundinbd681b92016-12-05 09:08:42 -0800468 EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AgcClippingLevelExperiment",
469 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700470 }
471 }
472}
473
peah7789fe72016-04-15 01:19:44 -0700474TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) {
475 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800476 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200477 apm_config.echo_canceller.enabled = true;
Sam Zackrisson2a959d92018-07-23 14:48:07 +0000478 DebugDumpGenerator generator(config, apm_config, true);
peah7789fe72016-04-15 01:19:44 -0700479 generator.StartRecording();
480 generator.Process(100);
481 generator.StopRecording();
482
483 DebugDumpReplayer debug_dump_replayer_;
484
485 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
486
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200487 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700488 debug_dump_replayer_.GetNextEvent()) {
489 debug_dump_replayer_.RunNextEvent();
490 if (event->type() == audioproc::Event::CONFIG) {
491 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700492 ASSERT_TRUE(msg->has_experiments_description());
Gustaf Ullbergce045ac2017-10-16 13:49:04 +0200493 EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700494 msg->experiments_description().c_str());
peah7789fe72016-04-15 01:19:44 -0700495 }
496 }
497}
498
henrik.lundinbd681b92016-12-05 09:08:42 -0800499TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) {
500 Config config;
501 // Arbitrarily set clipping gain to 17, which will never be the default.
502 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
503 DebugDumpGenerator generator(config, AudioProcessing::Config());
504 generator.StartRecording();
505 generator.Process(100);
506 generator.StopRecording();
507
508 DebugDumpReplayer debug_dump_replayer_;
509
510 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
511
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200512 while (const absl::optional<audioproc::Event> event =
henrik.lundinbd681b92016-12-05 09:08:42 -0800513 debug_dump_replayer_.GetNextEvent()) {
514 debug_dump_replayer_.RunNextEvent();
515 if (event->type() == audioproc::Event::CONFIG) {
516 const audioproc::Config* msg = &event->config();
517 ASSERT_TRUE(msg->has_experiments_description());
518 EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment",
519 msg->experiments_description().c_str());
520 }
521 }
522}
523
peah7789fe72016-04-15 01:19:44 -0700524TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) {
525 Config config;
peah88ac8532016-09-12 16:47:25 -0700526 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah7789fe72016-04-15 01:19:44 -0700527 generator.StartRecording();
528 generator.Process(100);
529 generator.StopRecording();
530
531 DebugDumpReplayer debug_dump_replayer_;
532
533 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
534
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200535 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700536 debug_dump_replayer_.GetNextEvent()) {
537 debug_dump_replayer_.RunNextEvent();
538 if (event->type() == audioproc::Event::CONFIG) {
539 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700540 ASSERT_TRUE(msg->has_experiments_description());
peah7789fe72016-04-15 01:19:44 -0700541 EXPECT_EQ(0u, msg->experiments_description().size());
542 }
543 }
544}
545
minyue275d2552015-11-04 06:23:54 -0800546TEST_F(DebugDumpTest, ToggleAecLevel) {
547 Config config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200548 AudioProcessing::Config apm_config;
549 apm_config.echo_canceller.enabled = true;
550 apm_config.echo_canceller.mobile_mode = false;
551 DebugDumpGenerator generator(config, apm_config);
minyue275d2552015-11-04 06:23:54 -0800552 EchoCancellation* aec = generator.apm()->echo_cancellation();
minyue275d2552015-11-04 06:23:54 -0800553 EXPECT_EQ(AudioProcessing::kNoError,
554 aec->set_suppression_level(EchoCancellation::kLowSuppression));
555 generator.StartRecording();
556 generator.Process(100);
557
558 EXPECT_EQ(AudioProcessing::kNoError,
559 aec->set_suppression_level(EchoCancellation::kHighSuppression));
560 generator.Process(100);
561 generator.StopRecording();
562 VerifyDebugDump(generator.dump_file_name());
563}
564
Kári Tristan Helgason470c0882016-10-03 13:13:29 +0200565// AGC is not supported on Android or iOS.
566#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
minyue275d2552015-11-04 06:23:54 -0800567#define MAYBE_ToggleAgc DISABLED_ToggleAgc
568#else
569#define MAYBE_ToggleAgc ToggleAgc
570#endif
571TEST_F(DebugDumpTest, MAYBE_ToggleAgc) {
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 GainControl* agc = generator.apm()->gain_control();
578 EXPECT_EQ(AudioProcessing::kNoError, agc->Enable(!agc->is_enabled()));
579
580 generator.Process(100);
581 generator.StopRecording();
582 VerifyDebugDump(generator.dump_file_name());
583}
584
585TEST_F(DebugDumpTest, ToggleNs) {
586 Config config;
peah88ac8532016-09-12 16:47:25 -0700587 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800588 generator.StartRecording();
589 generator.Process(100);
590
591 NoiseSuppression* ns = generator.apm()->noise_suppression();
592 EXPECT_EQ(AudioProcessing::kNoError, ns->Enable(!ns->is_enabled()));
593
594 generator.Process(100);
595 generator.StopRecording();
596 VerifyDebugDump(generator.dump_file_name());
597}
598
599TEST_F(DebugDumpTest, TransientSuppressionOn) {
600 Config config;
601 config.Set<ExperimentalNs>(new ExperimentalNs(true));
peah88ac8532016-09-12 16:47:25 -0700602 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800603 generator.StartRecording();
604 generator.Process(100);
605 generator.StopRecording();
606 VerifyDebugDump(generator.dump_file_name());
607}
608
Alex Loiko62347222018-09-10 10:18:07 +0200609TEST_F(DebugDumpTest, PreAmplifierIsOn) {
610 Config config;
611 AudioProcessing::Config apm_config;
612 apm_config.pre_amplifier.enabled = true;
613 DebugDumpGenerator generator(config, apm_config);
614 generator.StartRecording();
615 generator.Process(100);
616 generator.StopRecording();
617 VerifyDebugDump(generator.dump_file_name());
618}
619
minyue275d2552015-11-04 06:23:54 -0800620} // namespace test
621} // namespace webrtc