blob: 7d0a2bd5748278a021f3969b9da2296f37762fab [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"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "test/testsupport/file_utils.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;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200362 AudioProcessing::Config apm_config;
363 DebugDumpGenerator generator(config, apm_config);
minyue275d2552015-11-04 06:23:54 -0800364 generator.StartRecording();
365 generator.Process(100);
366
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200367 apm_config.echo_canceller.enabled = true;
368 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800369
370 generator.Process(100);
371 generator.StopRecording();
372 VerifyDebugDump(generator.dump_file_name());
373}
374
375TEST_F(DebugDumpTest, ToggleDelayAgnosticAec) {
376 Config config;
377 config.Set<DelayAgnostic>(new DelayAgnostic(true));
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200378 AudioProcessing::Config apm_config;
379 DebugDumpGenerator generator(config, apm_config);
minyue275d2552015-11-04 06:23:54 -0800380 generator.StartRecording();
381 generator.Process(100);
382
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200383 apm_config.echo_canceller.enabled = true;
384 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800385
386 generator.Process(100);
387 generator.StopRecording();
388 VerifyDebugDump(generator.dump_file_name());
389}
390
peah0332c2d2016-04-15 11:23:33 -0700391TEST_F(DebugDumpTest, VerifyRefinedAdaptiveFilterExperimentalString) {
392 Config config;
393 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
peah88ac8532016-09-12 16:47:25 -0700394 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah0332c2d2016-04-15 11:23:33 -0700395 generator.StartRecording();
396 generator.Process(100);
397 generator.StopRecording();
398
399 DebugDumpReplayer debug_dump_replayer_;
400
401 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
402
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200403 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700404 debug_dump_replayer_.GetNextEvent()) {
405 debug_dump_replayer_.RunNextEvent();
406 if (event->type() == audioproc::Event::CONFIG) {
407 const audioproc::Config* msg = &event->config();
408 ASSERT_TRUE(msg->has_experiments_description());
409 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
410 msg->experiments_description().c_str());
411 }
412 }
413}
414
415TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) {
416 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800417 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200418 apm_config.echo_canceller.enabled = true;
peah0332c2d2016-04-15 11:23:33 -0700419 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
henrik.lundinbd681b92016-12-05 09:08:42 -0800420 // Arbitrarily set clipping gain to 17, which will never be the default.
421 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200422 bool enable_aec3 = true;
423 DebugDumpGenerator generator(config, apm_config, enable_aec3);
peah0332c2d2016-04-15 11:23:33 -0700424 generator.StartRecording();
425 generator.Process(100);
426 generator.StopRecording();
427
428 DebugDumpReplayer debug_dump_replayer_;
429
430 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
431
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200432 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700433 debug_dump_replayer_.GetNextEvent()) {
434 debug_dump_replayer_.RunNextEvent();
435 if (event->type() == audioproc::Event::CONFIG) {
436 const audioproc::Config* msg = &event->config();
437 ASSERT_TRUE(msg->has_experiments_description());
438 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
439 msg->experiments_description().c_str());
Gustaf Ullbergce045ac2017-10-16 13:49:04 +0200440 EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700441 msg->experiments_description().c_str());
henrik.lundinbd681b92016-12-05 09:08:42 -0800442 EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment",
443 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700444 }
445 }
446}
447
448TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) {
449 Config config;
450 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
peah88ac8532016-09-12 16:47:25 -0700451 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah0332c2d2016-04-15 11:23:33 -0700452 generator.StartRecording();
453 generator.Process(100);
454 generator.StopRecording();
455
456 DebugDumpReplayer debug_dump_replayer_;
457
458 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
459
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200460 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700461 debug_dump_replayer_.GetNextEvent()) {
462 debug_dump_replayer_.RunNextEvent();
463 if (event->type() == audioproc::Event::CONFIG) {
464 const audioproc::Config* msg = &event->config();
465 ASSERT_TRUE(msg->has_experiments_description());
466 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
467 msg->experiments_description().c_str());
468 EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AEC3",
469 msg->experiments_description().c_str());
henrik.lundinbd681b92016-12-05 09:08:42 -0800470 EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AgcClippingLevelExperiment",
471 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700472 }
473 }
474}
475
peah7789fe72016-04-15 01:19:44 -0700476TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) {
477 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800478 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200479 apm_config.echo_canceller.enabled = true;
Sam Zackrisson2a959d92018-07-23 14:48:07 +0000480 DebugDumpGenerator generator(config, apm_config, true);
peah7789fe72016-04-15 01:19:44 -0700481 generator.StartRecording();
482 generator.Process(100);
483 generator.StopRecording();
484
485 DebugDumpReplayer debug_dump_replayer_;
486
487 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
488
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200489 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700490 debug_dump_replayer_.GetNextEvent()) {
491 debug_dump_replayer_.RunNextEvent();
492 if (event->type() == audioproc::Event::CONFIG) {
493 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700494 ASSERT_TRUE(msg->has_experiments_description());
Gustaf Ullbergce045ac2017-10-16 13:49:04 +0200495 EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700496 msg->experiments_description().c_str());
peah7789fe72016-04-15 01:19:44 -0700497 }
498 }
499}
500
henrik.lundinbd681b92016-12-05 09:08:42 -0800501TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) {
502 Config config;
503 // Arbitrarily set clipping gain to 17, which will never be the default.
504 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
505 DebugDumpGenerator generator(config, AudioProcessing::Config());
506 generator.StartRecording();
507 generator.Process(100);
508 generator.StopRecording();
509
510 DebugDumpReplayer debug_dump_replayer_;
511
512 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
513
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200514 while (const absl::optional<audioproc::Event> event =
henrik.lundinbd681b92016-12-05 09:08:42 -0800515 debug_dump_replayer_.GetNextEvent()) {
516 debug_dump_replayer_.RunNextEvent();
517 if (event->type() == audioproc::Event::CONFIG) {
518 const audioproc::Config* msg = &event->config();
519 ASSERT_TRUE(msg->has_experiments_description());
520 EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment",
521 msg->experiments_description().c_str());
522 }
523 }
524}
525
peah7789fe72016-04-15 01:19:44 -0700526TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) {
527 Config config;
peah88ac8532016-09-12 16:47:25 -0700528 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah7789fe72016-04-15 01:19:44 -0700529 generator.StartRecording();
530 generator.Process(100);
531 generator.StopRecording();
532
533 DebugDumpReplayer debug_dump_replayer_;
534
535 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
536
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200537 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700538 debug_dump_replayer_.GetNextEvent()) {
539 debug_dump_replayer_.RunNextEvent();
540 if (event->type() == audioproc::Event::CONFIG) {
541 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700542 ASSERT_TRUE(msg->has_experiments_description());
peah7789fe72016-04-15 01:19:44 -0700543 EXPECT_EQ(0u, msg->experiments_description().size());
544 }
545 }
546}
547
minyue275d2552015-11-04 06:23:54 -0800548TEST_F(DebugDumpTest, ToggleAecLevel) {
549 Config config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200550 AudioProcessing::Config apm_config;
551 apm_config.echo_canceller.enabled = true;
552 apm_config.echo_canceller.mobile_mode = false;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200553 apm_config.echo_canceller.legacy_moderate_suppression_level = true;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200554 DebugDumpGenerator generator(config, apm_config);
minyue275d2552015-11-04 06:23:54 -0800555 generator.StartRecording();
556 generator.Process(100);
557
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200558 apm_config.echo_canceller.legacy_moderate_suppression_level = false;
559 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800560 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