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