OLD | NEW |
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...) Loading... |
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 | |
163 void LevelController::Initialize(int sample_rate_hz) { | 158 void LevelController::Initialize(int sample_rate_hz) { |
164 RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz || | 159 RTC_DCHECK(sample_rate_hz == AudioProcessing::kSampleRate8kHz || |
165 sample_rate_hz == AudioProcessing::kSampleRate16kHz || | 160 sample_rate_hz == AudioProcessing::kSampleRate16kHz || |
166 sample_rate_hz == AudioProcessing::kSampleRate32kHz || | 161 sample_rate_hz == AudioProcessing::kSampleRate32kHz || |
167 sample_rate_hz == AudioProcessing::kSampleRate48kHz); | 162 sample_rate_hz == AudioProcessing::kSampleRate48kHz); |
168 data_dumper_->InitiateNewSetOfRecordings(); | 163 data_dumper_->InitiateNewSetOfRecordings(); |
169 gain_selector_.Initialize(sample_rate_hz); | 164 gain_selector_.Initialize(sample_rate_hz); |
170 gain_applier_.Initialize(sample_rate_hz); | 165 gain_applier_.Initialize(sample_rate_hz); |
171 signal_classifier_.Initialize(sample_rate_hz); | 166 signal_classifier_.Initialize(sample_rate_hz); |
172 noise_level_estimator_.Initialize(sample_rate_hz); | 167 noise_level_estimator_.Initialize(sample_rate_hz); |
(...skipping 31 matching lines...) Loading... |
204 float noise_energy = | 199 float noise_energy = |
205 noise_level_estimator_.Analyze(signal_type, FrameEnergy(*audio)); | 200 noise_level_estimator_.Analyze(signal_type, FrameEnergy(*audio)); |
206 | 201 |
207 // Estimate the overall signal peak level. | 202 // Estimate the overall signal peak level. |
208 float peak_level = | 203 float peak_level = |
209 peak_level_estimator_.Analyze(signal_type, PeakLevel(*audio)); | 204 peak_level_estimator_.Analyze(signal_type, PeakLevel(*audio)); |
210 | 205 |
211 float saturating_gain = saturating_gain_estimator_.GetGain(); | 206 float saturating_gain = saturating_gain_estimator_.GetGain(); |
212 | 207 |
213 // Compute the new gain to apply. | 208 // Compute the new gain to apply. |
214 last_gain_ = gain_selector_.GetNewGain( | 209 last_gain_ = gain_selector_.GetNewGain(peak_level, noise_energy, |
215 peak_level, noise_energy, saturating_gain, gain_jumpstart_, signal_type); | 210 saturating_gain, signal_type); |
216 | |
217 // Unflag the jumpstart of the gain as it should only happen once. | |
218 gain_jumpstart_ = false; | |
219 | 211 |
220 // Apply the gain to the signal. | 212 // Apply the gain to the signal. |
221 int num_saturations = gain_applier_.Process(last_gain_, audio); | 213 int num_saturations = gain_applier_.Process(last_gain_, audio); |
222 | 214 |
223 // Estimate the gain that saturates the overall signal. | 215 // Estimate the gain that saturates the overall signal. |
224 saturating_gain_estimator_.Update(last_gain_, num_saturations); | 216 saturating_gain_estimator_.Update(last_gain_, num_saturations); |
225 | 217 |
226 // Update the metrics. | 218 // Update the metrics. |
227 metrics_.Update(peak_level, noise_energy, last_gain_); | 219 metrics_.Update(peak_level, noise_energy, last_gain_); |
228 | 220 |
229 data_dumper_->DumpRaw("lc_selected_gain", 1, &last_gain_); | 221 data_dumper_->DumpRaw("lc_selected_gain", 1, &last_gain_); |
230 data_dumper_->DumpRaw("lc_noise_energy", 1, &noise_energy); | 222 data_dumper_->DumpRaw("lc_noise_energy", 1, &noise_energy); |
231 data_dumper_->DumpRaw("lc_peak_level", 1, &peak_level); | 223 data_dumper_->DumpRaw("lc_peak_level", 1, &peak_level); |
232 data_dumper_->DumpRaw("lc_saturating_gain", 1, &saturating_gain); | 224 data_dumper_->DumpRaw("lc_saturating_gain", 1, &saturating_gain); |
233 | 225 |
234 data_dumper_->DumpWav("lc_output", audio->num_frames(), | 226 data_dumper_->DumpWav("lc_output", audio->num_frames(), |
235 audio->channels_f()[0], *sample_rate_hz_, 1); | 227 audio->channels_f()[0], *sample_rate_hz_, 1); |
236 } | 228 } |
237 | 229 |
238 } // namespace webrtc | 230 } // namespace webrtc |
OLD | NEW |