Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 void EchoRemoverMetrics::DbMetric::FormatForReporting(bool negate, | |
| 40 float min_value, | |
| 41 float max_value, | |
| 42 float offset, | |
| 43 float scaling) { | |
| 44 aec3::TransformDbMetricForReporting(negate, min_value, max_value, offset, | |
| 45 scaling * kOneByMetricsCollectionBlocks, | |
| 46 &sum_value); | |
| 47 aec3::TransformDbMetricForReporting(negate, min_value, max_value, offset, | |
| 48 scaling, &ceil_value); | |
| 49 aec3::TransformDbMetricForReporting(negate, min_value, max_value, offset, | |
| 50 scaling, &floor_value); | |
| 51 } | |
| 52 | |
| 53 EchoRemoverMetrics::EchoRemoverMetrics() { | |
| 54 ResetMetrics(); | |
| 55 } | |
| 56 | |
| 57 void EchoRemoverMetrics::ResetMetrics() { | |
| 58 erl_.fill(DbMetric(0.f, 10000.f, 0.000f)); | |
| 59 erle_.fill(DbMetric(0.f, 0.f, 1000.f)); | |
| 60 comfort_noise_.fill(DbMetric(0.f, 100000000.f, 0.f)); | |
| 61 suppressor_gain_.fill(DbMetric(0.f, 1.f, 0.f)); | |
| 62 active_render_ = 0; | |
| 63 saturated_capture_ = false; | |
| 64 } | |
| 65 | |
| 66 void EchoRemoverMetrics::Update( | |
| 67 const AecState& aec_state, | |
| 68 const std::array<float, kFftLengthBy2Plus1>& comfort_noise_spectrum, | |
| 69 const std::array<float, kFftLengthBy2Plus1>& suppressor_gain) { | |
| 70 if (++block_counter_ <= kMetricsCollectionBlocks) { | |
| 71 aec3::UpdateDbMetric(aec_state.Erl(), &erl_); | |
| 72 aec3::UpdateDbMetric(aec_state.Erle(), &erle_); | |
| 73 aec3::UpdateDbMetric(comfort_noise_spectrum, &comfort_noise_); | |
| 74 aec3::UpdateDbMetric(suppressor_gain, &suppressor_gain_); | |
| 75 active_render_ += (aec_state.ActiveRender() ? 1 : 0); | |
|
hlundin-webrtc
2017/02/28 10:04:23
active_render_count_
peah-webrtc
2017/02/28 12:57:25
Done.
| |
| 76 saturated_capture_ = saturated_capture_ || aec_state.SaturatedCapture(); | |
| 77 } else { | |
| 78 // Report the metrics over several frames in order to lower the impact of | |
| 79 // the logarithms involved on the computational complexity. | |
| 80 constexpr int kMetricsCollectionBlocksBy2 = kMetricsCollectionBlocks / 2; | |
| 81 constexpr float kComfortNoiseScaling = 1.f / (kBlockSize * kBlockSize); | |
| 82 switch (block_counter_) { | |
| 83 case kMetricsCollectionBlocks + 1: | |
| 84 erle_[0].FormatForReporting(true, 0.f, 19.f, 0.f, 1.f); | |
| 85 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 86 "WebRTC.Audio.EchoCanceller.AverageErleBand0", | |
| 87 static_cast<int>(erle_[0].sum_value), 0, 19, 20); | |
| 88 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.EchoCanceller.MaxErleBand0", | |
| 89 static_cast<int>(erle_[0].ceil_value), 0, | |
| 90 19, 20); | |
| 91 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.EchoCanceller.MinErleBand0", | |
| 92 static_cast<int>(erle_[0].floor_value), 0, | |
| 93 19, 20); | |
| 94 break; | |
| 95 case kMetricsCollectionBlocks + 2: | |
| 96 erle_[1].FormatForReporting(true, 0.f, 19.f, 0.f, 1.f); | |
| 97 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 98 "WebRTC.Audio.EchoCanceller.AverageErleBand1", | |
| 99 static_cast<int>(erle_[1].sum_value), 0, 19, 20); | |
| 100 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.EchoCanceller.MaxErleBand1", | |
| 101 static_cast<int>(erle_[1].ceil_value), 0, | |
| 102 19, 20); | |
| 103 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.EchoCanceller.MinErleBand1", | |
| 104 static_cast<int>(erle_[1].floor_value), 0, | |
| 105 19, 20); | |
| 106 break; | |
| 107 case kMetricsCollectionBlocks + 3: | |
| 108 erl_[0].FormatForReporting(true, 0.f, 59.f, 30.f, 1.f); | |
| 109 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 110 "WebRTC.Audio.EchoCanceller.AverageErlBand0", | |
| 111 static_cast<int>(erl_[0].sum_value), 0, 59, 30); | |
| 112 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.EchoCanceller.MaxErlBand0", | |
| 113 static_cast<int>(erl_[0].ceil_value), 0, 59, | |
| 114 30); | |
| 115 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.EchoCanceller.MinErlBand0", | |
| 116 static_cast<int>(erl_[0].floor_value), 0, | |
| 117 59, 30); | |
| 118 break; | |
| 119 case kMetricsCollectionBlocks + 4: | |
| 120 erl_[1].FormatForReporting(true, 0.f, 59.f, 30.f, 1.f); | |
| 121 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 122 "WebRTC.Audio.EchoCanceller.AverageErlBand1", | |
| 123 static_cast<int>(erl_[1].sum_value), 0, 59, 30); | |
| 124 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.EchoCanceller.MaxErlBand1", | |
| 125 static_cast<int>(erl_[1].ceil_value), 0, 59, | |
| 126 30); | |
| 127 RTC_HISTOGRAM_COUNTS_LINEAR("WebRTC.Audio.EchoCanceller.MinErlBand1", | |
| 128 static_cast<int>(erl_[1].floor_value), 0, | |
| 129 59, 30); | |
| 130 break; | |
| 131 case kMetricsCollectionBlocks + 5: | |
| 132 comfort_noise_[0].FormatForReporting(true, 0.f, 89.f, -90.3f, | |
| 133 kComfortNoiseScaling); | |
| 134 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 135 "WebRTC.Audio.EchoCanceller.AverageComfortNoiseBand0", | |
| 136 comfort_noise_[0].sum_value, 0, 89, 45); | |
| 137 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 138 "WebRTC.Audio.EchoCanceller.MaxComfortNoiseBand0", | |
| 139 comfort_noise_[0].ceil_value, 0, 89, 45); | |
| 140 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 141 "WebRTC.Audio.EchoCanceller.MinComfortNoiseBand0", | |
| 142 comfort_noise_[0].floor_value, 0, 89, 45); | |
| 143 break; | |
| 144 case kMetricsCollectionBlocks + 6: | |
| 145 comfort_noise_[1].FormatForReporting(true, 0.f, 89.f, -90.3f, | |
| 146 kComfortNoiseScaling); | |
| 147 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 148 "WebRTC.Audio.EchoCanceller.AverageComfortNoiseBand1", | |
| 149 comfort_noise_[1].sum_value, 0, 89, 45); | |
| 150 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 151 "WebRTC.Audio.EchoCanceller.MaxComfortNoiseBand1", | |
| 152 comfort_noise_[1].ceil_value, 0, 89, 45); | |
| 153 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 154 "WebRTC.Audio.EchoCanceller.MinComfortNoiseBand1", | |
| 155 comfort_noise_[1].floor_value, 0, 89, 45); | |
| 156 break; | |
| 157 case kMetricsCollectionBlocks + 7: | |
| 158 suppressor_gain_[0].FormatForReporting(true, 0.f, 59.f, 0.f, 1.f); | |
| 159 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 160 "WebRTC.Audio.EchoCanceller.AverageSuppressorGainBand0", | |
| 161 suppressor_gain_[0].sum_value, 0, 59, 30); | |
| 162 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 163 "WebRTC.Audio.EchoCanceller.MaxSuppressorGainBand0", | |
| 164 suppressor_gain_[0].ceil_value, 0, 59, 30); | |
| 165 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 166 "WebRTC.Audio.EchoCanceller.MinSuppressorGainBand0", | |
| 167 suppressor_gain_[0].floor_value, 0, 59, 30); | |
| 168 break; | |
| 169 case kMetricsCollectionBlocks + 8: | |
| 170 suppressor_gain_[1].FormatForReporting(true, 0.f, 59.f, 0.f, 1.f); | |
| 171 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 172 "WebRTC.Audio.EchoCanceller.AverageSuppressorGainBand1", | |
| 173 suppressor_gain_[1].sum_value, 0, 59, 30); | |
| 174 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 175 "WebRTC.Audio.EchoCanceller.MaxSuppressorGainBand1", | |
| 176 suppressor_gain_[1].ceil_value, 0, 59, 30); | |
| 177 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 178 "WebRTC.Audio.EchoCanceller.MinSuppressorGainBand1", | |
| 179 suppressor_gain_[1].floor_value, 0, 59, 30); | |
| 180 break; | |
| 181 case kMetricsCollectionBlocks + 9: | |
| 182 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 183 "WebRTC.Audio.EchoCanceller.UsableLinearEstimate", | |
| 184 aec_state.UsableLinearEstimate() ? 1 : 0, 0, 1, 2); | |
| 185 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 186 "WebRTC.Audio.EchoCanceller.ModelBasedAecFeasible", | |
| 187 aec_state.ModelBasedAecFeasible() ? 1 : 0, 0, 1, 2); | |
| 188 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 189 "WebRTC.Audio.EchoCanceller.ActiveRender", | |
| 190 active_render_ > kMetricsCollectionBlocksBy2 ? 1 : 0, 0, 1, 2); | |
| 191 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 192 "WebRTC.Audio.EchoCanceller.FilterDelay", | |
| 193 aec_state.FilterDelay() ? *aec_state.FilterDelay() + 1 : 0, 0, 30, | |
| 194 31); | |
| 195 RTC_HISTOGRAM_COUNTS_LINEAR( | |
| 196 "WebRTC.Audio.EchoCanceller.CaptureSaturation", | |
| 197 saturated_capture_ ? 1 : 0, 0, 1, 2); | |
| 198 metric_reported_ = true; | |
| 199 break; | |
| 200 case kMetricsCollectionBlocks + 10: | |
| 201 RTC_DCHECK_EQ(kMetricsReportingInterval, block_counter_); | |
|
hlundin-webrtc
2017/02/28 10:04:23
So every 11 times you are not reporting anything.
peah-webrtc
2017/02/28 12:57:26
Done.
| |
| 202 block_counter_ = 0; | |
| 203 ResetMetrics(); | |
| 204 metric_reported_ = false; | |
| 205 break; | |
| 206 default: | |
| 207 RTC_NOTREACHED(); | |
| 208 break; | |
| 209 } | |
| 210 } | |
| 211 } | |
| 212 | |
| 213 namespace aec3 { | |
| 214 | |
| 215 void UpdateDbMetric(const std::array<float, kFftLengthBy2Plus1>& value, | |
| 216 std::array<EchoRemoverMetrics::DbMetric, 2>* statistic) { | |
| 217 RTC_DCHECK(statistic); | |
| 218 // Truncation is intended in the band width computation. | |
| 219 constexpr int kNumBands = 2; | |
| 220 constexpr int kBandWidth = 65 / kNumBands; | |
| 221 constexpr float kOneByBandWidth = 1.f / kBandWidth; | |
| 222 RTC_DCHECK_EQ(kNumBands, statistic->size()); | |
| 223 RTC_DCHECK_EQ(65, value.size()); | |
| 224 for (size_t k = 0; k < statistic->size(); ++k) { | |
| 225 float average_band = | |
| 226 std::accumulate(value.begin() + kBandWidth * k, | |
| 227 value.begin() + kBandWidth * (k + 1), 0.f) * | |
| 228 kOneByBandWidth; | |
| 229 (*statistic)[k].Update(average_band); | |
| 230 } | |
| 231 } | |
| 232 | |
| 233 void TransformDbMetricForReporting(bool negate, | |
|
hlundin-webrtc
2017/02/28 10:04:23
I'm not fond of this method altering the value. Ca
peah-webrtc
2017/02/28 12:57:26
Done.
| |
| 234 float min_value, | |
| 235 float max_value, | |
| 236 float offset, | |
| 237 float scaleing, | |
|
hlundin-webrtc
2017/02/28 10:04:23
scaleing -> scaling
peah-webrtc
2017/02/28 12:57:26
Done.
| |
| 238 float* value) { | |
| 239 RTC_DCHECK(value); | |
| 240 *value = 10.f * log10((*value) * scaleing + 1e-10f) + offset; | |
| 241 if (negate) { | |
| 242 *value = -*value; | |
| 243 } | |
| 244 *value = std::max(min_value, std::min(max_value, *value)); | |
| 245 } | |
| 246 | |
| 247 } // namespace aec3 | |
| 248 | |
| 249 } // namespace webrtc | |
| OLD | NEW |