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

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

Issue 2254973003: Added functionality for specifying the initial signal level to use for the gain estimation in the l… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 LevelController::LevelController() 148 LevelController::LevelController()
149 : data_dumper_(new ApmDataDumper(instance_count_)), 149 : data_dumper_(new ApmDataDumper(instance_count_)),
150 gain_applier_(data_dumper_.get()), 150 gain_applier_(data_dumper_.get()),
151 signal_classifier_(data_dumper_.get()) { 151 signal_classifier_(data_dumper_.get()) {
152 Initialize(AudioProcessing::kSampleRate48kHz); 152 Initialize(AudioProcessing::kSampleRate48kHz);
153 ++instance_count_; 153 ++instance_count_;
154 } 154 }
155 155
156 LevelController::~LevelController() {} 156 LevelController::~LevelController() {}
157 157
158 void LevelController::SetInitialLevel(float level) {
159 peak_level_estimator_.SetInitialPeakLevel(level);
160 gain_jumpstart_ = true;
161 }
162
158 void LevelController::Initialize(int sample_rate_hz) { 163 void LevelController::Initialize(int sample_rate_hz) {
159 RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz || 164 RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz ||
160 sample_rate_hz == AudioProcessing::kSampleRate16kHz || 165 sample_rate_hz == AudioProcessing::kSampleRate16kHz ||
161 sample_rate_hz == AudioProcessing::kSampleRate32kHz || 166 sample_rate_hz == AudioProcessing::kSampleRate32kHz ||
162 sample_rate_hz == AudioProcessing::kSampleRate48kHz); 167 sample_rate_hz == AudioProcessing::kSampleRate48kHz);
163 data_dumper_->InitiateNewSetOfRecordings(); 168 data_dumper_->InitiateNewSetOfRecordings();
164 gain_selector_.Initialize(sample_rate_hz); 169 gain_selector_.Initialize(sample_rate_hz);
165 gain_applier_.Initialize(sample_rate_hz); 170 gain_applier_.Initialize(sample_rate_hz);
166 signal_classifier_.Initialize(sample_rate_hz); 171 signal_classifier_.Initialize(sample_rate_hz);
167 noise_level_estimator_.Initialize(sample_rate_hz); 172 noise_level_estimator_.Initialize(sample_rate_hz);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 float noise_energy = 204 float noise_energy =
200 noise_level_estimator_.Analyze(signal_type, FrameEnergy(*audio)); 205 noise_level_estimator_.Analyze(signal_type, FrameEnergy(*audio));
201 206
202 // Estimate the overall signal peak level. 207 // Estimate the overall signal peak level.
203 float peak_level = 208 float peak_level =
204 peak_level_estimator_.Analyze(signal_type, PeakLevel(*audio)); 209 peak_level_estimator_.Analyze(signal_type, PeakLevel(*audio));
205 210
206 float saturating_gain = saturating_gain_estimator_.GetGain(); 211 float saturating_gain = saturating_gain_estimator_.GetGain();
207 212
208 // Compute the new gain to apply. 213 // Compute the new gain to apply.
209 last_gain_ = gain_selector_.GetNewGain(peak_level, noise_energy, 214 last_gain_ = gain_selector_.GetNewGain(
210 saturating_gain, signal_type); 215 peak_level, noise_energy, saturating_gain, gain_jumpstart_, signal_type);
216
217 // Unflag the jumpstart of the gain as it should only happen once.
218 gain_jumpstart_ = false;
211 219
212 // Apply the gain to the signal. 220 // Apply the gain to the signal.
213 int num_saturations = gain_applier_.Process(last_gain_, audio); 221 int num_saturations = gain_applier_.Process(last_gain_, audio);
214 222
215 // Estimate the gain that saturates the overall signal. 223 // Estimate the gain that saturates the overall signal.
216 saturating_gain_estimator_.Update(last_gain_, num_saturations); 224 saturating_gain_estimator_.Update(last_gain_, num_saturations);
217 225
218 // Update the metrics. 226 // Update the metrics.
219 metrics_.Update(peak_level, noise_energy, last_gain_); 227 metrics_.Update(peak_level, noise_energy, last_gain_);
220 228
221 data_dumper_->DumpRaw("lc_selected_gain", 1, &last_gain_); 229 data_dumper_->DumpRaw("lc_selected_gain", 1, &last_gain_);
222 data_dumper_->DumpRaw("lc_noise_energy", 1, &noise_energy); 230 data_dumper_->DumpRaw("lc_noise_energy", 1, &noise_energy);
223 data_dumper_->DumpRaw("lc_peak_level", 1, &peak_level); 231 data_dumper_->DumpRaw("lc_peak_level", 1, &peak_level);
224 data_dumper_->DumpRaw("lc_saturating_gain", 1, &saturating_gain); 232 data_dumper_->DumpRaw("lc_saturating_gain", 1, &saturating_gain);
225 233
226 data_dumper_->DumpWav("lc_output", audio->num_frames(), 234 data_dumper_->DumpWav("lc_output", audio->num_frames(),
227 audio->channels_f()[0], *sample_rate_hz_, 1); 235 audio->channels_f()[0], *sample_rate_hz_, 1);
228 } 236 }
229 237
230 } // namespace webrtc 238 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698