blob: 71478a988c8a7c55d3fc52921b67a1e69b828b3d [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.
Per Åhgren4011de02019-12-03 11:48:48 +000054 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));
Per Åhgren0695df12020-01-13 14:43:13 +0100213 apm_->set_stream_analog_level(100);
Alex Loiko62347222018-09-10 10:18:07 +0200214 if (enable_pre_amplifier_) {
215 apm_->SetRuntimeSetting(
216 AudioProcessing::RuntimeSetting::CreateCapturePreGain(1 + i % 10));
217 }
minyue275d2552015-11-04 06:23:54 -0800218 apm_->set_stream_key_pressed(i % 10 == 9);
219 RTC_CHECK_EQ(AudioProcessing::kNoError,
220 apm_->ProcessStream(input_->channels(), input_config_,
221 output_config_, output_->channels()));
222
Yves Gerey665174f2018-06-19 15:03:05 +0200223 RTC_CHECK_EQ(
224 AudioProcessing::kNoError,
225 apm_->ProcessReverseStream(reverse_->channels(), reverse_config_,
226 reverse_config_, reverse_->channels()));
minyue275d2552015-11-04 06:23:54 -0800227 }
228}
229
230void DebugDumpGenerator::StopRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700231 apm_->DetachAecDump();
minyue275d2552015-11-04 06:23:54 -0800232}
233
234void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio,
235 int channels,
236 const StreamConfig& config,
237 float* const* buffer) {
238 const size_t num_frames = config.num_frames();
239 const int out_channels = config.num_channels();
240
241 std::vector<int16_t> signal(channels * num_frames);
242
243 audio->Read(num_frames * channels, &signal[0]);
244
245 // We only allow reducing number of channels by discarding some channels.
246 RTC_CHECK_LE(out_channels, channels);
247 for (int channel = 0; channel < out_channels; ++channel) {
248 for (size_t i = 0; i < num_frames; ++i) {
249 buffer[channel][i] = S16ToFloat(signal[i * channels + channel]);
250 }
251 }
252}
253
254} // namespace
255
256class DebugDumpTest : public ::testing::Test {
257 public:
minyue275d2552015-11-04 06:23:54 -0800258 // VerifyDebugDump replays a debug dump using APM and verifies that the result
259 // is bit-exact-identical to the output channel in the dump. This is only
260 // guaranteed if the debug dump is started on the first frame.
Alex Loiko890988c2017-08-31 10:25:48 +0200261 void VerifyDebugDump(const std::string& in_filename);
minyue275d2552015-11-04 06:23:54 -0800262
263 private:
minyue0de1c132016-03-17 02:39:30 -0700264 DebugDumpReplayer debug_dump_replayer_;
minyue275d2552015-11-04 06:23:54 -0800265};
266
minyue275d2552015-11-04 06:23:54 -0800267void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) {
minyue0de1c132016-03-17 02:39:30 -0700268 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename));
minyue275d2552015-11-04 06:23:54 -0800269
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200270 while (const absl::optional<audioproc::Event> event =
271 debug_dump_replayer_.GetNextEvent()) {
minyue0de1c132016-03-17 02:39:30 -0700272 debug_dump_replayer_.RunNextEvent();
273 if (event->type() == audioproc::Event::STREAM) {
274 const audioproc::Stream* msg = &event->stream();
275 const StreamConfig output_config = debug_dump_replayer_.GetOutputConfig();
276 const ChannelBuffer<float>* output = debug_dump_replayer_.GetOutput();
277 // Check that output of APM is bit-exact to the output in the dump.
278 ASSERT_EQ(output_config.num_channels(),
279 static_cast<size_t>(msg->output_channel_size()));
280 ASSERT_EQ(output_config.num_frames() * sizeof(float),
281 msg->output_channel(0).size());
282 for (int i = 0; i < msg->output_channel_size(); ++i) {
Yves Gerey665174f2018-06-19 15:03:05 +0200283 ASSERT_EQ(0,
284 memcmp(output->channels()[i], msg->output_channel(i).data(),
285 msg->output_channel(i).size()));
minyue0de1c132016-03-17 02:39:30 -0700286 }
minyue275d2552015-11-04 06:23:54 -0800287 }
288 }
minyue275d2552015-11-04 06:23:54 -0800289}
290
291TEST_F(DebugDumpTest, SimpleCase) {
292 Config config;
peah88ac8532016-09-12 16:47:25 -0700293 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800294 generator.StartRecording();
295 generator.Process(100);
296 generator.StopRecording();
297 VerifyDebugDump(generator.dump_file_name());
298}
299
300TEST_F(DebugDumpTest, ChangeInputFormat) {
301 Config config;
peah88ac8532016-09-12 16:47:25 -0700302 DebugDumpGenerator generator(config, AudioProcessing::Config());
303
minyue275d2552015-11-04 06:23:54 -0800304 generator.StartRecording();
305 generator.Process(100);
306 generator.SetInputRate(48000);
307
308 generator.ForceInputMono(true);
309 // Number of output channel should not be larger than that of input. APM will
310 // fail otherwise.
311 generator.SetOutputChannels(1);
312
313 generator.Process(100);
314 generator.StopRecording();
315 VerifyDebugDump(generator.dump_file_name());
316}
317
318TEST_F(DebugDumpTest, ChangeReverseFormat) {
319 Config config;
peah88ac8532016-09-12 16:47:25 -0700320 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800321 generator.StartRecording();
322 generator.Process(100);
323 generator.SetReverseRate(48000);
324 generator.ForceReverseMono(true);
325 generator.Process(100);
326 generator.StopRecording();
327 VerifyDebugDump(generator.dump_file_name());
328}
329
330TEST_F(DebugDumpTest, ChangeOutputFormat) {
331 Config config;
peah88ac8532016-09-12 16:47:25 -0700332 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800333 generator.StartRecording();
334 generator.Process(100);
335 generator.SetOutputRate(48000);
336 generator.SetOutputChannels(1);
337 generator.Process(100);
338 generator.StopRecording();
339 VerifyDebugDump(generator.dump_file_name());
340}
341
342TEST_F(DebugDumpTest, ToggleAec) {
343 Config config;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200344 AudioProcessing::Config apm_config;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200345 apm_config.echo_canceller.enabled = true;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200346 DebugDumpGenerator generator(config, apm_config);
minyue275d2552015-11-04 06:23:54 -0800347 generator.StartRecording();
348 generator.Process(100);
349
Per Åhgrenb8106462019-12-04 08:34:12 +0100350 apm_config.echo_canceller.enabled = false;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200351 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800352
353 generator.Process(100);
354 generator.StopRecording();
355 VerifyDebugDump(generator.dump_file_name());
356}
357
peah0332c2d2016-04-15 11:23:33 -0700358TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) {
359 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800360 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200361 apm_config.echo_canceller.enabled = true;
Per Åhgren0695df12020-01-13 14:43:13 +0100362 apm_config.gain_controller1.analog_gain_controller.enabled = true;
363 apm_config.gain_controller1.analog_gain_controller.startup_min_volume = 0;
henrik.lundinbd681b92016-12-05 09:08:42 -0800364 // Arbitrarily set clipping gain to 17, which will never be the default.
Per Åhgren0695df12020-01-13 14:43:13 +0100365 apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17;
Per Åhgren200feba2019-03-06 04:16:46 +0100366 DebugDumpGenerator generator(config, apm_config);
peah0332c2d2016-04-15 11:23:33 -0700367 generator.StartRecording();
368 generator.Process(100);
369 generator.StopRecording();
370
371 DebugDumpReplayer debug_dump_replayer_;
372
373 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
374
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200375 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700376 debug_dump_replayer_.GetNextEvent()) {
377 debug_dump_replayer_.RunNextEvent();
378 if (event->type() == audioproc::Event::CONFIG) {
379 const audioproc::Config* msg = &event->config();
380 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200381 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700382 msg->experiments_description().c_str());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200383 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 09:08:42 -0800384 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700385 }
386 }
387}
388
389TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) {
390 Config config;
Per Åhgren200feba2019-03-06 04:16:46 +0100391 AudioProcessing::Config apm_config;
392 apm_config.echo_canceller.enabled = true;
Per Åhgren200feba2019-03-06 04:16:46 +0100393 DebugDumpGenerator generator(config, apm_config);
peah0332c2d2016-04-15 11:23:33 -0700394 generator.StartRecording();
395 generator.Process(100);
396 generator.StopRecording();
397
398 DebugDumpReplayer debug_dump_replayer_;
399
400 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
401
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200402 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700403 debug_dump_replayer_.GetNextEvent()) {
404 debug_dump_replayer_.RunNextEvent();
405 if (event->type() == audioproc::Event::CONFIG) {
406 const audioproc::Config* msg = &event->config();
407 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200408 EXPECT_PRED_FORMAT2(::testing::IsNotSubstring,
409 "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 09:08:42 -0800410 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700411 }
412 }
413}
414
peah7789fe72016-04-15 01:19:44 -0700415TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) {
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;
Per Åhgren200feba2019-03-06 04:16:46 +0100419 DebugDumpGenerator generator(config, apm_config);
peah7789fe72016-04-15 01:19:44 -0700420 generator.StartRecording();
421 generator.Process(100);
422 generator.StopRecording();
423
424 DebugDumpReplayer debug_dump_replayer_;
425
426 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
427
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200428 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700429 debug_dump_replayer_.GetNextEvent()) {
430 debug_dump_replayer_.RunNextEvent();
431 if (event->type() == audioproc::Event::CONFIG) {
432 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700433 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200434 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700435 msg->experiments_description().c_str());
peah7789fe72016-04-15 01:19:44 -0700436 }
437 }
438}
439
henrik.lundinbd681b92016-12-05 09:08:42 -0800440TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) {
441 Config config;
Per Åhgren0695df12020-01-13 14:43:13 +0100442 AudioProcessing::Config apm_config;
443 apm_config.gain_controller1.analog_gain_controller.enabled = true;
444 apm_config.gain_controller1.analog_gain_controller.startup_min_volume = 0;
henrik.lundinbd681b92016-12-05 09:08:42 -0800445 // Arbitrarily set clipping gain to 17, which will never be the default.
Per Åhgren0695df12020-01-13 14:43:13 +0100446 apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17;
447 DebugDumpGenerator generator(config, apm_config);
henrik.lundinbd681b92016-12-05 09:08:42 -0800448 generator.StartRecording();
449 generator.Process(100);
450 generator.StopRecording();
451
452 DebugDumpReplayer debug_dump_replayer_;
453
454 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
455
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200456 while (const absl::optional<audioproc::Event> event =
henrik.lundinbd681b92016-12-05 09:08:42 -0800457 debug_dump_replayer_.GetNextEvent()) {
458 debug_dump_replayer_.RunNextEvent();
459 if (event->type() == audioproc::Event::CONFIG) {
460 const audioproc::Config* msg = &event->config();
461 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200462 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 09:08:42 -0800463 msg->experiments_description().c_str());
464 }
465 }
466}
467
peah7789fe72016-04-15 01:19:44 -0700468TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) {
469 Config config;
peah88ac8532016-09-12 16:47:25 -0700470 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah7789fe72016-04-15 01:19:44 -0700471 generator.StartRecording();
472 generator.Process(100);
473 generator.StopRecording();
474
475 DebugDumpReplayer debug_dump_replayer_;
476
477 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
478
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200479 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700480 debug_dump_replayer_.GetNextEvent()) {
481 debug_dump_replayer_.RunNextEvent();
482 if (event->type() == audioproc::Event::CONFIG) {
483 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700484 ASSERT_TRUE(msg->has_experiments_description());
peah7789fe72016-04-15 01:19:44 -0700485 EXPECT_EQ(0u, msg->experiments_description().size());
486 }
487 }
488}
489
Kári Tristan Helgason470c0882016-10-03 13:13:29 +0200490// AGC is not supported on Android or iOS.
491#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
minyue275d2552015-11-04 06:23:54 -0800492#define MAYBE_ToggleAgc DISABLED_ToggleAgc
493#else
494#define MAYBE_ToggleAgc ToggleAgc
495#endif
496TEST_F(DebugDumpTest, MAYBE_ToggleAgc) {
497 Config config;
peah88ac8532016-09-12 16:47:25 -0700498 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800499 generator.StartRecording();
500 generator.Process(100);
501
Sam Zackrisson41478c72019-10-15 10:10:26 +0200502 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
503 apm_config.gain_controller1.enabled = !apm_config.gain_controller1.enabled;
504 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800505
506 generator.Process(100);
507 generator.StopRecording();
508 VerifyDebugDump(generator.dump_file_name());
509}
510
511TEST_F(DebugDumpTest, ToggleNs) {
512 Config config;
peah88ac8532016-09-12 16:47:25 -0700513 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800514 generator.StartRecording();
515 generator.Process(100);
516
Sam Zackrisson23513132019-01-11 15:10:32 +0100517 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
518 apm_config.noise_suppression.enabled = !apm_config.noise_suppression.enabled;
519 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800520
521 generator.Process(100);
522 generator.StopRecording();
523 VerifyDebugDump(generator.dump_file_name());
524}
525
526TEST_F(DebugDumpTest, TransientSuppressionOn) {
527 Config config;
peah88ac8532016-09-12 16:47:25 -0700528 DebugDumpGenerator generator(config, AudioProcessing::Config());
Per Åhgrenc0734712020-01-02 15:15:36 +0100529
530 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
531 apm_config.transient_suppression.enabled = true;
532 generator.apm()->ApplyConfig(apm_config);
533
minyue275d2552015-11-04 06:23:54 -0800534 generator.StartRecording();
535 generator.Process(100);
536 generator.StopRecording();
537 VerifyDebugDump(generator.dump_file_name());
538}
539
Alex Loiko62347222018-09-10 10:18:07 +0200540TEST_F(DebugDumpTest, PreAmplifierIsOn) {
541 Config config;
542 AudioProcessing::Config apm_config;
543 apm_config.pre_amplifier.enabled = true;
544 DebugDumpGenerator generator(config, apm_config);
545 generator.StartRecording();
546 generator.Process(100);
547 generator.StopRecording();
548 VerifyDebugDump(generator.dump_file_name());
549}
550
minyue275d2552015-11-04 06:23:54 -0800551} // namespace test
552} // namespace webrtc