Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: webrtc/modules/audio_processing/level_controller/level_controller_complexity_unittest.cc

Issue 2517523003: Added a perf test for the residual echo detector. (Closed)
Patch Set: Replaced <algorithm> by <numeric>. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <numeric> 11 #include <numeric>
12 #include <vector> 12 #include <vector>
13 13
14 #include "webrtc/base/array_view.h" 14 #include "webrtc/base/array_view.h"
15 #include "webrtc/base/random.h" 15 #include "webrtc/base/random.h"
16 #include "webrtc/modules/audio_processing/audio_buffer.h" 16 #include "webrtc/modules/audio_processing/audio_buffer.h"
17 #include "webrtc/modules/audio_processing/include/audio_processing.h" 17 #include "webrtc/modules/audio_processing/include/audio_processing.h"
18 #include "webrtc/modules/audio_processing/level_controller/level_controller.h" 18 #include "webrtc/modules/audio_processing/level_controller/level_controller.h"
19 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h" 19 #include "webrtc/modules/audio_processing/test/audio_buffer_tools.h"
20 #include "webrtc/modules/audio_processing/test/bitexactness_tools.h" 20 #include "webrtc/modules/audio_processing/test/bitexactness_tools.h"
21 #include "webrtc/modules/audio_processing/test/performance_timer.h"
22 #include "webrtc/modules/audio_processing/test/simulator_buffers.h"
21 #include "webrtc/system_wrappers/include/clock.h" 23 #include "webrtc/system_wrappers/include/clock.h"
22 #include "webrtc/test/gtest.h" 24 #include "webrtc/test/gtest.h"
23 #include "webrtc/test/testsupport/perf_test.h" 25 #include "webrtc/test/testsupport/perf_test.h"
24 26
25 namespace webrtc { 27 namespace webrtc {
26 namespace { 28 namespace {
27 29
28 const size_t kNumFramesToProcess = 100; 30 const size_t kNumFramesToProcess = 100;
29 31
30 struct SimulatorBuffers { 32 std::string FormPerformanceMeasureString(const test::PerformanceTimer& timer) {
31 SimulatorBuffers(int render_input_sample_rate_hz,
32 int capture_input_sample_rate_hz,
33 int render_output_sample_rate_hz,
34 int capture_output_sample_rate_hz,
35 size_t num_render_input_channels,
36 size_t num_capture_input_channels,
37 size_t num_render_output_channels,
38 size_t num_capture_output_channels) {
39 Random rand_gen(42);
40 CreateConfigAndBuffer(render_input_sample_rate_hz,
41 num_render_input_channels, &rand_gen,
42 &render_input_buffer, &render_input_config,
43 &render_input, &render_input_samples);
44
45 CreateConfigAndBuffer(render_output_sample_rate_hz,
46 num_render_output_channels, &rand_gen,
47 &render_output_buffer, &render_output_config,
48 &render_output, &render_output_samples);
49
50 CreateConfigAndBuffer(capture_input_sample_rate_hz,
51 num_capture_input_channels, &rand_gen,
52 &capture_input_buffer, &capture_input_config,
53 &capture_input, &capture_input_samples);
54
55 CreateConfigAndBuffer(capture_output_sample_rate_hz,
56 num_capture_output_channels, &rand_gen,
57 &capture_output_buffer, &capture_output_config,
58 &capture_output, &capture_output_samples);
59
60 UpdateInputBuffers();
61 }
62
63 void CreateConfigAndBuffer(int sample_rate_hz,
64 size_t num_channels,
65 Random* rand_gen,
66 std::unique_ptr<AudioBuffer>* buffer,
67 StreamConfig* config,
68 std::vector<float*>* buffer_data,
69 std::vector<float>* buffer_data_samples) {
70 int samples_per_channel = rtc::CheckedDivExact(sample_rate_hz, 100);
71 *config = StreamConfig(sample_rate_hz, num_channels, false);
72 buffer->reset(new AudioBuffer(config->num_frames(), config->num_channels(),
73 config->num_frames(), config->num_channels(),
74 config->num_frames()));
75
76 buffer_data_samples->resize(samples_per_channel * num_channels);
77 for (auto& v : *buffer_data_samples) {
78 v = rand_gen->Rand<float>();
79 }
80
81 buffer_data->resize(num_channels);
82 for (size_t ch = 0; ch < num_channels; ++ch) {
83 (*buffer_data)[ch] = &(*buffer_data_samples)[ch * samples_per_channel];
84 }
85 }
86
87 void UpdateInputBuffers() {
88 test::CopyVectorToAudioBuffer(capture_input_config, capture_input_samples,
89 capture_input_buffer.get());
90 test::CopyVectorToAudioBuffer(render_input_config, render_input_samples,
91 render_input_buffer.get());
92 }
93
94 std::unique_ptr<AudioBuffer> render_input_buffer;
95 std::unique_ptr<AudioBuffer> capture_input_buffer;
96 std::unique_ptr<AudioBuffer> render_output_buffer;
97 std::unique_ptr<AudioBuffer> capture_output_buffer;
98 StreamConfig render_input_config;
99 StreamConfig capture_input_config;
100 StreamConfig render_output_config;
101 StreamConfig capture_output_config;
102 std::vector<float*> render_input;
103 std::vector<float> render_input_samples;
104 std::vector<float*> capture_input;
105 std::vector<float> capture_input_samples;
106 std::vector<float*> render_output;
107 std::vector<float> render_output_samples;
108 std::vector<float*> capture_output;
109 std::vector<float> capture_output_samples;
110 };
111
112 class SubmodulePerformanceTimer {
113 public:
114 SubmodulePerformanceTimer() : clock_(webrtc::Clock::GetRealTimeClock()) {
115 timestamps_us_.reserve(kNumFramesToProcess);
116 }
117
118 void StartTimer() {
119 start_timestamp_us_ = rtc::Optional<int64_t>(clock_->TimeInMicroseconds());
120 }
121 void StopTimer() {
122 RTC_DCHECK(start_timestamp_us_);
123 timestamps_us_.push_back(clock_->TimeInMicroseconds() -
124 *start_timestamp_us_);
125 }
126
127 double GetDurationAverage() const {
128 RTC_DCHECK(!timestamps_us_.empty());
129 return static_cast<double>(std::accumulate(timestamps_us_.begin(),
130 timestamps_us_.end(), 0)) /
131 timestamps_us_.size();
132 }
133
134 double GetDurationStandardDeviation() const {
135 RTC_DCHECK(!timestamps_us_.empty());
136 double average_duration = GetDurationAverage();
137
138 double variance = std::accumulate(
139 timestamps_us_.begin(), timestamps_us_.end(), 0.0,
140 [average_duration](const double& a, const int64_t& b) {
141 return a + (b - average_duration) * (b - average_duration);
142 });
143
144 return sqrt(variance / timestamps_us_.size());
145 }
146
147 private:
148 webrtc::Clock* clock_;
149 rtc::Optional<int64_t> start_timestamp_us_;
150 std::vector<int64_t> timestamps_us_;
151 };
152
153 std::string FormPerformanceMeasureString(
154 const SubmodulePerformanceTimer& timer) {
155 std::string s = std::to_string(timer.GetDurationAverage()); 33 std::string s = std::to_string(timer.GetDurationAverage());
156 s += ", "; 34 s += ", ";
157 s += std::to_string(timer.GetDurationStandardDeviation()); 35 s += std::to_string(timer.GetDurationStandardDeviation());
158 return s; 36 return s;
159 } 37 }
160 38
161 void RunStandaloneSubmodule(int sample_rate_hz, size_t num_channels) { 39 void RunStandaloneSubmodule(int sample_rate_hz, size_t num_channels) {
162 SimulatorBuffers buffers(sample_rate_hz, sample_rate_hz, sample_rate_hz, 40 test::SimulatorBuffers buffers(sample_rate_hz, sample_rate_hz, sample_rate_hz,
163 sample_rate_hz, num_channels, num_channels, 41 sample_rate_hz, num_channels, num_channels,
164 num_channels, num_channels); 42 num_channels, num_channels);
165 SubmodulePerformanceTimer timer; 43 test::PerformanceTimer timer(kNumFramesToProcess);
166 44
167 LevelController level_controller; 45 LevelController level_controller;
168 level_controller.Initialize(sample_rate_hz); 46 level_controller.Initialize(sample_rate_hz);
169 47
170 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) { 48 for (size_t frame_no = 0; frame_no < kNumFramesToProcess; ++frame_no) {
171 buffers.UpdateInputBuffers(); 49 buffers.UpdateInputBuffers();
172 50
173 timer.StartTimer(); 51 timer.StartTimer();
174 level_controller.Process(buffers.capture_input_buffer.get()); 52 level_controller.Process(buffers.capture_input_buffer.get());
175 timer.StopTimer(); 53 timer.StopTimer();
176 } 54 }
177 webrtc::test::PrintResultMeanAndError( 55 webrtc::test::PrintResultMeanAndError(
178 "level_controller_call_durations", 56 "level_controller_call_durations",
179 "_" + std::to_string(sample_rate_hz) + "Hz_" + 57 "_" + std::to_string(sample_rate_hz) + "Hz_" +
180 std::to_string(num_channels) + "_channels", 58 std::to_string(num_channels) + "_channels",
181 "StandaloneLevelControl", FormPerformanceMeasureString(timer), "us", 59 "StandaloneLevelControl", FormPerformanceMeasureString(timer), "us",
182 false); 60 false);
183 } 61 }
184 62
185 void RunTogetherWithApm(std::string test_description, 63 void RunTogetherWithApm(std::string test_description,
186 int render_input_sample_rate_hz, 64 int render_input_sample_rate_hz,
187 int render_output_sample_rate_hz, 65 int render_output_sample_rate_hz,
188 int capture_input_sample_rate_hz, 66 int capture_input_sample_rate_hz,
189 int capture_output_sample_rate_hz, 67 int capture_output_sample_rate_hz,
190 size_t num_channels, 68 size_t num_channels,
191 bool use_mobile_aec, 69 bool use_mobile_aec,
192 bool include_default_apm_processing) { 70 bool include_default_apm_processing) {
193 SimulatorBuffers buffers( 71 test::SimulatorBuffers buffers(
194 render_input_sample_rate_hz, capture_input_sample_rate_hz, 72 render_input_sample_rate_hz, capture_input_sample_rate_hz,
195 render_output_sample_rate_hz, capture_output_sample_rate_hz, num_channels, 73 render_output_sample_rate_hz, capture_output_sample_rate_hz, num_channels,
196 num_channels, num_channels, num_channels); 74 num_channels, num_channels, num_channels);
197 SubmodulePerformanceTimer render_timer; 75 test::PerformanceTimer render_timer(kNumFramesToProcess);
198 SubmodulePerformanceTimer capture_timer; 76 test::PerformanceTimer capture_timer(kNumFramesToProcess);
199 SubmodulePerformanceTimer total_timer; 77 test::PerformanceTimer total_timer(kNumFramesToProcess);
200 78
201 webrtc::Config config; 79 webrtc::Config config;
202 AudioProcessing::Config apm_config; 80 AudioProcessing::Config apm_config;
203 if (include_default_apm_processing) { 81 if (include_default_apm_processing) {
204 config.Set<DelayAgnostic>(new DelayAgnostic(true)); 82 config.Set<DelayAgnostic>(new DelayAgnostic(true));
205 config.Set<ExtendedFilter>(new ExtendedFilter(true)); 83 config.Set<ExtendedFilter>(new ExtendedFilter(true));
206 } 84 }
207 apm_config.level_controller.enabled = true; 85 apm_config.level_controller.enabled = true;
208 apm_config.residual_echo_detector.enabled = include_default_apm_processing; 86 apm_config.residual_echo_detector.enabled = include_default_apm_processing;
209 87
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 RunTogetherWithApm("LevelControlAndDefaultMobileApm", 48000, 48000, 224 RunTogetherWithApm("LevelControlAndDefaultMobileApm", 48000, 48000,
347 capture_input_sample_rate_hz, 225 capture_input_sample_rate_hz,
348 capture_output_sample_rate_hz, num_channels, true, 226 capture_output_sample_rate_hz, num_channels, true,
349 true); 227 true);
350 } 228 }
351 } 229 }
352 } 230 }
353 } 231 }
354 232
355 } // namespace webrtc 233 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698