OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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/agc/agc_manager_direct.h" | 11 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" |
12 | 12 |
13 #include <cmath> | 13 #include <cmath> |
14 | 14 |
15 #ifdef WEBRTC_AGC_DEBUG_DUMP | 15 #ifdef WEBRTC_AGC_DEBUG_DUMP |
16 #include <cstdio> | 16 #include <cstdio> |
17 #endif | 17 #endif |
18 | 18 |
19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
20 #include "webrtc/modules/audio_processing/agc/gain_map_internal.h" | 20 #include "webrtc/modules/audio_processing/agc/gain_map_internal.h" |
21 #include "webrtc/modules/audio_processing/gain_control_impl.h" | 21 #include "webrtc/modules/audio_processing/gain_control_impl.h" |
22 #include "webrtc/modules/include/module_common_types.h" | 22 #include "webrtc/modules/include/module_common_types.h" |
23 #include "webrtc/system_wrappers/include/logging.h" | 23 #include "webrtc/system_wrappers/include/logging.h" |
| 24 #include "webrtc/system_wrappers/include/metrics.h" |
24 | 25 |
25 namespace webrtc { | 26 namespace webrtc { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 // Lowest the microphone level can be lowered due to clipping. | 30 // Lowest the microphone level can be lowered due to clipping. |
30 const int kClippedLevelMin = 170; | 31 const int kClippedLevelMin = 170; |
31 // Amount the microphone level is lowered with every clipping event. | 32 // Amount the microphone level is lowered with every clipping event. |
32 const int kClippedLevelStep = 15; | 33 const int kClippedLevelStep = 15; |
33 // Proportion of clipped samples required to declare a clipping event. | 34 // Proportion of clipped samples required to declare a clipping event. |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 // maximum. This harsh treatment is an effort to avoid repeated clipped echo | 212 // maximum. This harsh treatment is an effort to avoid repeated clipped echo |
212 // events. As compensation for this restriction, the maximum compression | 213 // events. As compensation for this restriction, the maximum compression |
213 // gain is increased, through SetMaxLevel(). | 214 // gain is increased, through SetMaxLevel(). |
214 float clipped_ratio = agc_->AnalyzePreproc(audio, length); | 215 float clipped_ratio = agc_->AnalyzePreproc(audio, length); |
215 if (clipped_ratio > kClippedRatioThreshold) { | 216 if (clipped_ratio > kClippedRatioThreshold) { |
216 LOG(LS_INFO) << "[agc] Clipping detected. clipped_ratio=" | 217 LOG(LS_INFO) << "[agc] Clipping detected. clipped_ratio=" |
217 << clipped_ratio; | 218 << clipped_ratio; |
218 // Always decrease the maximum level, even if the current level is below | 219 // Always decrease the maximum level, even if the current level is below |
219 // threshold. | 220 // threshold. |
220 SetMaxLevel(std::max(kClippedLevelMin, max_level_ - kClippedLevelStep)); | 221 SetMaxLevel(std::max(kClippedLevelMin, max_level_ - kClippedLevelStep)); |
| 222 RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.AgcClippingAdjustmentAllowed", |
| 223 level_ - kClippedLevelStep >= kClippedLevelMin); |
221 if (level_ > kClippedLevelMin) { | 224 if (level_ > kClippedLevelMin) { |
222 // Don't try to adjust the level if we're already below the limit. As | 225 // Don't try to adjust the level if we're already below the limit. As |
223 // a consequence, if the user has brought the level above the limit, we | 226 // a consequence, if the user has brought the level above the limit, we |
224 // will still not react until the postproc updates the level. | 227 // will still not react until the postproc updates the level. |
225 SetLevel(std::max(kClippedLevelMin, level_ - kClippedLevelStep)); | 228 SetLevel(std::max(kClippedLevelMin, level_ - kClippedLevelStep)); |
226 // Reset the AGC since the level has changed. | 229 // Reset the AGC since the level has changed. |
227 agc_->Reset(); | 230 agc_->Reset(); |
228 } | 231 } |
229 frames_since_clipped_ = 0; | 232 frames_since_clipped_ = 0; |
230 } | 233 } |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 compression_ = new_compression; | 438 compression_ = new_compression; |
436 compression_accumulator_ = new_compression; | 439 compression_accumulator_ = new_compression; |
437 if (gctrl_->set_compression_gain_db(compression_) != 0) { | 440 if (gctrl_->set_compression_gain_db(compression_) != 0) { |
438 LOG(LS_ERROR) << "set_compression_gain_db(" << compression_ | 441 LOG(LS_ERROR) << "set_compression_gain_db(" << compression_ |
439 << ") failed."; | 442 << ") failed."; |
440 } | 443 } |
441 } | 444 } |
442 } | 445 } |
443 | 446 |
444 } // namespace webrtc | 447 } // namespace webrtc |
OLD | NEW |