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

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

Issue 2337083002: Reland of added functionality for specifying the initial signal level to use for the gain estimation (Closed)
Patch Set: Changed parameter name from initial_level to the more correct initial_peak_level 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
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
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 noise_level_estimator_.Analyze(signal_type, FrameEnergy(*audio)); 233 noise_level_estimator_.Analyze(signal_type, FrameEnergy(*audio));
234 234
235 // Estimate the overall signal peak level. 235 // Estimate the overall signal peak level.
236 const float frame_peak_level = PeakLevel(*audio); 236 const float frame_peak_level = PeakLevel(*audio);
237 const float long_term_peak_level = 237 const float long_term_peak_level =
238 peak_level_estimator_.Analyze(signal_type, frame_peak_level); 238 peak_level_estimator_.Analyze(signal_type, frame_peak_level);
239 239
240 float saturating_gain = saturating_gain_estimator_.GetGain(); 240 float saturating_gain = saturating_gain_estimator_.GetGain();
241 241
242 // Compute the new gain to apply. 242 // Compute the new gain to apply.
243 last_gain_ = gain_selector_.GetNewGain(long_term_peak_level, noise_energy, 243 last_gain_ =
244 saturating_gain, signal_type); 244 gain_selector_.GetNewGain(long_term_peak_level, noise_energy,
245 saturating_gain, gain_jumpstart_, signal_type);
246
247 // Unflag the jumpstart of the gain as it should only happen once.
248 gain_jumpstart_ = false;
245 249
246 // Apply the gain to the signal. 250 // Apply the gain to the signal.
247 int num_saturations = gain_applier_.Process(last_gain_, audio); 251 int num_saturations = gain_applier_.Process(last_gain_, audio);
248 252
249 // Estimate the gain that saturates the overall signal. 253 // Estimate the gain that saturates the overall signal.
250 saturating_gain_estimator_.Update(last_gain_, num_saturations); 254 saturating_gain_estimator_.Update(last_gain_, num_saturations);
251 255
252 // Update the metrics. 256 // Update the metrics.
253 metrics_.Update(long_term_peak_level, noise_energy, last_gain_, 257 metrics_.Update(long_term_peak_level, noise_energy, last_gain_,
254 frame_peak_level); 258 frame_peak_level);
255 259
256 data_dumper_->DumpRaw("lc_selected_gain", 1, &last_gain_); 260 data_dumper_->DumpRaw("lc_selected_gain", 1, &last_gain_);
257 data_dumper_->DumpRaw("lc_noise_energy", 1, &noise_energy); 261 data_dumper_->DumpRaw("lc_noise_energy", 1, &noise_energy);
258 data_dumper_->DumpRaw("lc_peak_level", 1, &long_term_peak_level); 262 data_dumper_->DumpRaw("lc_peak_level", 1, &long_term_peak_level);
259 data_dumper_->DumpRaw("lc_saturating_gain", 1, &saturating_gain); 263 data_dumper_->DumpRaw("lc_saturating_gain", 1, &saturating_gain);
260 264
261 data_dumper_->DumpWav("lc_output", audio->num_frames(), 265 data_dumper_->DumpWav("lc_output", audio->num_frames(),
262 audio->channels_f()[0], *sample_rate_hz_, 1); 266 audio->channels_f()[0], *sample_rate_hz_, 1);
263 } 267 }
264 268
269 void LevelController::ApplyConfig(
270 const AudioProcessing::Config::LevelController& config) {
271 peak_level_estimator_.SetInitialPeakLevel(config.initial_peak_level);
272 gain_jumpstart_ = true;
273 }
274
265 std::string LevelController::ToString( 275 std::string LevelController::ToString(
266 const AudioProcessing::Config::LevelController& config) { 276 const AudioProcessing::Config::LevelController& config) {
267 std::stringstream ss; 277 std::stringstream ss;
268 ss << "{" 278 ss << "{"
269 << "enabled: " << (config.enabled ? "true" : "false") << "}"; 279 << "enabled: " << (config.enabled ? "true" : "false") << ","
280 << "initial_peak_level: " << config.initial_peak_level << "}";
270 return ss.str(); 281 return ss.str();
271 } 282 }
272 283
273 bool LevelController::Validate( 284 bool LevelController::Validate(
274 const AudioProcessing::Config::LevelController& config) { 285 const AudioProcessing::Config::LevelController& config) {
275 return true; 286 return (config.initial_peak_level < std::numeric_limits<float>::epsilon() &&
287 config.initial_peak_level >
288 -(100.f + std::numeric_limits<float>::epsilon()));
276 } 289 }
277 290
278 } // namespace webrtc 291 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698