Chromium Code Reviews| 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 { | |
|
Andrew MacDonald
2015/10/30 16:26:06
Why did you remove this namespace? It's fine to pu
minyue-webrtc
2015/10/30 16:32:25
Per mentioned that DebugDumpGenerator is used only
Andrew MacDonald
2015/10/30 16:39:42
You have an anonymous namespace starting on line 2
minyue-webrtc
2015/10/30 17:13:29
ah, I see that you mean a wrapped anonymous namesp
| |
| 27 namespace test { | |
| 28 | |
| 29 namespace { | |
| 30 | |
| 31 void MaybeResetBuffer(rtc::scoped_ptr<ChannelBuffer<float>>& buffer, | |
|
peah-webrtc
2015/10/29 22:25:02
Since this is only used inside the DebugDumpGenera
minyue-webrtc
2015/10/30 11:07:08
It is used in other test, see line 318
| |
| 32 const StreamConfig& config) { | |
| 33 if (!buffer.get() || buffer->num_frames() != config.num_frames() || | |
| 34 buffer->num_channels() != config.num_channels()) { | |
| 35 buffer.reset(new ChannelBuffer<float>(config.num_frames(), | |
| 36 config.num_channels())); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 class DebugDumpGenerator { | |
|
peah-webrtc
2015/10/29 22:25:02
Since this class is only used inside this function
minyue-webrtc
2015/10/30 11:07:07
Ok. I made a change. I needed to move some blocks.
| |
| 43 public: | |
| 44 DebugDumpGenerator(const std::string& input_file_name, | |
| 45 int input_file_rate_hz, | |
| 46 int input_channels, | |
| 47 const std::string& reverse_file_name, | |
| 48 int reverse_file_rate_hz, | |
| 49 int reverse_channels, | |
| 50 const Config& config, | |
| 51 const std::string& dump_file_name); | |
| 52 | |
| 53 // Constructor that uses default input files. | |
| 54 explicit DebugDumpGenerator(const Config& config); | |
| 55 | |
| 56 ~DebugDumpGenerator(); | |
| 57 | |
| 58 // Changes the sample rate of the input audio to the APM. | |
| 59 void SetInputRate(int rate_hz); | |
| 60 | |
| 61 // Sets if converts stereo input signal to mono by discarding other channels. | |
| 62 void ForceInputMono(bool mono); | |
| 63 | |
| 64 // Changes the sample rate of the reverse audio to the APM. | |
| 65 void SetReverseRate(int rate_hz); | |
| 66 | |
| 67 // Sets if converts stereo reverse signal to mono by discarding other | |
| 68 // channels. | |
| 69 void ForceReverseMono(bool mono); | |
| 70 | |
| 71 // Sets the required sample rate of the APM output. | |
| 72 void SetOutputRate(int rate_hz); | |
| 73 | |
| 74 // Sets the required channels of the APM output. | |
| 75 void SetOutputChannels(int channels); | |
| 76 | |
| 77 std::string dump_file_name() const { return dump_file_name_; } | |
| 78 | |
| 79 void StartRecording(); | |
| 80 void Process(size_t num_blocks); | |
| 81 void StopRecording(); | |
| 82 AudioProcessing* apm() const { return apm_.get(); } | |
| 83 | |
| 84 private: | |
| 85 void ReadAndDeinterleave(ResampleInputAudioFile* audio, int channels, | |
|
peah-webrtc
2015/10/29 22:25:02
This does not at all depend on the state apart fro
minyue-webrtc
2015/10/30 11:07:07
agree!
| |
| 86 const StreamConfig& config, float* const* buffer); | |
| 87 | |
| 88 void MonoToStereo(float* const* buffer, size_t num_frames); | |
|
peah-webrtc
2015/10/29 22:25:02
I cannot find the implementation of this method. I
minyue-webrtc
2015/10/30 11:07:07
Oh, good catch? why is it still there. I thought I
| |
| 89 | |
| 90 // APM input/output settings | |
|
peah-webrtc
2015/10/29 22:25:02
Should end with a "."
minyue-webrtc
2015/10/30 11:07:07
Done.
| |
| 91 StreamConfig input_config_; | |
| 92 StreamConfig reverse_config_; | |
| 93 StreamConfig output_config_; | |
| 94 | |
| 95 // Input file format. | |
| 96 const std::string input_file_name_; | |
| 97 ResampleInputAudioFile input_audio_; | |
| 98 const int input_file_channels_; | |
| 99 | |
| 100 // Reverse file format. | |
| 101 const std::string reverse_file_name_; | |
| 102 ResampleInputAudioFile reverse_audio_; | |
| 103 const int reverse_file_channels_; | |
| 104 | |
| 105 // Buffer for APM input/output. | |
| 106 rtc::scoped_ptr<ChannelBuffer<float>> input_; | |
| 107 rtc::scoped_ptr<ChannelBuffer<float>> reverse_; | |
| 108 rtc::scoped_ptr<ChannelBuffer<float>> output_; | |
| 109 | |
| 110 rtc::scoped_ptr<AudioProcessing> apm_; | |
| 111 | |
| 112 const std::string dump_file_name_; | |
| 113 | |
| 114 // Buffer for reading audio files. | |
| 115 std::vector<int16_t> signal_; | |
| 116 }; | |
| 117 | |
| 118 class DebugDumpTest : public ::testing::Test { | |
| 119 public: | |
| 120 DebugDumpTest(); | |
| 121 | |
| 122 // VerifyDebugDump replays a debug dump using APM and verifies that the result | |
| 123 // is bit-exact-identical to the output channel in the dump. This is only | |
| 124 // guaranteed if the debug dump is started on the first frame. | |
| 125 void VerifyDebugDump(const std::string& dump_file_name); | |
| 126 | |
| 127 private: | |
| 128 // Following functions are facilities for replaying debug dumps. | |
| 129 void OnInitEvent(const audioproc::Init& msg); | |
| 130 void OnStreamEvent(const audioproc::Stream& msg); | |
| 131 void OnReverseStreamEvent(const audioproc::ReverseStream& msg); | |
| 132 void OnConfigEvent(const audioproc::Config& msg); | |
| 133 | |
| 134 void MaybeRecreateApm(const audioproc::Config& msg); | |
| 135 void ConfigureApm(const audioproc::Config& msg); | |
| 136 | |
| 137 // Buffer for APM input/output. | |
| 138 rtc::scoped_ptr<ChannelBuffer<float>> input_; | |
| 139 rtc::scoped_ptr<ChannelBuffer<float>> reverse_; | |
| 140 rtc::scoped_ptr<ChannelBuffer<float>> output_; | |
| 141 | |
| 142 rtc::scoped_ptr<AudioProcessing> apm_; | |
| 143 | |
| 144 StreamConfig input_config_; | |
| 145 StreamConfig reverse_config_; | |
| 146 StreamConfig output_config_; | |
| 147 }; | |
| 148 | |
| 149 DebugDumpGenerator::DebugDumpGenerator(const std::string& input_file_name, | |
| 150 int input_rate_hz, | |
| 151 int input_channels, | |
| 152 const std::string& reverse_file_name, | |
| 153 int reverse_rate_hz, | |
| 154 int reverse_channels, | |
| 155 const Config& config, | |
| 156 const std::string& dump_file_name) | |
| 157 : input_config_(input_rate_hz, input_channels), | |
| 158 reverse_config_(reverse_rate_hz, reverse_channels), | |
| 159 output_config_(input_rate_hz, input_channels), | |
| 160 input_audio_(input_file_name, input_rate_hz, input_rate_hz), | |
| 161 input_file_channels_(input_channels), | |
| 162 reverse_audio_(reverse_file_name, reverse_rate_hz, reverse_rate_hz), | |
| 163 reverse_file_channels_(reverse_channels), | |
| 164 input_(new ChannelBuffer<float>(input_config_.num_frames(), | |
| 165 input_config_.num_channels())), | |
| 166 reverse_(new ChannelBuffer<float>(reverse_config_.num_frames(), | |
| 167 reverse_config_.num_channels())), | |
| 168 output_(new ChannelBuffer<float>(output_config_.num_frames(), | |
| 169 output_config_.num_channels())), | |
| 170 apm_(AudioProcessing::Create(config)), | |
| 171 dump_file_name_(dump_file_name) { | |
| 172 } | |
| 173 | |
| 174 DebugDumpGenerator::DebugDumpGenerator(const Config& config) | |
| 175 : DebugDumpGenerator(test::ResourcePath("near32_stereo", "pcm"), 32000, 2, | |
| 176 test::ResourcePath("far32_stereo", "pcm"), 32000, 2, | |
| 177 config, | |
| 178 test::TempFilename(test::OutputPath(), "debug_aec")) { | |
| 179 } | |
| 180 | |
| 181 DebugDumpGenerator::~DebugDumpGenerator() { | |
| 182 remove(dump_file_name_.c_str()); | |
| 183 } | |
| 184 | |
| 185 void DebugDumpGenerator::SetInputRate(int rate_hz) { | |
| 186 input_audio_.set_output_rate_hz(rate_hz); | |
| 187 input_config_.set_sample_rate_hz(rate_hz); | |
| 188 MaybeResetBuffer(input_, input_config_); | |
| 189 } | |
| 190 | |
| 191 void DebugDumpGenerator::ForceInputMono(bool mono) { | |
| 192 const int channels = mono ? 1 : input_file_channels_; | |
| 193 input_config_.set_num_channels(channels); | |
| 194 MaybeResetBuffer(input_, input_config_); | |
| 195 } | |
| 196 | |
| 197 void DebugDumpGenerator::SetReverseRate(int rate_hz) { | |
| 198 reverse_audio_.set_output_rate_hz(rate_hz); | |
| 199 reverse_config_.set_sample_rate_hz(rate_hz); | |
| 200 MaybeResetBuffer(reverse_, reverse_config_); | |
| 201 } | |
| 202 | |
| 203 void DebugDumpGenerator::ForceReverseMono(bool mono) { | |
| 204 const int channels = mono ? 1 : reverse_file_channels_; | |
| 205 reverse_config_.set_num_channels(channels); | |
| 206 MaybeResetBuffer(reverse_, reverse_config_); | |
| 207 } | |
| 208 | |
| 209 void DebugDumpGenerator::SetOutputRate(int rate_hz) { | |
| 210 output_config_.set_sample_rate_hz(rate_hz); | |
| 211 MaybeResetBuffer(output_, output_config_); | |
| 212 } | |
| 213 | |
| 214 void DebugDumpGenerator::SetOutputChannels(int channels) { | |
| 215 output_config_.set_num_channels(channels); | |
| 216 MaybeResetBuffer(output_, output_config_); | |
| 217 } | |
| 218 | |
| 219 void DebugDumpGenerator::StartRecording() { | |
| 220 apm_->StartDebugRecording(dump_file_name_.c_str()); | |
| 221 } | |
| 222 | |
| 223 void DebugDumpGenerator::Process(size_t num_blocks) { | |
| 224 for (size_t i = 0; i < num_blocks; ++i) { | |
| 225 ReadAndDeinterleave(&reverse_audio_, reverse_file_channels_, | |
| 226 reverse_config_, reverse_->channels()); | |
| 227 ReadAndDeinterleave(&input_audio_, input_file_channels_, input_config_, | |
| 228 input_->channels()); | |
| 229 RTC_CHECK_EQ(AudioProcessing::kNoError, apm_->set_stream_delay_ms(100)); | |
| 230 apm_->set_stream_key_pressed(i % 10 == 9); | |
| 231 RTC_CHECK_EQ(AudioProcessing::kNoError, | |
| 232 apm_->ProcessStream(input_->channels(), input_config_, | |
| 233 output_config_, output_->channels())); | |
| 234 | |
| 235 RTC_CHECK_EQ(AudioProcessing::kNoError, | |
| 236 apm_->ProcessReverseStream(reverse_->channels(), | |
| 237 reverse_config_, | |
| 238 reverse_config_, | |
| 239 reverse_->channels())); | |
| 240 } | |
| 241 } | |
| 242 | |
| 243 void DebugDumpGenerator::StopRecording() { | |
| 244 apm_->StopDebugRecording(); | |
| 245 } | |
| 246 | |
| 247 void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio, | |
| 248 int channels, | |
| 249 const StreamConfig& config, | |
| 250 float* const* buffer) { | |
| 251 const size_t num_frames = config.num_frames(); | |
| 252 const int out_channels = config.num_channels(); | |
| 253 | |
| 254 // Make sure the buffer for reading the file is large enough. | |
| 255 if (channels * num_frames > signal_.size()) { | |
| 256 signal_.resize(num_frames * channels); | |
| 257 } | |
| 258 | |
| 259 audio->Read(num_frames * channels, &signal_[0]); | |
| 260 | |
| 261 // We only allow reducing number of channels by discarding some channels. | |
| 262 RTC_CHECK_LE(out_channels, channels); | |
| 263 for (int channel = 0; channel < out_channels; ++channel) { | |
| 264 for (size_t i = 0; i < num_frames; ++i) { | |
| 265 buffer[channel][i] = S16ToFloat(signal_[i * channels + channel]); | |
| 266 } | |
| 267 } | |
| 268 } | |
| 269 | |
| 270 DebugDumpTest::DebugDumpTest() | |
| 271 : input_(nullptr), // will be created upon usage. | |
| 272 reverse_(nullptr), | |
| 273 output_(nullptr), | |
| 274 apm_(nullptr) { | |
| 275 } | |
| 276 | |
| 277 void DebugDumpTest::VerifyDebugDump(const std::string& in_filename) { | |
| 278 FILE* in_file = fopen(in_filename.c_str(), "rb"); | |
| 279 ASSERT_TRUE(in_file); | |
| 280 audioproc::Event event_msg; | |
| 281 | |
| 282 while (ReadMessageFromFile(in_file, &event_msg)) { | |
| 283 switch (event_msg.type()) { | |
| 284 case audioproc::Event::INIT: | |
| 285 OnInitEvent(event_msg.init()); | |
| 286 break; | |
| 287 case audioproc::Event::STREAM: | |
| 288 OnStreamEvent(event_msg.stream()); | |
| 289 break; | |
| 290 case audioproc::Event::REVERSE_STREAM: | |
| 291 OnReverseStreamEvent(event_msg.reverse_stream()); | |
| 292 break; | |
| 293 case audioproc::Event::CONFIG: | |
| 294 OnConfigEvent(event_msg.config()); | |
| 295 break; | |
| 296 case audioproc::Event::UNKNOWN_EVENT: | |
| 297 // We do not expect receive UNKNOWN event currently. | |
| 298 ASSERT_TRUE(false); | |
|
peah-webrtc
2015/10/29 22:25:02
Should use FAIL() instead.
minyue-webrtc
2015/10/30 11:07:07
Done.
| |
| 299 } | |
| 300 } | |
| 301 fclose(in_file); | |
| 302 } | |
| 303 | |
| 304 // OnInitEvent reset the input/output/reserve channel format. | |
| 305 void DebugDumpTest::OnInitEvent(const audioproc::Init& msg) { | |
| 306 ASSERT_TRUE(msg.has_num_input_channels()); | |
| 307 ASSERT_TRUE(msg.has_output_sample_rate()); | |
| 308 ASSERT_TRUE(msg.has_num_output_channels()); | |
| 309 ASSERT_TRUE(msg.has_reverse_sample_rate()); | |
| 310 ASSERT_TRUE(msg.has_num_reverse_channels()); | |
| 311 | |
| 312 input_config_ = StreamConfig(msg.sample_rate(), msg.num_input_channels()); | |
| 313 output_config_ = | |
| 314 StreamConfig(msg.output_sample_rate(), msg.num_output_channels()); | |
| 315 reverse_config_ = | |
| 316 StreamConfig(msg.reverse_sample_rate(), msg.num_reverse_channels()); | |
| 317 | |
| 318 MaybeResetBuffer(input_, input_config_); | |
| 319 MaybeResetBuffer(output_, output_config_); | |
| 320 MaybeResetBuffer(reverse_, reverse_config_); | |
| 321 } | |
| 322 | |
| 323 // OnStreamEvent replays an input signal and verifies the output. | |
| 324 void DebugDumpTest::OnStreamEvent(const audioproc::Stream& msg) { | |
| 325 // APM should have been created. | |
| 326 ASSERT_TRUE(apm_.get()); | |
| 327 | |
| 328 EXPECT_NOERR(apm_->gain_control()->set_stream_analog_level(msg.level())); | |
| 329 EXPECT_NOERR(apm_->set_stream_delay_ms(msg.delay())); | |
| 330 apm_->echo_cancellation()->set_stream_drift_samples(msg.drift()); | |
| 331 if (msg.has_keypress()) | |
| 332 apm_->set_stream_key_pressed(msg.keypress()); | |
| 333 else | |
| 334 apm_->set_stream_key_pressed(true); | |
| 335 | |
| 336 ASSERT_EQ(input_config_.num_channels(), msg.input_channel_size()); | |
| 337 ASSERT_EQ(input_config_.num_frames() * sizeof(float), | |
| 338 msg.input_channel(0).size()); | |
| 339 | |
| 340 for (int i = 0; i < msg.input_channel_size(); ++i) { | |
| 341 memcpy(input_->channels()[i], msg.input_channel(i).data(), | |
| 342 msg.input_channel(i).size()); | |
| 343 } | |
| 344 | |
| 345 ASSERT_EQ(AudioProcessing::kNoError, | |
| 346 apm_->ProcessStream(input_->channels(), input_config_, | |
| 347 output_config_, output_->channels())); | |
| 348 | |
| 349 // Check that output of APM is bit-exact to the output in the dump. | |
| 350 ASSERT_EQ(output_config_.num_channels(), msg.output_channel_size()); | |
| 351 ASSERT_EQ(output_config_.num_frames() * sizeof(float), | |
| 352 msg.output_channel(0).size()); | |
| 353 for (int i = 0; i < msg.output_channel_size(); ++i) { | |
| 354 ASSERT_EQ(0, memcmp(output_->channels()[i], msg.output_channel(i).data(), | |
| 355 msg.output_channel(i).size())); | |
| 356 } | |
| 357 } | |
| 358 | |
| 359 void DebugDumpTest::OnReverseStreamEvent(const audioproc::ReverseStream& msg) { | |
| 360 // APM should have been created. | |
| 361 ASSERT_TRUE(apm_.get()); | |
| 362 | |
| 363 ASSERT_GT(msg.channel_size(), 0); | |
| 364 ASSERT_EQ(reverse_config_.num_channels(), msg.channel_size()); | |
| 365 ASSERT_EQ(reverse_config_.num_frames() * sizeof(float), | |
| 366 msg.channel(0).size()); | |
| 367 | |
| 368 for (int i = 0; i < msg.channel_size(); ++i) { | |
| 369 memcpy(reverse_->channels()[i], msg.channel(i).data(), | |
| 370 msg.channel(i).size()); | |
| 371 } | |
| 372 | |
| 373 ASSERT_EQ(AudioProcessing::kNoError, | |
| 374 apm_->ProcessReverseStream(reverse_->channels(), | |
| 375 reverse_config_, | |
| 376 reverse_config_, | |
| 377 reverse_->channels())); | |
| 378 } | |
| 379 | |
| 380 void DebugDumpTest::OnConfigEvent(const audioproc::Config& msg) { | |
| 381 MaybeRecreateApm(msg); | |
| 382 ConfigureApm(msg); | |
| 383 } | |
| 384 | |
| 385 void DebugDumpTest::MaybeRecreateApm(const audioproc::Config& msg) { | |
| 386 // These configurations cannot be changed on the fly. | |
| 387 Config config; | |
| 388 ASSERT_TRUE(msg.has_aec_delay_agnostic_enabled()); | |
| 389 config.Set<DelayAgnostic>( | |
| 390 new DelayAgnostic(msg.aec_delay_agnostic_enabled())); | |
| 391 | |
| 392 ASSERT_TRUE(msg.has_noise_robust_agc_enabled()); | |
| 393 config.Set<ExperimentalAgc>( | |
| 394 new ExperimentalAgc(msg.noise_robust_agc_enabled())); | |
| 395 | |
| 396 ASSERT_TRUE(msg.has_transient_suppression_enabled()); | |
| 397 config.Set<ExperimentalNs>( | |
| 398 new ExperimentalNs(msg.transient_suppression_enabled())); | |
| 399 | |
| 400 ASSERT_TRUE(msg.has_aec_extended_filter_enabled()); | |
| 401 config.Set<ExtendedFilter>(new ExtendedFilter( | |
| 402 msg.aec_extended_filter_enabled())); | |
| 403 | |
| 404 // We only create APM once, since changes on these fields should not | |
| 405 // happen in current implementation. | |
| 406 if (!apm_.get()) { | |
| 407 apm_.reset(AudioProcessing::Create(config)); | |
| 408 } | |
| 409 } | |
| 410 | |
| 411 void DebugDumpTest::ConfigureApm(const audioproc::Config& msg) { | |
| 412 // AEC configs. | |
| 413 ASSERT_TRUE(msg.has_aec_enabled()); | |
| 414 EXPECT_EQ(AudioProcessing::kNoError, | |
| 415 apm_->echo_cancellation()->Enable(msg.aec_enabled())); | |
| 416 | |
| 417 ASSERT_TRUE(msg.has_aec_drift_compensation_enabled()); | |
| 418 EXPECT_EQ(AudioProcessing::kNoError, | |
| 419 apm_->echo_cancellation()->enable_drift_compensation( | |
| 420 msg.aec_drift_compensation_enabled())); | |
| 421 | |
| 422 ASSERT_TRUE(msg.has_aec_suppression_level()); | |
| 423 EXPECT_EQ(AudioProcessing::kNoError, | |
| 424 apm_->echo_cancellation()->set_suppression_level( | |
| 425 static_cast<webrtc::EchoCancellation::SuppressionLevel>( | |
| 426 msg.aec_suppression_level()))); | |
| 427 | |
| 428 // AECM configs. | |
| 429 ASSERT_TRUE(msg.has_aecm_enabled()); | |
| 430 EXPECT_EQ(AudioProcessing::kNoError, | |
| 431 apm_->echo_control_mobile()->Enable(msg.aecm_enabled())); | |
| 432 | |
| 433 ASSERT_TRUE(msg.has_aecm_comfort_noise_enabled()); | |
| 434 EXPECT_EQ(AudioProcessing::kNoError, | |
| 435 apm_->echo_control_mobile()->enable_comfort_noise( | |
| 436 msg.aecm_comfort_noise_enabled())); | |
| 437 | |
| 438 ASSERT_TRUE(msg.has_aecm_routing_mode()); | |
| 439 EXPECT_EQ(AudioProcessing::kNoError, | |
| 440 apm_->echo_control_mobile()->set_routing_mode( | |
| 441 static_cast<webrtc::EchoControlMobile::RoutingMode>( | |
| 442 msg.aecm_routing_mode()))); | |
| 443 | |
| 444 // AGC configs. | |
| 445 ASSERT_TRUE(msg.has_agc_enabled()); | |
| 446 EXPECT_EQ(AudioProcessing::kNoError, | |
| 447 apm_->gain_control()->Enable(msg.agc_enabled())); | |
| 448 | |
| 449 ASSERT_TRUE(msg.has_agc_mode()); | |
| 450 EXPECT_EQ(AudioProcessing::kNoError, | |
| 451 apm_->gain_control()->set_mode( | |
| 452 static_cast<webrtc::GainControl::Mode>(msg.agc_mode()))); | |
| 453 | |
| 454 ASSERT_TRUE(msg.has_agc_limiter_enabled()); | |
| 455 EXPECT_EQ(AudioProcessing::kNoError, | |
| 456 apm_->gain_control()->enable_limiter(msg.agc_limiter_enabled())); | |
| 457 | |
| 458 // HPF configs. | |
| 459 ASSERT_TRUE(msg.has_hpf_enabled()); | |
| 460 EXPECT_EQ(AudioProcessing::kNoError, | |
| 461 apm_->high_pass_filter()->Enable(msg.hpf_enabled())); | |
| 462 | |
| 463 // NS configs. | |
| 464 ASSERT_TRUE(msg.has_ns_enabled()); | |
| 465 EXPECT_EQ(AudioProcessing::kNoError, | |
| 466 apm_->noise_suppression()->Enable(msg.ns_enabled())); | |
| 467 | |
| 468 ASSERT_TRUE(msg.has_ns_level()); | |
| 469 EXPECT_EQ(AudioProcessing::kNoError, | |
| 470 apm_->noise_suppression()->set_level( | |
| 471 static_cast<webrtc::NoiseSuppression::Level>(msg.ns_level()))); | |
| 472 } | |
| 473 | |
| 474 TEST_F(DebugDumpTest, SimpleCase) { | |
| 475 Config config; | |
| 476 DebugDumpGenerator generator(config); | |
| 477 generator.StartRecording(); | |
| 478 generator.Process(100); | |
| 479 generator.StopRecording(); | |
| 480 VerifyDebugDump(generator.dump_file_name()); | |
| 481 } | |
| 482 | |
| 483 TEST_F(DebugDumpTest, ChangeInputFormat) { | |
| 484 Config config; | |
| 485 DebugDumpGenerator generator(config); | |
| 486 generator.StartRecording(); | |
| 487 generator.Process(100); | |
| 488 generator.SetInputRate(48000); | |
| 489 | |
| 490 generator.ForceInputMono(true); | |
| 491 // #channel of out put should not be larger than that of input. APM will fail | |
|
peah-webrtc
2015/10/29 22:25:02
Number of output channels should....
minyue-webrtc
2015/10/30 11:07:08
Done.
| |
| 492 // otherwise. | |
| 493 generator.SetOutputChannels(1); | |
| 494 | |
| 495 generator.Process(100); | |
| 496 generator.StopRecording(); | |
| 497 VerifyDebugDump(generator.dump_file_name()); | |
| 498 } | |
| 499 | |
| 500 TEST_F(DebugDumpTest, ChangeReverseFormat) { | |
| 501 Config config; | |
| 502 DebugDumpGenerator generator(config); | |
| 503 generator.StartRecording(); | |
| 504 generator.Process(100); | |
| 505 generator.SetReverseRate(48000); | |
| 506 generator.ForceReverseMono(true); | |
| 507 generator.Process(100); | |
| 508 generator.StopRecording(); | |
| 509 VerifyDebugDump(generator.dump_file_name()); | |
| 510 } | |
| 511 | |
| 512 TEST_F(DebugDumpTest, ChangeOutputFormat) { | |
| 513 Config config; | |
| 514 DebugDumpGenerator generator(config); | |
| 515 generator.StartRecording(); | |
| 516 generator.Process(100); | |
| 517 generator.SetOutputRate(48000); | |
| 518 generator.SetOutputChannels(1); | |
| 519 generator.Process(100); | |
| 520 generator.StopRecording(); | |
| 521 VerifyDebugDump(generator.dump_file_name()); | |
| 522 } | |
| 523 | |
| 524 TEST_F(DebugDumpTest, ToggleAec) { | |
| 525 Config config; | |
| 526 DebugDumpGenerator generator(config); | |
| 527 generator.StartRecording(); | |
| 528 generator.Process(100); | |
| 529 | |
| 530 EchoCancellation* aec = generator.apm()->echo_cancellation(); | |
| 531 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled())); | |
| 532 | |
| 533 generator.Process(100); | |
| 534 generator.StopRecording(); | |
| 535 VerifyDebugDump(generator.dump_file_name()); | |
| 536 } | |
| 537 | |
| 538 TEST_F(DebugDumpTest, ToggleDelayAgnosticAec) { | |
| 539 Config config; | |
| 540 config.Set<DelayAgnostic>(new DelayAgnostic(true)); | |
| 541 DebugDumpGenerator generator(config); | |
| 542 generator.StartRecording(); | |
| 543 generator.Process(100); | |
| 544 | |
| 545 EchoCancellation* aec = generator.apm()->echo_cancellation(); | |
| 546 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(!aec->is_enabled())); | |
| 547 | |
| 548 generator.Process(100); | |
| 549 generator.StopRecording(); | |
| 550 VerifyDebugDump(generator.dump_file_name()); | |
| 551 } | |
| 552 | |
| 553 TEST_F(DebugDumpTest, ToggleAecLevel) { | |
| 554 Config config; | |
| 555 DebugDumpGenerator generator(config); | |
| 556 EchoCancellation* aec = generator.apm()->echo_cancellation(); | |
| 557 EXPECT_EQ(AudioProcessing::kNoError, aec->Enable(true)); | |
| 558 EXPECT_EQ(AudioProcessing::kNoError, | |
| 559 aec->set_suppression_level(EchoCancellation::kLowSuppression)); | |
| 560 generator.StartRecording(); | |
| 561 generator.Process(100); | |
| 562 | |
| 563 EXPECT_EQ(AudioProcessing::kNoError, | |
| 564 aec->set_suppression_level(EchoCancellation::kHighSuppression)); | |
| 565 generator.Process(100); | |
| 566 generator.StopRecording(); | |
| 567 VerifyDebugDump(generator.dump_file_name()); | |
| 568 } | |
| 569 | |
| 570 TEST_F(DebugDumpTest, 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 |