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