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

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

Issue 2337083002: Reland of added functionality for specifying the initial signal level to use for the gain estimation (Closed)
Patch Set: Fixed type conversion error Created 4 years, 2 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
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/peak_level_estimator. h" 11 #include "webrtc/modules/audio_processing/level_controller/peak_level_estimator. h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "webrtc/modules/audio_processing/audio_buffer.h" 15 #include "webrtc/modules/audio_processing/audio_buffer.h"
16 #include "webrtc/modules/audio_processing/level_controller/lc_constants.h"
17 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" 16 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
18 17
19 namespace webrtc { 18 namespace webrtc {
19 namespace {
20 20
21 PeakLevelEstimator::PeakLevelEstimator() { 21 constexpr float kMinLevel = 30.f;
22 Initialize(); 22
23 } // namespace
24
25 PeakLevelEstimator::PeakLevelEstimator(float initial_peak_level_dbfs) {
26 Initialize(initial_peak_level_dbfs);
23 } 27 }
24 28
25 PeakLevelEstimator::~PeakLevelEstimator() {} 29 PeakLevelEstimator::~PeakLevelEstimator() {}
26 30
27 void PeakLevelEstimator::Initialize() { 31 void PeakLevelEstimator::Initialize(float initial_peak_level_dbfs) {
28 peak_level_ = kTargetLcPeakLevel; 32 RTC_DCHECK_LE(-100.f, initial_peak_level_dbfs);
33 RTC_DCHECK_GE(0.f, initial_peak_level_dbfs);
34
35 peak_level_ = std::pow(10.f, initial_peak_level_dbfs / 20.f) * 32768.f;
36 peak_level_ = std::max(peak_level_, kMinLevel);
37
29 hold_counter_ = 0; 38 hold_counter_ = 0;
30 initialization_phase_ = true; 39 initialization_phase_ = true;
31 } 40 }
32 41
33 float PeakLevelEstimator::Analyze(SignalClassifier::SignalType signal_type, 42 float PeakLevelEstimator::Analyze(SignalClassifier::SignalType signal_type,
34 float frame_peak_level) { 43 float frame_peak_level) {
35 if (frame_peak_level == 0) { 44 if (frame_peak_level == 0) {
36 RTC_DCHECK_LE(30.f, peak_level_); 45 RTC_DCHECK_LE(kMinLevel, peak_level_);
37 return peak_level_; 46 return peak_level_;
38 } 47 }
39 48
40 if (peak_level_ < frame_peak_level) { 49 if (peak_level_ < frame_peak_level) {
41 // Smoothly update the estimate upwards when the frame peak level is 50 // Smoothly update the estimate upwards when the frame peak level is
42 // higher than the estimate. 51 // higher than the estimate.
43 peak_level_ += 0.1f * (frame_peak_level - peak_level_); 52 peak_level_ += 0.1f * (frame_peak_level - peak_level_);
44 hold_counter_ = 100; 53 hold_counter_ = 100;
45 initialization_phase_ = false; 54 initialization_phase_ = false;
46 } else { 55 } else {
47 hold_counter_ = std::max(0, hold_counter_ - 1); 56 hold_counter_ = std::max(0, hold_counter_ - 1);
48 57
49 // When the signal is highly non-stationary, update the estimate slowly 58 // When the signal is highly non-stationary, update the estimate slowly
50 // downwards if the estimate is lower than the frame peak level. 59 // downwards if the estimate is lower than the frame peak level.
51 if ((signal_type == SignalClassifier::SignalType::kHighlyNonStationary && 60 if ((signal_type == SignalClassifier::SignalType::kHighlyNonStationary &&
52 hold_counter_ == 0) || 61 hold_counter_ == 0) ||
53 initialization_phase_) { 62 initialization_phase_) {
54 peak_level_ = 63 peak_level_ =
55 std::max(peak_level_ + 0.01f * (frame_peak_level - peak_level_), 64 std::max(peak_level_ + 0.01f * (frame_peak_level - peak_level_),
56 peak_level_ * 0.995f); 65 peak_level_ * 0.995f);
57 } 66 }
58 } 67 }
59 68
60 peak_level_ = std::max(peak_level_, 30.f); 69 peak_level_ = std::max(peak_level_, kMinLevel);
61 70
62 return peak_level_; 71 return peak_level_;
63 } 72 }
64 73
65 } // namespace webrtc 74 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698