OLD | NEW |
(Empty) | |
| 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 |
| 12 #include <string> |
| 13 #include <vector> |
| 14 |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "webrtc/audio_processing/debug.pb.h" |
| 17 #include "webrtc/base/checks.h" |
| 18 #include "webrtc/base/scoped_ptr.h" |
| 19 #include "webrtc/common_audio/channel_buffer.h" |
| 20 #include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h" |
| 21 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 22 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" |
| 23 #include "webrtc/modules/audio_processing/test/test_utils.h" |
| 24 #include "webrtc/test/testsupport/fileutils.h" |
| 25 |
| 26 namespace webrtc { |
| 27 namespace test { |
| 28 |
| 29 namespace { |
| 30 |
| 31 void MaybeResetBuffer(rtc::scoped_ptr<ChannelBuffer<float>>* buffer, |
| 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()) { |
| 36 buffer_ref.reset(new ChannelBuffer<float>(config.num_frames(), |
| 37 config.num_channels())); |
| 38 } |
| 39 } |
| 40 |
| 41 class DebugDumpGenerator { |
| 42 public: |
| 43 DebugDumpGenerator(const std::string& input_file_name, |
| 44 int input_file_rate_hz, |
| 45 int input_channels, |
| 46 const std::string& reverse_file_name, |
| 47 int reverse_file_rate_hz, |
| 48 int reverse_channels, |
| 49 const Config& config, |
| 50 const std::string& dump_file_name); |
| 51 |
| 52 // Constructor that uses default input files. |
| 53 explicit DebugDumpGenerator(const Config& config); |
| 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. |
| 104 rtc::scoped_ptr<ChannelBuffer<float>> input_; |
| 105 rtc::scoped_ptr<ChannelBuffer<float>> reverse_; |
| 106 rtc::scoped_ptr<ChannelBuffer<float>> output_; |
| 107 |
| 108 rtc::scoped_ptr<AudioProcessing> apm_; |
| 109 |
| 110 const std::string dump_file_name_; |
| 111 }; |
| 112 |
| 113 DebugDumpGenerator::DebugDumpGenerator(const std::string& input_file_name, |
| 114 int input_rate_hz, |
| 115 int input_channels, |
| 116 const std::string& reverse_file_name, |
| 117 int reverse_rate_hz, |
| 118 int reverse_channels, |
| 119 const Config& config, |
| 120 const std::string& dump_file_name) |
| 121 : input_config_(input_rate_hz, input_channels), |
| 122 reverse_config_(reverse_rate_hz, reverse_channels), |
| 123 output_config_(input_rate_hz, input_channels), |
| 124 input_audio_(input_file_name, input_rate_hz, input_rate_hz), |
| 125 input_file_channels_(input_channels), |
| 126 reverse_audio_(reverse_file_name, reverse_rate_hz, reverse_rate_hz), |
| 127 reverse_file_channels_(reverse_channels), |
| 128 input_(new ChannelBuffer<float>(input_config_.num_frames(), |
| 129 input_config_.num_channels())), |
| 130 reverse_(new ChannelBuffer<float>(reverse_config_.num_frames(), |
| 131 reverse_config_.num_channels())), |
| 132 output_(new ChannelBuffer<float>(output_config_.num_frames(), |
| 133 output_config_.num_channels())), |
| 134 apm_(AudioProcessing::Create(config)), |
| 135 dump_file_name_(dump_file_name) { |
| 136 } |
| 137 |
| 138 DebugDumpGenerator::DebugDumpGenerator(const Config& config) |
| 139 : DebugDumpGenerator(ResourcePath("near32_stereo", "pcm"), 32000, 2, |
| 140 ResourcePath("far32_stereo", "pcm"), 32000, 2, |
| 141 config, |
| 142 TempFilename(OutputPath(), "debug_aec")) { |
| 143 } |
| 144 |
| 145 DebugDumpGenerator::~DebugDumpGenerator() { |
| 146 remove(dump_file_name_.c_str()); |
| 147 } |
| 148 |
| 149 void DebugDumpGenerator::SetInputRate(int rate_hz) { |
| 150 input_audio_.set_output_rate_hz(rate_hz); |
| 151 input_config_.set_sample_rate_hz(rate_hz); |
| 152 MaybeResetBuffer(&input_, input_config_); |
| 153 } |
| 154 |
| 155 void DebugDumpGenerator::ForceInputMono(bool mono) { |
| 156 const int channels = mono ? 1 : input_file_channels_; |
| 157 input_config_.set_num_channels(channels); |
| 158 MaybeResetBuffer(&input_, input_config_); |
| 159 } |
| 160 |
| 161 void DebugDumpGenerator::SetReverseRate(int rate_hz) { |
| 162 reverse_audio_.set_output_rate_hz(rate_hz); |
| 163 reverse_config_.set_sample_rate_hz(rate_hz); |
| 164 MaybeResetBuffer(&reverse_, reverse_config_); |
| 165 } |
| 166 |
| 167 void DebugDumpGenerator::ForceReverseMono(bool mono) { |
| 168 const int channels = mono ? 1 : reverse_file_channels_; |
| 169 reverse_config_.set_num_channels(channels); |
| 170 MaybeResetBuffer(&reverse_, reverse_config_); |
| 171 } |
| 172 |
| 173 void DebugDumpGenerator::SetOutputRate(int rate_hz) { |
| 174 output_config_.set_sample_rate_hz(rate_hz); |
| 175 MaybeResetBuffer(&output_, output_config_); |
| 176 } |
| 177 |
| 178 void DebugDumpGenerator::SetOutputChannels(int channels) { |
| 179 output_config_.set_num_channels(channels); |
| 180 MaybeResetBuffer(&output_, output_config_); |
| 181 } |
| 182 |
| 183 void DebugDumpGenerator::StartRecording() { |
| 184 apm_->StartDebugRecording(dump_file_name_.c_str()); |
| 185 } |
| 186 |
| 187 void DebugDumpGenerator::Process(size_t num_blocks) { |
| 188 for (size_t i = 0; i < num_blocks; ++i) { |
| 189 ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_, |
| 190 reverse_config_, reverse_->channels()); |
| 191 ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_, |
| 192 input_->channels()); |
| 193 RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100)); |
| 194 apm_->set_stream_key_pressed(i % 10 == 9); |
| 195 RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 196 apm_->ProcessStream(input_->channels(), input_config_, |
| 197 output_config_, output_->channels())); |
| 198 |
| 199 RTC_CHECK_EQ(AudioProcessing::kNoError, |
| 200 apm_->ProcessReverseStream(reverse_->channels(), |
| 201 reverse_config_, |
| 202 reverse_config_, |
| 203 reverse_->channels())); |
| 204 } |
| 205 } |
| 206 |
| 207 void DebugDumpGenerator::StopRecording() { |
| 208 apm_->StopDebugRecording(); |
| 209 } |
| 210 |
| 211 void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio, |
| 212 int channels, |
| 213 const StreamConfig& config, |
| 214 float* const* buffer) { |
| 215 const size_t num_frames = config.num_frames(); |
| 216 const int out_channels = config.num_channels(); |
| 217 |
| 218 std::vector<int16_t> signal(channels * num_frames); |
| 219 |
| 220 audio->Read(num_frames * channels, &signal[0]); |
| 221 |
| 222 // We only allow reducing number of channels by discarding some channels. |
| 223 RTC_CHECK_LE(out_channels, channels); |
| 224 for (int channel = 0; channel < out_channels; ++channel) { |
| 225 for (size_t i = 0; i < num_frames; ++i) { |
| 226 buffer[channel][i] = S16ToFloat(signal[i * channels + channel]); |
| 227 } |
| 228 } |
| 229 } |
| 230 |
| 231 } // namespace |
| 232 |
| 233 class DebugDumpTest : public ::testing::Test { |
| 234 public: |
| 235 DebugDumpTest(); |
| 236 |
| 237 // VerifyDebugDump replays a debug dump using APM and verifies that the result |
| 238 // is bit-exact-identical to the output channel in the dump. This is only |
| 239 // guaranteed if the debug dump is started on the first frame. |
| 240 void VerifyDebugDump(const std::string& dump_file_name); |
| 241 |
| 242 private: |
| 243 // Following functions are facilities for replaying debug dumps. |
| 244 void OnInitEvent(const audioproc::Init& msg); |
| 245 void OnStreamEvent(const audioproc::Stream& msg); |
| 246 void OnReverseStreamEvent(const audioproc::ReverseStream& msg); |
| 247 void OnConfigEvent(const audioproc::Config& msg); |
| 248 |
| 249 void MaybeRecreateApm(const audioproc::Config& msg); |
| 250 void ConfigureApm(const audioproc::Config& msg); |
| 251 |
| 252 // Buffer for APM input/output. |
| 253 rtc::scoped_ptr<ChannelBuffer<float>> input_; |
| 254 rtc::scoped_ptr<ChannelBuffer<float>> reverse_; |
| 255 rtc::scoped_ptr<ChannelBuffer<float>> output_; |
| 256 |
| 257 rtc::scoped_ptr<AudioProcessing> apm_; |
| 258 |
| 259 StreamConfig input_config_; |
| 260 StreamConfig reverse_config_; |
| 261 StreamConfig output_config_; |
| 262 }; |
| 263 |
| 264 DebugDumpTest::DebugDumpTest() |
| 265 : input_(nullptr), // will be created upon usage. |
| 266 reverse_(nullptr), |
| 267 output_(nullptr), |
| 268 apm_(nullptr) { |
| 269 } |
| 270 |
| 271 void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) { |
| 272 FILE* in_file = fopen(in_filename.c_str(), "rb"); |
| 273 ASSERT_TRUE(in_file); |
| 274 audioproc::Event event_msg; |
| 275 |
| 276 while (ReadMessageFromFile(in_file, &event_msg)) { |
| 277 switch (event_msg.type()) { |
| 278 case audioproc::Event::INIT: |
| 279 OnInitEvent(event_msg.init()); |
| 280 break; |
| 281 case audioproc::Event::STREAM: |
| 282 OnStreamEvent(event_msg.stream()); |
| 283 break; |
| 284 case audioproc::Event::REVERSE_STREAM: |
| 285 OnReverseStreamEvent(event_msg.reverse_stream()); |
| 286 break; |
| 287 case audioproc::Event::CONFIG: |
| 288 OnConfigEvent(event_msg.config()); |
| 289 break; |
| 290 case audioproc::Event::UNKNOWN_EVENT: |
| 291 // We do not expect receive UNKNOWN event currently. |
| 292 FAIL(); |
| 293 } |
| 294 } |
| 295 fclose(in_file); |
| 296 } |
| 297 |
| 298 // OnInitEvent reset the input/output/reserve channel format. |
| 299 void DebugDumpTest::OnInitEvent(const audioproc::Init& msg) { |
| 300 ASSERT_TRUE(msg.has_num_input_channels()); |
| 301 ASSERT_TRUE(msg.has_output_sample_rate()); |
| 302 ASSERT_TRUE(msg.has_num_output_channels()); |
| 303 ASSERT_TRUE(msg.has_reverse_sample_rate()); |
| 304 ASSERT_TRUE(msg.has_num_reverse_channels()); |
| 305 |
| 306 input_config_ = StreamConfig(msg.sample_rate(), msg.num_input_channels()); |
| 307 output_config_ = |
| 308 StreamConfig(msg.output_sample_rate(), msg.num_output_channels()); |
| 309 reverse_config_ = |
| 310 StreamConfig(msg.reverse_sample_rate(), msg.num_reverse_channels()); |
| 311 |
| 312 MaybeResetBuffer(&input_, input_config_); |
| 313 MaybeResetBuffer(&output_, output_config_); |
| 314 MaybeResetBuffer(&reverse_, reverse_config_); |
| 315 } |
| 316 |
| 317 // OnStreamEvent replays an input signal and verifies the output. |
| 318 void DebugDumpTest::OnStreamEvent(const audioproc::Stream& msg) { |
| 319 // APM should have been created. |
| 320 ASSERT_TRUE(apm_.get()); |
| 321 |
| 322 EXPECT_NOERR(apm_->gain_control()->set_stream_analog_level(msg.level())); |
| 323 EXPECT_NOERR(apm_->set_stream_delay_ms(msg.delay())); |
| 324 apm_->echo_cancellation()->set_stream_drift_samples(msg.drift()); |
| 325 if (msg.has_keypress()) |
| 326 apm_->set_stream_key_pressed(msg.keypress()); |
| 327 else |
| 328 apm_->set_stream_key_pressed(true); |
| 329 |
| 330 ASSERT_EQ(input_config_.num_channels(), msg.input_channel_size()); |
| 331 ASSERT_EQ(input_config_.num_frames() * sizeof(float), |
| 332 msg.input_channel(0).size()); |
| 333 |
| 334 for (int i = 0; i < msg.input_channel_size(); ++i) { |
| 335 memcpy(input_->channels()[i], msg.input_channel(i).data(), |
| 336 msg.input_channel(i).size()); |
| 337 } |
| 338 |
| 339 ASSERT_EQ(AudioProcessing::kNoError, |
| 340 apm_->ProcessStream(input_->channels(), input_config_, |
| 341 output_config_, output_->channels())); |
| 342 |
| 343 // Check that output of APM is bit-exact to the output in the dump. |
| 344 ASSERT_EQ(output_config_.num_channels(), msg.output_channel_size()); |
| 345 ASSERT_EQ(output_config_.num_frames() * sizeof(float), |
| 346 msg.output_channel(0).size()); |
| 347 for (int i = 0; i < msg.output_channel_size(); ++i) { |
| 348 ASSERT_EQ(0, memcmp(output_->channels()[i], msg.output_channel(i).data(), |
| 349 msg.output_channel(i).size())); |
| 350 } |
| 351 } |
| 352 |
| 353 void DebugDumpTest::OnReverseStreamEvent(const audioproc::ReverseStream& msg) { |
| 354 // APM should have been created. |
| 355 ASSERT_TRUE(apm_.get()); |
| 356 |
| 357 ASSERT_GT(msg.channel_size(), 0); |
| 358 ASSERT_EQ(reverse_config_.num_channels(), msg.channel_size()); |
| 359 ASSERT_EQ(reverse_config_.num_frames() * sizeof(float), |
| 360 msg.channel(0).size()); |
| 361 |
| 362 for (int i = 0; i < msg.channel_size(); ++i) { |
| 363 memcpy(reverse_->channels()[i], msg.channel(i).data(), |
| 364 msg.channel(i).size()); |
| 365 } |
| 366 |
| 367 ASSERT_EQ(AudioProcessing::kNoError, |
| 368 apm_->ProcessReverseStream(reverse_->channels(), |
| 369 reverse_config_, |
| 370 reverse_config_, |
| 371 reverse_->channels())); |
| 372 } |
| 373 |
| 374 void DebugDumpTest::OnConfigEvent(const audioproc::Config& msg) { |
| 375 MaybeRecreateApm(msg); |
| 376 ConfigureApm(msg); |
| 377 } |
| 378 |
| 379 void DebugDumpTest::MaybeRecreateApm(const audioproc::Config& msg) { |
| 380 // These configurations cannot be changed on the fly. |
| 381 Config config; |
| 382 ASSERT_TRUE(msg.has_aec_delay_agnostic_enabled()); |
| 383 config.Set<DelayAgnostic>( |
| 384 new DelayAgnostic(msg.aec_delay_agnostic_enabled())); |
| 385 |
| 386 ASSERT_TRUE(msg.has_noise_robust_agc_enabled()); |
| 387 config.Set<ExperimentalAgc>( |
| 388 new ExperimentalAgc(msg.noise_robust_agc_enabled())); |
| 389 |
| 390 ASSERT_TRUE(msg.has_transient_suppression_enabled()); |
| 391 config.Set<ExperimentalNs>( |
| 392 new ExperimentalNs(msg.transient_suppression_enabled())); |
| 393 |
| 394 ASSERT_TRUE(msg.has_aec_extended_filter_enabled()); |
| 395 config.Set<ExtendedFilter>(new ExtendedFilter( |
| 396 msg.aec_extended_filter_enabled())); |
| 397 |
| 398 // We only create APM once, since changes on these fields should not |
| 399 // happen in current implementation. |
| 400 if (!apm_.get()) { |
| 401 apm_.reset(AudioProcessing::Create(config)); |
| 402 } |
| 403 } |
| 404 |
| 405 void DebugDumpTest::ConfigureApm(const audioproc::Config& msg) { |
| 406 // AEC configs. |
| 407 ASSERT_TRUE(msg.has_aec_enabled()); |
| 408 EXPECT_EQ(AudioProcessing::kNoError, |
| 409 apm_->echo_cancellation()->Enable(msg.aec_enabled())); |
| 410 |
| 411 ASSERT_TRUE(msg.has_aec_drift_compensation_enabled()); |
| 412 EXPECT_EQ(AudioProcessing::kNoError, |
| 413 apm_->echo_cancellation()->enable_drift_compensation( |
| 414 msg.aec_drift_compensation_enabled())); |
| 415 |
| 416 ASSERT_TRUE(msg.has_aec_suppression_level()); |
| 417 EXPECT_EQ(AudioProcessing::kNoError, |
| 418 apm_->echo_cancellation()->set_suppression_level( |
| 419 static_cast<EchoCancellation::SuppressionLevel>( |
| 420 msg.aec_suppression_level()))); |
| 421 |
| 422 // AECM configs. |
| 423 ASSERT_TRUE(msg.has_aecm_enabled()); |
| 424 EXPECT_EQ(AudioProcessing::kNoError, |
| 425 apm_->echo_control_mobile()->Enable(msg.aecm_enabled())); |
| 426 |
| 427 ASSERT_TRUE(msg.has_aecm_comfort_noise_enabled()); |
| 428 EXPECT_EQ(AudioProcessing::kNoError, |
| 429 apm_->echo_control_mobile()->enable_comfort_noise( |
| 430 msg.aecm_comfort_noise_enabled())); |
| 431 |
| 432 ASSERT_TRUE(msg.has_aecm_routing_mode()); |
| 433 EXPECT_EQ(AudioProcessing::kNoError, |
| 434 apm_->echo_control_mobile()->set_routing_mode( |
| 435 static_cast<EchoControlMobile::RoutingMode>( |
| 436 msg.aecm_routing_mode()))); |
| 437 |
| 438 // AGC configs. |
| 439 ASSERT_TRUE(msg.has_agc_enabled()); |
| 440 EXPECT_EQ(AudioProcessing::kNoError, |
| 441 apm_->gain_control()->Enable(msg.agc_enabled())); |
| 442 |
| 443 ASSERT_TRUE(msg.has_agc_mode()); |
| 444 EXPECT_EQ(AudioProcessing::kNoError, |
| 445 apm_->gain_control()->set_mode( |
| 446 static_cast<GainControl::Mode>(msg.agc_mode()))); |
| 447 |
| 448 ASSERT_TRUE(msg.has_agc_limiter_enabled()); |
| 449 EXPECT_EQ(AudioProcessing::kNoError, |
| 450 apm_->gain_control()->enable_limiter(msg.agc_limiter_enabled())); |
| 451 |
| 452 // HPF configs. |
| 453 ASSERT_TRUE(msg.has_hpf_enabled()); |
| 454 EXPECT_EQ(AudioProcessing::kNoError, |
| 455 apm_->high_pass_filter()->Enable(msg.hpf_enabled())); |
| 456 |
| 457 // NS configs. |
| 458 ASSERT_TRUE(msg.has_ns_enabled()); |
| 459 EXPECT_EQ(AudioProcessing::kNoError, |
| 460 apm_->noise_suppression()->Enable(msg.ns_enabled())); |
| 461 |
| 462 ASSERT_TRUE(msg.has_ns_level()); |
| 463 EXPECT_EQ(AudioProcessing::kNoError, |
| 464 apm_->noise_suppression()->set_level( |
| 465 static_cast<NoiseSuppression::Level>(msg.ns_level()))); |
| 466 } |
| 467 |
| 468 TEST_F(DebugDumpTest, SimpleCase) { |
| 469 Config config; |
| 470 DebugDumpGenerator generator(config); |
| 471 generator.StartRecording(); |
| 472 generator.Process(100); |
| 473 generator.StopRecording(); |
| 474 VerifyDebugDump(generator.dump_file_name()); |
| 475 } |
| 476 |
| 477 TEST_F(DebugDumpTest, ChangeInputFormat) { |
| 478 Config config; |
| 479 DebugDumpGenerator generator(config); |
| 480 generator.StartRecording(); |
| 481 generator.Process(100); |
| 482 generator.SetInputRate(48000); |
| 483 |
| 484 generator.ForceInputMono(true); |
| 485 // Number of output channel should not be larger than that of input. APM will |
| 486 // fail otherwise. |
| 487 generator.SetOutputChannels(1); |
| 488 |
| 489 generator.Process(100); |
| 490 generator.StopRecording(); |
| 491 VerifyDebugDump(generator.dump_file_name()); |
| 492 } |
| 493 |
| 494 TEST_F(DebugDumpTest, ChangeReverseFormat) { |
| 495 Config config; |
| 496 DebugDumpGenerator generator(config); |
| 497 generator.StartRecording(); |
| 498 generator.Process(100); |
| 499 generator.SetReverseRate(48000); |
| 500 generator.ForceReverseMono(true); |
| 501 generator.Process(100); |
| 502 generator.StopRecording(); |
| 503 VerifyDebugDump(generator.dump_file_name()); |
| 504 } |
| 505 |
| 506 TEST_F(DebugDumpTest, ChangeOutputFormat) { |
| 507 Config config; |
| 508 DebugDumpGenerator generator(config); |
| 509 generator.StartRecording(); |
| 510 generator.Process(100); |
| 511 generator.SetOutputRate(48000); |
| 512 generator.SetOutputChannels(1); |
| 513 generator.Process(100); |
| 514 generator.StopRecording(); |
| 515 VerifyDebugDump(generator.dump_file_name()); |
| 516 } |
| 517 |
| 518 TEST_F(DebugDumpTest, ToggleAec) { |
| 519 Config config; |
| 520 DebugDumpGenerator generator(config); |
| 521 generator.StartRecording(); |
| 522 generator.Process(100); |
| 523 |
| 524 EchoCancellation* aec = generator.apm()->echo_cancellation(); |
| 525 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled())); |
| 526 |
| 527 generator.Process(100); |
| 528 generator.StopRecording(); |
| 529 VerifyDebugDump(generator.dump_file_name()); |
| 530 } |
| 531 |
| 532 TEST_F(DebugDumpTest, ToggleDelayAgnosticAec) { |
| 533 Config config; |
| 534 config.Set<DelayAgnostic>(new DelayAgnostic(true)); |
| 535 DebugDumpGenerator generator(config); |
| 536 generator.StartRecording(); |
| 537 generator.Process(100); |
| 538 |
| 539 EchoCancellation* aec = generator.apm()->echo_cancellation(); |
| 540 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled())); |
| 541 |
| 542 generator.Process(100); |
| 543 generator.StopRecording(); |
| 544 VerifyDebugDump(generator.dump_file_name()); |
| 545 } |
| 546 |
| 547 TEST_F(DebugDumpTest, ToggleAecLevel) { |
| 548 Config config; |
| 549 DebugDumpGenerator generator(config); |
| 550 EchoCancellation* aec = generator.apm()->echo_cancellation(); |
| 551 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(true)); |
| 552 EXPECT_EQ(AudioProcessing::kNoError, |
| 553 aec->set_suppression_level(EchoCancellation::kLowSuppression)); |
| 554 generator.StartRecording(); |
| 555 generator.Process(100); |
| 556 |
| 557 EXPECT_EQ(AudioProcessing::kNoError, |
| 558 aec->set_suppression_level(EchoCancellation::kHighSuppression)); |
| 559 generator.Process(100); |
| 560 generator.StopRecording(); |
| 561 VerifyDebugDump(generator.dump_file_name()); |
| 562 } |
| 563 |
| 564 #if defined(WEBRTC_ANDROID) |
| 565 // AGC may not be supported on Android. |
| 566 #define MAYBE_ToggleAgc DISABLED_ToggleAgc |
| 567 #else |
| 568 #define MAYBE_ToggleAgc ToggleAgc |
| 569 #endif |
| 570 TEST_F(DebugDumpTest, MAYBE_ToggleAgc) { |
| 571 Config config; |
| 572 DebugDumpGenerator generator(config); |
| 573 generator.StartRecording(); |
| 574 generator.Process(100); |
| 575 |
| 576 GainControl* agc = generator.apm()->gain_control(); |
| 577 EXPECT_EQ(AudioProcessing::kNoError, agc->Enable(!agc->is_enabled())); |
| 578 |
| 579 generator.Process(100); |
| 580 generator.StopRecording(); |
| 581 VerifyDebugDump(generator.dump_file_name()); |
| 582 } |
| 583 |
| 584 TEST_F(DebugDumpTest, ToggleNs) { |
| 585 Config config; |
| 586 DebugDumpGenerator generator(config); |
| 587 generator.StartRecording(); |
| 588 generator.Process(100); |
| 589 |
| 590 NoiseSuppression* ns = generator.apm()->noise_suppression(); |
| 591 EXPECT_EQ(AudioProcessing::kNoError, ns->Enable(!ns->is_enabled())); |
| 592 |
| 593 generator.Process(100); |
| 594 generator.StopRecording(); |
| 595 VerifyDebugDump(generator.dump_file_name()); |
| 596 } |
| 597 |
| 598 TEST_F(DebugDumpTest, TransientSuppressionOn) { |
| 599 Config config; |
| 600 config.Set<ExperimentalNs>(new ExperimentalNs(true)); |
| 601 DebugDumpGenerator generator(config); |
| 602 generator.StartRecording(); |
| 603 generator.Process(100); |
| 604 generator.StopRecording(); |
| 605 VerifyDebugDump(generator.dump_file_name()); |
| 606 } |
| 607 |
| 608 } // namespace test |
| 609 } // namespace webrtc |
OLD | NEW |