blob: 6c02571a15b673d57a6dbb0053583dcef962d005 [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"
Per Åhgrencc73ed32020-04-26 23:56:17 +020020#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "modules/audio_processing/test/debug_dump_replayer.h"
22#include "modules/audio_processing/test/test_utils.h"
Danil Chapovalov07122bc2019-03-26 14:37:01 +010023#include "rtc_base/task_queue_for_test.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "test/gtest.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "test/testsupport/file_utils.h"
minyue275d2552015-11-04 06:23:54 -080026
27namespace webrtc {
28namespace test {
29
30namespace {
31
kwiberg62eaacf2016-02-17 06:39:05 -080032void MaybeResetBuffer(std::unique_ptr<ChannelBuffer<float>>* buffer,
minyue275d2552015-11-04 06:23:54 -080033 const StreamConfig& config) {
34 auto& buffer_ref = *buffer;
35 if (!buffer_ref.get() || buffer_ref->num_frames() != config.num_frames() ||
36 buffer_ref->num_channels() != config.num_channels()) {
Yves Gerey665174f2018-06-19 15:03:05 +020037 buffer_ref.reset(
38 new ChannelBuffer<float>(config.num_frames(), config.num_channels()));
minyue275d2552015-11-04 06:23:54 -080039 }
40}
41
42class DebugDumpGenerator {
43 public:
44 DebugDumpGenerator(const std::string& input_file_name,
Alex Loiko890988c2017-08-31 10:25:48 +020045 int input_rate_hz,
minyue275d2552015-11-04 06:23:54 -080046 int input_channels,
47 const std::string& reverse_file_name,
Alex Loiko890988c2017-08-31 10:25:48 +020048 int reverse_rate_hz,
minyue275d2552015-11-04 06:23:54 -080049 int reverse_channels,
50 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +020051 const std::string& dump_file_name,
Alex Loiko62347222018-09-10 10:18:07 +020052 bool enable_pre_amplifier);
minyue275d2552015-11-04 06:23:54 -080053
54 // Constructor that uses default input files.
Per Åhgren4011de02019-12-03 11:48:48 +000055 explicit DebugDumpGenerator(const Config& config,
56 const AudioProcessing::Config& apm_config);
minyue275d2552015-11-04 06:23:54 -080057
58 ~DebugDumpGenerator();
59
60 // Changes the sample rate of the input audio to the APM.
61 void SetInputRate(int rate_hz);
62
63 // Sets if converts stereo input signal to mono by discarding other channels.
64 void ForceInputMono(bool mono);
65
66 // Changes the sample rate of the reverse audio to the APM.
67 void SetReverseRate(int rate_hz);
68
69 // Sets if converts stereo reverse signal to mono by discarding other
70 // channels.
71 void ForceReverseMono(bool mono);
72
73 // Sets the required sample rate of the APM output.
74 void SetOutputRate(int rate_hz);
75
76 // Sets the required channels of the APM output.
77 void SetOutputChannels(int channels);
78
79 std::string dump_file_name() const { return dump_file_name_; }
80
81 void StartRecording();
82 void Process(size_t num_blocks);
83 void StopRecording();
84 AudioProcessing* apm() const { return apm_.get(); }
85
86 private:
Yves Gerey665174f2018-06-19 15:03:05 +020087 static void ReadAndDeinterleave(ResampleInputAudioFile* audio,
88 int channels,
minyue275d2552015-11-04 06:23:54 -080089 const StreamConfig& config,
90 float* const* buffer);
91
92 // APM input/output settings.
93 StreamConfig input_config_;
94 StreamConfig reverse_config_;
95 StreamConfig output_config_;
96
97 // Input file format.
98 const std::string input_file_name_;
99 ResampleInputAudioFile input_audio_;
100 const int input_file_channels_;
101
102 // Reverse file format.
103 const std::string reverse_file_name_;
104 ResampleInputAudioFile reverse_audio_;
105 const int reverse_file_channels_;
106
107 // Buffer for APM input/output.
kwiberg62eaacf2016-02-17 06:39:05 -0800108 std::unique_ptr<ChannelBuffer<float>> input_;
109 std::unique_ptr<ChannelBuffer<float>> reverse_;
110 std::unique_ptr<ChannelBuffer<float>> output_;
minyue275d2552015-11-04 06:23:54 -0800111
Alex Loiko62347222018-09-10 10:18:07 +0200112 bool enable_pre_amplifier_;
113
Danil Chapovalov07122bc2019-03-26 14:37:01 +0100114 TaskQueueForTest worker_queue_;
Niels Möller4f776ac2021-07-02 11:30:54 +0200115 rtc::scoped_refptr<AudioProcessing> apm_;
minyue275d2552015-11-04 06:23:54 -0800116
117 const std::string dump_file_name_;
118};
119
120DebugDumpGenerator::DebugDumpGenerator(const std::string& input_file_name,
121 int input_rate_hz,
122 int input_channels,
123 const std::string& reverse_file_name,
124 int reverse_rate_hz,
125 int reverse_channels,
126 const Config& config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200127 const std::string& dump_file_name,
Alex Loiko62347222018-09-10 10:18:07 +0200128 bool enable_pre_amplifier)
minyue275d2552015-11-04 06:23:54 -0800129 : input_config_(input_rate_hz, input_channels),
130 reverse_config_(reverse_rate_hz, reverse_channels),
131 output_config_(input_rate_hz, input_channels),
132 input_audio_(input_file_name, input_rate_hz, input_rate_hz),
133 input_file_channels_(input_channels),
134 reverse_audio_(reverse_file_name, reverse_rate_hz, reverse_rate_hz),
135 reverse_file_channels_(reverse_channels),
136 input_(new ChannelBuffer<float>(input_config_.num_frames(),
137 input_config_.num_channels())),
138 reverse_(new ChannelBuffer<float>(reverse_config_.num_frames(),
139 reverse_config_.num_channels())),
140 output_(new ChannelBuffer<float>(output_config_.num_frames(),
141 output_config_.num_channels())),
Alex Loiko62347222018-09-10 10:18:07 +0200142 enable_pre_amplifier_(enable_pre_amplifier),
aleloif4dd1912017-06-15 01:55:38 -0700143 worker_queue_("debug_dump_generator_worker_queue"),
Ivo Creusen62337e52018-01-09 14:17:33 +0100144 dump_file_name_(dump_file_name) {
Per Åhgrencc73ed32020-04-26 23:56:17 +0200145 AudioProcessingBuilderForTesting apm_builder;
Niels Möller4f776ac2021-07-02 11:30:54 +0200146 apm_ = apm_builder.Create(config);
Ivo Creusen62337e52018-01-09 14:17:33 +0100147}
minyue275d2552015-11-04 06:23:54 -0800148
peah88ac8532016-09-12 16:47:25 -0700149DebugDumpGenerator::DebugDumpGenerator(
150 const Config& config,
Per Åhgren200feba2019-03-06 04:16:46 +0100151 const AudioProcessing::Config& apm_config)
peah88ac8532016-09-12 16:47:25 -0700152 : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"),
153 32000,
154 2,
155 ResourcePath("far32_stereo", "pcm"),
156 32000,
157 2,
158 config,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200159 TempFilename(OutputPath(), "debug_aec"),
Alex Loiko62347222018-09-10 10:18:07 +0200160 apm_config.pre_amplifier.enabled) {
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200161 apm_->ApplyConfig(apm_config);
162}
163
minyue275d2552015-11-04 06:23:54 -0800164DebugDumpGenerator::~DebugDumpGenerator() {
165 remove(dump_file_name_.c_str());
166}
167
168void DebugDumpGenerator::SetInputRate(int rate_hz) {
169 input_audio_.set_output_rate_hz(rate_hz);
170 input_config_.set_sample_rate_hz(rate_hz);
171 MaybeResetBuffer(&input_, input_config_);
172}
173
174void DebugDumpGenerator::ForceInputMono(bool mono) {
175 const int channels = mono ? 1 : input_file_channels_;
176 input_config_.set_num_channels(channels);
177 MaybeResetBuffer(&input_, input_config_);
178}
179
180void DebugDumpGenerator::SetReverseRate(int rate_hz) {
181 reverse_audio_.set_output_rate_hz(rate_hz);
182 reverse_config_.set_sample_rate_hz(rate_hz);
183 MaybeResetBuffer(&reverse_, reverse_config_);
184}
185
186void DebugDumpGenerator::ForceReverseMono(bool mono) {
187 const int channels = mono ? 1 : reverse_file_channels_;
188 reverse_config_.set_num_channels(channels);
189 MaybeResetBuffer(&reverse_, reverse_config_);
190}
191
192void DebugDumpGenerator::SetOutputRate(int rate_hz) {
193 output_config_.set_sample_rate_hz(rate_hz);
194 MaybeResetBuffer(&output_, output_config_);
195}
196
197void DebugDumpGenerator::SetOutputChannels(int channels) {
198 output_config_.set_num_channels(channels);
199 MaybeResetBuffer(&output_, output_config_);
200}
201
202void DebugDumpGenerator::StartRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700203 apm_->AttachAecDump(
204 AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_));
minyue275d2552015-11-04 06:23:54 -0800205}
206
207void DebugDumpGenerator::Process(size_t num_blocks) {
208 for (size_t i = 0; i < num_blocks; ++i) {
209 ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_,
210 reverse_config_, reverse_->channels());
211 ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_,
212 input_->channels());
213 RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100));
Per Åhgren0695df12020-01-13 14:43:13 +0100214 apm_->set_stream_analog_level(100);
Alex Loiko62347222018-09-10 10:18:07 +0200215 if (enable_pre_amplifier_) {
216 apm_->SetRuntimeSetting(
217 AudioProcessing::RuntimeSetting::CreateCapturePreGain(1 + i % 10));
218 }
minyue275d2552015-11-04 06:23:54 -0800219 apm_->set_stream_key_pressed(i % 10 == 9);
220 RTC_CHECK_EQ(AudioProcessing::kNoError,
221 apm_->ProcessStream(input_->channels(), input_config_,
222 output_config_, output_->channels()));
223
Yves Gerey665174f2018-06-19 15:03:05 +0200224 RTC_CHECK_EQ(
225 AudioProcessing::kNoError,
226 apm_->ProcessReverseStream(reverse_->channels(), reverse_config_,
227 reverse_config_, reverse_->channels()));
minyue275d2552015-11-04 06:23:54 -0800228 }
229}
230
231void DebugDumpGenerator::StopRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700232 apm_->DetachAecDump();
minyue275d2552015-11-04 06:23:54 -0800233}
234
235void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio,
236 int channels,
237 const StreamConfig& config,
238 float* const* buffer) {
239 const size_t num_frames = config.num_frames();
240 const int out_channels = config.num_channels();
241
242 std::vector<int16_t> signal(channels * num_frames);
243
244 audio->Read(num_frames * channels, &signal[0]);
245
246 // We only allow reducing number of channels by discarding some channels.
247 RTC_CHECK_LE(out_channels, channels);
248 for (int channel = 0; channel < out_channels; ++channel) {
249 for (size_t i = 0; i < num_frames; ++i) {
250 buffer[channel][i] = S16ToFloat(signal[i * channels + channel]);
251 }
252 }
253}
254
255} // namespace
256
257class DebugDumpTest : public ::testing::Test {
258 public:
minyue275d2552015-11-04 06:23:54 -0800259 // VerifyDebugDump replays a debug dump using APM and verifies that the result
260 // is bit-exact-identical to the output channel in the dump. This is only
261 // guaranteed if the debug dump is started on the first frame.
Alex Loiko890988c2017-08-31 10:25:48 +0200262 void VerifyDebugDump(const std::string& in_filename);
minyue275d2552015-11-04 06:23:54 -0800263
264 private:
minyue0de1c132016-03-17 02:39:30 -0700265 DebugDumpReplayer debug_dump_replayer_;
minyue275d2552015-11-04 06:23:54 -0800266};
267
minyue275d2552015-11-04 06:23:54 -0800268void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) {
minyue0de1c132016-03-17 02:39:30 -0700269 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename));
minyue275d2552015-11-04 06:23:54 -0800270
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200271 while (const absl::optional<audioproc::Event> event =
272 debug_dump_replayer_.GetNextEvent()) {
minyue0de1c132016-03-17 02:39:30 -0700273 debug_dump_replayer_.RunNextEvent();
274 if (event->type() == audioproc::Event::STREAM) {
275 const audioproc::Stream* msg = &event->stream();
276 const StreamConfig output_config = debug_dump_replayer_.GetOutputConfig();
277 const ChannelBuffer<float>* output = debug_dump_replayer_.GetOutput();
278 // Check that output of APM is bit-exact to the output in the dump.
279 ASSERT_EQ(output_config.num_channels(),
280 static_cast<size_t>(msg->output_channel_size()));
281 ASSERT_EQ(output_config.num_frames() * sizeof(float),
282 msg->output_channel(0).size());
283 for (int i = 0; i < msg->output_channel_size(); ++i) {
Yves Gerey665174f2018-06-19 15:03:05 +0200284 ASSERT_EQ(0,
285 memcmp(output->channels()[i], msg->output_channel(i).data(),
286 msg->output_channel(i).size()));
minyue0de1c132016-03-17 02:39:30 -0700287 }
minyue275d2552015-11-04 06:23:54 -0800288 }
289 }
minyue275d2552015-11-04 06:23:54 -0800290}
291
292TEST_F(DebugDumpTest, SimpleCase) {
293 Config config;
peah88ac8532016-09-12 16:47:25 -0700294 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800295 generator.StartRecording();
296 generator.Process(100);
297 generator.StopRecording();
298 VerifyDebugDump(generator.dump_file_name());
299}
300
301TEST_F(DebugDumpTest, ChangeInputFormat) {
302 Config config;
peah88ac8532016-09-12 16:47:25 -0700303 DebugDumpGenerator generator(config, AudioProcessing::Config());
304
minyue275d2552015-11-04 06:23:54 -0800305 generator.StartRecording();
306 generator.Process(100);
307 generator.SetInputRate(48000);
308
309 generator.ForceInputMono(true);
310 // Number of output channel should not be larger than that of input. APM will
311 // fail otherwise.
312 generator.SetOutputChannels(1);
313
314 generator.Process(100);
315 generator.StopRecording();
316 VerifyDebugDump(generator.dump_file_name());
317}
318
319TEST_F(DebugDumpTest, ChangeReverseFormat) {
320 Config config;
peah88ac8532016-09-12 16:47:25 -0700321 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800322 generator.StartRecording();
323 generator.Process(100);
324 generator.SetReverseRate(48000);
325 generator.ForceReverseMono(true);
326 generator.Process(100);
327 generator.StopRecording();
328 VerifyDebugDump(generator.dump_file_name());
329}
330
331TEST_F(DebugDumpTest, ChangeOutputFormat) {
332 Config config;
peah88ac8532016-09-12 16:47:25 -0700333 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800334 generator.StartRecording();
335 generator.Process(100);
336 generator.SetOutputRate(48000);
337 generator.SetOutputChannels(1);
338 generator.Process(100);
339 generator.StopRecording();
340 VerifyDebugDump(generator.dump_file_name());
341}
342
343TEST_F(DebugDumpTest, ToggleAec) {
344 Config config;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200345 AudioProcessing::Config apm_config;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200346 apm_config.echo_canceller.enabled = true;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200347 DebugDumpGenerator generator(config, apm_config);
minyue275d2552015-11-04 06:23:54 -0800348 generator.StartRecording();
349 generator.Process(100);
350
Per Åhgrenb8106462019-12-04 08:34:12 +0100351 apm_config.echo_canceller.enabled = false;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200352 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800353
354 generator.Process(100);
355 generator.StopRecording();
356 VerifyDebugDump(generator.dump_file_name());
357}
358
peah0332c2d2016-04-15 11:23:33 -0700359TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) {
360 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800361 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200362 apm_config.echo_canceller.enabled = true;
Per Åhgren0695df12020-01-13 14:43:13 +0100363 apm_config.gain_controller1.analog_gain_controller.enabled = true;
364 apm_config.gain_controller1.analog_gain_controller.startup_min_volume = 0;
henrik.lundinbd681b92016-12-05 09:08:42 -0800365 // Arbitrarily set clipping gain to 17, which will never be the default.
Per Åhgren0695df12020-01-13 14:43:13 +0100366 apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17;
Per Åhgren200feba2019-03-06 04:16:46 +0100367 DebugDumpGenerator generator(config, apm_config);
peah0332c2d2016-04-15 11:23:33 -0700368 generator.StartRecording();
369 generator.Process(100);
370 generator.StopRecording();
371
372 DebugDumpReplayer debug_dump_replayer_;
373
374 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
375
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200376 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700377 debug_dump_replayer_.GetNextEvent()) {
378 debug_dump_replayer_.RunNextEvent();
379 if (event->type() == audioproc::Event::CONFIG) {
380 const audioproc::Config* msg = &event->config();
381 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200382 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700383 msg->experiments_description().c_str());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200384 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 09:08:42 -0800385 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700386 }
387 }
388}
389
390TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) {
391 Config config;
Per Åhgren200feba2019-03-06 04:16:46 +0100392 AudioProcessing::Config apm_config;
393 apm_config.echo_canceller.enabled = true;
Per Åhgren200feba2019-03-06 04:16:46 +0100394 DebugDumpGenerator generator(config, apm_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());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200409 EXPECT_PRED_FORMAT2(::testing::IsNotSubstring,
410 "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 09:08:42 -0800411 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700412 }
413 }
414}
415
peah7789fe72016-04-15 01:19:44 -0700416TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) {
417 Config config;
peahe0eae3c2016-12-14 01:16:23 -0800418 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200419 apm_config.echo_canceller.enabled = true;
Per Åhgren200feba2019-03-06 04:16:46 +0100420 DebugDumpGenerator generator(config, apm_config);
peah7789fe72016-04-15 01:19:44 -0700421 generator.StartRecording();
422 generator.Process(100);
423 generator.StopRecording();
424
425 DebugDumpReplayer debug_dump_replayer_;
426
427 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
428
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200429 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700430 debug_dump_replayer_.GetNextEvent()) {
431 debug_dump_replayer_.RunNextEvent();
432 if (event->type() == audioproc::Event::CONFIG) {
433 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700434 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200435 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700436 msg->experiments_description().c_str());
peah7789fe72016-04-15 01:19:44 -0700437 }
438 }
439}
440
henrik.lundinbd681b92016-12-05 09:08:42 -0800441TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) {
442 Config config;
Per Åhgren0695df12020-01-13 14:43:13 +0100443 AudioProcessing::Config apm_config;
444 apm_config.gain_controller1.analog_gain_controller.enabled = true;
445 apm_config.gain_controller1.analog_gain_controller.startup_min_volume = 0;
henrik.lundinbd681b92016-12-05 09:08:42 -0800446 // Arbitrarily set clipping gain to 17, which will never be the default.
Per Åhgren0695df12020-01-13 14:43:13 +0100447 apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17;
448 DebugDumpGenerator generator(config, apm_config);
henrik.lundinbd681b92016-12-05 09:08:42 -0800449 generator.StartRecording();
450 generator.Process(100);
451 generator.StopRecording();
452
453 DebugDumpReplayer debug_dump_replayer_;
454
455 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
456
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200457 while (const absl::optional<audioproc::Event> event =
henrik.lundinbd681b92016-12-05 09:08:42 -0800458 debug_dump_replayer_.GetNextEvent()) {
459 debug_dump_replayer_.RunNextEvent();
460 if (event->type() == audioproc::Event::CONFIG) {
461 const audioproc::Config* msg = &event->config();
462 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200463 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 09:08:42 -0800464 msg->experiments_description().c_str());
465 }
466 }
467}
468
peah7789fe72016-04-15 01:19:44 -0700469TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) {
470 Config config;
peah88ac8532016-09-12 16:47:25 -0700471 DebugDumpGenerator generator(config, AudioProcessing::Config());
peah7789fe72016-04-15 01:19:44 -0700472 generator.StartRecording();
473 generator.Process(100);
474 generator.StopRecording();
475
476 DebugDumpReplayer debug_dump_replayer_;
477
478 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
479
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200480 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700481 debug_dump_replayer_.GetNextEvent()) {
482 debug_dump_replayer_.RunNextEvent();
483 if (event->type() == audioproc::Event::CONFIG) {
484 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700485 ASSERT_TRUE(msg->has_experiments_description());
peah7789fe72016-04-15 01:19:44 -0700486 EXPECT_EQ(0u, msg->experiments_description().size());
487 }
488 }
489}
490
Kári Tristan Helgason470c0882016-10-03 13:13:29 +0200491// AGC is not supported on Android or iOS.
492#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
minyue275d2552015-11-04 06:23:54 -0800493#define MAYBE_ToggleAgc DISABLED_ToggleAgc
494#else
495#define MAYBE_ToggleAgc ToggleAgc
496#endif
497TEST_F(DebugDumpTest, MAYBE_ToggleAgc) {
498 Config config;
peah88ac8532016-09-12 16:47:25 -0700499 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800500 generator.StartRecording();
501 generator.Process(100);
502
Sam Zackrisson41478c72019-10-15 10:10:26 +0200503 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
504 apm_config.gain_controller1.enabled = !apm_config.gain_controller1.enabled;
505 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800506
507 generator.Process(100);
508 generator.StopRecording();
509 VerifyDebugDump(generator.dump_file_name());
510}
511
512TEST_F(DebugDumpTest, ToggleNs) {
513 Config config;
peah88ac8532016-09-12 16:47:25 -0700514 DebugDumpGenerator generator(config, AudioProcessing::Config());
minyue275d2552015-11-04 06:23:54 -0800515 generator.StartRecording();
516 generator.Process(100);
517
Sam Zackrisson23513132019-01-11 15:10:32 +0100518 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
519 apm_config.noise_suppression.enabled = !apm_config.noise_suppression.enabled;
520 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800521
522 generator.Process(100);
523 generator.StopRecording();
524 VerifyDebugDump(generator.dump_file_name());
525}
526
527TEST_F(DebugDumpTest, TransientSuppressionOn) {
528 Config config;
peah88ac8532016-09-12 16:47:25 -0700529 DebugDumpGenerator generator(config, AudioProcessing::Config());
Per Åhgrenc0734712020-01-02 15:15:36 +0100530
531 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
532 apm_config.transient_suppression.enabled = true;
533 generator.apm()->ApplyConfig(apm_config);
534
minyue275d2552015-11-04 06:23:54 -0800535 generator.StartRecording();
536 generator.Process(100);
537 generator.StopRecording();
538 VerifyDebugDump(generator.dump_file_name());
539}
540
Alex Loiko62347222018-09-10 10:18:07 +0200541TEST_F(DebugDumpTest, PreAmplifierIsOn) {
542 Config config;
543 AudioProcessing::Config apm_config;
544 apm_config.pre_amplifier.enabled = true;
545 DebugDumpGenerator generator(config, apm_config);
546 generator.StartRecording();
547 generator.Process(100);
548 generator.StopRecording();
549 VerifyDebugDump(generator.dump_file_name());
550}
551
minyue275d2552015-11-04 06:23:54 -0800552} // namespace test
553} // namespace webrtc