blob: b7351609ecb2657ba61ffcacad9f219bfd2ad7ea [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,
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.
Alessio Bazzicabe1b8982021-09-17 08:26:10 +020054 explicit DebugDumpGenerator(const AudioProcessing::Config& apm_config);
minyue275d2552015-11-04 06:23:54 -080055
56 ~DebugDumpGenerator();
57
58 // Changes the sample rate of the input audio to the APM.
59 void SetInputRate(int rate_hz);
60
61 // Sets if converts stereo input signal to mono by discarding other channels.
62 void ForceInputMono(bool mono);
63
64 // Changes the sample rate of the reverse audio to the APM.
65 void SetReverseRate(int rate_hz);
66
67 // Sets if converts stereo reverse signal to mono by discarding other
68 // channels.
69 void ForceReverseMono(bool mono);
70
71 // Sets the required sample rate of the APM output.
72 void SetOutputRate(int rate_hz);
73
74 // Sets the required channels of the APM output.
75 void SetOutputChannels(int channels);
76
77 std::string dump_file_name() const { return dump_file_name_; }
78
79 void StartRecording();
80 void Process(size_t num_blocks);
81 void StopRecording();
82 AudioProcessing* apm() const { return apm_.get(); }
83
84 private:
Yves Gerey665174f2018-06-19 15:03:05 +020085 static void ReadAndDeinterleave(ResampleInputAudioFile* audio,
86 int channels,
minyue275d2552015-11-04 06:23:54 -080087 const StreamConfig& config,
88 float* const* buffer);
89
90 // APM input/output settings.
91 StreamConfig input_config_;
92 StreamConfig reverse_config_;
93 StreamConfig output_config_;
94
95 // Input file format.
96 const std::string input_file_name_;
97 ResampleInputAudioFile input_audio_;
98 const int input_file_channels_;
99
100 // Reverse file format.
101 const std::string reverse_file_name_;
102 ResampleInputAudioFile reverse_audio_;
103 const int reverse_file_channels_;
104
105 // Buffer for APM input/output.
kwiberg62eaacf2016-02-17 06:39:05 -0800106 std::unique_ptr<ChannelBuffer<float>> input_;
107 std::unique_ptr<ChannelBuffer<float>> reverse_;
108 std::unique_ptr<ChannelBuffer<float>> output_;
minyue275d2552015-11-04 06:23:54 -0800109
Alex Loiko62347222018-09-10 10:18:07 +0200110 bool enable_pre_amplifier_;
111
Danil Chapovalov07122bc2019-03-26 14:37:01 +0100112 TaskQueueForTest worker_queue_;
Niels Möller4f776ac2021-07-02 11:30:54 +0200113 rtc::scoped_refptr<AudioProcessing> apm_;
minyue275d2552015-11-04 06:23:54 -0800114
115 const std::string dump_file_name_;
116};
117
118DebugDumpGenerator::DebugDumpGenerator(const std::string& input_file_name,
119 int input_rate_hz,
120 int input_channels,
121 const std::string& reverse_file_name,
122 int reverse_rate_hz,
123 int reverse_channels,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200124 const std::string& dump_file_name,
Alex Loiko62347222018-09-10 10:18:07 +0200125 bool enable_pre_amplifier)
minyue275d2552015-11-04 06:23:54 -0800126 : input_config_(input_rate_hz, input_channels),
127 reverse_config_(reverse_rate_hz, reverse_channels),
128 output_config_(input_rate_hz, input_channels),
129 input_audio_(input_file_name, input_rate_hz, input_rate_hz),
130 input_file_channels_(input_channels),
131 reverse_audio_(reverse_file_name, reverse_rate_hz, reverse_rate_hz),
132 reverse_file_channels_(reverse_channels),
133 input_(new ChannelBuffer<float>(input_config_.num_frames(),
134 input_config_.num_channels())),
135 reverse_(new ChannelBuffer<float>(reverse_config_.num_frames(),
136 reverse_config_.num_channels())),
137 output_(new ChannelBuffer<float>(output_config_.num_frames(),
138 output_config_.num_channels())),
Alex Loiko62347222018-09-10 10:18:07 +0200139 enable_pre_amplifier_(enable_pre_amplifier),
aleloif4dd1912017-06-15 01:55:38 -0700140 worker_queue_("debug_dump_generator_worker_queue"),
Ivo Creusen62337e52018-01-09 14:17:33 +0100141 dump_file_name_(dump_file_name) {
Per Åhgrencc73ed32020-04-26 23:56:17 +0200142 AudioProcessingBuilderForTesting apm_builder;
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200143 apm_ = apm_builder.Create();
Ivo Creusen62337e52018-01-09 14:17:33 +0100144}
minyue275d2552015-11-04 06:23:54 -0800145
peah88ac8532016-09-12 16:47:25 -0700146DebugDumpGenerator::DebugDumpGenerator(
Per Åhgren200feba2019-03-06 04:16:46 +0100147 const AudioProcessing::Config& apm_config)
peah88ac8532016-09-12 16:47:25 -0700148 : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"),
149 32000,
150 2,
151 ResourcePath("far32_stereo", "pcm"),
152 32000,
153 2,
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200154 TempFilename(OutputPath(), "debug_aec"),
Alex Loiko62347222018-09-10 10:18:07 +0200155 apm_config.pre_amplifier.enabled) {
Gustaf Ullbergbd83b912017-10-18 12:32:42 +0200156 apm_->ApplyConfig(apm_config);
157}
158
minyue275d2552015-11-04 06:23:54 -0800159DebugDumpGenerator::~DebugDumpGenerator() {
160 remove(dump_file_name_.c_str());
161}
162
163void DebugDumpGenerator::SetInputRate(int rate_hz) {
164 input_audio_.set_output_rate_hz(rate_hz);
165 input_config_.set_sample_rate_hz(rate_hz);
166 MaybeResetBuffer(&input_, input_config_);
167}
168
169void DebugDumpGenerator::ForceInputMono(bool mono) {
170 const int channels = mono ? 1 : input_file_channels_;
171 input_config_.set_num_channels(channels);
172 MaybeResetBuffer(&input_, input_config_);
173}
174
175void DebugDumpGenerator::SetReverseRate(int rate_hz) {
176 reverse_audio_.set_output_rate_hz(rate_hz);
177 reverse_config_.set_sample_rate_hz(rate_hz);
178 MaybeResetBuffer(&reverse_, reverse_config_);
179}
180
181void DebugDumpGenerator::ForceReverseMono(bool mono) {
182 const int channels = mono ? 1 : reverse_file_channels_;
183 reverse_config_.set_num_channels(channels);
184 MaybeResetBuffer(&reverse_, reverse_config_);
185}
186
187void DebugDumpGenerator::SetOutputRate(int rate_hz) {
188 output_config_.set_sample_rate_hz(rate_hz);
189 MaybeResetBuffer(&output_, output_config_);
190}
191
192void DebugDumpGenerator::SetOutputChannels(int channels) {
193 output_config_.set_num_channels(channels);
194 MaybeResetBuffer(&output_, output_config_);
195}
196
197void DebugDumpGenerator::StartRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700198 apm_->AttachAecDump(
199 AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_));
minyue275d2552015-11-04 06:23:54 -0800200}
201
202void DebugDumpGenerator::Process(size_t num_blocks) {
203 for (size_t i = 0; i < num_blocks; ++i) {
204 ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_,
205 reverse_config_, reverse_->channels());
206 ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_,
207 input_->channels());
208 RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100));
Per Åhgren0695df12020-01-13 14:43:13 +0100209 apm_->set_stream_analog_level(100);
Alex Loiko62347222018-09-10 10:18:07 +0200210 if (enable_pre_amplifier_) {
211 apm_->SetRuntimeSetting(
212 AudioProcessing::RuntimeSetting::CreateCapturePreGain(1 + i % 10));
213 }
minyue275d2552015-11-04 06:23:54 -0800214 apm_->set_stream_key_pressed(i % 10 == 9);
215 RTC_CHECK_EQ(AudioProcessing::kNoError,
216 apm_->ProcessStream(input_->channels(), input_config_,
217 output_config_, output_->channels()));
218
Yves Gerey665174f2018-06-19 15:03:05 +0200219 RTC_CHECK_EQ(
220 AudioProcessing::kNoError,
221 apm_->ProcessReverseStream(reverse_->channels(), reverse_config_,
222 reverse_config_, reverse_->channels()));
minyue275d2552015-11-04 06:23:54 -0800223 }
224}
225
226void DebugDumpGenerator::StopRecording() {
aleloif4dd1912017-06-15 01:55:38 -0700227 apm_->DetachAecDump();
minyue275d2552015-11-04 06:23:54 -0800228}
229
230void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio,
231 int channels,
232 const StreamConfig& config,
233 float* const* buffer) {
234 const size_t num_frames = config.num_frames();
235 const int out_channels = config.num_channels();
236
237 std::vector<int16_t> signal(channels * num_frames);
238
239 audio->Read(num_frames * channels, &signal[0]);
240
241 // We only allow reducing number of channels by discarding some channels.
242 RTC_CHECK_LE(out_channels, channels);
243 for (int channel = 0; channel < out_channels; ++channel) {
244 for (size_t i = 0; i < num_frames; ++i) {
245 buffer[channel][i] = S16ToFloat(signal[i * channels + channel]);
246 }
247 }
248}
249
250} // namespace
251
252class DebugDumpTest : public ::testing::Test {
253 public:
minyue275d2552015-11-04 06:23:54 -0800254 // VerifyDebugDump replays a debug dump using APM and verifies that the result
255 // is bit-exact-identical to the output channel in the dump. This is only
256 // guaranteed if the debug dump is started on the first frame.
Alex Loiko890988c2017-08-31 10:25:48 +0200257 void VerifyDebugDump(const std::string& in_filename);
minyue275d2552015-11-04 06:23:54 -0800258
259 private:
minyue0de1c132016-03-17 02:39:30 -0700260 DebugDumpReplayer debug_dump_replayer_;
minyue275d2552015-11-04 06:23:54 -0800261};
262
minyue275d2552015-11-04 06:23:54 -0800263void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) {
minyue0de1c132016-03-17 02:39:30 -0700264 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename));
minyue275d2552015-11-04 06:23:54 -0800265
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200266 while (const absl::optional<audioproc::Event> event =
267 debug_dump_replayer_.GetNextEvent()) {
minyue0de1c132016-03-17 02:39:30 -0700268 debug_dump_replayer_.RunNextEvent();
269 if (event->type() == audioproc::Event::STREAM) {
270 const audioproc::Stream* msg = &event->stream();
271 const StreamConfig output_config = debug_dump_replayer_.GetOutputConfig();
272 const ChannelBuffer<float>* output = debug_dump_replayer_.GetOutput();
273 // Check that output of APM is bit-exact to the output in the dump.
274 ASSERT_EQ(output_config.num_channels(),
275 static_cast<size_t>(msg->output_channel_size()));
276 ASSERT_EQ(output_config.num_frames() * sizeof(float),
277 msg->output_channel(0).size());
278 for (int i = 0; i < msg->output_channel_size(); ++i) {
Yves Gerey665174f2018-06-19 15:03:05 +0200279 ASSERT_EQ(0,
280 memcmp(output->channels()[i], msg->output_channel(i).data(),
281 msg->output_channel(i).size()));
minyue0de1c132016-03-17 02:39:30 -0700282 }
minyue275d2552015-11-04 06:23:54 -0800283 }
284 }
minyue275d2552015-11-04 06:23:54 -0800285}
286
287TEST_F(DebugDumpTest, SimpleCase) {
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200288 DebugDumpGenerator generator(/*apm_config=*/{});
minyue275d2552015-11-04 06:23:54 -0800289 generator.StartRecording();
290 generator.Process(100);
291 generator.StopRecording();
292 VerifyDebugDump(generator.dump_file_name());
293}
294
295TEST_F(DebugDumpTest, ChangeInputFormat) {
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200296 DebugDumpGenerator generator(/*apm_config=*/{});
peah88ac8532016-09-12 16:47:25 -0700297
minyue275d2552015-11-04 06:23:54 -0800298 generator.StartRecording();
299 generator.Process(100);
300 generator.SetInputRate(48000);
301
302 generator.ForceInputMono(true);
303 // Number of output channel should not be larger than that of input. APM will
304 // fail otherwise.
305 generator.SetOutputChannels(1);
306
307 generator.Process(100);
308 generator.StopRecording();
309 VerifyDebugDump(generator.dump_file_name());
310}
311
312TEST_F(DebugDumpTest, ChangeReverseFormat) {
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200313 DebugDumpGenerator generator(/*apm_config=*/{});
minyue275d2552015-11-04 06:23:54 -0800314 generator.StartRecording();
315 generator.Process(100);
316 generator.SetReverseRate(48000);
317 generator.ForceReverseMono(true);
318 generator.Process(100);
319 generator.StopRecording();
320 VerifyDebugDump(generator.dump_file_name());
321}
322
323TEST_F(DebugDumpTest, ChangeOutputFormat) {
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200324 DebugDumpGenerator generator(/*apm_config=*/{});
minyue275d2552015-11-04 06:23:54 -0800325 generator.StartRecording();
326 generator.Process(100);
327 generator.SetOutputRate(48000);
328 generator.SetOutputChannels(1);
329 generator.Process(100);
330 generator.StopRecording();
331 VerifyDebugDump(generator.dump_file_name());
332}
333
334TEST_F(DebugDumpTest, ToggleAec) {
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200335 AudioProcessing::Config apm_config;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200336 apm_config.echo_canceller.enabled = true;
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200337 DebugDumpGenerator generator(apm_config);
minyue275d2552015-11-04 06:23:54 -0800338 generator.StartRecording();
339 generator.Process(100);
340
Per Åhgrenb8106462019-12-04 08:34:12 +0100341 apm_config.echo_canceller.enabled = false;
Sam Zackrissoncdf0e6d2018-09-17 11:05:17 +0200342 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800343
344 generator.Process(100);
345 generator.StopRecording();
346 VerifyDebugDump(generator.dump_file_name());
347}
348
peah0332c2d2016-04-15 11:23:33 -0700349TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) {
peahe0eae3c2016-12-14 01:16:23 -0800350 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200351 apm_config.echo_canceller.enabled = true;
Per Åhgren0695df12020-01-13 14:43:13 +0100352 apm_config.gain_controller1.analog_gain_controller.enabled = true;
353 apm_config.gain_controller1.analog_gain_controller.startup_min_volume = 0;
henrik.lundinbd681b92016-12-05 09:08:42 -0800354 // Arbitrarily set clipping gain to 17, which will never be the default.
Per Åhgren0695df12020-01-13 14:43:13 +0100355 apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17;
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200356 DebugDumpGenerator generator(apm_config);
peah0332c2d2016-04-15 11:23:33 -0700357 generator.StartRecording();
358 generator.Process(100);
359 generator.StopRecording();
360
361 DebugDumpReplayer debug_dump_replayer_;
362
363 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
364
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200365 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700366 debug_dump_replayer_.GetNextEvent()) {
367 debug_dump_replayer_.RunNextEvent();
368 if (event->type() == audioproc::Event::CONFIG) {
369 const audioproc::Config* msg = &event->config();
370 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200371 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700372 msg->experiments_description().c_str());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200373 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 09:08:42 -0800374 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700375 }
376 }
377}
378
379TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) {
Per Åhgren200feba2019-03-06 04:16:46 +0100380 AudioProcessing::Config apm_config;
381 apm_config.echo_canceller.enabled = true;
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200382 DebugDumpGenerator generator(apm_config);
peah0332c2d2016-04-15 11:23:33 -0700383 generator.StartRecording();
384 generator.Process(100);
385 generator.StopRecording();
386
387 DebugDumpReplayer debug_dump_replayer_;
388
389 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
390
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200391 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 11:23:33 -0700392 debug_dump_replayer_.GetNextEvent()) {
393 debug_dump_replayer_.RunNextEvent();
394 if (event->type() == audioproc::Event::CONFIG) {
395 const audioproc::Config* msg = &event->config();
396 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200397 EXPECT_PRED_FORMAT2(::testing::IsNotSubstring,
398 "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 09:08:42 -0800399 msg->experiments_description().c_str());
peah0332c2d2016-04-15 11:23:33 -0700400 }
401 }
402}
403
peah7789fe72016-04-15 01:19:44 -0700404TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) {
peahe0eae3c2016-12-14 01:16:23 -0800405 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 16:26:14 +0200406 apm_config.echo_canceller.enabled = true;
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200407 DebugDumpGenerator generator(apm_config);
peah7789fe72016-04-15 01:19:44 -0700408 generator.StartRecording();
409 generator.Process(100);
410 generator.StopRecording();
411
412 DebugDumpReplayer debug_dump_replayer_;
413
414 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
415
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200416 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700417 debug_dump_replayer_.GetNextEvent()) {
418 debug_dump_replayer_.RunNextEvent();
419 if (event->type() == audioproc::Event::CONFIG) {
420 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700421 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200422 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 11:23:33 -0700423 msg->experiments_description().c_str());
peah7789fe72016-04-15 01:19:44 -0700424 }
425 }
426}
427
henrik.lundinbd681b92016-12-05 09:08:42 -0800428TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) {
Per Åhgren0695df12020-01-13 14:43:13 +0100429 AudioProcessing::Config apm_config;
430 apm_config.gain_controller1.analog_gain_controller.enabled = true;
431 apm_config.gain_controller1.analog_gain_controller.startup_min_volume = 0;
henrik.lundinbd681b92016-12-05 09:08:42 -0800432 // Arbitrarily set clipping gain to 17, which will never be the default.
Per Åhgren0695df12020-01-13 14:43:13 +0100433 apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17;
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200434 DebugDumpGenerator generator(apm_config);
henrik.lundinbd681b92016-12-05 09:08:42 -0800435 generator.StartRecording();
436 generator.Process(100);
437 generator.StopRecording();
438
439 DebugDumpReplayer debug_dump_replayer_;
440
441 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
442
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200443 while (const absl::optional<audioproc::Event> event =
henrik.lundinbd681b92016-12-05 09:08:42 -0800444 debug_dump_replayer_.GetNextEvent()) {
445 debug_dump_replayer_.RunNextEvent();
446 if (event->type() == audioproc::Event::CONFIG) {
447 const audioproc::Config* msg = &event->config();
448 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200449 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 09:08:42 -0800450 msg->experiments_description().c_str());
451 }
452 }
453}
454
peah7789fe72016-04-15 01:19:44 -0700455TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) {
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200456 DebugDumpGenerator generator(/*apm_config=*/{});
peah7789fe72016-04-15 01:19:44 -0700457 generator.StartRecording();
458 generator.Process(100);
459 generator.StopRecording();
460
461 DebugDumpReplayer debug_dump_replayer_;
462
463 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
464
Danil Chapovalovdb9f7ab2018-06-19 10:50:11 +0200465 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 01:19:44 -0700466 debug_dump_replayer_.GetNextEvent()) {
467 debug_dump_replayer_.RunNextEvent();
468 if (event->type() == audioproc::Event::CONFIG) {
469 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 11:23:33 -0700470 ASSERT_TRUE(msg->has_experiments_description());
peah7789fe72016-04-15 01:19:44 -0700471 EXPECT_EQ(0u, msg->experiments_description().size());
472 }
473 }
474}
475
Kári Tristan Helgason470c0882016-10-03 13:13:29 +0200476// AGC is not supported on Android or iOS.
477#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
minyue275d2552015-11-04 06:23:54 -0800478#define MAYBE_ToggleAgc DISABLED_ToggleAgc
479#else
480#define MAYBE_ToggleAgc ToggleAgc
481#endif
482TEST_F(DebugDumpTest, MAYBE_ToggleAgc) {
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200483 DebugDumpGenerator generator(/*apm_config=*/{});
minyue275d2552015-11-04 06:23:54 -0800484 generator.StartRecording();
485 generator.Process(100);
486
Sam Zackrisson41478c72019-10-15 10:10:26 +0200487 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
488 apm_config.gain_controller1.enabled = !apm_config.gain_controller1.enabled;
489 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800490
491 generator.Process(100);
492 generator.StopRecording();
493 VerifyDebugDump(generator.dump_file_name());
494}
495
496TEST_F(DebugDumpTest, ToggleNs) {
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200497 DebugDumpGenerator generator(/*apm_config=*/{});
minyue275d2552015-11-04 06:23:54 -0800498 generator.StartRecording();
499 generator.Process(100);
500
Sam Zackrisson23513132019-01-11 15:10:32 +0100501 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
502 apm_config.noise_suppression.enabled = !apm_config.noise_suppression.enabled;
503 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 06:23:54 -0800504
505 generator.Process(100);
506 generator.StopRecording();
507 VerifyDebugDump(generator.dump_file_name());
508}
509
510TEST_F(DebugDumpTest, TransientSuppressionOn) {
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200511 DebugDumpGenerator generator(/*apm_config=*/{});
Per Åhgrenc0734712020-01-02 15:15:36 +0100512
513 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
514 apm_config.transient_suppression.enabled = true;
515 generator.apm()->ApplyConfig(apm_config);
516
minyue275d2552015-11-04 06:23:54 -0800517 generator.StartRecording();
518 generator.Process(100);
519 generator.StopRecording();
520 VerifyDebugDump(generator.dump_file_name());
521}
522
Alex Loiko62347222018-09-10 10:18:07 +0200523TEST_F(DebugDumpTest, PreAmplifierIsOn) {
Alex Loiko62347222018-09-10 10:18:07 +0200524 AudioProcessing::Config apm_config;
525 apm_config.pre_amplifier.enabled = true;
Alessio Bazzicabe1b8982021-09-17 08:26:10 +0200526 DebugDumpGenerator generator(apm_config);
Alex Loiko62347222018-09-10 10:18:07 +0200527 generator.StartRecording();
528 generator.Process(100);
529 generator.StopRecording();
530 VerifyDebugDump(generator.dump_file_name());
531}
532
minyue275d2552015-11-04 06:23:54 -0800533} // namespace test
534} // namespace webrtc