blob: b769a6659af5890b3d4a3ba5f95e0de49e676a59 [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"
Danil Chapovalov07122bc2019-03-26 14:37:01 +010022#include "rtc_base/task_queue_for_test.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#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_pre_amplifier);
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,
55 const AudioProcessing::Config& apm_config);
minyue275d2552015-11-04 06:23:54 -080056
57 ~DebugDumpGenerator();
58
59 // Changes the sample rate of the input audio to the APM.
60 void SetInputRate(int rate_hz);
61
62 // Sets if converts stereo input signal to mono by discarding other channels.
63 void ForceInputMono(bool mono);
64
65 // Changes the sample rate of the reverse audio to the APM.
66 void SetReverseRate(int rate_hz);
67
68 // Sets if converts stereo reverse signal to mono by discarding other
69 // channels.
70 void ForceReverseMono(bool mono);
71
72 // Sets the required sample rate of the APM output.
73 void SetOutputRate(int rate_hz);
74
75 // Sets the required channels of the APM output.
76 void SetOutputChannels(int channels);
77
78 std::string dump_file_name() const { return dump_file_name_; }
79
80 void StartRecording();
81 void Process(size_t num_blocks);
82 void StopRecording();
83 AudioProcessing* apm() const { return apm_.get(); }
84
85 private:
Yves Gerey665174f2018-06-19 15:03:05 +020086 static void ReadAndDeinterleave(ResampleInputAudioFile* audio,
87 int channels,
minyue275d2552015-11-04 06:23:54 -080088 const StreamConfig& config,
89 float* const* buffer);
90
91 // APM input/output settings.
92 StreamConfig input_config_;
93 StreamConfig reverse_config_;
94 StreamConfig output_config_;
95
96 // Input file format.
97 const std::string input_file_name_;
98 ResampleInputAudioFile input_audio_;
99 const int input_file_channels_;
100
101 // Reverse file format.
102 const std::string reverse_file_name_;
103 ResampleInputAudioFile reverse_audio_;
104 const int reverse_file_channels_;
105
106 // Buffer for APM input/output.
kwiberg62eaacf2016-02-17 06:39:05 -0800107 std::unique_ptr<ChannelBuffer<float>> input_;
108 std::unique_ptr<ChannelBuffer<float>> reverse_;
109 std::unique_ptr<ChannelBuffer<float>> output_;
minyue275d2552015-11-04 06:23:54 -0800110
Alex Loiko62347222018-09-10 10:18:07 +0200111 bool enable_pre_amplifier_;
112
Danil Chapovalov07122bc2019-03-26 14:37:01 +0100113 TaskQueueForTest worker_queue_;
kwiberg62eaacf2016-02-17 06:39:05 -0800114 std::unique_ptr<AudioProcessing> apm_;
minyue275d2552015-11-04 06:23:54 -0800115
116 const std::string dump_file_name_;
117};
118
119DebugDumpGenerator::DebugDumpGenerator(const std::string& input_file_name,
120 int input_rate_hz,
121 int input_channels,
122 const std::string& reverse_file_name,
123 int reverse_rate_hz,
124 int reverse_channels,
125 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200126 const std::string& dump_file_name,
Alex Loiko62347222018-09-10 10:18:07 +0200127 bool enable_pre_amplifier)
minyue275d2552015-11-04 06:23:54 -0800128 : input_config_(input_rate_hz, input_channels),
129 reverse_config_(reverse_rate_hz, reverse_channels),
130 output_config_(input_rate_hz, input_channels),
131 input_audio_(input_file_name, input_rate_hz, input_rate_hz),
132 input_file_channels_(input_channels),
133 reverse_audio_(reverse_file_name, reverse_rate_hz, reverse_rate_hz),
134 reverse_file_channels_(reverse_channels),
135 input_(new ChannelBuffer<float>(input_config_.num_frames(),
136 input_config_.num_channels())),
137 reverse_(new ChannelBuffer<float>(reverse_config_.num_frames(),
138 reverse_config_.num_channels())),
139 output_(new ChannelBuffer<float>(output_config_.num_frames(),
140 output_config_.num_channels())),
Alex Loiko62347222018-09-10 10:18:07 +0200141 enable_pre_amplifier_(enable_pre_amplifier),
aleloif4dd1912017-06-15 01:55:38 -0700142 worker_queue_("debug_dump_generator_worker_queue"),
Ivo Creusen62337e52018-01-09 14:17:33 +0100143 dump_file_name_(dump_file_name) {
144 AudioProcessingBuilder apm_builder;
Ivo Creusen62337e52018-01-09 14:17:33 +0100145 apm_.reset(apm_builder.Create(config));
146}
minyue275d2552015-11-04 06:23:54 -0800147
peah88ac8532016-09-12 16:47:25 -0700148DebugDumpGenerator::DebugDumpGenerator(
149 const Config& config,
Per Åhgren200feba2019-03-06 04:16:46 +0100150 const AudioProcessing::Config& apm_config)
peah88ac8532016-09-12 16:47:25 -0700151 : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"),
152 32000,
153 2,
154 ResourcePath("far32_stereo", "pcm"),
155 32000,
156 2,
157 config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200158 TempFilename(OutputPath(), "debug_aec"),
Alex Loiko62347222018-09-10 10:18:07 +0200159 apm_config.pre_amplifier.enabled) {
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200160 apm_->ApplyConfig(apm_config);
161}
162
minyue275d2552015-11-04 06:23:54 -0800163DebugDumpGenerator::~DebugDumpGenerator() {
164 remove(dump_file_name_.c_str());
165}
166
167void DebugDumpGenerator::SetInputRate(int rate_hz) {
168 input_audio_.set_output_rate_hz(rate_hz);
169 input_config_.set_sample_rate_hz(rate_hz);
170 MaybeResetBuffer(&input_, input_config_);
171}
172
173void DebugDumpGenerator::ForceInputMono(bool mono) {
174 const int channels = mono ? 1 : input_file_channels_;
175 input_config_.set_num_channels(channels);
176 MaybeResetBuffer(&input_, input_config_);
177}
178
179void DebugDumpGenerator::SetReverseRate(int rate_hz) {
180 reverse_audio_.set_output_rate_hz(rate_hz);
181 reverse_config_.set_sample_rate_hz(rate_hz);
182 MaybeResetBuffer(&reverse_, reverse_config_);
183}
184
185void DebugDumpGenerator::ForceReverseMono(bool mono) {
186 const int channels = mono ? 1 : reverse_file_channels_;
187 reverse_config_.set_num_channels(channels);
188 MaybeResetBuffer(&reverse_, reverse_config_);
189}
190
191void DebugDumpGenerator::SetOutputRate(int rate_hz) {
192 output_config_.set_sample_rate_hz(rate_hz);
193 MaybeResetBuffer(&output_, output_config_);
194}
195
196void DebugDumpGenerator::SetOutputChannels(int channels) {
197 output_config_.set_num_channels(channels);
198 MaybeResetBuffer(&output_, output_config_);
199}
200
201void DebugDumpGenerator::StartRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700202 apm_->AttachAecDump(
203 AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_));
minyue275d2552015-11-04 06:23:54 -0800204}
205
206void DebugDumpGenerator::Process(size_t num_blocks) {
207 for (size_t i = 0; i < num_blocks; ++i) {
208 ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_,
209 reverse_config_, reverse_->channels());
210 ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_,
211 input_->channels());
212 RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100));
Alex Loiko62347222018-09-10 10:18:07 +0200213 if (enable_pre_amplifier_) {
214 apm_->SetRuntimeSetting(
215 AudioProcessing::RuntimeSetting::CreateCapturePreGain(1 + i % 10));
216 }
minyue275d2552015-11-04 06:23:54 -0800217 apm_->set_stream_key_pressed(i % 10 == 9);
218 RTC_CHECK_EQ(AudioProcessing::kNoError,
219 apm_->ProcessStream(input_->channels(), input_config_,
220 output_config_, output_->channels()));
221
Yves Gerey665174f2018-06-19 15:03:05 +0200222 RTC_CHECK_EQ(
223 AudioProcessing::kNoError,
224 apm_->ProcessReverseStream(reverse_->channels(), reverse_config_,
225 reverse_config_, reverse_->channels()));
minyue275d2552015-11-04 06:23:54 -0800226 }
227}
228
229void DebugDumpGenerator::StopRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700230 apm_->DetachAecDump();
minyue275d2552015-11-04 06:23:54 -0800231}
232
233void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio,
234 int channels,
235 const StreamConfig& config,
236 float* const* buffer) {
237 const size_t num_frames = config.num_frames();
238 const int out_channels = config.num_channels();
239
240 std::vector<int16_t> signal(channels * num_frames);
241
242 audio->Read(num_frames * channels, &signal[0]);
243
244 // We only allow reducing number of channels by discarding some channels.
245 RTC_CHECK_LE(out_channels, channels);
246 for (int channel = 0; channel < out_channels; ++channel) {
247 for (size_t i = 0; i < num_frames; ++i) {
248 buffer[channel][i] = S16ToFloat(signal[i * channels + channel]);
249 }
250 }
251}
252
253} // namespace
254
255class DebugDumpTest : public ::testing::Test {
256 public:
minyue275d2552015-11-04 06:23:54 -0800257 // VerifyDebugDump replays a debug dump using APM and verifies that the result
258 // is bit-exact-identical to the output channel in the dump. This is only
259 // guaranteed if the debug dump is started on the first frame.
Alex Loiko890988c2017-08-31 10:25:48 +0200260 void VerifyDebugDump(const std::string& in_filename);
minyue275d2552015-11-04 06:23:54 -0800261
262 private:
minyue0de1c132016-03-17 02:39:30 -0700263 DebugDumpReplayer debug_dump_replayer_;
minyue275d2552015-11-04 06:23:54 -0800264};
265
minyue275d2552015-11-04 06:23:54 -0800266void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) {
minyue0de1c132016-03-17 02:39:30 -0700267 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename));
minyue275d2552015-11-04 06:23:54 -0800268
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200269 while (const absl::optional<audioproc::Event> event =
270 debug_dump_replayer_.GetNextEvent()) {
minyue0de1c132016-03-17 02:39:30 -0700271 debug_dump_replayer_.RunNextEvent();
272 if (event->type() == audioproc::Event::STREAM) {
273 const audioproc::Stream* msg = &event->stream();
274 const StreamConfig output_config = debug_dump_replayer_.GetOutputConfig();
275 const ChannelBuffer<float>* output = debug_dump_replayer_.GetOutput();
276 // Check that output of APM is bit-exact to the output in the dump.
277 ASSERT_EQ(output_config.num_channels(),
278 static_cast<size_t>(msg->output_channel_size()));
279 ASSERT_EQ(output_config.num_frames() * sizeof(float),
280 msg->output_channel(0).size());
281 for (int i = 0; i < msg->output_channel_size(); ++i) {
Yves Gerey665174f2018-06-19 15:03:05 +0200282 ASSERT_EQ(0,
283 memcmp(output->channels()[i], msg->output_channel(i).data(),
284 msg->output_channel(i).size()));
minyue0de1c132016-03-17 02:39:30 -0700285 }
minyue275d2552015-11-04 06:23:54 -0800286 }
287 }
minyue275d2552015-11-04 06:23:54 -0800288}
289
290TEST_F(DebugDumpTest, SimpleCase) {
291 Config config;
peah88ac8532016-09-12 16:47:25 -0700292 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800293 generator.StartRecording();
294 generator.Process(100);
295 generator.StopRecording();
296 VerifyDebugDump(generator.dump_file_name());
297}
298
299TEST_F(DebugDumpTest, ChangeInputFormat) {
300 Config config;
peah88ac8532016-09-12 16:47:25 -0700301 DebugDumpGenerator generator(config, AudioProcessing::Config());
302
minyue275d2552015-11-04 06:23:54 -0800303 generator.StartRecording();
304 generator.Process(100);
305 generator.SetInputRate(48000);
306
307 generator.ForceInputMono(true);
308 // Number of output channel should not be larger than that of input. APM will
309 // fail otherwise.
310 generator.SetOutputChannels(1);
311
312 generator.Process(100);
313 generator.StopRecording();
314 VerifyDebugDump(generator.dump_file_name());
315}
316
317TEST_F(DebugDumpTest, ChangeReverseFormat) {
318 Config config;
peah88ac8532016-09-12 16:47:25 -0700319 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800320 generator.StartRecording();
321 generator.Process(100);
322 generator.SetReverseRate(48000);
323 generator.ForceReverseMono(true);
324 generator.Process(100);
325 generator.StopRecording();
326 VerifyDebugDump(generator.dump_file_name());
327}
328
329TEST_F(DebugDumpTest, ChangeOutputFormat) {
330 Config config;
peah88ac8532016-09-12 16:47:25 -0700331 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800332 generator.StartRecording();
333 generator.Process(100);
334 generator.SetOutputRate(48000);
335 generator.SetOutputChannels(1);
336 generator.Process(100);
337 generator.StopRecording();
338 VerifyDebugDump(generator.dump_file_name());
339}
340
341TEST_F(DebugDumpTest, ToggleAec) {
342 Config config;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200343 AudioProcessing::Config apm_config;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200344 apm_config.echo_canceller.enabled = true;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200345 DebugDumpGenerator generator(config, apm_config);
minyue275d2552015-11-04 06:23:54 -0800346 generator.StartRecording();
347 generator.Process(100);
348
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200349 apm_config.echo_canceller.enabled = true;
350 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800351
352 generator.Process(100);
353 generator.StopRecording();
354 VerifyDebugDump(generator.dump_file_name());
355}
356
peah0332c2d2016-04-15 11:23:33 -0700357TEST_F(DebugDumpTest, VerifyRefinedAdaptiveFilterExperimentalString) {
358 Config config;
Per Åhgren200feba2019-03-06 04:16:46 +0100359 AudioProcessing::Config apm_config;
360 apm_config.echo_canceller.enabled = true;
361 apm_config.echo_canceller.use_legacy_aec = true;
peah0332c2d2016-04-15 11:23:33 -0700362 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
Per Åhgren200feba2019-03-06 04:16:46 +0100363 DebugDumpGenerator generator(config, apm_config);
peah0332c2d2016-04-15 11:23:33 -0700364 generator.StartRecording();
365 generator.Process(100);
366 generator.StopRecording();
367
368 DebugDumpReplayer debug_dump_replayer_;
369
370 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
371
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200372 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700373 debug_dump_replayer_.GetNextEvent()) {
374 debug_dump_replayer_.RunNextEvent();
375 if (event->type() == audioproc::Event::CONFIG) {
376 const audioproc::Config* msg = &event->config();
377 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200378 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "RefinedAdaptiveFilter",
peah0332c2d2016-04-15 11:23:33 -0700379 msg->experiments_description().c_str());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200380 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "Legacy AEC",
Per Åhgren200feba2019-03-06 04:16:46 +0100381 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700382 }
383 }
384}
385
386TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) {
387 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800388 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200389 apm_config.echo_canceller.enabled = true;
henrik.lundinbd681b92016-12-05 09:08:42 -0800390 // Arbitrarily set clipping gain to 17, which will never be the default.
391 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
Per Åhgren200feba2019-03-06 04:16:46 +0100392 DebugDumpGenerator generator(config, apm_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());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200407 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700408 msg->experiments_description().c_str());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200409 EXPECT_PRED_FORMAT2(::testing::IsNotSubstring, "Legacy AEC",
Per Åhgren200feba2019-03-06 04:16:46 +0100410 msg->experiments_description().c_str());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200411 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 09:08:42 -0800412 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700413 }
414 }
415}
416
417TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) {
418 Config config;
Per Åhgren200feba2019-03-06 04:16:46 +0100419 AudioProcessing::Config apm_config;
420 apm_config.echo_canceller.enabled = true;
421 apm_config.echo_canceller.use_legacy_aec = true;
422 DebugDumpGenerator generator(config, apm_config);
peah0332c2d2016-04-15 11:23:33 -0700423 generator.StartRecording();
424 generator.Process(100);
425 generator.StopRecording();
426
427 DebugDumpReplayer debug_dump_replayer_;
428
429 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
430
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200431 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700432 debug_dump_replayer_.GetNextEvent()) {
433 debug_dump_replayer_.RunNextEvent();
434 if (event->type() == audioproc::Event::CONFIG) {
435 const audioproc::Config* msg = &event->config();
436 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200437 EXPECT_PRED_FORMAT2(::testing::IsNotSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700438 msg->experiments_description().c_str());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200439 EXPECT_PRED_FORMAT2(::testing::IsNotSubstring,
440 "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 09:08:42 -0800441 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700442 }
443 }
444}
445
peah7789fe72016-04-15 01:19:44 -0700446TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) {
447 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800448 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200449 apm_config.echo_canceller.enabled = true;
Per Åhgren200feba2019-03-06 04:16:46 +0100450 DebugDumpGenerator generator(config, apm_config);
peah7789fe72016-04-15 01:19:44 -0700451 generator.StartRecording();
452 generator.Process(100);
453 generator.StopRecording();
454
455 DebugDumpReplayer debug_dump_replayer_;
456
457 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
458
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200459 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700460 debug_dump_replayer_.GetNextEvent()) {
461 debug_dump_replayer_.RunNextEvent();
462 if (event->type() == audioproc::Event::CONFIG) {
463 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700464 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200465 EXPECT_PRED_FORMAT2(::testing::IsNotSubstring, "Legacy AEC",
Per Åhgren200feba2019-03-06 04:16:46 +0100466 msg->experiments_description().c_str());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200467 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700468 msg->experiments_description().c_str());
peah7789fe72016-04-15 01:19:44 -0700469 }
470 }
471}
472
henrik.lundinbd681b92016-12-05 09:08:42 -0800473TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) {
474 Config config;
475 // Arbitrarily set clipping gain to 17, which will never be the default.
476 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
477 DebugDumpGenerator generator(config, AudioProcessing::Config());
478 generator.StartRecording();
479 generator.Process(100);
480 generator.StopRecording();
481
482 DebugDumpReplayer debug_dump_replayer_;
483
484 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
485
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200486 while (const absl::optional<audioproc::Event> event =
henrik.lundinbd681b92016-12-05 09:08:42 -0800487 debug_dump_replayer_.GetNextEvent()) {
488 debug_dump_replayer_.RunNextEvent();
489 if (event->type() == audioproc::Event::CONFIG) {
490 const audioproc::Config* msg = &event->config();
491 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200492 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 09:08:42 -0800493 msg->experiments_description().c_str());
494 }
495 }
496}
497
peah7789fe72016-04-15 01:19:44 -0700498TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) {
499 Config config;
peah88ac8532016-09-12 16:47:25 -0700500 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah7789fe72016-04-15 01:19:44 -0700501 generator.StartRecording();
502 generator.Process(100);
503 generator.StopRecording();
504
505 DebugDumpReplayer debug_dump_replayer_;
506
507 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
508
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200509 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700510 debug_dump_replayer_.GetNextEvent()) {
511 debug_dump_replayer_.RunNextEvent();
512 if (event->type() == audioproc::Event::CONFIG) {
513 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700514 ASSERT_TRUE(msg->has_experiments_description());
peah7789fe72016-04-15 01:19:44 -0700515 EXPECT_EQ(0u, msg->experiments_description().size());
516 }
517 }
518}
519
Kári Tristan Helgason470c0882016-10-03 13:13:29 +0200520// AGC is not supported on Android or iOS.
521#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
minyue275d2552015-11-04 06:23:54 -0800522#define MAYBE_ToggleAgc DISABLED_ToggleAgc
523#else
524#define MAYBE_ToggleAgc ToggleAgc
525#endif
526TEST_F(DebugDumpTest, MAYBE_ToggleAgc) {
527 Config config;
peah88ac8532016-09-12 16:47:25 -0700528 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800529 generator.StartRecording();
530 generator.Process(100);
531
Sam Zackrisson41478c72019-10-15 10:10:26 +0200532 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
533 apm_config.gain_controller1.enabled = !apm_config.gain_controller1.enabled;
534 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800535
536 generator.Process(100);
537 generator.StopRecording();
538 VerifyDebugDump(generator.dump_file_name());
539}
540
541TEST_F(DebugDumpTest, ToggleNs) {
542 Config config;
peah88ac8532016-09-12 16:47:25 -0700543 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800544 generator.StartRecording();
545 generator.Process(100);
546
Sam Zackrisson23513132019-01-11 15:10:32 +0100547 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
548 apm_config.noise_suppression.enabled = !apm_config.noise_suppression.enabled;
549 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800550
551 generator.Process(100);
552 generator.StopRecording();
553 VerifyDebugDump(generator.dump_file_name());
554}
555
556TEST_F(DebugDumpTest, TransientSuppressionOn) {
557 Config config;
558 config.Set<ExperimentalNs>(new ExperimentalNs(true));
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 generator.StopRecording();
563 VerifyDebugDump(generator.dump_file_name());
564}
565
Alex Loiko62347222018-09-10 10:18:07 +0200566TEST_F(DebugDumpTest, PreAmplifierIsOn) {
567 Config config;
568 AudioProcessing::Config apm_config;
569 apm_config.pre_amplifier.enabled = true;
570 DebugDumpGenerator generator(config, apm_config);
571 generator.StartRecording();
572 generator.Process(100);
573 generator.StopRecording();
574 VerifyDebugDump(generator.dump_file_name());
575}
576
minyue275d2552015-11-04 06:23:54 -0800577} // namespace test
578} // namespace webrtc