OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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 <numeric> |
| 12 #include <vector> |
| 13 |
| 14 #include "webrtc/base/array_view.h" |
| 15 #include "webrtc/base/random.h" |
| 16 #include "webrtc/modules/audio_processing/audio_buffer.h" |
| 17 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 18 #include "webrtc/modules/audio_processing/residual_echo_detector.h" |
| 19 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h" |
| 20 #include "webrtc/modules/audio_processing/test/performance_timer.h" |
| 21 #include "webrtc/modules/audio_processing/test/simulator_buffers.h" |
| 22 #include "webrtc/system_wrappers/include/clock.h" |
| 23 #include "webrtc/test/gtest.h" |
| 24 #include "webrtc/test/testsupport/perf_test.h" |
| 25 |
| 26 namespace webrtc { |
| 27 namespace { |
| 28 |
| 29 const size_t kNumFramesToProcess = 100; |
| 30 const int kSampleRate = AudioProcessing::kSampleRate48kHz; |
| 31 const int kNumberOfChannels = 1; |
| 32 |
| 33 std::string FormPerformanceMeasureString(const test::PerformanceTimer& timer) { |
| 34 std::string s = std::to_string(timer.GetDurationAverage()); |
| 35 s += ", "; |
| 36 s += std::to_string(timer.GetDurationStandardDeviation()); |
| 37 return s; |
| 38 } |
| 39 |
| 40 void RunStandaloneSubmodule() { |
| 41 test::SimulatorBuffers buffers( |
| 42 kSampleRate, kSampleRate, kSampleRate, kSampleRate, kNumberOfChannels, |
| 43 kNumberOfChannels, kNumberOfChannels, kNumberOfChannels); |
| 44 test::PerformanceTimer timer(kNumFramesToProcess); |
| 45 |
| 46 ResidualEchoDetector echo_detector; |
| 47 echo_detector.Initialize(); |
| 48 |
| 49 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) { |
| 50 buffers.UpdateInputBuffers(); |
| 51 |
| 52 timer.StartTimer(); |
| 53 echo_detector.AnalyzeRenderAudio(rtc::ArrayView<const float>( |
| 54 buffers.render_input_buffer->split_bands_const_f(0)[kBand0To8kHz], |
| 55 buffers.render_input_buffer->num_frames_per_band())); |
| 56 echo_detector.AnalyzeCaptureAudio(rtc::ArrayView<const float>( |
| 57 buffers.capture_input_buffer->split_bands_const_f(0)[kBand0To8kHz], |
| 58 buffers.capture_input_buffer->num_frames_per_band())); |
| 59 timer.StopTimer(); |
| 60 } |
| 61 webrtc::test::PrintResultMeanAndError( |
| 62 "echo_detector_call_durations", "", "StandaloneEchoDetector", |
| 63 FormPerformanceMeasureString(timer), "us", false); |
| 64 } |
| 65 |
| 66 void RunTogetherWithApm(std::string test_description, |
| 67 bool use_mobile_aec, |
| 68 bool include_default_apm_processing) { |
| 69 test::SimulatorBuffers buffers( |
| 70 kSampleRate, kSampleRate, kSampleRate, kSampleRate, kNumberOfChannels, |
| 71 kNumberOfChannels, kNumberOfChannels, kNumberOfChannels); |
| 72 test::PerformanceTimer render_timer(kNumFramesToProcess); |
| 73 test::PerformanceTimer capture_timer(kNumFramesToProcess); |
| 74 test::PerformanceTimer total_timer(kNumFramesToProcess); |
| 75 |
| 76 webrtc::Config config; |
| 77 AudioProcessing::Config apm_config; |
| 78 if (include_default_apm_processing) { |
| 79 config.Set<DelayAgnostic>(new DelayAgnostic(true)); |
| 80 config.Set<ExtendedFilter>(new ExtendedFilter(true)); |
| 81 } |
| 82 apm_config.level_controller.enabled = include_default_apm_processing; |
| 83 apm_config.residual_echo_detector.enabled = true; |
| 84 |
| 85 std::unique_ptr<AudioProcessing> apm; |
| 86 apm.reset(AudioProcessing::Create(config)); |
| 87 ASSERT_TRUE(apm.get()); |
| 88 apm->ApplyConfig(apm_config); |
| 89 |
| 90 ASSERT_EQ(AudioProcessing::kNoError, |
| 91 apm->gain_control()->Enable(include_default_apm_processing)); |
| 92 if (use_mobile_aec) { |
| 93 ASSERT_EQ(AudioProcessing::kNoError, |
| 94 apm->echo_cancellation()->Enable(false)); |
| 95 ASSERT_EQ(AudioProcessing::kNoError, apm->echo_control_mobile()->Enable( |
| 96 include_default_apm_processing)); |
| 97 } else { |
| 98 ASSERT_EQ(AudioProcessing::kNoError, |
| 99 apm->echo_cancellation()->Enable(include_default_apm_processing)); |
| 100 ASSERT_EQ(AudioProcessing::kNoError, |
| 101 apm->echo_control_mobile()->Enable(false)); |
| 102 } |
| 103 ASSERT_EQ(AudioProcessing::kNoError, |
| 104 apm->high_pass_filter()->Enable(include_default_apm_processing)); |
| 105 ASSERT_EQ(AudioProcessing::kNoError, |
| 106 apm->noise_suppression()->Enable(include_default_apm_processing)); |
| 107 ASSERT_EQ(AudioProcessing::kNoError, |
| 108 apm->voice_detection()->Enable(include_default_apm_processing)); |
| 109 ASSERT_EQ(AudioProcessing::kNoError, |
| 110 apm->level_estimator()->Enable(include_default_apm_processing)); |
| 111 |
| 112 StreamConfig stream_config(kSampleRate, kNumberOfChannels, false); |
| 113 |
| 114 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) { |
| 115 buffers.UpdateInputBuffers(); |
| 116 |
| 117 total_timer.StartTimer(); |
| 118 render_timer.StartTimer(); |
| 119 ASSERT_EQ( |
| 120 AudioProcessing::kNoError, |
| 121 apm->ProcessReverseStream(&buffers.render_input[0], stream_config, |
| 122 stream_config, &buffers.render_output[0])); |
| 123 |
| 124 render_timer.StopTimer(); |
| 125 |
| 126 capture_timer.StartTimer(); |
| 127 ASSERT_EQ(AudioProcessing::kNoError, apm->set_stream_delay_ms(0)); |
| 128 if (include_default_apm_processing) { |
| 129 apm->gain_control()->set_stream_analog_level(0); |
| 130 if (!use_mobile_aec) { |
| 131 apm->echo_cancellation()->set_stream_drift_samples(0); |
| 132 } |
| 133 } |
| 134 ASSERT_EQ(AudioProcessing::kNoError, |
| 135 apm->ProcessStream(&buffers.capture_input[0], stream_config, |
| 136 stream_config, &buffers.capture_output[0])); |
| 137 |
| 138 capture_timer.StopTimer(); |
| 139 total_timer.StopTimer(); |
| 140 } |
| 141 |
| 142 webrtc::test::PrintResultMeanAndError( |
| 143 "echo_detector_call_durations", "_render", test_description, |
| 144 FormPerformanceMeasureString(render_timer), "us", false); |
| 145 webrtc::test::PrintResultMeanAndError( |
| 146 "echo_detector_call_durations", "_capture", test_description, |
| 147 FormPerformanceMeasureString(capture_timer), "us", false); |
| 148 webrtc::test::PrintResultMeanAndError( |
| 149 "echo_detector_call_durations", "_total", test_description, |
| 150 FormPerformanceMeasureString(total_timer), "us", false); |
| 151 } |
| 152 |
| 153 } // namespace |
| 154 |
| 155 TEST(EchoDetectorPerformanceTest, StandaloneProcessing) { |
| 156 RunStandaloneSubmodule(); |
| 157 } |
| 158 |
| 159 TEST(EchoDetectorPerformanceTest, ProcessingViaApm) { |
| 160 RunTogetherWithApm("SimpleEchoDetectorViaApm", false, false); |
| 161 } |
| 162 |
| 163 TEST(EchoDetectorPerformanceTest, InteractionWithDefaultApm) { |
| 164 RunTogetherWithApm("EchoDetectorAndDefaultDesktopApm", false, true); |
| 165 RunTogetherWithApm("EchoDetectorAndDefaultMobileApm", true, true); |
| 166 } |
| 167 |
| 168 } // namespace webrtc |
OLD | NEW |