minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 1 | /* |
| 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 |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 12 | |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 13 | #include <memory> |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
Gustaf Ullberg | 0efa941 | 2018-02-27 13:58:45 +0100 | [diff] [blame] | 17 | #include "api/audio/echo_canceller3_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "modules/audio_coding/neteq/tools/resample_input_audio_file.h" |
| 19 | #include "modules/audio_processing/aec_dump/aec_dump_factory.h" |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 20 | #include "modules/audio_processing/test/audio_processing_builder_for_testing.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "modules/audio_processing/test/debug_dump_replayer.h" |
| 22 | #include "modules/audio_processing/test/test_utils.h" |
Danil Chapovalov | 07122bc | 2019-03-26 14:37:01 +0100 | [diff] [blame] | 23 | #include "rtc_base/task_queue_for_test.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "test/gtest.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 25 | #include "test/testsupport/file_utils.h" |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | namespace test { |
| 29 | |
| 30 | namespace { |
| 31 | |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 32 | void MaybeResetBuffer(std::unique_ptr<ChannelBuffer<float>>* buffer, |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 33 | 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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 37 | buffer_ref.reset( |
| 38 | new ChannelBuffer<float>(config.num_frames(), config.num_channels())); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
| 42 | class DebugDumpGenerator { |
| 43 | public: |
| 44 | DebugDumpGenerator(const std::string& input_file_name, |
Alex Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 45 | int input_rate_hz, |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 46 | int input_channels, |
| 47 | const std::string& reverse_file_name, |
Alex Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 48 | int reverse_rate_hz, |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 49 | int reverse_channels, |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 50 | const std::string& dump_file_name, |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 51 | bool enable_pre_amplifier); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 52 | |
| 53 | // Constructor that uses default input files. |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 54 | explicit DebugDumpGenerator(const AudioProcessing::Config& apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 55 | |
| 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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 85 | static void ReadAndDeinterleave(ResampleInputAudioFile* audio, |
| 86 | int channels, |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 87 | 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. |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 106 | std::unique_ptr<ChannelBuffer<float>> input_; |
| 107 | std::unique_ptr<ChannelBuffer<float>> reverse_; |
| 108 | std::unique_ptr<ChannelBuffer<float>> output_; |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 109 | |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 110 | bool enable_pre_amplifier_; |
| 111 | |
Danil Chapovalov | 07122bc | 2019-03-26 14:37:01 +0100 | [diff] [blame] | 112 | TaskQueueForTest worker_queue_; |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame] | 113 | rtc::scoped_refptr<AudioProcessing> apm_; |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 114 | |
| 115 | const std::string dump_file_name_; |
| 116 | }; |
| 117 | |
| 118 | DebugDumpGenerator::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 Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 124 | const std::string& dump_file_name, |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 125 | bool enable_pre_amplifier) |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 126 | : 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 Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 139 | enable_pre_amplifier_(enable_pre_amplifier), |
aleloi | f4dd191 | 2017-06-15 01:55:38 -0700 | [diff] [blame] | 140 | worker_queue_("debug_dump_generator_worker_queue"), |
Ivo Creusen | 62337e5 | 2018-01-09 14:17:33 +0100 | [diff] [blame] | 141 | dump_file_name_(dump_file_name) { |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 142 | AudioProcessingBuilderForTesting apm_builder; |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 143 | apm_ = apm_builder.Create(); |
Ivo Creusen | 62337e5 | 2018-01-09 14:17:33 +0100 | [diff] [blame] | 144 | } |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 145 | |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 146 | DebugDumpGenerator::DebugDumpGenerator( |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 147 | const AudioProcessing::Config& apm_config) |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 148 | : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"), |
| 149 | 32000, |
| 150 | 2, |
| 151 | ResourcePath("far32_stereo", "pcm"), |
| 152 | 32000, |
| 153 | 2, |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 154 | TempFilename(OutputPath(), "debug_aec"), |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 155 | apm_config.pre_amplifier.enabled) { |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 156 | apm_->ApplyConfig(apm_config); |
| 157 | } |
| 158 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 159 | DebugDumpGenerator::~DebugDumpGenerator() { |
| 160 | remove(dump_file_name_.c_str()); |
| 161 | } |
| 162 | |
| 163 | void 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 | |
| 169 | void 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 | |
| 175 | void 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 | |
| 181 | void 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 | |
| 187 | void DebugDumpGenerator::SetOutputRate(int rate_hz) { |
| 188 | output_config_.set_sample_rate_hz(rate_hz); |
| 189 | MaybeResetBuffer(&output_, output_config_); |
| 190 | } |
| 191 | |
| 192 | void DebugDumpGenerator::SetOutputChannels(int channels) { |
| 193 | output_config_.set_num_channels(channels); |
| 194 | MaybeResetBuffer(&output_, output_config_); |
| 195 | } |
| 196 | |
| 197 | void DebugDumpGenerator::StartRecording() { |
aleloi | f4dd191 | 2017-06-15 01:55:38 -0700 | [diff] [blame] | 198 | apm_->AttachAecDump( |
| 199 | AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_)); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void 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 Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 209 | apm_->set_stream_analog_level(100); |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 210 | if (enable_pre_amplifier_) { |
| 211 | apm_->SetRuntimeSetting( |
| 212 | AudioProcessing::RuntimeSetting::CreateCapturePreGain(1 + i % 10)); |
| 213 | } |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 214 | 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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 219 | RTC_CHECK_EQ( |
| 220 | AudioProcessing::kNoError, |
| 221 | apm_->ProcessReverseStream(reverse_->channels(), reverse_config_, |
| 222 | reverse_config_, reverse_->channels())); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
| 226 | void DebugDumpGenerator::StopRecording() { |
aleloi | f4dd191 | 2017-06-15 01:55:38 -0700 | [diff] [blame] | 227 | apm_->DetachAecDump(); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | void 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 | |
| 252 | class DebugDumpTest : public ::testing::Test { |
| 253 | public: |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 254 | // 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 Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 257 | void VerifyDebugDump(const std::string& in_filename); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 258 | |
| 259 | private: |
minyue | 0de1c13 | 2016-03-17 02:39:30 -0700 | [diff] [blame] | 260 | DebugDumpReplayer debug_dump_replayer_; |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 261 | }; |
| 262 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 263 | void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) { |
minyue | 0de1c13 | 2016-03-17 02:39:30 -0700 | [diff] [blame] | 264 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename)); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 265 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 266 | while (const absl::optional<audioproc::Event> event = |
| 267 | debug_dump_replayer_.GetNextEvent()) { |
minyue | 0de1c13 | 2016-03-17 02:39:30 -0700 | [diff] [blame] | 268 | 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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 279 | ASSERT_EQ(0, |
| 280 | memcmp(output->channels()[i], msg->output_channel(i).data(), |
| 281 | msg->output_channel(i).size())); |
minyue | 0de1c13 | 2016-03-17 02:39:30 -0700 | [diff] [blame] | 282 | } |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 283 | } |
| 284 | } |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | TEST_F(DebugDumpTest, SimpleCase) { |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 288 | DebugDumpGenerator generator(/*apm_config=*/{}); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 289 | generator.StartRecording(); |
| 290 | generator.Process(100); |
| 291 | generator.StopRecording(); |
| 292 | VerifyDebugDump(generator.dump_file_name()); |
| 293 | } |
| 294 | |
| 295 | TEST_F(DebugDumpTest, ChangeInputFormat) { |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 296 | DebugDumpGenerator generator(/*apm_config=*/{}); |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 297 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 298 | 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 | |
| 312 | TEST_F(DebugDumpTest, ChangeReverseFormat) { |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 313 | DebugDumpGenerator generator(/*apm_config=*/{}); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 314 | 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 | |
| 323 | TEST_F(DebugDumpTest, ChangeOutputFormat) { |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 324 | DebugDumpGenerator generator(/*apm_config=*/{}); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 325 | 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 | |
| 334 | TEST_F(DebugDumpTest, ToggleAec) { |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 335 | AudioProcessing::Config apm_config; |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 336 | apm_config.echo_canceller.enabled = true; |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 337 | DebugDumpGenerator generator(apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 338 | generator.StartRecording(); |
| 339 | generator.Process(100); |
| 340 | |
Per Åhgren | b810646 | 2019-12-04 08:34:12 +0100 | [diff] [blame] | 341 | apm_config.echo_canceller.enabled = false; |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 342 | generator.apm()->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 343 | |
| 344 | generator.Process(100); |
| 345 | generator.StopRecording(); |
| 346 | VerifyDebugDump(generator.dump_file_name()); |
| 347 | } |
| 348 | |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 349 | TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) { |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 350 | AudioProcessing::Config apm_config; |
Sam Zackrisson | b3b47ad | 2018-08-17 16:26:14 +0200 | [diff] [blame] | 351 | apm_config.echo_canceller.enabled = true; |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 352 | apm_config.gain_controller1.analog_gain_controller.enabled = true; |
| 353 | apm_config.gain_controller1.analog_gain_controller.startup_min_volume = 0; |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 354 | // Arbitrarily set clipping gain to 17, which will never be the default. |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 355 | apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17; |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 356 | DebugDumpGenerator generator(apm_config); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 357 | 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 Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 365 | while (const absl::optional<audioproc::Event> event = |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 366 | 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 Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 371 | EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController", |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 372 | msg->experiments_description().c_str()); |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 373 | EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment", |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 374 | msg->experiments_description().c_str()); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) { |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 380 | AudioProcessing::Config apm_config; |
| 381 | apm_config.echo_canceller.enabled = true; |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 382 | DebugDumpGenerator generator(apm_config); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 383 | 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 Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 391 | while (const absl::optional<audioproc::Event> event = |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 392 | 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 Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 397 | EXPECT_PRED_FORMAT2(::testing::IsNotSubstring, |
| 398 | "AgcClippingLevelExperiment", |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 399 | msg->experiments_description().c_str()); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 404 | TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) { |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 405 | AudioProcessing::Config apm_config; |
Sam Zackrisson | b3b47ad | 2018-08-17 16:26:14 +0200 | [diff] [blame] | 406 | apm_config.echo_canceller.enabled = true; |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 407 | DebugDumpGenerator generator(apm_config); |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 408 | 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 Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 416 | while (const absl::optional<audioproc::Event> event = |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 417 | debug_dump_replayer_.GetNextEvent()) { |
| 418 | debug_dump_replayer_.RunNextEvent(); |
| 419 | if (event->type() == audioproc::Event::CONFIG) { |
| 420 | const audioproc::Config* msg = &event->config(); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 421 | ASSERT_TRUE(msg->has_experiments_description()); |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 422 | EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController", |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 423 | msg->experiments_description().c_str()); |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 428 | TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) { |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 429 | 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.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 432 | // Arbitrarily set clipping gain to 17, which will never be the default. |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 433 | apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17; |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 434 | DebugDumpGenerator generator(apm_config); |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 435 | 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 Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 443 | while (const absl::optional<audioproc::Event> event = |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 444 | 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 Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 449 | EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment", |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 450 | msg->experiments_description().c_str()); |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 455 | TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) { |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 456 | DebugDumpGenerator generator(/*apm_config=*/{}); |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 457 | 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 Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 465 | while (const absl::optional<audioproc::Event> event = |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 466 | debug_dump_replayer_.GetNextEvent()) { |
| 467 | debug_dump_replayer_.RunNextEvent(); |
| 468 | if (event->type() == audioproc::Event::CONFIG) { |
| 469 | const audioproc::Config* msg = &event->config(); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 470 | ASSERT_TRUE(msg->has_experiments_description()); |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 471 | EXPECT_EQ(0u, msg->experiments_description().size()); |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | |
Kári Tristan Helgason | 470c088 | 2016-10-03 13:13:29 +0200 | [diff] [blame] | 476 | // AGC is not supported on Android or iOS. |
| 477 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 478 | #define MAYBE_ToggleAgc DISABLED_ToggleAgc |
| 479 | #else |
| 480 | #define MAYBE_ToggleAgc ToggleAgc |
| 481 | #endif |
| 482 | TEST_F(DebugDumpTest, MAYBE_ToggleAgc) { |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 483 | DebugDumpGenerator generator(/*apm_config=*/{}); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 484 | generator.StartRecording(); |
| 485 | generator.Process(100); |
| 486 | |
Sam Zackrisson | 41478c7 | 2019-10-15 10:10:26 +0200 | [diff] [blame] | 487 | AudioProcessing::Config apm_config = generator.apm()->GetConfig(); |
| 488 | apm_config.gain_controller1.enabled = !apm_config.gain_controller1.enabled; |
| 489 | generator.apm()->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 490 | |
| 491 | generator.Process(100); |
| 492 | generator.StopRecording(); |
| 493 | VerifyDebugDump(generator.dump_file_name()); |
| 494 | } |
| 495 | |
| 496 | TEST_F(DebugDumpTest, ToggleNs) { |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 497 | DebugDumpGenerator generator(/*apm_config=*/{}); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 498 | generator.StartRecording(); |
| 499 | generator.Process(100); |
| 500 | |
Sam Zackrisson | 2351313 | 2019-01-11 15:10:32 +0100 | [diff] [blame] | 501 | AudioProcessing::Config apm_config = generator.apm()->GetConfig(); |
| 502 | apm_config.noise_suppression.enabled = !apm_config.noise_suppression.enabled; |
| 503 | generator.apm()->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 504 | |
| 505 | generator.Process(100); |
| 506 | generator.StopRecording(); |
| 507 | VerifyDebugDump(generator.dump_file_name()); |
| 508 | } |
| 509 | |
| 510 | TEST_F(DebugDumpTest, TransientSuppressionOn) { |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 511 | DebugDumpGenerator generator(/*apm_config=*/{}); |
Per Åhgren | c073471 | 2020-01-02 15:15:36 +0100 | [diff] [blame] | 512 | |
| 513 | AudioProcessing::Config apm_config = generator.apm()->GetConfig(); |
| 514 | apm_config.transient_suppression.enabled = true; |
| 515 | generator.apm()->ApplyConfig(apm_config); |
| 516 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 517 | generator.StartRecording(); |
| 518 | generator.Process(100); |
| 519 | generator.StopRecording(); |
| 520 | VerifyDebugDump(generator.dump_file_name()); |
| 521 | } |
| 522 | |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 523 | TEST_F(DebugDumpTest, PreAmplifierIsOn) { |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 524 | AudioProcessing::Config apm_config; |
| 525 | apm_config.pre_amplifier.enabled = true; |
Alessio Bazzica | be1b898 | 2021-09-17 08:26:10 +0200 | [diff] [blame^] | 526 | DebugDumpGenerator generator(apm_config); |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 527 | generator.StartRecording(); |
| 528 | generator.Process(100); |
| 529 | generator.StopRecording(); |
| 530 | VerifyDebugDump(generator.dump_file_name()); |
| 531 | } |
| 532 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 533 | } // namespace test |
| 534 | } // namespace webrtc |