blob: d69d3a4eeaaa6f5a3dd409fa9bf1f1d37ad84eb4 [file] [log] [blame]
minyue275d2552015-11-04 14:23:541/*
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 14:39:0512
kwiberg84be5112016-04-27 08:19:5813#include <memory>
minyue275d2552015-11-04 14:23:5414#include <string>
15#include <vector>
16
Ali Tofighf3592cb2022-08-16 12:44:3817#include "absl/strings/string_view.h"
Gustaf Ullberg0efa9412018-02-27 12:58:4518#include "api/audio/echo_canceller3_factory.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3119#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
20#include "modules/audio_processing/aec_dump/aec_dump_factory.h"
Per Åhgrencc73ed32020-04-26 21:56:1721#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3122#include "modules/audio_processing/test/debug_dump_replayer.h"
23#include "modules/audio_processing/test/test_utils.h"
Danil Chapovalov07122bc2019-03-26 13:37:0124#include "rtc_base/task_queue_for_test.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3125#include "test/gtest.h"
Steve Anton10542f22019-01-11 17:11:0026#include "test/testsupport/file_utils.h"
minyue275d2552015-11-04 14:23:5427
28namespace webrtc {
29namespace test {
30
31namespace {
32
kwiberg62eaacf2016-02-17 14:39:0533void MaybeResetBuffer(std::unique_ptr<ChannelBuffer<float>>* buffer,
minyue275d2552015-11-04 14:23:5434 const StreamConfig& config) {
35 auto& buffer_ref = *buffer;
36 if (!buffer_ref.get() || buffer_ref->num_frames() != config.num_frames() ||
37 buffer_ref->num_channels() != config.num_channels()) {
Yves Gerey665174f2018-06-19 13:03:0538 buffer_ref.reset(
39 new ChannelBuffer<float>(config.num_frames(), config.num_channels()));
minyue275d2552015-11-04 14:23:5440 }
41}
42
43class DebugDumpGenerator {
44 public:
Ali Tofighf3592cb2022-08-16 12:44:3845 DebugDumpGenerator(absl::string_view input_file_name,
Alex Loiko890988c2017-08-31 08:25:4846 int input_rate_hz,
minyue275d2552015-11-04 14:23:5447 int input_channels,
Ali Tofighf3592cb2022-08-16 12:44:3848 absl::string_view reverse_file_name,
Alex Loiko890988c2017-08-31 08:25:4849 int reverse_rate_hz,
minyue275d2552015-11-04 14:23:5450 int reverse_channels,
Ali Tofighf3592cb2022-08-16 12:44:3851 absl::string_view dump_file_name,
Alex Loiko62347222018-09-10 08:18:0752 bool enable_pre_amplifier);
minyue275d2552015-11-04 14:23:5453
54 // Constructor that uses default input files.
Alessio Bazzicabe1b8982021-09-17 06:26:1055 explicit DebugDumpGenerator(const AudioProcessing::Config& apm_config);
minyue275d2552015-11-04 14:23:5456
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 13:03:0586 static void ReadAndDeinterleave(ResampleInputAudioFile* audio,
87 int channels,
minyue275d2552015-11-04 14:23:5488 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 14:39:05107 std::unique_ptr<ChannelBuffer<float>> input_;
108 std::unique_ptr<ChannelBuffer<float>> reverse_;
109 std::unique_ptr<ChannelBuffer<float>> output_;
minyue275d2552015-11-04 14:23:54110
Alex Loiko62347222018-09-10 08:18:07111 bool enable_pre_amplifier_;
112
Danil Chapovalov07122bc2019-03-26 13:37:01113 TaskQueueForTest worker_queue_;
Niels Möller4f776ac2021-07-02 09:30:54114 rtc::scoped_refptr<AudioProcessing> apm_;
minyue275d2552015-11-04 14:23:54115
116 const std::string dump_file_name_;
117};
118
Ali Tofighf3592cb2022-08-16 12:44:38119DebugDumpGenerator::DebugDumpGenerator(absl::string_view input_file_name,
minyue275d2552015-11-04 14:23:54120 int input_rate_hz,
121 int input_channels,
Ali Tofighf3592cb2022-08-16 12:44:38122 absl::string_view reverse_file_name,
minyue275d2552015-11-04 14:23:54123 int reverse_rate_hz,
124 int reverse_channels,
Ali Tofighf3592cb2022-08-16 12:44:38125 absl::string_view dump_file_name,
Alex Loiko62347222018-09-10 08:18:07126 bool enable_pre_amplifier)
minyue275d2552015-11-04 14:23:54127 : input_config_(input_rate_hz, input_channels),
128 reverse_config_(reverse_rate_hz, reverse_channels),
129 output_config_(input_rate_hz, input_channels),
130 input_audio_(input_file_name, input_rate_hz, input_rate_hz),
131 input_file_channels_(input_channels),
132 reverse_audio_(reverse_file_name, reverse_rate_hz, reverse_rate_hz),
133 reverse_file_channels_(reverse_channels),
134 input_(new ChannelBuffer<float>(input_config_.num_frames(),
135 input_config_.num_channels())),
136 reverse_(new ChannelBuffer<float>(reverse_config_.num_frames(),
137 reverse_config_.num_channels())),
138 output_(new ChannelBuffer<float>(output_config_.num_frames(),
139 output_config_.num_channels())),
Alex Loiko62347222018-09-10 08:18:07140 enable_pre_amplifier_(enable_pre_amplifier),
aleloif4dd1912017-06-15 08:55:38141 worker_queue_("debug_dump_generator_worker_queue"),
Ivo Creusen62337e52018-01-09 13:17:33142 dump_file_name_(dump_file_name) {
Per Åhgrencc73ed32020-04-26 21:56:17143 AudioProcessingBuilderForTesting apm_builder;
Alessio Bazzicabe1b8982021-09-17 06:26:10144 apm_ = apm_builder.Create();
Ivo Creusen62337e52018-01-09 13:17:33145}
minyue275d2552015-11-04 14:23:54146
peah88ac8532016-09-12 23:47:25147DebugDumpGenerator::DebugDumpGenerator(
Per Åhgren200feba1c2019-03-06 03:16:46148 const AudioProcessing::Config& apm_config)
peah88ac8532016-09-12 23:47:25149 : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"),
150 32000,
151 2,
152 ResourcePath("far32_stereo", "pcm"),
153 32000,
154 2,
Gustaf Ullbergbd83b912017-10-18 10:32:42155 TempFilename(OutputPath(), "debug_aec"),
Alex Loiko62347222018-09-10 08:18:07156 apm_config.pre_amplifier.enabled) {
Gustaf Ullbergbd83b912017-10-18 10:32:42157 apm_->ApplyConfig(apm_config);
158}
159
minyue275d2552015-11-04 14:23:54160DebugDumpGenerator::~DebugDumpGenerator() {
161 remove(dump_file_name_.c_str());
162}
163
164void DebugDumpGenerator::SetInputRate(int rate_hz) {
165 input_audio_.set_output_rate_hz(rate_hz);
166 input_config_.set_sample_rate_hz(rate_hz);
167 MaybeResetBuffer(&input_, input_config_);
168}
169
170void DebugDumpGenerator::ForceInputMono(bool mono) {
171 const int channels = mono ? 1 : input_file_channels_;
172 input_config_.set_num_channels(channels);
173 MaybeResetBuffer(&input_, input_config_);
174}
175
176void DebugDumpGenerator::SetReverseRate(int rate_hz) {
177 reverse_audio_.set_output_rate_hz(rate_hz);
178 reverse_config_.set_sample_rate_hz(rate_hz);
179 MaybeResetBuffer(&reverse_, reverse_config_);
180}
181
182void DebugDumpGenerator::ForceReverseMono(bool mono) {
183 const int channels = mono ? 1 : reverse_file_channels_;
184 reverse_config_.set_num_channels(channels);
185 MaybeResetBuffer(&reverse_, reverse_config_);
186}
187
188void DebugDumpGenerator::SetOutputRate(int rate_hz) {
189 output_config_.set_sample_rate_hz(rate_hz);
190 MaybeResetBuffer(&output_, output_config_);
191}
192
193void DebugDumpGenerator::SetOutputChannels(int channels) {
194 output_config_.set_num_channels(channels);
195 MaybeResetBuffer(&output_, output_config_);
196}
197
198void DebugDumpGenerator::StartRecording() {
aleloif4dd1912017-06-15 08:55:38199 apm_->AttachAecDump(
200 AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_));
minyue275d2552015-11-04 14:23:54201}
202
203void DebugDumpGenerator::Process(size_t num_blocks) {
204 for (size_t i = 0; i < num_blocks; ++i) {
205 ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_,
206 reverse_config_, reverse_->channels());
207 ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_,
208 input_->channels());
209 RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100));
Per Åhgren0695df12020-01-13 13:43:13210 apm_->set_stream_analog_level(100);
Alex Loiko62347222018-09-10 08:18:07211 if (enable_pre_amplifier_) {
212 apm_->SetRuntimeSetting(
213 AudioProcessing::RuntimeSetting::CreateCapturePreGain(1 + i % 10));
214 }
minyue275d2552015-11-04 14:23:54215 apm_->set_stream_key_pressed(i % 10 == 9);
216 RTC_CHECK_EQ(AudioProcessing::kNoError,
217 apm_->ProcessStream(input_->channels(), input_config_,
218 output_config_, output_->channels()));
219
Yves Gerey665174f2018-06-19 13:03:05220 RTC_CHECK_EQ(
221 AudioProcessing::kNoError,
222 apm_->ProcessReverseStream(reverse_->channels(), reverse_config_,
223 reverse_config_, reverse_->channels()));
minyue275d2552015-11-04 14:23:54224 }
225}
226
227void DebugDumpGenerator::StopRecording() {
aleloif4dd1912017-06-15 08:55:38228 apm_->DetachAecDump();
minyue275d2552015-11-04 14:23:54229}
230
231void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio,
232 int channels,
233 const StreamConfig& config,
234 float* const* buffer) {
235 const size_t num_frames = config.num_frames();
236 const int out_channels = config.num_channels();
237
238 std::vector<int16_t> signal(channels * num_frames);
239
240 audio->Read(num_frames * channels, &signal[0]);
241
242 // We only allow reducing number of channels by discarding some channels.
243 RTC_CHECK_LE(out_channels, channels);
244 for (int channel = 0; channel < out_channels; ++channel) {
245 for (size_t i = 0; i < num_frames; ++i) {
246 buffer[channel][i] = S16ToFloat(signal[i * channels + channel]);
247 }
248 }
249}
250
251} // namespace
252
253class DebugDumpTest : public ::testing::Test {
254 public:
minyue275d2552015-11-04 14:23:54255 // VerifyDebugDump replays a debug dump using APM and verifies that the result
256 // is bit-exact-identical to the output channel in the dump. This is only
257 // guaranteed if the debug dump is started on the first frame.
Ali Tofighf3592cb2022-08-16 12:44:38258 void VerifyDebugDump(absl::string_view in_filename);
minyue275d2552015-11-04 14:23:54259
260 private:
minyue0de1c132016-03-17 09:39:30261 DebugDumpReplayer debug_dump_replayer_;
minyue275d2552015-11-04 14:23:54262};
263
Ali Tofighf3592cb2022-08-16 12:44:38264void DebugDumpTest::VerifyDebugDump(absl::string_view in_filename) {
minyue0de1c132016-03-17 09:39:30265 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename));
minyue275d2552015-11-04 14:23:54266
Danil Chapovalovdb9f7ab2018-06-19 08:50:11267 while (const absl::optional<audioproc::Event> event =
268 debug_dump_replayer_.GetNextEvent()) {
minyue0de1c132016-03-17 09:39:30269 debug_dump_replayer_.RunNextEvent();
270 if (event->type() == audioproc::Event::STREAM) {
271 const audioproc::Stream* msg = &event->stream();
272 const StreamConfig output_config = debug_dump_replayer_.GetOutputConfig();
273 const ChannelBuffer<float>* output = debug_dump_replayer_.GetOutput();
274 // Check that output of APM is bit-exact to the output in the dump.
275 ASSERT_EQ(output_config.num_channels(),
276 static_cast<size_t>(msg->output_channel_size()));
277 ASSERT_EQ(output_config.num_frames() * sizeof(float),
278 msg->output_channel(0).size());
279 for (int i = 0; i < msg->output_channel_size(); ++i) {
Yves Gerey665174f2018-06-19 13:03:05280 ASSERT_EQ(0,
281 memcmp(output->channels()[i], msg->output_channel(i).data(),
282 msg->output_channel(i).size()));
minyue0de1c132016-03-17 09:39:30283 }
minyue275d2552015-11-04 14:23:54284 }
285 }
minyue275d2552015-11-04 14:23:54286}
287
288TEST_F(DebugDumpTest, SimpleCase) {
Alessio Bazzicabe1b8982021-09-17 06:26:10289 DebugDumpGenerator generator(/*apm_config=*/{});
minyue275d2552015-11-04 14:23:54290 generator.StartRecording();
291 generator.Process(100);
292 generator.StopRecording();
293 VerifyDebugDump(generator.dump_file_name());
294}
295
296TEST_F(DebugDumpTest, ChangeInputFormat) {
Alessio Bazzicabe1b8982021-09-17 06:26:10297 DebugDumpGenerator generator(/*apm_config=*/{});
peah88ac8532016-09-12 23:47:25298
minyue275d2552015-11-04 14:23:54299 generator.StartRecording();
300 generator.Process(100);
301 generator.SetInputRate(48000);
302
303 generator.ForceInputMono(true);
304 // Number of output channel should not be larger than that of input. APM will
305 // fail otherwise.
306 generator.SetOutputChannels(1);
307
308 generator.Process(100);
309 generator.StopRecording();
310 VerifyDebugDump(generator.dump_file_name());
311}
312
313TEST_F(DebugDumpTest, ChangeReverseFormat) {
Alessio Bazzicabe1b8982021-09-17 06:26:10314 DebugDumpGenerator generator(/*apm_config=*/{});
minyue275d2552015-11-04 14:23:54315 generator.StartRecording();
316 generator.Process(100);
317 generator.SetReverseRate(48000);
318 generator.ForceReverseMono(true);
319 generator.Process(100);
320 generator.StopRecording();
321 VerifyDebugDump(generator.dump_file_name());
322}
323
324TEST_F(DebugDumpTest, ChangeOutputFormat) {
Alessio Bazzicabe1b8982021-09-17 06:26:10325 DebugDumpGenerator generator(/*apm_config=*/{});
minyue275d2552015-11-04 14:23:54326 generator.StartRecording();
327 generator.Process(100);
328 generator.SetOutputRate(48000);
329 generator.SetOutputChannels(1);
330 generator.Process(100);
331 generator.StopRecording();
332 VerifyDebugDump(generator.dump_file_name());
333}
334
335TEST_F(DebugDumpTest, ToggleAec) {
Sam Zackrissoncdf0e6d2018-09-17 09:05:17336 AudioProcessing::Config apm_config;
Sam Zackrissoncdf0e6d2018-09-17 09:05:17337 apm_config.echo_canceller.enabled = true;
Alessio Bazzicabe1b8982021-09-17 06:26:10338 DebugDumpGenerator generator(apm_config);
minyue275d2552015-11-04 14:23:54339 generator.StartRecording();
340 generator.Process(100);
341
Per Åhgrenb8106462019-12-04 07:34:12342 apm_config.echo_canceller.enabled = false;
Sam Zackrissoncdf0e6d2018-09-17 09:05:17343 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 14:23:54344
345 generator.Process(100);
346 generator.StopRecording();
347 VerifyDebugDump(generator.dump_file_name());
348}
349
peah0332c2d2016-04-15 18:23:33350TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) {
peahe0eae3c2016-12-14 09:16:23351 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 14:26:14352 apm_config.echo_canceller.enabled = true;
Per Åhgren0695df12020-01-13 13:43:13353 apm_config.gain_controller1.analog_gain_controller.enabled = true;
354 apm_config.gain_controller1.analog_gain_controller.startup_min_volume = 0;
henrik.lundinbd681b92016-12-05 17:08:42355 // Arbitrarily set clipping gain to 17, which will never be the default.
Per Åhgren0695df12020-01-13 13:43:13356 apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17;
Alessio Bazzicabe1b8982021-09-17 06:26:10357 DebugDumpGenerator generator(apm_config);
peah0332c2d2016-04-15 18:23:33358 generator.StartRecording();
359 generator.Process(100);
360 generator.StopRecording();
361
362 DebugDumpReplayer debug_dump_replayer_;
363
364 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
365
Danil Chapovalovdb9f7ab2018-06-19 08:50:11366 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 18:23:33367 debug_dump_replayer_.GetNextEvent()) {
368 debug_dump_replayer_.RunNextEvent();
369 if (event->type() == audioproc::Event::CONFIG) {
370 const audioproc::Config* msg = &event->config();
371 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 13:11:12372 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 18:23:33373 msg->experiments_description().c_str());
Mirko Bonadei6a489f22019-04-09 13:11:12374 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 17:08:42375 msg->experiments_description().c_str());
peah0332c2d2016-04-15 18:23:33376 }
377 }
378}
379
380TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) {
Per Åhgren200feba1c2019-03-06 03:16:46381 AudioProcessing::Config apm_config;
382 apm_config.echo_canceller.enabled = true;
Alessio Bazzicabe1b8982021-09-17 06:26:10383 DebugDumpGenerator generator(apm_config);
peah0332c2d2016-04-15 18:23:33384 generator.StartRecording();
385 generator.Process(100);
386 generator.StopRecording();
387
388 DebugDumpReplayer debug_dump_replayer_;
389
390 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
391
Danil Chapovalovdb9f7ab2018-06-19 08:50:11392 while (const absl::optional<audioproc::Event> event =
peah0332c2d2016-04-15 18:23:33393 debug_dump_replayer_.GetNextEvent()) {
394 debug_dump_replayer_.RunNextEvent();
395 if (event->type() == audioproc::Event::CONFIG) {
396 const audioproc::Config* msg = &event->config();
397 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 13:11:12398 EXPECT_PRED_FORMAT2(::testing::IsNotSubstring,
399 "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 17:08:42400 msg->experiments_description().c_str());
peah0332c2d2016-04-15 18:23:33401 }
402 }
403}
404
peah7789fe72016-04-15 08:19:44405TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) {
peahe0eae3c2016-12-14 09:16:23406 AudioProcessing::Config apm_config;
Sam Zackrissonb3b47ad2018-08-17 14:26:14407 apm_config.echo_canceller.enabled = true;
Alessio Bazzicabe1b8982021-09-17 06:26:10408 DebugDumpGenerator generator(apm_config);
peah7789fe72016-04-15 08:19:44409 generator.StartRecording();
410 generator.Process(100);
411 generator.StopRecording();
412
413 DebugDumpReplayer debug_dump_replayer_;
414
415 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
416
Danil Chapovalovdb9f7ab2018-06-19 08:50:11417 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 08:19:44418 debug_dump_replayer_.GetNextEvent()) {
419 debug_dump_replayer_.RunNextEvent();
420 if (event->type() == audioproc::Event::CONFIG) {
421 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 18:23:33422 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 13:11:12423 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController",
peah0332c2d2016-04-15 18:23:33424 msg->experiments_description().c_str());
peah7789fe72016-04-15 08:19:44425 }
426 }
427}
428
henrik.lundinbd681b92016-12-05 17:08:42429TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) {
Per Åhgren0695df12020-01-13 13:43:13430 AudioProcessing::Config apm_config;
431 apm_config.gain_controller1.analog_gain_controller.enabled = true;
432 apm_config.gain_controller1.analog_gain_controller.startup_min_volume = 0;
henrik.lundinbd681b92016-12-05 17:08:42433 // Arbitrarily set clipping gain to 17, which will never be the default.
Per Åhgren0695df12020-01-13 13:43:13434 apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17;
Alessio Bazzicabe1b8982021-09-17 06:26:10435 DebugDumpGenerator generator(apm_config);
henrik.lundinbd681b92016-12-05 17:08:42436 generator.StartRecording();
437 generator.Process(100);
438 generator.StopRecording();
439
440 DebugDumpReplayer debug_dump_replayer_;
441
442 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
443
Danil Chapovalovdb9f7ab2018-06-19 08:50:11444 while (const absl::optional<audioproc::Event> event =
henrik.lundinbd681b92016-12-05 17:08:42445 debug_dump_replayer_.GetNextEvent()) {
446 debug_dump_replayer_.RunNextEvent();
447 if (event->type() == audioproc::Event::CONFIG) {
448 const audioproc::Config* msg = &event->config();
449 ASSERT_TRUE(msg->has_experiments_description());
Mirko Bonadei6a489f22019-04-09 13:11:12450 EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment",
henrik.lundinbd681b92016-12-05 17:08:42451 msg->experiments_description().c_str());
452 }
453 }
454}
455
peah7789fe72016-04-15 08:19:44456TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) {
Alessio Bazzicabe1b8982021-09-17 06:26:10457 DebugDumpGenerator generator(/*apm_config=*/{});
peah7789fe72016-04-15 08:19:44458 generator.StartRecording();
459 generator.Process(100);
460 generator.StopRecording();
461
462 DebugDumpReplayer debug_dump_replayer_;
463
464 ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name()));
465
Danil Chapovalovdb9f7ab2018-06-19 08:50:11466 while (const absl::optional<audioproc::Event> event =
peah7789fe72016-04-15 08:19:44467 debug_dump_replayer_.GetNextEvent()) {
468 debug_dump_replayer_.RunNextEvent();
469 if (event->type() == audioproc::Event::CONFIG) {
470 const audioproc::Config* msg = &event->config();
peah0332c2d2016-04-15 18:23:33471 ASSERT_TRUE(msg->has_experiments_description());
peah7789fe72016-04-15 08:19:44472 EXPECT_EQ(0u, msg->experiments_description().size());
473 }
474 }
475}
476
Kári Tristan Helgason470c0882016-10-03 11:13:29477// AGC is not supported on Android or iOS.
478#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
minyue275d2552015-11-04 14:23:54479#define MAYBE_ToggleAgc DISABLED_ToggleAgc
480#else
481#define MAYBE_ToggleAgc ToggleAgc
482#endif
483TEST_F(DebugDumpTest, MAYBE_ToggleAgc) {
Alessio Bazzicabe1b8982021-09-17 06:26:10484 DebugDumpGenerator generator(/*apm_config=*/{});
minyue275d2552015-11-04 14:23:54485 generator.StartRecording();
486 generator.Process(100);
487
Sam Zackrisson41478c72019-10-15 08:10:26488 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
489 apm_config.gain_controller1.enabled = !apm_config.gain_controller1.enabled;
490 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 14:23:54491
492 generator.Process(100);
493 generator.StopRecording();
494 VerifyDebugDump(generator.dump_file_name());
495}
496
497TEST_F(DebugDumpTest, ToggleNs) {
Alessio Bazzicabe1b8982021-09-17 06:26:10498 DebugDumpGenerator generator(/*apm_config=*/{});
minyue275d2552015-11-04 14:23:54499 generator.StartRecording();
500 generator.Process(100);
501
Sam Zackrisson23513132019-01-11 14:10:32502 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
503 apm_config.noise_suppression.enabled = !apm_config.noise_suppression.enabled;
504 generator.apm()->ApplyConfig(apm_config);
minyue275d2552015-11-04 14:23:54505
506 generator.Process(100);
507 generator.StopRecording();
508 VerifyDebugDump(generator.dump_file_name());
509}
510
511TEST_F(DebugDumpTest, TransientSuppressionOn) {
Alessio Bazzicabe1b8982021-09-17 06:26:10512 DebugDumpGenerator generator(/*apm_config=*/{});
Per Åhgrenc0734712020-01-02 14:15:36513
514 AudioProcessing::Config apm_config = generator.apm()->GetConfig();
515 apm_config.transient_suppression.enabled = true;
516 generator.apm()->ApplyConfig(apm_config);
517
minyue275d2552015-11-04 14:23:54518 generator.StartRecording();
519 generator.Process(100);
520 generator.StopRecording();
521 VerifyDebugDump(generator.dump_file_name());
522}
523
Alex Loiko62347222018-09-10 08:18:07524TEST_F(DebugDumpTest, PreAmplifierIsOn) {
Alex Loiko62347222018-09-10 08:18:07525 AudioProcessing::Config apm_config;
526 apm_config.pre_amplifier.enabled = true;
Alessio Bazzicabe1b8982021-09-17 06:26:10527 DebugDumpGenerator generator(apm_config);
Alex Loiko62347222018-09-10 08:18:07528 generator.StartRecording();
529 generator.Process(100);
530 generator.StopRecording();
531 VerifyDebugDump(generator.dump_file_name());
532}
533
minyue275d2552015-11-04 14:23:54534} // namespace test
535} // namespace webrtc