blob: 2c839d3bac00fb67199535f12d2691945c584d4e [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
18#include "modules/audio_processing/aec_dump/aec_dump_factory.h"
19#include "modules/audio_processing/test/debug_dump_replayer.h"
20#include "modules/audio_processing/test/test_utils.h"
21#include "rtc_base/task_queue.h"
22#include "test/gtest.h"
23#include "test/testsupport/fileutils.h"
minyue275d2552015-11-04 06:23:54 -080024
25namespace webrtc {
26namespace test {
27
28namespace {
29
kwiberg62eaacf2016-02-17 06:39:05 -080030void MaybeResetBuffer(std::unique_ptr<ChannelBuffer<float>>* buffer,
minyue275d2552015-11-04 06:23:54 -080031 const StreamConfig& config) {
32 auto& buffer_ref = *buffer;
33 if (!buffer_ref.get() || buffer_ref->num_frames() != config.num_frames() ||
34 buffer_ref->num_channels() != config.num_channels()) {
35 buffer_ref.reset(new ChannelBuffer<float>(config.num_frames(),
36 config.num_channels()));
37 }
38}
39
40class DebugDumpGenerator {
41 public:
42 DebugDumpGenerator(const std::string& input_file_name,
Alex Loiko890988c2017-08-31 10:25:48 +020043 int input_rate_hz,
minyue275d2552015-11-04 06:23:54 -080044 int input_channels,
45 const std::string& reverse_file_name,
Alex Loiko890988c2017-08-31 10:25:48 +020046 int reverse_rate_hz,
minyue275d2552015-11-04 06:23:54 -080047 int reverse_channels,
48 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +020049 const std::string& dump_file_name,
50 bool enable_aec3);
minyue275d2552015-11-04 06:23:54 -080051
52 // Constructor that uses default input files.
peah88ac8532016-09-12 16:47:25 -070053 explicit DebugDumpGenerator(const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +020054 const AudioProcessing::Config& apm_config,
55 bool enable_aec3);
56
57 explicit DebugDumpGenerator(const Config& config,
peah88ac8532016-09-12 16:47:25 -070058 const AudioProcessing::Config& apm_config);
minyue275d2552015-11-04 06:23:54 -080059
60 ~DebugDumpGenerator();
61
62 // Changes the sample rate of the input audio to the APM.
63 void SetInputRate(int rate_hz);
64
65 // Sets if converts stereo input signal to mono by discarding other channels.
66 void ForceInputMono(bool mono);
67
68 // Changes the sample rate of the reverse audio to the APM.
69 void SetReverseRate(int rate_hz);
70
71 // Sets if converts stereo reverse signal to mono by discarding other
72 // channels.
73 void ForceReverseMono(bool mono);
74
75 // Sets the required sample rate of the APM output.
76 void SetOutputRate(int rate_hz);
77
78 // Sets the required channels of the APM output.
79 void SetOutputChannels(int channels);
80
81 std::string dump_file_name() const { return dump_file_name_; }
82
83 void StartRecording();
84 void Process(size_t num_blocks);
85 void StopRecording();
86 AudioProcessing* apm() const { return apm_.get(); }
87
88 private:
89 static void ReadAndDeinterleave(ResampleInputAudioFile* audio, int channels,
90 const StreamConfig& config,
91 float* const* buffer);
92
93 // APM input/output settings.
94 StreamConfig input_config_;
95 StreamConfig reverse_config_;
96 StreamConfig output_config_;
97
98 // Input file format.
99 const std::string input_file_name_;
100 ResampleInputAudioFile input_audio_;
101 const int input_file_channels_;
102
103 // Reverse file format.
104 const std::string reverse_file_name_;
105 ResampleInputAudioFile reverse_audio_;
106 const int reverse_file_channels_;
107
108 // Buffer for APM input/output.
kwiberg62eaacf2016-02-17 06:39:05 -0800109 std::unique_ptr<ChannelBuffer<float>> input_;
110 std::unique_ptr<ChannelBuffer<float>> reverse_;
111 std::unique_ptr<ChannelBuffer<float>> output_;
minyue275d2552015-11-04 06:23:54 -0800112
aleloif4dd1912017-06-15 01:55:38 -0700113 rtc::TaskQueue 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,
127 bool enable_aec3)
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())),
aleloif4dd1912017-06-15 01:55:38 -0700141 worker_queue_("debug_dump_generator_worker_queue"),
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200142 apm_(AudioProcessing::Create(
143 config,
144 nullptr,
145 (enable_aec3 ? std::unique_ptr<EchoControlFactory>(
146 new EchoCanceller3Factory())
147 : nullptr),
148 nullptr)),
aleloif4dd1912017-06-15 01:55:38 -0700149 dump_file_name_(dump_file_name) {}
minyue275d2552015-11-04 06:23:54 -0800150
peah88ac8532016-09-12 16:47:25 -0700151DebugDumpGenerator::DebugDumpGenerator(
152 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200153 const AudioProcessing::Config& apm_config,
154 bool enable_aec3)
peah88ac8532016-09-12 16:47:25 -0700155 : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"),
156 32000,
157 2,
158 ResourcePath("far32_stereo", "pcm"),
159 32000,
160 2,
161 config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200162 TempFilename(OutputPath(), "debug_aec"),
163 enable_aec3) {
164 apm_->ApplyConfig(apm_config);
165}
166
167DebugDumpGenerator::DebugDumpGenerator(
168 const Config& config,
169 const AudioProcessing::Config& apm_config)
170 : DebugDumpGenerator(config, apm_config, false) {
peah88ac8532016-09-12 16:47:25 -0700171 apm_->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800172}
173
174DebugDumpGenerator::~DebugDumpGenerator() {
175 remove(dump_file_name_.c_str());
176}
177
178void DebugDumpGenerator::SetInputRate(int rate_hz) {
179 input_audio_.set_output_rate_hz(rate_hz);
180 input_config_.set_sample_rate_hz(rate_hz);
181 MaybeResetBuffer(&input_, input_config_);
182}
183
184void DebugDumpGenerator::ForceInputMono(bool mono) {
185 const int channels = mono ? 1 : input_file_channels_;
186 input_config_.set_num_channels(channels);
187 MaybeResetBuffer(&input_, input_config_);
188}
189
190void DebugDumpGenerator::SetReverseRate(int rate_hz) {
191 reverse_audio_.set_output_rate_hz(rate_hz);
192 reverse_config_.set_sample_rate_hz(rate_hz);
193 MaybeResetBuffer(&reverse_, reverse_config_);
194}
195
196void DebugDumpGenerator::ForceReverseMono(bool mono) {
197 const int channels = mono ? 1 : reverse_file_channels_;
198 reverse_config_.set_num_channels(channels);
199 MaybeResetBuffer(&reverse_, reverse_config_);
200}
201
202void DebugDumpGenerator::SetOutputRate(int rate_hz) {
203 output_config_.set_sample_rate_hz(rate_hz);
204 MaybeResetBuffer(&output_, output_config_);
205}
206
207void DebugDumpGenerator::SetOutputChannels(int channels) {
208 output_config_.set_num_channels(channels);
209 MaybeResetBuffer(&output_, output_config_);
210}
211
212void DebugDumpGenerator::StartRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700213 apm_->AttachAecDump(
214 AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_));
minyue275d2552015-11-04 06:23:54 -0800215}
216
217void DebugDumpGenerator::Process(size_t num_blocks) {
218 for (size_t i = 0; i < num_blocks; ++i) {
219 ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_,
220 reverse_config_, reverse_->channels());
221 ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_,
222 input_->channels());
223 RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100));
224 apm_->set_stream_key_pressed(i % 10 == 9);
225 RTC_CHECK_EQ(AudioProcessing::kNoError,
226 apm_->ProcessStream(input_->channels(), input_config_,
227 output_config_, output_->channels()));
228
229 RTC_CHECK_EQ(AudioProcessing::kNoError,
230 apm_->ProcessReverseStream(reverse_->channels(),
231 reverse_config_,
232 reverse_config_,
233 reverse_->channels()));
234 }
235}
236
237void DebugDumpGenerator::StopRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700238 apm_->DetachAecDump();
minyue275d2552015-11-04 06:23:54 -0800239}
240
241void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio,
242 int channels,
243 const StreamConfig& config,
244 float* const* buffer) {
245 const size_t num_frames = config.num_frames();
246 const int out_channels = config.num_channels();
247
248 std::vector<int16_t> signal(channels * num_frames);
249
250 audio->Read(num_frames * channels, &signal[0]);
251
252 // We only allow reducing number of channels by discarding some channels.
253 RTC_CHECK_LE(out_channels, channels);
254 for (int channel = 0; channel < out_channels; ++channel) {
255 for (size_t i = 0; i < num_frames; ++i) {
256 buffer[channel][i] = S16ToFloat(signal[i * channels + channel]);
257 }
258 }
259}
260
261} // namespace
262
263class DebugDumpTest : public ::testing::Test {
264 public:
minyue275d2552015-11-04 06:23:54 -0800265 // VerifyDebugDump replays a debug dump using APM and verifies that the result
266 // is bit-exact-identical to the output channel in the dump. This is only
267 // guaranteed if the debug dump is started on the first frame.
Alex Loiko890988c2017-08-31 10:25:48 +0200268 void VerifyDebugDump(const std::string& in_filename);
minyue275d2552015-11-04 06:23:54 -0800269
270 private:
minyue0de1c132016-03-17 02:39:30 -0700271 DebugDumpReplayer debug_dump_replayer_;
minyue275d2552015-11-04 06:23:54 -0800272};
273
minyue275d2552015-11-04 06:23:54 -0800274void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) {
minyue0de1c132016-03-17 02:39:30 -0700275 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename));
minyue275d2552015-11-04 06:23:54 -0800276
minyue9705bb82016-04-05 04:39:15 -0700277 while (const rtc::Optional<audioproc::Event> event =
minyue0de1c132016-03-17 02:39:30 -0700278 debug_dump_replayer_.GetNextEvent()) {
279 debug_dump_replayer_.RunNextEvent();
280 if (event->type() == audioproc::Event::STREAM) {
281 const audioproc::Stream* msg = &event->stream();
282 const StreamConfig output_config = debug_dump_replayer_.GetOutputConfig();
283 const ChannelBuffer<float>* output = debug_dump_replayer_.GetOutput();
284 // Check that output of APM is bit-exact to the output in the dump.
285 ASSERT_EQ(output_config.num_channels(),
286 static_cast<size_t>(msg->output_channel_size()));
287 ASSERT_EQ(output_config.num_frames() * sizeof(float),
288 msg->output_channel(0).size());
289 for (int i = 0; i < msg->output_channel_size(); ++i) {
290 ASSERT_EQ(0, memcmp(output->channels()[i],
291 msg->output_channel(i).data(),
292 msg->output_channel(i).size()));
293 }
minyue275d2552015-11-04 06:23:54 -0800294 }
295 }
minyue275d2552015-11-04 06:23:54 -0800296}
297
298TEST_F(DebugDumpTest, SimpleCase) {
299 Config config;
peah88ac8532016-09-12 16:47:25 -0700300 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800301 generator.StartRecording();
302 generator.Process(100);
303 generator.StopRecording();
304 VerifyDebugDump(generator.dump_file_name());
305}
306
307TEST_F(DebugDumpTest, ChangeInputFormat) {
308 Config config;
peah88ac8532016-09-12 16:47:25 -0700309 DebugDumpGenerator generator(config, AudioProcessing::Config());
310
minyue275d2552015-11-04 06:23:54 -0800311 generator.StartRecording();
312 generator.Process(100);
313 generator.SetInputRate(48000);
314
315 generator.ForceInputMono(true);
316 // Number of output channel should not be larger than that of input. APM will
317 // fail otherwise.
318 generator.SetOutputChannels(1);
319
320 generator.Process(100);
321 generator.StopRecording();
322 VerifyDebugDump(generator.dump_file_name());
323}
324
325TEST_F(DebugDumpTest, ChangeReverseFormat) {
326 Config config;
peah88ac8532016-09-12 16:47:25 -0700327 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800328 generator.StartRecording();
329 generator.Process(100);
330 generator.SetReverseRate(48000);
331 generator.ForceReverseMono(true);
332 generator.Process(100);
333 generator.StopRecording();
334 VerifyDebugDump(generator.dump_file_name());
335}
336
337TEST_F(DebugDumpTest, ChangeOutputFormat) {
338 Config config;
peah88ac8532016-09-12 16:47:25 -0700339 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800340 generator.StartRecording();
341 generator.Process(100);
342 generator.SetOutputRate(48000);
343 generator.SetOutputChannels(1);
344 generator.Process(100);
345 generator.StopRecording();
346 VerifyDebugDump(generator.dump_file_name());
347}
348
349TEST_F(DebugDumpTest, ToggleAec) {
350 Config config;
peah88ac8532016-09-12 16:47:25 -0700351 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800352 generator.StartRecording();
353 generator.Process(100);
354
355 EchoCancellation* aec = generator.apm()->echo_cancellation();
356 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled()));
357
358 generator.Process(100);
359 generator.StopRecording();
360 VerifyDebugDump(generator.dump_file_name());
361}
362
363TEST_F(DebugDumpTest, ToggleDelayAgnosticAec) {
364 Config config;
365 config.Set<DelayAgnostic>(new DelayAgnostic(true));
peah88ac8532016-09-12 16:47:25 -0700366 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800367 generator.StartRecording();
368 generator.Process(100);
369
370 EchoCancellation* aec = generator.apm()->echo_cancellation();
371 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled()));
372
373 generator.Process(100);
374 generator.StopRecording();
375 VerifyDebugDump(generator.dump_file_name());
376}
377
peah0332c2d2016-04-15 11:23:33 -0700378TEST_F(DebugDumpTest, VerifyRefinedAdaptiveFilterExperimentalString) {
379 Config config;
380 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
peah88ac8532016-09-12 16:47:25 -0700381 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah0332c2d2016-04-15 11:23:33 -0700382 generator.StartRecording();
383 generator.Process(100);
384 generator.StopRecording();
385
386 DebugDumpReplayer debug_dump_replayer_;
387
388 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
389
390 while (const rtc::Optional<audioproc::Event> event =
391 debug_dump_replayer_.GetNextEvent()) {
392 debug_dump_replayer_.RunNextEvent();
393 if (event->type() == audioproc::Event::CONFIG) {
394 const audioproc::Config* msg = &event->config();
395 ASSERT_TRUE(msg->has_experiments_description());
396 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
397 msg->experiments_description().c_str());
398 }
399 }
400}
401
402TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) {
403 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800404 AudioProcessing::Config apm_config;
peah0332c2d2016-04-15 11:23:33 -0700405 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
henrik.lundinbd681b92016-12-05 09:08:42 -0800406 // Arbitrarily set clipping gain to 17, which will never be the default.
407 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200408 bool enable_aec3 = true;
409 DebugDumpGenerator generator(config, apm_config, enable_aec3);
peah0332c2d2016-04-15 11:23:33 -0700410 generator.StartRecording();
411 generator.Process(100);
412 generator.StopRecording();
413
414 DebugDumpReplayer debug_dump_replayer_;
415
416 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
417
418 while (const rtc::Optional<audioproc::Event> event =
419 debug_dump_replayer_.GetNextEvent()) {
420 debug_dump_replayer_.RunNextEvent();
421 if (event->type() == audioproc::Event::CONFIG) {
422 const audioproc::Config* msg = &event->config();
423 ASSERT_TRUE(msg->has_experiments_description());
424 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
425 msg->experiments_description().c_str());
Gustaf Ullbergce045ac2017-10-16 13:49:04 +0200426 EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700427 msg->experiments_description().c_str());
henrik.lundinbd681b92016-12-05 09:08:42 -0800428 EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment",
429 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700430 }
431 }
432}
433
434TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) {
435 Config config;
436 config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true));
peah88ac8532016-09-12 16:47:25 -0700437 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah0332c2d2016-04-15 11:23:33 -0700438 generator.StartRecording();
439 generator.Process(100);
440 generator.StopRecording();
441
442 DebugDumpReplayer debug_dump_replayer_;
443
444 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
445
446 while (const rtc::Optional<audioproc::Event> event =
447 debug_dump_replayer_.GetNextEvent()) {
448 debug_dump_replayer_.RunNextEvent();
449 if (event->type() == audioproc::Event::CONFIG) {
450 const audioproc::Config* msg = &event->config();
451 ASSERT_TRUE(msg->has_experiments_description());
452 EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter",
453 msg->experiments_description().c_str());
454 EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AEC3",
455 msg->experiments_description().c_str());
henrik.lundinbd681b92016-12-05 09:08:42 -0800456 EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AgcClippingLevelExperiment",
457 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700458 }
459 }
460}
461
peah7789fe72016-04-15 01:19:44 -0700462TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) {
463 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800464 AudioProcessing::Config apm_config;
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200465 DebugDumpGenerator generator(config, apm_config, true);
peah7789fe72016-04-15 01:19:44 -0700466 generator.StartRecording();
467 generator.Process(100);
468 generator.StopRecording();
469
470 DebugDumpReplayer debug_dump_replayer_;
471
472 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
473
474 while (const rtc::Optional<audioproc::Event> event =
475 debug_dump_replayer_.GetNextEvent()) {
476 debug_dump_replayer_.RunNextEvent();
477 if (event->type() == audioproc::Event::CONFIG) {
478 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700479 ASSERT_TRUE(msg->has_experiments_description());
Gustaf Ullbergce045ac2017-10-16 13:49:04 +0200480 EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700481 msg->experiments_description().c_str());
peah7789fe72016-04-15 01:19:44 -0700482 }
483 }
484}
485
peahca4cac72016-06-29 15:26:12 -0700486TEST_F(DebugDumpTest, VerifyLevelControllerExperimentalString) {
487 Config config;
peah88ac8532016-09-12 16:47:25 -0700488 AudioProcessing::Config apm_config;
489 apm_config.level_controller.enabled = true;
490 DebugDumpGenerator generator(config, apm_config);
peahca4cac72016-06-29 15:26:12 -0700491 generator.StartRecording();
492 generator.Process(100);
493 generator.StopRecording();
494
495 DebugDumpReplayer debug_dump_replayer_;
496
497 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
498
499 while (const rtc::Optional<audioproc::Event> event =
500 debug_dump_replayer_.GetNextEvent()) {
501 debug_dump_replayer_.RunNextEvent();
502 if (event->type() == audioproc::Event::CONFIG) {
503 const audioproc::Config* msg = &event->config();
504 ASSERT_TRUE(msg->has_experiments_description());
505 EXPECT_PRED_FORMAT2(testing::IsSubstring, "LevelController",
506 msg->experiments_description().c_str());
507 }
508 }
509}
510
henrik.lundinbd681b92016-12-05 09:08:42 -0800511TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) {
512 Config config;
513 // Arbitrarily set clipping gain to 17, which will never be the default.
514 config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17));
515 DebugDumpGenerator generator(config, AudioProcessing::Config());
516 generator.StartRecording();
517 generator.Process(100);
518 generator.StopRecording();
519
520 DebugDumpReplayer debug_dump_replayer_;
521
522 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
523
524 while (const rtc::Optional<audioproc::Event> event =
525 debug_dump_replayer_.GetNextEvent()) {
526 debug_dump_replayer_.RunNextEvent();
527 if (event->type() == audioproc::Event::CONFIG) {
528 const audioproc::Config* msg = &event->config();
529 ASSERT_TRUE(msg->has_experiments_description());
530 EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment",
531 msg->experiments_description().c_str());
532 }
533 }
534}
535
peah7789fe72016-04-15 01:19:44 -0700536TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) {
537 Config config;
peah88ac8532016-09-12 16:47:25 -0700538 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah7789fe72016-04-15 01:19:44 -0700539 generator.StartRecording();
540 generator.Process(100);
541 generator.StopRecording();
542
543 DebugDumpReplayer debug_dump_replayer_;
544
545 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
546
547 while (const rtc::Optional<audioproc::Event> event =
548 debug_dump_replayer_.GetNextEvent()) {
549 debug_dump_replayer_.RunNextEvent();
550 if (event->type() == audioproc::Event::CONFIG) {
551 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700552 ASSERT_TRUE(msg->has_experiments_description());
peah7789fe72016-04-15 01:19:44 -0700553 EXPECT_EQ(0u, msg->experiments_description().size());
554 }
555 }
556}
557
minyue275d2552015-11-04 06:23:54 -0800558TEST_F(DebugDumpTest, ToggleAecLevel) {
559 Config config;
peah88ac8532016-09-12 16:47:25 -0700560 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800561 EchoCancellation* aec = generator.apm()->echo_cancellation();
562 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(true));
563 EXPECT_EQ(AudioProcessing::kNoError,
564 aec->set_suppression_level(EchoCancellation::kLowSuppression));
565 generator.StartRecording();
566 generator.Process(100);
567
568 EXPECT_EQ(AudioProcessing::kNoError,
569 aec->set_suppression_level(EchoCancellation::kHighSuppression));
570 generator.Process(100);
571 generator.StopRecording();
572 VerifyDebugDump(generator.dump_file_name());
573}
574
Kári Tristan Helgason470c0882016-10-03 13:13:29 +0200575// AGC is not supported on Android or iOS.
576#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
minyue275d2552015-11-04 06:23:54 -0800577#define MAYBE_ToggleAgc DISABLED_ToggleAgc
578#else
579#define MAYBE_ToggleAgc ToggleAgc
580#endif
581TEST_F(DebugDumpTest, MAYBE_ToggleAgc) {
582 Config config;
peah88ac8532016-09-12 16:47:25 -0700583 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800584 generator.StartRecording();
585 generator.Process(100);
586
587 GainControl* agc = generator.apm()->gain_control();
588 EXPECT_EQ(AudioProcessing::kNoError, agc->Enable(!agc->is_enabled()));
589
590 generator.Process(100);
591 generator.StopRecording();
592 VerifyDebugDump(generator.dump_file_name());
593}
594
595TEST_F(DebugDumpTest, ToggleNs) {
596 Config config;
peah88ac8532016-09-12 16:47:25 -0700597 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800598 generator.StartRecording();
599 generator.Process(100);
600
601 NoiseSuppression* ns = generator.apm()->noise_suppression();
602 EXPECT_EQ(AudioProcessing::kNoError, ns->Enable(!ns->is_enabled()));
603
604 generator.Process(100);
605 generator.StopRecording();
606 VerifyDebugDump(generator.dump_file_name());
607}
608
609TEST_F(DebugDumpTest, TransientSuppressionOn) {
610 Config config;
611 config.Set<ExperimentalNs>(new ExperimentalNs(true));
peah88ac8532016-09-12 16:47:25 -0700612 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800613 generator.StartRecording();
614 generator.Process(100);
615 generator.StopRecording();
616 VerifyDebugDump(generator.dump_file_name());
617}
618
minyue275d2552015-11-04 06:23:54 -0800619} // namespace test
620} // namespace webrtc