Index: webrtc/modules/audio_processing/level_controller/level_controller.cc |
diff --git a/webrtc/modules/audio_processing/level_controller/level_controller.cc b/webrtc/modules/audio_processing/level_controller/level_controller.cc |
index c0edeb91c50f5a472019f07eb45ce97910d9ea12..939b0e8f2c0e757642715d1d284ac68589752e22 100644 |
--- a/webrtc/modules/audio_processing/level_controller/level_controller.cc |
+++ b/webrtc/modules/audio_processing/level_controller/level_controller.cc |
@@ -188,6 +188,11 @@ LevelController::LevelController() |
LevelController::~LevelController() {} |
+void LevelController::SetInitialLevel(float level) { |
+ peak_level_estimator_.SetInitialPeakLevel(level); |
+ gain_jumpstart_ = true; |
+} |
+ |
void LevelController::Initialize(int sample_rate_hz) { |
RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz || |
sample_rate_hz == AudioProcessing::kSampleRate16kHz || |
@@ -240,8 +245,12 @@ void LevelController::Process(AudioBuffer* audio) { |
float saturating_gain = saturating_gain_estimator_.GetGain(); |
// Compute the new gain to apply. |
- last_gain_ = gain_selector_.GetNewGain(long_term_peak_level, noise_energy, |
- saturating_gain, signal_type); |
+ last_gain_ = |
+ gain_selector_.GetNewGain(long_term_peak_level, noise_energy, |
+ saturating_gain, gain_jumpstart_, signal_type); |
+ |
+ // Unflag the jumpstart of the gain as it should only happen once. |
+ gain_jumpstart_ = false; |
// Apply the gain to the signal. |
int num_saturations = gain_applier_.Process(last_gain_, audio); |
@@ -262,17 +271,33 @@ void LevelController::Process(AudioBuffer* audio) { |
audio->channels_f()[0], *sample_rate_hz_, 1); |
} |
+void LevelController::ApplyConfig( |
+ const AudioProcessing::Config::LevelController& config) { |
+ if (config.initial_level) { |
+ peak_level_estimator_.SetInitialPeakLevel(*config.initial_level); |
+ gain_jumpstart_ = true; |
+ } |
+} |
+ |
std::string LevelController::ToString( |
const AudioProcessing::Config::LevelController& config) { |
std::stringstream ss; |
ss << "{" |
- << "enabled: " << (config.enabled ? "true" : "false") << "}"; |
+ << "enabled: " << (config.enabled ? "true" : "false") << "," |
+ << "initial level: : "; |
+ if (config.initial_level) { |
+ ss << *config.initial_level; |
+ } else { |
+ ss << "Not specified"; |
+ } |
+ ss << "}"; |
return ss.str(); |
} |
bool LevelController::Validate( |
const AudioProcessing::Config::LevelController& config) { |
- return true; |
+ return !config.initial_level || |
+ (*config.initial_level < 0.1f && *config.initial_level > -100.1f); |
the sun
2016/09/14 10:00:59
Should you be comparing with an epsilon?
peah-webrtc
2016/09/16 07:11:07
I added a variant of that. Please take another loo
|
} |
} // namespace webrtc |