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