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, |
| 50 | const Config& config, |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 51 | const std::string& dump_file_name, |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 52 | bool enable_pre_amplifier); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 53 | |
| 54 | // Constructor that uses default input files. |
Per Åhgren | 4011de0 | 2019-12-03 11:48:48 +0000 | [diff] [blame] | 55 | explicit DebugDumpGenerator(const Config& config, |
| 56 | const AudioProcessing::Config& apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 57 | |
| 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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 87 | static void ReadAndDeinterleave(ResampleInputAudioFile* audio, |
| 88 | int channels, |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 89 | 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. |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 108 | std::unique_ptr<ChannelBuffer<float>> input_; |
| 109 | std::unique_ptr<ChannelBuffer<float>> reverse_; |
| 110 | std::unique_ptr<ChannelBuffer<float>> output_; |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 111 | |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 112 | bool enable_pre_amplifier_; |
| 113 | |
Danil Chapovalov | 07122bc | 2019-03-26 14:37:01 +0100 | [diff] [blame] | 114 | TaskQueueForTest worker_queue_; |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame^] | 115 | rtc::scoped_refptr<AudioProcessing> apm_; |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 116 | |
| 117 | const std::string dump_file_name_; |
| 118 | }; |
| 119 | |
| 120 | DebugDumpGenerator::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 Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 127 | const std::string& dump_file_name, |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 128 | bool enable_pre_amplifier) |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 129 | : 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 Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 142 | enable_pre_amplifier_(enable_pre_amplifier), |
aleloi | f4dd191 | 2017-06-15 01:55:38 -0700 | [diff] [blame] | 143 | worker_queue_("debug_dump_generator_worker_queue"), |
Ivo Creusen | 62337e5 | 2018-01-09 14:17:33 +0100 | [diff] [blame] | 144 | dump_file_name_(dump_file_name) { |
Per Åhgren | cc73ed3 | 2020-04-26 23:56:17 +0200 | [diff] [blame] | 145 | AudioProcessingBuilderForTesting apm_builder; |
Niels Möller | 4f776ac | 2021-07-02 11:30:54 +0200 | [diff] [blame^] | 146 | apm_ = apm_builder.Create(config); |
Ivo Creusen | 62337e5 | 2018-01-09 14:17:33 +0100 | [diff] [blame] | 147 | } |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 148 | |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 149 | DebugDumpGenerator::DebugDumpGenerator( |
| 150 | const Config& config, |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 151 | const AudioProcessing::Config& apm_config) |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 152 | : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"), |
| 153 | 32000, |
| 154 | 2, |
| 155 | ResourcePath("far32_stereo", "pcm"), |
| 156 | 32000, |
| 157 | 2, |
| 158 | config, |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 159 | TempFilename(OutputPath(), "debug_aec"), |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 160 | apm_config.pre_amplifier.enabled) { |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 161 | apm_->ApplyConfig(apm_config); |
| 162 | } |
| 163 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 164 | DebugDumpGenerator::~DebugDumpGenerator() { |
| 165 | remove(dump_file_name_.c_str()); |
| 166 | } |
| 167 | |
| 168 | void 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 | |
| 174 | void 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 | |
| 180 | void 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 | |
| 186 | void 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 | |
| 192 | void DebugDumpGenerator::SetOutputRate(int rate_hz) { |
| 193 | output_config_.set_sample_rate_hz(rate_hz); |
| 194 | MaybeResetBuffer(&output_, output_config_); |
| 195 | } |
| 196 | |
| 197 | void DebugDumpGenerator::SetOutputChannels(int channels) { |
| 198 | output_config_.set_num_channels(channels); |
| 199 | MaybeResetBuffer(&output_, output_config_); |
| 200 | } |
| 201 | |
| 202 | void DebugDumpGenerator::StartRecording() { |
aleloi | f4dd191 | 2017-06-15 01:55:38 -0700 | [diff] [blame] | 203 | apm_->AttachAecDump( |
| 204 | AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_)); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | void 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 Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 214 | apm_->set_stream_analog_level(100); |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 215 | if (enable_pre_amplifier_) { |
| 216 | apm_->SetRuntimeSetting( |
| 217 | AudioProcessing::RuntimeSetting::CreateCapturePreGain(1 + i % 10)); |
| 218 | } |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 219 | 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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 224 | RTC_CHECK_EQ( |
| 225 | AudioProcessing::kNoError, |
| 226 | apm_->ProcessReverseStream(reverse_->channels(), reverse_config_, |
| 227 | reverse_config_, reverse_->channels())); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
| 231 | void DebugDumpGenerator::StopRecording() { |
aleloi | f4dd191 | 2017-06-15 01:55:38 -0700 | [diff] [blame] | 232 | apm_->DetachAecDump(); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | void 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 | |
| 257 | class DebugDumpTest : public ::testing::Test { |
| 258 | public: |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 259 | // 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 Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 262 | void VerifyDebugDump(const std::string& in_filename); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 263 | |
| 264 | private: |
minyue | 0de1c13 | 2016-03-17 02:39:30 -0700 | [diff] [blame] | 265 | DebugDumpReplayer debug_dump_replayer_; |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 266 | }; |
| 267 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 268 | void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) { |
minyue | 0de1c13 | 2016-03-17 02:39:30 -0700 | [diff] [blame] | 269 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename)); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 270 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 271 | while (const absl::optional<audioproc::Event> event = |
| 272 | debug_dump_replayer_.GetNextEvent()) { |
minyue | 0de1c13 | 2016-03-17 02:39:30 -0700 | [diff] [blame] | 273 | 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 Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 284 | ASSERT_EQ(0, |
| 285 | memcmp(output->channels()[i], msg->output_channel(i).data(), |
| 286 | msg->output_channel(i).size())); |
minyue | 0de1c13 | 2016-03-17 02:39:30 -0700 | [diff] [blame] | 287 | } |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 288 | } |
| 289 | } |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | TEST_F(DebugDumpTest, SimpleCase) { |
| 293 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 294 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 295 | generator.StartRecording(); |
| 296 | generator.Process(100); |
| 297 | generator.StopRecording(); |
| 298 | VerifyDebugDump(generator.dump_file_name()); |
| 299 | } |
| 300 | |
| 301 | TEST_F(DebugDumpTest, ChangeInputFormat) { |
| 302 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 303 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
| 304 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 305 | 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 | |
| 319 | TEST_F(DebugDumpTest, ChangeReverseFormat) { |
| 320 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 321 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 322 | 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 | |
| 331 | TEST_F(DebugDumpTest, ChangeOutputFormat) { |
| 332 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 333 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 334 | 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 | |
| 343 | TEST_F(DebugDumpTest, ToggleAec) { |
| 344 | Config config; |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 345 | AudioProcessing::Config apm_config; |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 346 | apm_config.echo_canceller.enabled = true; |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 347 | DebugDumpGenerator generator(config, apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 348 | generator.StartRecording(); |
| 349 | generator.Process(100); |
| 350 | |
Per Åhgren | b810646 | 2019-12-04 08:34:12 +0100 | [diff] [blame] | 351 | apm_config.echo_canceller.enabled = false; |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 352 | generator.apm()->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 353 | |
| 354 | generator.Process(100); |
| 355 | generator.StopRecording(); |
| 356 | VerifyDebugDump(generator.dump_file_name()); |
| 357 | } |
| 358 | |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 359 | TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) { |
| 360 | Config config; |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 361 | AudioProcessing::Config apm_config; |
Sam Zackrisson | b3b47ad | 2018-08-17 16:26:14 +0200 | [diff] [blame] | 362 | apm_config.echo_canceller.enabled = true; |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 363 | apm_config.gain_controller1.analog_gain_controller.enabled = true; |
| 364 | apm_config.gain_controller1.analog_gain_controller.startup_min_volume = 0; |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 365 | // Arbitrarily set clipping gain to 17, which will never be the default. |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 366 | apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17; |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 367 | DebugDumpGenerator generator(config, apm_config); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 368 | 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 Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 376 | while (const absl::optional<audioproc::Event> event = |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 377 | 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 Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 382 | EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController", |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 383 | msg->experiments_description().c_str()); |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 384 | EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment", |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 385 | msg->experiments_description().c_str()); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) { |
| 391 | Config config; |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 392 | AudioProcessing::Config apm_config; |
| 393 | apm_config.echo_canceller.enabled = true; |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 394 | DebugDumpGenerator generator(config, apm_config); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 395 | 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 Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 403 | while (const absl::optional<audioproc::Event> event = |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 404 | 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 Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 409 | EXPECT_PRED_FORMAT2(::testing::IsNotSubstring, |
| 410 | "AgcClippingLevelExperiment", |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 411 | msg->experiments_description().c_str()); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 416 | TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) { |
| 417 | Config config; |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 418 | AudioProcessing::Config apm_config; |
Sam Zackrisson | b3b47ad | 2018-08-17 16:26:14 +0200 | [diff] [blame] | 419 | apm_config.echo_canceller.enabled = true; |
Per Åhgren | 200feba | 2019-03-06 04:16:46 +0100 | [diff] [blame] | 420 | DebugDumpGenerator generator(config, apm_config); |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 421 | 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 Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 429 | while (const absl::optional<audioproc::Event> event = |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 430 | debug_dump_replayer_.GetNextEvent()) { |
| 431 | debug_dump_replayer_.RunNextEvent(); |
| 432 | if (event->type() == audioproc::Event::CONFIG) { |
| 433 | const audioproc::Config* msg = &event->config(); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 434 | ASSERT_TRUE(msg->has_experiments_description()); |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 435 | EXPECT_PRED_FORMAT2(::testing::IsSubstring, "EchoController", |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 436 | msg->experiments_description().c_str()); |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 441 | TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) { |
| 442 | Config config; |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 443 | 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.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 446 | // Arbitrarily set clipping gain to 17, which will never be the default. |
Per Åhgren | 0695df1 | 2020-01-13 14:43:13 +0100 | [diff] [blame] | 447 | apm_config.gain_controller1.analog_gain_controller.clipped_level_min = 17; |
| 448 | DebugDumpGenerator generator(config, apm_config); |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 449 | 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 Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 457 | while (const absl::optional<audioproc::Event> event = |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 458 | 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 Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 463 | EXPECT_PRED_FORMAT2(::testing::IsSubstring, "AgcClippingLevelExperiment", |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 464 | msg->experiments_description().c_str()); |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 469 | TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) { |
| 470 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 471 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 472 | 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 Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 480 | while (const absl::optional<audioproc::Event> event = |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 481 | debug_dump_replayer_.GetNextEvent()) { |
| 482 | debug_dump_replayer_.RunNextEvent(); |
| 483 | if (event->type() == audioproc::Event::CONFIG) { |
| 484 | const audioproc::Config* msg = &event->config(); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 485 | ASSERT_TRUE(msg->has_experiments_description()); |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 486 | EXPECT_EQ(0u, msg->experiments_description().size()); |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
Kári Tristan Helgason | 470c088 | 2016-10-03 13:13:29 +0200 | [diff] [blame] | 491 | // AGC is not supported on Android or iOS. |
| 492 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 493 | #define MAYBE_ToggleAgc DISABLED_ToggleAgc |
| 494 | #else |
| 495 | #define MAYBE_ToggleAgc ToggleAgc |
| 496 | #endif |
| 497 | TEST_F(DebugDumpTest, MAYBE_ToggleAgc) { |
| 498 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 499 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 500 | generator.StartRecording(); |
| 501 | generator.Process(100); |
| 502 | |
Sam Zackrisson | 41478c7 | 2019-10-15 10:10:26 +0200 | [diff] [blame] | 503 | AudioProcessing::Config apm_config = generator.apm()->GetConfig(); |
| 504 | apm_config.gain_controller1.enabled = !apm_config.gain_controller1.enabled; |
| 505 | generator.apm()->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 506 | |
| 507 | generator.Process(100); |
| 508 | generator.StopRecording(); |
| 509 | VerifyDebugDump(generator.dump_file_name()); |
| 510 | } |
| 511 | |
| 512 | TEST_F(DebugDumpTest, ToggleNs) { |
| 513 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 514 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 515 | generator.StartRecording(); |
| 516 | generator.Process(100); |
| 517 | |
Sam Zackrisson | 2351313 | 2019-01-11 15:10:32 +0100 | [diff] [blame] | 518 | AudioProcessing::Config apm_config = generator.apm()->GetConfig(); |
| 519 | apm_config.noise_suppression.enabled = !apm_config.noise_suppression.enabled; |
| 520 | generator.apm()->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 521 | |
| 522 | generator.Process(100); |
| 523 | generator.StopRecording(); |
| 524 | VerifyDebugDump(generator.dump_file_name()); |
| 525 | } |
| 526 | |
| 527 | TEST_F(DebugDumpTest, TransientSuppressionOn) { |
| 528 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 529 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
Per Åhgren | c073471 | 2020-01-02 15:15:36 +0100 | [diff] [blame] | 530 | |
| 531 | AudioProcessing::Config apm_config = generator.apm()->GetConfig(); |
| 532 | apm_config.transient_suppression.enabled = true; |
| 533 | generator.apm()->ApplyConfig(apm_config); |
| 534 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 535 | generator.StartRecording(); |
| 536 | generator.Process(100); |
| 537 | generator.StopRecording(); |
| 538 | VerifyDebugDump(generator.dump_file_name()); |
| 539 | } |
| 540 | |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 541 | TEST_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 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 552 | } // namespace test |
| 553 | } // namespace webrtc |