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" |
| 20 | #include "modules/audio_processing/test/debug_dump_replayer.h" |
| 21 | #include "modules/audio_processing/test/test_utils.h" |
| 22 | #include "rtc_base/task_queue.h" |
| 23 | #include "test/gtest.h" |
| 24 | #include "test/testsupport/fileutils.h" |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | namespace test { |
| 28 | |
| 29 | namespace { |
| 30 | |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 31 | void MaybeResetBuffer(std::unique_ptr<ChannelBuffer<float>>* buffer, |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 32 | const StreamConfig& config) { |
| 33 | auto& buffer_ref = *buffer; |
| 34 | if (!buffer_ref.get() || buffer_ref->num_frames() != config.num_frames() || |
| 35 | buffer_ref->num_channels() != config.num_channels()) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 36 | buffer_ref.reset( |
| 37 | new ChannelBuffer<float>(config.num_frames(), config.num_channels())); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
| 41 | class DebugDumpGenerator { |
| 42 | public: |
| 43 | DebugDumpGenerator(const std::string& input_file_name, |
Alex Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 44 | int input_rate_hz, |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 45 | int input_channels, |
| 46 | const std::string& reverse_file_name, |
Alex Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 47 | int reverse_rate_hz, |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 48 | int reverse_channels, |
| 49 | const Config& config, |
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_aec3, |
| 52 | bool enable_pre_amplifier); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 53 | |
| 54 | // Constructor that uses default input files. |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 55 | explicit DebugDumpGenerator(const Config& config, |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 56 | const AudioProcessing::Config& apm_config, |
| 57 | bool enable_aec3); |
| 58 | |
| 59 | explicit DebugDumpGenerator(const Config& config, |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 60 | const AudioProcessing::Config& apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 61 | |
| 62 | ~DebugDumpGenerator(); |
| 63 | |
| 64 | // Changes the sample rate of the input audio to the APM. |
| 65 | void SetInputRate(int rate_hz); |
| 66 | |
| 67 | // Sets if converts stereo input signal to mono by discarding other channels. |
| 68 | void ForceInputMono(bool mono); |
| 69 | |
| 70 | // Changes the sample rate of the reverse audio to the APM. |
| 71 | void SetReverseRate(int rate_hz); |
| 72 | |
| 73 | // Sets if converts stereo reverse signal to mono by discarding other |
| 74 | // channels. |
| 75 | void ForceReverseMono(bool mono); |
| 76 | |
| 77 | // Sets the required sample rate of the APM output. |
| 78 | void SetOutputRate(int rate_hz); |
| 79 | |
| 80 | // Sets the required channels of the APM output. |
| 81 | void SetOutputChannels(int channels); |
| 82 | |
| 83 | std::string dump_file_name() const { return dump_file_name_; } |
| 84 | |
| 85 | void StartRecording(); |
| 86 | void Process(size_t num_blocks); |
| 87 | void StopRecording(); |
| 88 | AudioProcessing* apm() const { return apm_.get(); } |
| 89 | |
| 90 | private: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 91 | static void ReadAndDeinterleave(ResampleInputAudioFile* audio, |
| 92 | int channels, |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 93 | const StreamConfig& config, |
| 94 | float* const* buffer); |
| 95 | |
| 96 | // APM input/output settings. |
| 97 | StreamConfig input_config_; |
| 98 | StreamConfig reverse_config_; |
| 99 | StreamConfig output_config_; |
| 100 | |
| 101 | // Input file format. |
| 102 | const std::string input_file_name_; |
| 103 | ResampleInputAudioFile input_audio_; |
| 104 | const int input_file_channels_; |
| 105 | |
| 106 | // Reverse file format. |
| 107 | const std::string reverse_file_name_; |
| 108 | ResampleInputAudioFile reverse_audio_; |
| 109 | const int reverse_file_channels_; |
| 110 | |
| 111 | // Buffer for APM input/output. |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 112 | std::unique_ptr<ChannelBuffer<float>> input_; |
| 113 | std::unique_ptr<ChannelBuffer<float>> reverse_; |
| 114 | std::unique_ptr<ChannelBuffer<float>> output_; |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 115 | |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 116 | bool enable_pre_amplifier_; |
| 117 | |
aleloi | f4dd191 | 2017-06-15 01:55:38 -0700 | [diff] [blame] | 118 | rtc::TaskQueue worker_queue_; |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 119 | std::unique_ptr<AudioProcessing> apm_; |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 120 | |
| 121 | const std::string dump_file_name_; |
| 122 | }; |
| 123 | |
| 124 | DebugDumpGenerator::DebugDumpGenerator(const std::string& input_file_name, |
| 125 | int input_rate_hz, |
| 126 | int input_channels, |
| 127 | const std::string& reverse_file_name, |
| 128 | int reverse_rate_hz, |
| 129 | int reverse_channels, |
| 130 | const Config& config, |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 131 | const std::string& dump_file_name, |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 132 | bool enable_aec3, |
| 133 | bool enable_pre_amplifier) |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 134 | : input_config_(input_rate_hz, input_channels), |
| 135 | reverse_config_(reverse_rate_hz, reverse_channels), |
| 136 | output_config_(input_rate_hz, input_channels), |
| 137 | input_audio_(input_file_name, input_rate_hz, input_rate_hz), |
| 138 | input_file_channels_(input_channels), |
| 139 | reverse_audio_(reverse_file_name, reverse_rate_hz, reverse_rate_hz), |
| 140 | reverse_file_channels_(reverse_channels), |
| 141 | input_(new ChannelBuffer<float>(input_config_.num_frames(), |
| 142 | input_config_.num_channels())), |
| 143 | reverse_(new ChannelBuffer<float>(reverse_config_.num_frames(), |
| 144 | reverse_config_.num_channels())), |
| 145 | output_(new ChannelBuffer<float>(output_config_.num_frames(), |
| 146 | output_config_.num_channels())), |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 147 | enable_pre_amplifier_(enable_pre_amplifier), |
aleloi | f4dd191 | 2017-06-15 01:55:38 -0700 | [diff] [blame] | 148 | worker_queue_("debug_dump_generator_worker_queue"), |
Ivo Creusen | 62337e5 | 2018-01-09 14:17:33 +0100 | [diff] [blame] | 149 | dump_file_name_(dump_file_name) { |
| 150 | AudioProcessingBuilder apm_builder; |
| 151 | if (enable_aec3) { |
| 152 | apm_builder.SetEchoControlFactory( |
| 153 | std::unique_ptr<EchoControlFactory>(new EchoCanceller3Factory())); |
| 154 | } |
| 155 | apm_.reset(apm_builder.Create(config)); |
| 156 | } |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 157 | |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 158 | DebugDumpGenerator::DebugDumpGenerator( |
| 159 | const Config& config, |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 160 | const AudioProcessing::Config& apm_config, |
| 161 | bool enable_aec3) |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 162 | : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"), |
| 163 | 32000, |
| 164 | 2, |
| 165 | ResourcePath("far32_stereo", "pcm"), |
| 166 | 32000, |
| 167 | 2, |
| 168 | config, |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 169 | TempFilename(OutputPath(), "debug_aec"), |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 170 | enable_aec3, |
| 171 | apm_config.pre_amplifier.enabled) { |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 172 | apm_->ApplyConfig(apm_config); |
| 173 | } |
| 174 | |
| 175 | DebugDumpGenerator::DebugDumpGenerator( |
| 176 | const Config& config, |
| 177 | const AudioProcessing::Config& apm_config) |
| 178 | : DebugDumpGenerator(config, apm_config, false) { |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 179 | apm_->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | DebugDumpGenerator::~DebugDumpGenerator() { |
| 183 | remove(dump_file_name_.c_str()); |
| 184 | } |
| 185 | |
| 186 | void DebugDumpGenerator::SetInputRate(int rate_hz) { |
| 187 | input_audio_.set_output_rate_hz(rate_hz); |
| 188 | input_config_.set_sample_rate_hz(rate_hz); |
| 189 | MaybeResetBuffer(&input_, input_config_); |
| 190 | } |
| 191 | |
| 192 | void DebugDumpGenerator::ForceInputMono(bool mono) { |
| 193 | const int channels = mono ? 1 : input_file_channels_; |
| 194 | input_config_.set_num_channels(channels); |
| 195 | MaybeResetBuffer(&input_, input_config_); |
| 196 | } |
| 197 | |
| 198 | void DebugDumpGenerator::SetReverseRate(int rate_hz) { |
| 199 | reverse_audio_.set_output_rate_hz(rate_hz); |
| 200 | reverse_config_.set_sample_rate_hz(rate_hz); |
| 201 | MaybeResetBuffer(&reverse_, reverse_config_); |
| 202 | } |
| 203 | |
| 204 | void DebugDumpGenerator::ForceReverseMono(bool mono) { |
| 205 | const int channels = mono ? 1 : reverse_file_channels_; |
| 206 | reverse_config_.set_num_channels(channels); |
| 207 | MaybeResetBuffer(&reverse_, reverse_config_); |
| 208 | } |
| 209 | |
| 210 | void DebugDumpGenerator::SetOutputRate(int rate_hz) { |
| 211 | output_config_.set_sample_rate_hz(rate_hz); |
| 212 | MaybeResetBuffer(&output_, output_config_); |
| 213 | } |
| 214 | |
| 215 | void DebugDumpGenerator::SetOutputChannels(int channels) { |
| 216 | output_config_.set_num_channels(channels); |
| 217 | MaybeResetBuffer(&output_, output_config_); |
| 218 | } |
| 219 | |
| 220 | void DebugDumpGenerator::StartRecording() { |
aleloi | f4dd191 | 2017-06-15 01:55:38 -0700 | [diff] [blame] | 221 | apm_->AttachAecDump( |
| 222 | AecDumpFactory::Create(dump_file_name_.c_str(), -1, &worker_queue_)); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | void DebugDumpGenerator::Process(size_t num_blocks) { |
| 226 | for (size_t i = 0; i < num_blocks; ++i) { |
| 227 | ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_, |
| 228 | reverse_config_, reverse_->channels()); |
| 229 | ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_, |
| 230 | input_->channels()); |
| 231 | RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100)); |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 232 | if (enable_pre_amplifier_) { |
| 233 | apm_->SetRuntimeSetting( |
| 234 | AudioProcessing::RuntimeSetting::CreateCapturePreGain(1 + i % 10)); |
| 235 | } |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 236 | apm_->set_stream_key_pressed(i % 10 == 9); |
| 237 | RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 238 | apm_->ProcessStream(input_->channels(), input_config_, |
| 239 | output_config_, output_->channels())); |
| 240 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 241 | RTC_CHECK_EQ( |
| 242 | AudioProcessing::kNoError, |
| 243 | apm_->ProcessReverseStream(reverse_->channels(), reverse_config_, |
| 244 | reverse_config_, reverse_->channels())); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
| 248 | void DebugDumpGenerator::StopRecording() { |
aleloi | f4dd191 | 2017-06-15 01:55:38 -0700 | [diff] [blame] | 249 | apm_->DetachAecDump(); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio, |
| 253 | int channels, |
| 254 | const StreamConfig& config, |
| 255 | float* const* buffer) { |
| 256 | const size_t num_frames = config.num_frames(); |
| 257 | const int out_channels = config.num_channels(); |
| 258 | |
| 259 | std::vector<int16_t> signal(channels * num_frames); |
| 260 | |
| 261 | audio->Read(num_frames * channels, &signal[0]); |
| 262 | |
| 263 | // We only allow reducing number of channels by discarding some channels. |
| 264 | RTC_CHECK_LE(out_channels, channels); |
| 265 | for (int channel = 0; channel < out_channels; ++channel) { |
| 266 | for (size_t i = 0; i < num_frames; ++i) { |
| 267 | buffer[channel][i] = S16ToFloat(signal[i * channels + channel]); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | } // namespace |
| 273 | |
| 274 | class DebugDumpTest : public ::testing::Test { |
| 275 | public: |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 276 | // VerifyDebugDump replays a debug dump using APM and verifies that the result |
| 277 | // is bit-exact-identical to the output channel in the dump. This is only |
| 278 | // guaranteed if the debug dump is started on the first frame. |
Alex Loiko | 890988c | 2017-08-31 10:25:48 +0200 | [diff] [blame] | 279 | void VerifyDebugDump(const std::string& in_filename); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 280 | |
| 281 | private: |
minyue | 0de1c13 | 2016-03-17 02:39:30 -0700 | [diff] [blame] | 282 | DebugDumpReplayer debug_dump_replayer_; |
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 | void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) { |
minyue | 0de1c13 | 2016-03-17 02:39:30 -0700 | [diff] [blame] | 286 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(in_filename)); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 287 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 288 | while (const absl::optional<audioproc::Event> event = |
| 289 | debug_dump_replayer_.GetNextEvent()) { |
minyue | 0de1c13 | 2016-03-17 02:39:30 -0700 | [diff] [blame] | 290 | debug_dump_replayer_.RunNextEvent(); |
| 291 | if (event->type() == audioproc::Event::STREAM) { |
| 292 | const audioproc::Stream* msg = &event->stream(); |
| 293 | const StreamConfig output_config = debug_dump_replayer_.GetOutputConfig(); |
| 294 | const ChannelBuffer<float>* output = debug_dump_replayer_.GetOutput(); |
| 295 | // Check that output of APM is bit-exact to the output in the dump. |
| 296 | ASSERT_EQ(output_config.num_channels(), |
| 297 | static_cast<size_t>(msg->output_channel_size())); |
| 298 | ASSERT_EQ(output_config.num_frames() * sizeof(float), |
| 299 | msg->output_channel(0).size()); |
| 300 | for (int i = 0; i < msg->output_channel_size(); ++i) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 301 | ASSERT_EQ(0, |
| 302 | memcmp(output->channels()[i], msg->output_channel(i).data(), |
| 303 | msg->output_channel(i).size())); |
minyue | 0de1c13 | 2016-03-17 02:39:30 -0700 | [diff] [blame] | 304 | } |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 305 | } |
| 306 | } |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | TEST_F(DebugDumpTest, SimpleCase) { |
| 310 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 311 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 312 | generator.StartRecording(); |
| 313 | generator.Process(100); |
| 314 | generator.StopRecording(); |
| 315 | VerifyDebugDump(generator.dump_file_name()); |
| 316 | } |
| 317 | |
| 318 | TEST_F(DebugDumpTest, ChangeInputFormat) { |
| 319 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 320 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
| 321 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 322 | generator.StartRecording(); |
| 323 | generator.Process(100); |
| 324 | generator.SetInputRate(48000); |
| 325 | |
| 326 | generator.ForceInputMono(true); |
| 327 | // Number of output channel should not be larger than that of input. APM will |
| 328 | // fail otherwise. |
| 329 | generator.SetOutputChannels(1); |
| 330 | |
| 331 | generator.Process(100); |
| 332 | generator.StopRecording(); |
| 333 | VerifyDebugDump(generator.dump_file_name()); |
| 334 | } |
| 335 | |
| 336 | TEST_F(DebugDumpTest, ChangeReverseFormat) { |
| 337 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 338 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 339 | generator.StartRecording(); |
| 340 | generator.Process(100); |
| 341 | generator.SetReverseRate(48000); |
| 342 | generator.ForceReverseMono(true); |
| 343 | generator.Process(100); |
| 344 | generator.StopRecording(); |
| 345 | VerifyDebugDump(generator.dump_file_name()); |
| 346 | } |
| 347 | |
| 348 | TEST_F(DebugDumpTest, ChangeOutputFormat) { |
| 349 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 350 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 351 | generator.StartRecording(); |
| 352 | generator.Process(100); |
| 353 | generator.SetOutputRate(48000); |
| 354 | generator.SetOutputChannels(1); |
| 355 | generator.Process(100); |
| 356 | generator.StopRecording(); |
| 357 | VerifyDebugDump(generator.dump_file_name()); |
| 358 | } |
| 359 | |
| 360 | TEST_F(DebugDumpTest, ToggleAec) { |
| 361 | Config config; |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 362 | AudioProcessing::Config apm_config; |
| 363 | DebugDumpGenerator generator(config, apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 364 | generator.StartRecording(); |
| 365 | generator.Process(100); |
| 366 | |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 367 | apm_config.echo_canceller.enabled = true; |
| 368 | generator.apm()->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 369 | |
| 370 | generator.Process(100); |
| 371 | generator.StopRecording(); |
| 372 | VerifyDebugDump(generator.dump_file_name()); |
| 373 | } |
| 374 | |
| 375 | TEST_F(DebugDumpTest, ToggleDelayAgnosticAec) { |
| 376 | Config config; |
| 377 | config.Set<DelayAgnostic>(new DelayAgnostic(true)); |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 378 | AudioProcessing::Config apm_config; |
| 379 | DebugDumpGenerator generator(config, apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 380 | generator.StartRecording(); |
| 381 | generator.Process(100); |
| 382 | |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 383 | apm_config.echo_canceller.enabled = true; |
| 384 | generator.apm()->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 385 | |
| 386 | generator.Process(100); |
| 387 | generator.StopRecording(); |
| 388 | VerifyDebugDump(generator.dump_file_name()); |
| 389 | } |
| 390 | |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 391 | TEST_F(DebugDumpTest, VerifyRefinedAdaptiveFilterExperimentalString) { |
| 392 | Config config; |
| 393 | config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true)); |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 394 | DebugDumpGenerator generator(config, AudioProcessing::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()); |
| 409 | EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter", |
| 410 | msg->experiments_description().c_str()); |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringInclusive) { |
| 416 | Config config; |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 417 | AudioProcessing::Config apm_config; |
Sam Zackrisson | b3b47ad | 2018-08-17 16:26:14 +0200 | [diff] [blame] | 418 | apm_config.echo_canceller.enabled = true; |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 419 | config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true)); |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 420 | // Arbitrarily set clipping gain to 17, which will never be the default. |
| 421 | config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17)); |
Gustaf Ullberg | bd83b91 | 2017-10-18 12:32:42 +0200 | [diff] [blame] | 422 | bool enable_aec3 = true; |
| 423 | DebugDumpGenerator generator(config, apm_config, enable_aec3); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 424 | generator.StartRecording(); |
| 425 | generator.Process(100); |
| 426 | generator.StopRecording(); |
| 427 | |
| 428 | DebugDumpReplayer debug_dump_replayer_; |
| 429 | |
| 430 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name())); |
| 431 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 432 | while (const absl::optional<audioproc::Event> event = |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 433 | debug_dump_replayer_.GetNextEvent()) { |
| 434 | debug_dump_replayer_.RunNextEvent(); |
| 435 | if (event->type() == audioproc::Event::CONFIG) { |
| 436 | const audioproc::Config* msg = &event->config(); |
| 437 | ASSERT_TRUE(msg->has_experiments_description()); |
| 438 | EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter", |
| 439 | msg->experiments_description().c_str()); |
Gustaf Ullberg | ce045ac | 2017-10-16 13:49:04 +0200 | [diff] [blame] | 440 | EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoController", |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 441 | msg->experiments_description().c_str()); |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 442 | EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment", |
| 443 | msg->experiments_description().c_str()); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | TEST_F(DebugDumpTest, VerifyCombinedExperimentalStringExclusive) { |
| 449 | Config config; |
| 450 | config.Set<RefinedAdaptiveFilter>(new RefinedAdaptiveFilter(true)); |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 451 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 452 | generator.StartRecording(); |
| 453 | generator.Process(100); |
| 454 | generator.StopRecording(); |
| 455 | |
| 456 | DebugDumpReplayer debug_dump_replayer_; |
| 457 | |
| 458 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name())); |
| 459 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 460 | while (const absl::optional<audioproc::Event> event = |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 461 | debug_dump_replayer_.GetNextEvent()) { |
| 462 | debug_dump_replayer_.RunNextEvent(); |
| 463 | if (event->type() == audioproc::Event::CONFIG) { |
| 464 | const audioproc::Config* msg = &event->config(); |
| 465 | ASSERT_TRUE(msg->has_experiments_description()); |
| 466 | EXPECT_PRED_FORMAT2(testing::IsSubstring, "RefinedAdaptiveFilter", |
| 467 | msg->experiments_description().c_str()); |
| 468 | EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AEC3", |
| 469 | msg->experiments_description().c_str()); |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 470 | EXPECT_PRED_FORMAT2(testing::IsNotSubstring, "AgcClippingLevelExperiment", |
| 471 | msg->experiments_description().c_str()); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | } |
| 475 | |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 476 | TEST_F(DebugDumpTest, VerifyAec3ExperimentalString) { |
| 477 | Config config; |
peah | e0eae3c | 2016-12-14 01:16:23 -0800 | [diff] [blame] | 478 | AudioProcessing::Config apm_config; |
Sam Zackrisson | b3b47ad | 2018-08-17 16:26:14 +0200 | [diff] [blame] | 479 | apm_config.echo_canceller.enabled = true; |
Sam Zackrisson | 2a959d9 | 2018-07-23 14:48:07 +0000 | [diff] [blame] | 480 | DebugDumpGenerator generator(config, apm_config, true); |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 481 | generator.StartRecording(); |
| 482 | generator.Process(100); |
| 483 | generator.StopRecording(); |
| 484 | |
| 485 | DebugDumpReplayer debug_dump_replayer_; |
| 486 | |
| 487 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name())); |
| 488 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 489 | while (const absl::optional<audioproc::Event> event = |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 490 | debug_dump_replayer_.GetNextEvent()) { |
| 491 | debug_dump_replayer_.RunNextEvent(); |
| 492 | if (event->type() == audioproc::Event::CONFIG) { |
| 493 | const audioproc::Config* msg = &event->config(); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 494 | ASSERT_TRUE(msg->has_experiments_description()); |
Gustaf Ullberg | ce045ac | 2017-10-16 13:49:04 +0200 | [diff] [blame] | 495 | EXPECT_PRED_FORMAT2(testing::IsSubstring, "EchoController", |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 496 | msg->experiments_description().c_str()); |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | } |
| 500 | |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 501 | TEST_F(DebugDumpTest, VerifyAgcClippingLevelExperimentalString) { |
| 502 | Config config; |
| 503 | // Arbitrarily set clipping gain to 17, which will never be the default. |
| 504 | config.Set<ExperimentalAgc>(new ExperimentalAgc(true, 0, 17)); |
| 505 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
| 506 | generator.StartRecording(); |
| 507 | generator.Process(100); |
| 508 | generator.StopRecording(); |
| 509 | |
| 510 | DebugDumpReplayer debug_dump_replayer_; |
| 511 | |
| 512 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name())); |
| 513 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 514 | while (const absl::optional<audioproc::Event> event = |
henrik.lundin | bd681b9 | 2016-12-05 09:08:42 -0800 | [diff] [blame] | 515 | debug_dump_replayer_.GetNextEvent()) { |
| 516 | debug_dump_replayer_.RunNextEvent(); |
| 517 | if (event->type() == audioproc::Event::CONFIG) { |
| 518 | const audioproc::Config* msg = &event->config(); |
| 519 | ASSERT_TRUE(msg->has_experiments_description()); |
| 520 | EXPECT_PRED_FORMAT2(testing::IsSubstring, "AgcClippingLevelExperiment", |
| 521 | msg->experiments_description().c_str()); |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 526 | TEST_F(DebugDumpTest, VerifyEmptyExperimentalString) { |
| 527 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 528 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 529 | generator.StartRecording(); |
| 530 | generator.Process(100); |
| 531 | generator.StopRecording(); |
| 532 | |
| 533 | DebugDumpReplayer debug_dump_replayer_; |
| 534 | |
| 535 | ASSERT_TRUE(debug_dump_replayer_.SetDumpFile(generator.dump_file_name())); |
| 536 | |
Danil Chapovalov | db9f7ab | 2018-06-19 10:50:11 +0200 | [diff] [blame] | 537 | while (const absl::optional<audioproc::Event> event = |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 538 | debug_dump_replayer_.GetNextEvent()) { |
| 539 | debug_dump_replayer_.RunNextEvent(); |
| 540 | if (event->type() == audioproc::Event::CONFIG) { |
| 541 | const audioproc::Config* msg = &event->config(); |
peah | 0332c2d | 2016-04-15 11:23:33 -0700 | [diff] [blame] | 542 | ASSERT_TRUE(msg->has_experiments_description()); |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 543 | EXPECT_EQ(0u, msg->experiments_description().size()); |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 548 | TEST_F(DebugDumpTest, ToggleAecLevel) { |
| 549 | Config config; |
Sam Zackrisson | b3b47ad | 2018-08-17 16:26:14 +0200 | [diff] [blame] | 550 | AudioProcessing::Config apm_config; |
| 551 | apm_config.echo_canceller.enabled = true; |
| 552 | apm_config.echo_canceller.mobile_mode = false; |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 553 | apm_config.echo_canceller.legacy_moderate_suppression_level = true; |
Sam Zackrisson | b3b47ad | 2018-08-17 16:26:14 +0200 | [diff] [blame] | 554 | DebugDumpGenerator generator(config, apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 555 | generator.StartRecording(); |
| 556 | generator.Process(100); |
| 557 | |
Sam Zackrisson | cdf0e6d | 2018-09-17 11:05:17 +0200 | [diff] [blame] | 558 | apm_config.echo_canceller.legacy_moderate_suppression_level = false; |
| 559 | generator.apm()->ApplyConfig(apm_config); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 560 | generator.Process(100); |
| 561 | generator.StopRecording(); |
| 562 | VerifyDebugDump(generator.dump_file_name()); |
| 563 | } |
| 564 | |
Kári Tristan Helgason | 470c088 | 2016-10-03 13:13:29 +0200 | [diff] [blame] | 565 | // AGC is not supported on Android or iOS. |
| 566 | #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 567 | #define MAYBE_ToggleAgc DISABLED_ToggleAgc |
| 568 | #else |
| 569 | #define MAYBE_ToggleAgc ToggleAgc |
| 570 | #endif |
| 571 | TEST_F(DebugDumpTest, MAYBE_ToggleAgc) { |
| 572 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 573 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 574 | generator.StartRecording(); |
| 575 | generator.Process(100); |
| 576 | |
| 577 | GainControl* agc = generator.apm()->gain_control(); |
| 578 | EXPECT_EQ(AudioProcessing::kNoError, agc->Enable(!agc->is_enabled())); |
| 579 | |
| 580 | generator.Process(100); |
| 581 | generator.StopRecording(); |
| 582 | VerifyDebugDump(generator.dump_file_name()); |
| 583 | } |
| 584 | |
| 585 | TEST_F(DebugDumpTest, ToggleNs) { |
| 586 | Config config; |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 587 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 588 | generator.StartRecording(); |
| 589 | generator.Process(100); |
| 590 | |
| 591 | NoiseSuppression* ns = generator.apm()->noise_suppression(); |
| 592 | EXPECT_EQ(AudioProcessing::kNoError, ns->Enable(!ns->is_enabled())); |
| 593 | |
| 594 | generator.Process(100); |
| 595 | generator.StopRecording(); |
| 596 | VerifyDebugDump(generator.dump_file_name()); |
| 597 | } |
| 598 | |
| 599 | TEST_F(DebugDumpTest, TransientSuppressionOn) { |
| 600 | Config config; |
| 601 | config.Set<ExperimentalNs>(new ExperimentalNs(true)); |
peah | 88ac853 | 2016-09-12 16:47:25 -0700 | [diff] [blame] | 602 | DebugDumpGenerator generator(config, AudioProcessing::Config()); |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 603 | generator.StartRecording(); |
| 604 | generator.Process(100); |
| 605 | generator.StopRecording(); |
| 606 | VerifyDebugDump(generator.dump_file_name()); |
| 607 | } |
| 608 | |
Alex Loiko | 6234722 | 2018-09-10 10:18:07 +0200 | [diff] [blame] | 609 | TEST_F(DebugDumpTest, PreAmplifierIsOn) { |
| 610 | Config config; |
| 611 | AudioProcessing::Config apm_config; |
| 612 | apm_config.pre_amplifier.enabled = true; |
| 613 | DebugDumpGenerator generator(config, apm_config); |
| 614 | generator.StartRecording(); |
| 615 | generator.Process(100); |
| 616 | generator.StopRecording(); |
| 617 | VerifyDebugDump(generator.dump_file_name()); |
| 618 | } |
| 619 | |
minyue | 275d255 | 2015-11-04 06:23:54 -0800 | [diff] [blame] | 620 | } // namespace test |
| 621 | } // namespace webrtc |