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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 if (config.initial_level) { | |
272 peak_level_estimator_.SetInitialPeakLevel(*config.initial_level); | |
273 gain_jumpstart_ = true; | |
274 } | |
275 } | |
276 | |
265 std::string LevelController::ToString( | 277 std::string LevelController::ToString( |
266 const AudioProcessing::Config::LevelController& config) { | 278 const AudioProcessing::Config::LevelController& config) { |
267 std::stringstream ss; | 279 std::stringstream ss; |
268 ss << "{" | 280 ss << "{" |
269 << "enabled: " << (config.enabled ? "true" : "false") << "}"; | 281 << "enabled: " << (config.enabled ? "true" : "false") << "," |
282 << "initial level: : "; | |
283 if (config.initial_level) { | |
284 ss << *config.initial_level; | |
285 } else { | |
286 ss << "Not specified"; | |
287 } | |
288 ss << "}"; | |
270 return ss.str(); | 289 return ss.str(); |
271 } | 290 } |
272 | 291 |
273 bool LevelController::Validate( | 292 bool LevelController::Validate( |
274 const AudioProcessing::Config::LevelController& config) { | 293 const AudioProcessing::Config::LevelController& config) { |
275 return true; | 294 return !config.initial_level || |
295 (*config.initial_level < std::numeric_limits<float>::epsilon() && | |
the sun
2016/09/16 08:00:40
In the future, consider making a utility for this
peah-webrtc
2016/09/16 11:36:05
Acknowledged.
| |
296 *config.initial_level > | |
297 -(100.f + std::numeric_limits<float>::epsilon())); | |
276 } | 298 } |
277 | 299 |
278 } // namespace webrtc | 300 } // namespace webrtc |
OLD | NEW |