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

Side by Side Diff: webrtc/modules/audio_processing/aec3/echo_remover_metrics.cc

Issue 2722453002: Adding metrics to AEC3 (Closed)
Patch Set: Changed some of the names for the metrics Created 3 years, 9 months 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
(Empty)
1 /*
2 * Copyright (c) 2017 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 "webrtc/modules/audio_processing/aec3/echo_remover_metrics.h"
12
13 #include <math.h>
14 #include <algorithm>
15 #include <numeric>
16
17 #include "webrtc/system_wrappers/include/metrics.h"
18
19 namespace webrtc {
20
21 namespace {
22
23 constexpr float kOneByMetricsCollectionBlocks = 1.f / kMetricsCollectionBlocks;
24
25 } // namespace
26
27 EchoRemoverMetrics::DbMetric::DbMetric() : DbMetric(0.f, 0.f, 0.f) {}
28 EchoRemoverMetrics::DbMetric::DbMetric(float sum_value,
29 float floor_value,
30 float ceil_value)
31 : sum_value(sum_value), floor_value(floor_value), ceil_value(ceil_value) {}
32
33 void EchoRemoverMetrics::DbMetric::Update(float value) {
34 sum_value += value;
35 floor_value = std::min(floor_value, value);
36 ceil_value = std::max(ceil_value, value);
37 }
38
39 EchoRemoverMetrics::EchoRemoverMetrics() {
40 ResetMetrics();
41 }
42
43 void EchoRemoverMetrics::ResetMetrics() {
44 erl_.fill(DbMetric(0.f, 10000.f, 0.000f));
45 erle_.fill(DbMetric(0.f, 0.f, 1000.f));
46 comfort_noise_.fill(DbMetric(0.f, 100000000.f, 0.f));
47 suppressor_gain_.fill(DbMetric(0.f, 1.f, 0.f));
48 active_render_count_ = 0;
49 saturated_capture_ = false;
50 }
51
52 void EchoRemoverMetrics::Update(
53 const AecState& aec_state,
54 const std::array<float, kFftLengthBy2Plus1>& comfort_noise_spectrum,
55 const std::array<float, kFftLengthBy2Plus1>& suppressor_gain) {
56 metrics_reported_ = false;
57 if (++block_counter_ <= kMetricsCollectionBlocks) {
58 aec3::UpdateDbMetric(aec_state.Erl(), &erl_);
59 aec3::UpdateDbMetric(aec_state.Erle(), &erle_);
60 aec3::UpdateDbMetric(comfort_noise_spectrum, &comfort_noise_);
61 aec3::UpdateDbMetric(suppressor_gain, &suppressor_gain_);
62 active_render_count_ += (aec_state.ActiveRender() ? 1 : 0);
63 saturated_capture_ = saturated_capture_ || aec_state.SaturatedCapture();
64 } else {
65 // Report the metrics over several frames in order to lower the impact of
66 // the logarithms involved on the computational complexity.
67 constexpr int kMetricsCollectionBlocksBy2 = kMetricsCollectionBlocks / 2;
68 constexpr float kComfortNoiseScaling = 1.f / (kBlockSize * kBlockSize);
69 switch (block_counter_) {
70 case kMetricsCollectionBlocks + 1:
71 RTC_HISTOGRAM_COUNTS_LINEAR(
72 "WebRTC.Audio.EchoCanceller.ErleBand0.Average",
73 aec3::TransformDbMetricForReporting(true, 0.f, 19.f, 0.f,
74 kOneByMetricsCollectionBlocks,
75 erle_[0].sum_value),
76 0, 19, 20);
77 RTC_HISTOGRAM_COUNTS_LINEAR(
78 "WebRTC.Audio.EchoCanceller.ErleBand0.Max",
79 aec3::TransformDbMetricForReporting(true, 0.f, 19.f, 0.f, 1.f,
80 erle_[0].ceil_value),
81 0, 19, 20);
82 RTC_HISTOGRAM_COUNTS_LINEAR(
83 "WebRTC.Audio.EchoCanceller.ErleBand0.Min",
84 aec3::TransformDbMetricForReporting(true, 0.f, 19.f, 0.f, 1.f,
85 erle_[0].floor_value),
86 0, 19, 20);
87 break;
88 case kMetricsCollectionBlocks + 2:
89 RTC_HISTOGRAM_COUNTS_LINEAR(
90 "WebRTC.Audio.EchoCanceller.ErleBand1.Average",
91 aec3::TransformDbMetricForReporting(true, 0.f, 19.f, 0.f,
92 kOneByMetricsCollectionBlocks,
93 erle_[1].sum_value),
94 0, 19, 20);
95 RTC_HISTOGRAM_COUNTS_LINEAR(
96 "WebRTC.Audio.EchoCanceller.ErleBand1.Max",
97 aec3::TransformDbMetricForReporting(true, 0.f, 19.f, 0.f, 1.f,
98 erle_[1].ceil_value),
99 0, 19, 20);
100 RTC_HISTOGRAM_COUNTS_LINEAR(
101 "WebRTC.Audio.EchoCanceller.ErleBand1.Min",
102 aec3::TransformDbMetricForReporting(true, 0.f, 19.f, 0.f, 1.f,
103 erle_[1].floor_value),
104 0, 19, 20);
105 break;
106 case kMetricsCollectionBlocks + 3:
107 RTC_HISTOGRAM_COUNTS_LINEAR(
108 "WebRTC.Audio.EchoCanceller.ErlBand0.Average",
109 aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 30.f,
110 kOneByMetricsCollectionBlocks,
111 erl_[0].sum_value),
112 0, 59, 30);
113 RTC_HISTOGRAM_COUNTS_LINEAR(
114 "WebRTC.Audio.EchoCanceller.ErlBand0.Max",
115 aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 30.f, 1.f,
116 erl_[0].ceil_value),
117 0, 59, 30);
118 RTC_HISTOGRAM_COUNTS_LINEAR(
119 "WebRTC.Audio.EchoCanceller.ErlBand0.Min",
120 aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 30.f, 1.f,
121 erl_[0].floor_value),
122 0, 59, 30);
123 break;
124 case kMetricsCollectionBlocks + 4:
125 RTC_HISTOGRAM_COUNTS_LINEAR(
126 "WebRTC.Audio.EchoCanceller.ErlBand1.Average",
127 aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 30.f,
128 kOneByMetricsCollectionBlocks,
129 erl_[1].sum_value),
130 0, 59, 30);
131 RTC_HISTOGRAM_COUNTS_LINEAR(
132 "WebRTC.Audio.EchoCanceller.ErlBand1.Max",
133 aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 30.f, 1.f,
134 erl_[1].ceil_value),
135 0, 59, 30);
136 RTC_HISTOGRAM_COUNTS_LINEAR(
137 "WebRTC.Audio.EchoCanceller.ErlBand1.Min",
138 aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 30.f, 1.f,
139 erl_[1].floor_value),
140 0, 59, 30);
141 break;
142 case kMetricsCollectionBlocks + 5:
143 RTC_HISTOGRAM_COUNTS_LINEAR(
144 "WebRTC.Audio.EchoCanceller.ComfortNoiseBand0.Average",
145 aec3::TransformDbMetricForReporting(
146 true, 0.f, 89.f, -90.3f,
147 kComfortNoiseScaling * kOneByMetricsCollectionBlocks,
148 comfort_noise_[0].sum_value),
149 0, 89, 45);
150 RTC_HISTOGRAM_COUNTS_LINEAR(
151 "WebRTC.Audio.EchoCanceller.ComfortNoiseBand0.Max",
152 aec3::TransformDbMetricForReporting(true, 0.f, 89.f, -90.3f,
153 kComfortNoiseScaling,
154 comfort_noise_[0].ceil_value),
155 0, 89, 45);
156 RTC_HISTOGRAM_COUNTS_LINEAR(
157 "WebRTC.Audio.EchoCanceller.ComfortNoiseBand0.Min",
158 aec3::TransformDbMetricForReporting(true, 0.f, 89.f, -90.3f,
159 kComfortNoiseScaling,
160 comfort_noise_[0].floor_value),
161 0, 89, 45);
162 break;
163 case kMetricsCollectionBlocks + 6:
164 RTC_HISTOGRAM_COUNTS_LINEAR(
165 "WebRTC.Audio.EchoCanceller.ComfortNoiseBand1.Average",
166 aec3::TransformDbMetricForReporting(
167 true, 0.f, 89.f, -90.3f,
168 kComfortNoiseScaling * kOneByMetricsCollectionBlocks,
169 comfort_noise_[1].sum_value),
170 0, 89, 45);
171 RTC_HISTOGRAM_COUNTS_LINEAR(
172 "WebRTC.Audio.EchoCanceller.ComfortNoiseBand1.Max",
173 aec3::TransformDbMetricForReporting(true, 0.f, 89.f, -90.3f,
174 kComfortNoiseScaling,
175 comfort_noise_[1].ceil_value),
176 0, 89, 45);
177 RTC_HISTOGRAM_COUNTS_LINEAR(
178 "WebRTC.Audio.EchoCanceller.ComfortNoiseBand1.Min",
179 aec3::TransformDbMetricForReporting(true, 0.f, 89.f, -90.3f,
180 kComfortNoiseScaling,
181 comfort_noise_[1].floor_value),
182 0, 89, 45);
183 break;
184 case kMetricsCollectionBlocks + 7:
185 RTC_HISTOGRAM_COUNTS_LINEAR(
186 "WebRTC.Audio.EchoCanceller.SuppressorGainBand0.Average",
187 aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 0.f,
188 kOneByMetricsCollectionBlocks,
189 suppressor_gain_[0].sum_value),
190 0, 59, 30);
191 RTC_HISTOGRAM_COUNTS_LINEAR(
192 "WebRTC.Audio.EchoCanceller.SuppressorGainBand0.Max",
193 aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 0.f, 1.f,
194 suppressor_gain_[0].ceil_value),
195 0, 59, 30);
196 RTC_HISTOGRAM_COUNTS_LINEAR(
197 "WebRTC.Audio.EchoCanceller.SuppressorGainBand0.Min",
198 aec3::TransformDbMetricForReporting(
199 true, 0.f, 59.f, 0.f, 1.f, suppressor_gain_[0].floor_value),
200 0, 59, 30);
201 break;
202 case kMetricsCollectionBlocks + 8:
203 RTC_HISTOGRAM_COUNTS_LINEAR(
204 "WebRTC.Audio.EchoCanceller.SuppressorGainBand1.Average",
205 aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 0.f,
206 kOneByMetricsCollectionBlocks,
207 suppressor_gain_[1].sum_value),
208 0, 59, 30);
209 RTC_HISTOGRAM_COUNTS_LINEAR(
210 "WebRTC.Audio.EchoCanceller.SuppressorGainBand1.Max",
211 aec3::TransformDbMetricForReporting(true, 0.f, 59.f, 0.f, 1.f,
212 suppressor_gain_[1].ceil_value),
213 0, 59, 30);
214 RTC_HISTOGRAM_COUNTS_LINEAR(
215 "WebRTC.Audio.EchoCanceller.SuppressorGainBand1.Min",
216 aec3::TransformDbMetricForReporting(
217 true, 0.f, 59.f, 0.f, 1.f, suppressor_gain_[1].floor_value),
218 0, 59, 30);
219 break;
220 case kMetricsCollectionBlocks + 9:
221 RTC_HISTOGRAM_BOOLEAN(
222 "WebRTC.Audio.EchoCanceller.UsableLinearEstimate",
223 static_cast<int>(aec_state.UsableLinearEstimate() ? 1 : 0));
224 RTC_HISTOGRAM_BOOLEAN(
225 "WebRTC.Audio.EchoCanceller.ModelBasedAecFeasible",
226 static_cast<int>(aec_state.ModelBasedAecFeasible() ? 1 : 0));
227 RTC_HISTOGRAM_BOOLEAN(
228 "WebRTC.Audio.EchoCanceller.ActiveRender",
229 static_cast<int>(
230 active_render_count_ > kMetricsCollectionBlocksBy2 ? 1 : 0));
231 RTC_HISTOGRAM_COUNTS_LINEAR(
232 "WebRTC.Audio.EchoCanceller.FilterDelay",
233 aec_state.FilterDelay() ? *aec_state.FilterDelay() + 1 : 0, 0, 30,
234 31);
235 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.EchoCanceller.CaptureSaturation",
236 static_cast<int>(saturated_capture_ ? 1 : 0));
237 metrics_reported_ = true;
238 RTC_DCHECK_EQ(kMetricsReportingIntervalBlocks, block_counter_);
239 block_counter_ = 0;
240 ResetMetrics();
241 break;
242 default:
243 RTC_NOTREACHED();
244 break;
245 }
246 }
247 }
248
249 namespace aec3 {
250
251 void UpdateDbMetric(const std::array<float, kFftLengthBy2Plus1>& value,
252 std::array<EchoRemoverMetrics::DbMetric, 2>* statistic) {
253 RTC_DCHECK(statistic);
254 // Truncation is intended in the band width computation.
255 constexpr int kNumBands = 2;
256 constexpr int kBandWidth = 65 / kNumBands;
257 constexpr float kOneByBandWidth = 1.f / kBandWidth;
258 RTC_DCHECK_EQ(kNumBands, statistic->size());
259 RTC_DCHECK_EQ(65, value.size());
260 for (size_t k = 0; k < statistic->size(); ++k) {
261 float average_band =
262 std::accumulate(value.begin() + kBandWidth * k,
263 value.begin() + kBandWidth * (k + 1), 0.f) *
264 kOneByBandWidth;
265 (*statistic)[k].Update(average_band);
266 }
267 }
268
269 int TransformDbMetricForReporting(bool negate,
270 float min_value,
271 float max_value,
272 float offset,
273 float scaling,
274 float value) {
275 float new_value = 10.f * log10(value * scaling + 1e-10f) + offset;
276 if (negate) {
277 new_value = -new_value;
278 }
279 return static_cast<int>(std::max(min_value, std::min(max_value, new_value)));
280 }
281
282 } // namespace aec3
283
284 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698