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

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

Issue 2278393002: Added logging of the level controller metrics (Closed)
Patch Set: Rebase Created 4 years, 3 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
« no previous file with comments | « webrtc/modules/audio_processing/level_controller/level_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webrtc/modules/audio_processing/level_controller/level_controller.h" 11 #include "webrtc/modules/audio_processing/level_controller/level_controller.h"
12 12
13 #include <math.h> 13 #include <math.h>
14 #include <algorithm> 14 #include <algorithm>
15 #include <numeric> 15 #include <numeric>
16 16
17 #include "webrtc/base/array_view.h" 17 #include "webrtc/base/array_view.h"
18 #include "webrtc/base/arraysize.h" 18 #include "webrtc/base/arraysize.h"
19 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
20 #include "webrtc/modules/audio_processing/audio_buffer.h" 20 #include "webrtc/modules/audio_processing/audio_buffer.h"
21 #include "webrtc/modules/audio_processing/level_controller/gain_applier.h" 21 #include "webrtc/modules/audio_processing/level_controller/gain_applier.h"
22 #include "webrtc/modules/audio_processing/level_controller/gain_selector.h" 22 #include "webrtc/modules/audio_processing/level_controller/gain_selector.h"
23 #include "webrtc/modules/audio_processing/level_controller/noise_level_estimator .h" 23 #include "webrtc/modules/audio_processing/level_controller/noise_level_estimator .h"
24 #include "webrtc/modules/audio_processing/level_controller/peak_level_estimator. h" 24 #include "webrtc/modules/audio_processing/level_controller/peak_level_estimator. h"
25 #include "webrtc/modules/audio_processing/level_controller/saturating_gain_estim ator.h" 25 #include "webrtc/modules/audio_processing/level_controller/saturating_gain_estim ator.h"
26 #include "webrtc/modules/audio_processing/level_controller/signal_classifier.h" 26 #include "webrtc/modules/audio_processing/level_controller/signal_classifier.h"
27 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" 27 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
28 #include "webrtc/system_wrappers/include/logging.h"
28 #include "webrtc/system_wrappers/include/metrics.h" 29 #include "webrtc/system_wrappers/include/metrics.h"
29 30
30 namespace webrtc { 31 namespace webrtc {
31 namespace { 32 namespace {
32 33
33 void UpdateAndRemoveDcLevel(float forgetting_factor, 34 void UpdateAndRemoveDcLevel(float forgetting_factor,
34 float* dc_level, 35 float* dc_level,
35 rtc::ArrayView<float> x) { 36 rtc::ArrayView<float> x) {
36 RTC_DCHECK(!x.empty()); 37 RTC_DCHECK(!x.empty());
37 float mean = 38 float mean =
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 void LevelController::Metrics::Reset() { 87 void LevelController::Metrics::Reset() {
87 metrics_frame_counter_ = 0; 88 metrics_frame_counter_ = 0;
88 gain_sum_ = 0.f; 89 gain_sum_ = 0.f;
89 peak_level_sum_ = 0.f; 90 peak_level_sum_ = 0.f;
90 noise_energy_sum_ = 0.f; 91 noise_energy_sum_ = 0.f;
91 max_gain_ = 0.f; 92 max_gain_ = 0.f;
92 max_peak_level_ = 0.f; 93 max_peak_level_ = 0.f;
93 max_noise_energy_ = 0.f; 94 max_noise_energy_ = 0.f;
94 } 95 }
95 96
96 void LevelController::Metrics::Update(float peak_level, 97 void LevelController::Metrics::Update(float long_term_peak_level,
97 float noise_energy, 98 float noise_energy,
98 float gain) { 99 float gain,
100 float frame_peak_level) {
99 const float kdBFSOffset = 90.3090f; 101 const float kdBFSOffset = 90.3090f;
100 gain_sum_ += gain; 102 gain_sum_ += gain;
101 peak_level_sum_ += peak_level; 103 peak_level_sum_ += long_term_peak_level;
102 noise_energy_sum_ += noise_energy; 104 noise_energy_sum_ += noise_energy;
103 max_gain_ = std::max(max_gain_, gain); 105 max_gain_ = std::max(max_gain_, gain);
104 max_peak_level_ = std::max(max_peak_level_, peak_level); 106 max_peak_level_ = std::max(max_peak_level_, long_term_peak_level);
105 max_noise_energy_ = std::max(max_noise_energy_, noise_energy); 107 max_noise_energy_ = std::max(max_noise_energy_, noise_energy);
106 108
107 ++metrics_frame_counter_; 109 ++metrics_frame_counter_;
108 if (metrics_frame_counter_ == kMetricsFrameInterval) { 110 if (metrics_frame_counter_ == kMetricsFrameInterval) {
109 RTC_HISTOGRAM_COUNTS( 111 RTC_DCHECK_LT(0, frame_length_);
110 "WebRTC.Audio.LevelControl.MaxNoisePower", 112 RTC_DCHECK_LT(0, kMetricsFrameInterval);
111 static_cast<int>(10 * log10(max_noise_energy_ / frame_length_ + 1e-10f)
112 - kdBFSOffset),
113 -90, 0, 50);
114 RTC_HISTOGRAM_COUNTS(
115 "WebRTC.Audio.LevelControl.AverageNoisePower",
116 static_cast<int>(10 * log10(noise_energy_sum_ /
117 (frame_length_ * kMetricsFrameInterval) +
118 1e-10f) - kdBFSOffset),
119 -90, 0, 50);
120 113
121 RTC_HISTOGRAM_COUNTS( 114 const int max_noise_power_dbfs = static_cast<int>(
122 "WebRTC.Audio.LevelControl.MaxPeakLevel", 115 10 * log10(max_noise_energy_ / frame_length_ + 1e-10f) - kdBFSOffset);
123 static_cast<int>(10 * log10(max_peak_level_ * max_peak_level_ + 1e-10f) 116 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.LevelControl.MaxNoisePower",
124 - kdBFSOffset), 117 max_noise_power_dbfs, -90, 0, 50);
125 -90, 0, 50); 118
126 RTC_HISTOGRAM_COUNTS( 119 const int average_noise_power_dbfs = static_cast<int>(
127 "WebRTC.Audio.LevelControl.AveragePeakLevel", 120 10 * log10(noise_energy_sum_ / (frame_length_ * kMetricsFrameInterval) +
128 static_cast<int>(10 * log10(peak_level_sum_ * peak_level_sum_ / 121 1e-10f) -
129 (kMetricsFrameInterval * 122 kdBFSOffset);
130 kMetricsFrameInterval) + 123 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.LevelControl.AverageNoisePower",
131 1e-10f) - kdBFSOffset), 124 average_noise_power_dbfs, -90, 0, 50);
132 -90, 0, 50); 125
126 const int max_peak_level_dbfs = static_cast<int>(
127 10 * log10(max_peak_level_ * max_peak_level_ + 1e-10f) - kdBFSOffset);
128 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.LevelControl.MaxPeakLevel",
129 max_peak_level_dbfs, -90, 0, 50);
130
131 const int average_peak_level_dbfs = static_cast<int>(
132 10 * log10(peak_level_sum_ * peak_level_sum_ /
133 (kMetricsFrameInterval * kMetricsFrameInterval) +
134 1e-10f) -
135 kdBFSOffset);
136 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.LevelControl.AveragePeakLevel",
137 average_peak_level_dbfs, -90, 0, 50);
133 138
134 RTC_DCHECK_LE(1.f, max_gain_); 139 RTC_DCHECK_LE(1.f, max_gain_);
135 RTC_DCHECK_LE(1.f, gain_sum_ / kMetricsFrameInterval); 140 RTC_DCHECK_LE(1.f, gain_sum_ / kMetricsFrameInterval);
136 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.LevelControl.MaxGain", 141
137 static_cast<int>(10 * log10(max_gain_ * max_gain_)), 142 const int max_gain_db = static_cast<int>(10 * log10(max_gain_ * max_gain_));
138 0, 33, 30); 143 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.LevelControl.MaxGain", max_gain_db, 0,
144 33, 30);
145
146 const int average_gain_db = static_cast<int>(
147 10 * log10(gain_sum_ * gain_sum_ /
148 (kMetricsFrameInterval * kMetricsFrameInterval)));
139 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.LevelControl.AverageGain", 149 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.LevelControl.AverageGain",
140 static_cast<int>(10 * log10(gain_sum_ * gain_sum_ / 150 average_gain_db, 0, 33, 30);
141 (kMetricsFrameInterval * 151
142 kMetricsFrameInterval))), 152 const int long_term_peak_level_dbfs = static_cast<int>(
143 0, 33, 30); 153 10 * log10(long_term_peak_level * long_term_peak_level + 1e-10f) -
154 kdBFSOffset);
155
156 const int frame_peak_level_dbfs = static_cast<int>(
157 10 * log10(frame_peak_level * frame_peak_level + 1e-10f) - kdBFSOffset);
158
159 LOG(LS_INFO) << "Level Controller metrics: " << std::endl
160 << "Max noise power: " << max_noise_power_dbfs
161 << " dBFS" << std::endl
162 << "Average noise power: " << average_noise_power_dbfs
163 << " dBFS" << std::endl
164 << "Max long term peak level: " << max_peak_level_dbfs
165 << " dBFS" << std::endl
166 << "Average long term peak level: " << average_peak_level_dbfs
167 << " dBFS" << std::endl
168 << "Max gain: " << max_gain_db << " dB"
169 << std::endl
170 << "Average gain: " << average_gain_db << " dB"
171 << std::endl
172 << "Long term peak level: "
173 << long_term_peak_level_dbfs << " dBFS" << std::endl
174 << "Last frame peak level: " << frame_peak_level_dbfs
175 << " dBFS";
176
144 Reset(); 177 Reset();
145 } 178 }
146 } 179 }
147 180
148 LevelController::LevelController() 181 LevelController::LevelController()
149 : data_dumper_(new ApmDataDumper(instance_count_)), 182 : data_dumper_(new ApmDataDumper(instance_count_)),
150 gain_applier_(data_dumper_.get()), 183 gain_applier_(data_dumper_.get()),
151 signal_classifier_(data_dumper_.get()) { 184 signal_classifier_(data_dumper_.get()) {
152 Initialize(AudioProcessing::kSampleRate48kHz); 185 Initialize(AudioProcessing::kSampleRate48kHz);
153 ++instance_count_; 186 ++instance_count_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 SignalClassifier::SignalType signal_type; 226 SignalClassifier::SignalType signal_type;
194 signal_classifier_.Analyze(*audio, &signal_type); 227 signal_classifier_.Analyze(*audio, &signal_type);
195 int tmp = static_cast<int>(signal_type); 228 int tmp = static_cast<int>(signal_type);
196 data_dumper_->DumpRaw("lc_signal_type", 1, &tmp); 229 data_dumper_->DumpRaw("lc_signal_type", 1, &tmp);
197 230
198 // Estimate the noise energy. 231 // Estimate the noise energy.
199 float noise_energy = 232 float noise_energy =
200 noise_level_estimator_.Analyze(signal_type, FrameEnergy(*audio)); 233 noise_level_estimator_.Analyze(signal_type, FrameEnergy(*audio));
201 234
202 // Estimate the overall signal peak level. 235 // Estimate the overall signal peak level.
203 float peak_level = 236 const float frame_peak_level = PeakLevel(*audio);
204 peak_level_estimator_.Analyze(signal_type, PeakLevel(*audio)); 237 const float long_term_peak_level =
238 peak_level_estimator_.Analyze(signal_type, frame_peak_level);
205 239
206 float saturating_gain = saturating_gain_estimator_.GetGain(); 240 float saturating_gain = saturating_gain_estimator_.GetGain();
207 241
208 // Compute the new gain to apply. 242 // Compute the new gain to apply.
209 last_gain_ = gain_selector_.GetNewGain(peak_level, noise_energy, 243 last_gain_ = gain_selector_.GetNewGain(long_term_peak_level, noise_energy,
210 saturating_gain, signal_type); 244 saturating_gain, signal_type);
211 245
212 // Apply the gain to the signal. 246 // Apply the gain to the signal.
213 int num_saturations = gain_applier_.Process(last_gain_, audio); 247 int num_saturations = gain_applier_.Process(last_gain_, audio);
214 248
215 // Estimate the gain that saturates the overall signal. 249 // Estimate the gain that saturates the overall signal.
216 saturating_gain_estimator_.Update(last_gain_, num_saturations); 250 saturating_gain_estimator_.Update(last_gain_, num_saturations);
217 251
218 // Update the metrics. 252 // Update the metrics.
219 metrics_.Update(peak_level, noise_energy, last_gain_); 253 metrics_.Update(long_term_peak_level, noise_energy, last_gain_,
254 frame_peak_level);
220 255
221 data_dumper_->DumpRaw("lc_selected_gain", 1, &last_gain_); 256 data_dumper_->DumpRaw("lc_selected_gain", 1, &last_gain_);
222 data_dumper_->DumpRaw("lc_noise_energy", 1, &noise_energy); 257 data_dumper_->DumpRaw("lc_noise_energy", 1, &noise_energy);
223 data_dumper_->DumpRaw("lc_peak_level", 1, &peak_level); 258 data_dumper_->DumpRaw("lc_peak_level", 1, &long_term_peak_level);
224 data_dumper_->DumpRaw("lc_saturating_gain", 1, &saturating_gain); 259 data_dumper_->DumpRaw("lc_saturating_gain", 1, &saturating_gain);
225 260
226 data_dumper_->DumpWav("lc_output", audio->num_frames(), 261 data_dumper_->DumpWav("lc_output", audio->num_frames(),
227 audio->channels_f()[0], *sample_rate_hz_, 1); 262 audio->channels_f()[0], *sample_rate_hz_, 1);
228 } 263 }
229 264
230 } // namespace webrtc 265 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/level_controller/level_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698