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

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: 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 LevelController::LevelController() 181 LevelController::LevelController()
182 : data_dumper_(new ApmDataDumper(instance_count_)), 182 : data_dumper_(new ApmDataDumper(instance_count_)),
183 gain_applier_(data_dumper_.get()), 183 gain_applier_(data_dumper_.get()),
184 signal_classifier_(data_dumper_.get()) { 184 signal_classifier_(data_dumper_.get()) {
185 Initialize(AudioProcessing::kSampleRate48kHz); 185 Initialize(AudioProcessing::kSampleRate48kHz);
186 ++instance_count_; 186 ++instance_count_;
187 } 187 }
188 188
189 LevelController::~LevelController() {} 189 LevelController::~LevelController() {}
190 190
191 void LevelController::SetInitialLevel(float level) {
192 peak_level_estimator_.SetInitialPeakLevel(level);
193 gain_jumpstart_ = true;
194 }
195
191 void LevelController::Initialize(int sample_rate_hz) { 196 void LevelController::Initialize(int sample_rate_hz) {
192 RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz || 197 RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz ||
193 sample_rate_hz == AudioProcessing::kSampleRate16kHz || 198 sample_rate_hz == AudioProcessing::kSampleRate16kHz ||
194 sample_rate_hz == AudioProcessing::kSampleRate32kHz || 199 sample_rate_hz == AudioProcessing::kSampleRate32kHz ||
195 sample_rate_hz == AudioProcessing::kSampleRate48kHz); 200 sample_rate_hz == AudioProcessing::kSampleRate48kHz);
196 data_dumper_->InitiateNewSetOfRecordings(); 201 data_dumper_->InitiateNewSetOfRecordings();
197 gain_selector_.Initialize(sample_rate_hz); 202 gain_selector_.Initialize(sample_rate_hz);
198 gain_applier_.Initialize(sample_rate_hz); 203 gain_applier_.Initialize(sample_rate_hz);
199 signal_classifier_.Initialize(sample_rate_hz); 204 signal_classifier_.Initialize(sample_rate_hz);
200 noise_level_estimator_.Initialize(sample_rate_hz); 205 noise_level_estimator_.Initialize(sample_rate_hz);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 noise_level_estimator_.Analyze(signal_type, FrameEnergy(*audio)); 238 noise_level_estimator_.Analyze(signal_type, FrameEnergy(*audio));
234 239
235 // Estimate the overall signal peak level. 240 // Estimate the overall signal peak level.
236 const float frame_peak_level = PeakLevel(*audio); 241 const float frame_peak_level = PeakLevel(*audio);
237 const float long_term_peak_level = 242 const float long_term_peak_level =
238 peak_level_estimator_.Analyze(signal_type, frame_peak_level); 243 peak_level_estimator_.Analyze(signal_type, frame_peak_level);
239 244
240 float saturating_gain = saturating_gain_estimator_.GetGain(); 245 float saturating_gain = saturating_gain_estimator_.GetGain();
241 246
242 // Compute the new gain to apply. 247 // Compute the new gain to apply.
243 last_gain_ = gain_selector_.GetNewGain(long_term_peak_level, noise_energy, 248 last_gain_ =
244 saturating_gain, signal_type); 249 gain_selector_.GetNewGain(long_term_peak_level, noise_energy,
250 saturating_gain, gain_jumpstart_, signal_type);
251
252 // Unflag the jumpstart of the gain as it should only happen once.
253 gain_jumpstart_ = false;
245 254
246 // Apply the gain to the signal. 255 // Apply the gain to the signal.
247 int num_saturations = gain_applier_.Process(last_gain_, audio); 256 int num_saturations = gain_applier_.Process(last_gain_, audio);
248 257
249 // Estimate the gain that saturates the overall signal. 258 // Estimate the gain that saturates the overall signal.
250 saturating_gain_estimator_.Update(last_gain_, num_saturations); 259 saturating_gain_estimator_.Update(last_gain_, num_saturations);
251 260
252 // Update the metrics. 261 // Update the metrics.
253 metrics_.Update(long_term_peak_level, noise_energy, last_gain_, 262 metrics_.Update(long_term_peak_level, noise_energy, last_gain_,
254 frame_peak_level); 263 frame_peak_level);
255 264
256 data_dumper_->DumpRaw("lc_selected_gain", 1, &last_gain_); 265 data_dumper_->DumpRaw("lc_selected_gain", 1, &last_gain_);
257 data_dumper_->DumpRaw("lc_noise_energy", 1, &noise_energy); 266 data_dumper_->DumpRaw("lc_noise_energy", 1, &noise_energy);
258 data_dumper_->DumpRaw("lc_peak_level", 1, &long_term_peak_level); 267 data_dumper_->DumpRaw("lc_peak_level", 1, &long_term_peak_level);
259 data_dumper_->DumpRaw("lc_saturating_gain", 1, &saturating_gain); 268 data_dumper_->DumpRaw("lc_saturating_gain", 1, &saturating_gain);
260 269
261 data_dumper_->DumpWav("lc_output", audio->num_frames(), 270 data_dumper_->DumpWav("lc_output", audio->num_frames(),
262 audio->channels_f()[0], *sample_rate_hz_, 1); 271 audio->channels_f()[0], *sample_rate_hz_, 1);
263 } 272 }
264 273
274 void LevelController::ApplyConfig(
275 const AudioProcessing::Config::LevelController& config) {
276 if (config.initial_level) {
277 peak_level_estimator_.SetInitialPeakLevel(*config.initial_level);
278 gain_jumpstart_ = true;
279 }
280 }
281
265 std::string LevelController::ToString( 282 std::string LevelController::ToString(
266 const AudioProcessing::Config::LevelController& config) { 283 const AudioProcessing::Config::LevelController& config) {
267 std::stringstream ss; 284 std::stringstream ss;
268 ss << "{" 285 ss << "{"
269 << "enabled: " << (config.enabled ? "true" : "false") << "}"; 286 << "enabled: " << (config.enabled ? "true" : "false") << ","
287 << "initial level: : ";
288 if (config.initial_level) {
289 ss << *config.initial_level;
290 } else {
291 ss << "Not specified";
292 }
293 ss << "}";
270 return ss.str(); 294 return ss.str();
271 } 295 }
272 296
273 bool LevelController::Validate( 297 bool LevelController::Validate(
274 const AudioProcessing::Config::LevelController& config) { 298 const AudioProcessing::Config::LevelController& config) {
275 return true; 299 return !config.initial_level ||
300 (*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
276 } 301 }
277 302
278 } // namespace webrtc 303 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698