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