OLD | NEW |
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" | |
29 #include "webrtc/system_wrappers/include/metrics.h" | 28 #include "webrtc/system_wrappers/include/metrics.h" |
30 | 29 |
31 namespace webrtc { | 30 namespace webrtc { |
32 namespace { | 31 namespace { |
33 | 32 |
34 void UpdateAndRemoveDcLevel(float forgetting_factor, | 33 void UpdateAndRemoveDcLevel(float forgetting_factor, |
35 float* dc_level, | 34 float* dc_level, |
36 rtc::ArrayView<float> x) { | 35 rtc::ArrayView<float> x) { |
37 RTC_DCHECK(!x.empty()); | 36 RTC_DCHECK(!x.empty()); |
38 float mean = | 37 float mean = |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.LevelControl.AverageGain", | 148 RTC_HISTOGRAM_COUNTS("WebRTC.Audio.LevelControl.AverageGain", |
150 average_gain_db, 0, 33, 30); | 149 average_gain_db, 0, 33, 30); |
151 | 150 |
152 const int long_term_peak_level_dbfs = static_cast<int>( | 151 const int long_term_peak_level_dbfs = static_cast<int>( |
153 10 * log10(long_term_peak_level * long_term_peak_level + 1e-10f) - | 152 10 * log10(long_term_peak_level * long_term_peak_level + 1e-10f) - |
154 kdBFSOffset); | 153 kdBFSOffset); |
155 | 154 |
156 const int frame_peak_level_dbfs = static_cast<int>( | 155 const int frame_peak_level_dbfs = static_cast<int>( |
157 10 * log10(frame_peak_level * frame_peak_level + 1e-10f) - kdBFSOffset); | 156 10 * log10(frame_peak_level * frame_peak_level + 1e-10f) - kdBFSOffset); |
158 | 157 |
159 LOG(LS_INFO) << "Level Controller metrics: {" | 158 (void) long_term_peak_level_dbfs; |
160 << "Max noise power: " << max_noise_power_dbfs << " dBFS, " | 159 (void) frame_peak_level_dbfs; |
161 << "Average noise power: " << average_noise_power_dbfs | |
162 << " dBFS, " | |
163 << "Max long term peak level: " << max_peak_level_dbfs | |
164 << " dBFS, " | |
165 << "Average long term peak level: " << average_peak_level_dbfs | |
166 << " dBFS, " | |
167 << "Max gain: " << max_gain_db << " dB, " | |
168 << "Average gain: " << average_gain_db << " dB, " | |
169 << "Long term peak level: " << long_term_peak_level_dbfs | |
170 << " dBFS, " | |
171 << "Last frame peak level: " << frame_peak_level_dbfs | |
172 << " dBFS" | |
173 << "}"; | |
174 | |
175 Reset(); | 160 Reset(); |
176 } | 161 } |
177 } | 162 } |
178 | 163 |
179 LevelController::LevelController() | 164 LevelController::LevelController() |
180 : data_dumper_(new ApmDataDumper(instance_count_)), | 165 : data_dumper_(new ApmDataDumper(instance_count_)), |
181 gain_applier_(data_dumper_.get()), | 166 gain_applier_(data_dumper_.get()), |
182 signal_classifier_(data_dumper_.get()), | 167 signal_classifier_(data_dumper_.get()), |
183 peak_level_estimator_(kTargetLcPeakLeveldBFS) { | 168 peak_level_estimator_(kTargetLcPeakLeveldBFS) { |
184 Initialize(AudioProcessing::kSampleRate48kHz); | 169 Initialize(AudioProcessing::kSampleRate48kHz); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 269 |
285 bool LevelController::Validate( | 270 bool LevelController::Validate( |
286 const AudioProcessing::Config::LevelController& config) { | 271 const AudioProcessing::Config::LevelController& config) { |
287 return (config.initial_peak_level_dbfs < | 272 return (config.initial_peak_level_dbfs < |
288 std::numeric_limits<float>::epsilon() && | 273 std::numeric_limits<float>::epsilon() && |
289 config.initial_peak_level_dbfs > | 274 config.initial_peak_level_dbfs > |
290 -(100.f + std::numeric_limits<float>::epsilon())); | 275 -(100.f + std::numeric_limits<float>::epsilon())); |
291 } | 276 } |
292 | 277 |
293 } // namespace webrtc | 278 } // namespace webrtc |
OLD | NEW |