OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 23 matching lines...) Expand all Loading... | |
34 namespace webrtc { | 34 namespace webrtc { |
35 | 35 |
36 const int IntelligibilityEnhancer::kErbResolution = 2; | 36 const int IntelligibilityEnhancer::kErbResolution = 2; |
37 const int IntelligibilityEnhancer::kWindowSizeMs = 2; | 37 const int IntelligibilityEnhancer::kWindowSizeMs = 2; |
38 const int IntelligibilityEnhancer::kChunkSizeMs = 10; // Size provided by APM. | 38 const int IntelligibilityEnhancer::kChunkSizeMs = 10; // Size provided by APM. |
39 const int IntelligibilityEnhancer::kAnalyzeRate = 800; | 39 const int IntelligibilityEnhancer::kAnalyzeRate = 800; |
40 const int IntelligibilityEnhancer::kVarianceRate = 2; | 40 const int IntelligibilityEnhancer::kVarianceRate = 2; |
41 const float IntelligibilityEnhancer::kClipFreq = 200.0f; | 41 const float IntelligibilityEnhancer::kClipFreq = 200.0f; |
42 const float IntelligibilityEnhancer::kConfigRho = 0.02f; | 42 const float IntelligibilityEnhancer::kConfigRho = 0.02f; |
43 const float IntelligibilityEnhancer::kKbdAlpha = 1.5f; | 43 const float IntelligibilityEnhancer::kKbdAlpha = 1.5f; |
44 | 44 |
hlundin-webrtc
2015/06/30 14:00:52
Delete empty line.
ekm
2015/07/01 23:48:25
Done.
| |
45 const float IntelligibilityEnhancer::kLambdaBot = -1.0; | |
hlundin-webrtc
2015/06/30 14:00:52
Are all of these constants only used locally in th
ekm
2015/07/01 23:48:25
Done.
| |
46 const float IntelligibilityEnhancer::kLambdaTop = -10e-18f; | |
47 | |
45 // To disable gain update smoothing, set gain limit to be VERY high. | 48 // To disable gain update smoothing, set gain limit to be VERY high. |
46 // TODO(ekmeyerson): Add option to disable gain smoothing altogether | 49 // TODO(ekmeyerson): Add option to disable gain smoothing altogether |
47 // to avoid the extra computation. | 50 // to avoid the extra computation. |
48 const float IntelligibilityEnhancer::kGainChangeLimit = 0.0125f; | 51 const float IntelligibilityEnhancer::kGainChangeLimit = 0.0125f; |
49 | 52 |
50 using VarianceType = intelligibility::VarianceArray::StepType; | 53 using VarianceType = intelligibility::VarianceArray::StepType; |
51 | 54 |
52 IntelligibilityEnhancer::TransformCallback::TransformCallback( | 55 IntelligibilityEnhancer::TransformCallback::TransformCallback( |
53 IntelligibilityEnhancer* parent, | 56 IntelligibilityEnhancer* parent, |
54 IntelligibilityEnhancer::AudioSource source) | 57 IntelligibilityEnhancer::AudioSource source) |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 } | 235 } |
233 | 236 |
234 /* efidata(n,:) = sqrt(b(n)) * fidata(n,:) */ | 237 /* efidata(n,:) = sqrt(b(n)) * fidata(n,:) */ |
235 gain_applier_.Apply(in_block, out_block); | 238 gain_applier_.Apply(in_block, out_block); |
236 } | 239 } |
237 | 240 |
238 void IntelligibilityEnhancer::AnalyzeClearBlock(float power_target) { | 241 void IntelligibilityEnhancer::AnalyzeClearBlock(float power_target) { |
239 FilterVariance(clear_variance_.variance(), filtered_clear_var_.get()); | 242 FilterVariance(clear_variance_.variance(), filtered_clear_var_.get()); |
240 FilterVariance(noise_variance_.variance(), filtered_noise_var_.get()); | 243 FilterVariance(noise_variance_.variance(), filtered_noise_var_.get()); |
241 | 244 |
242 // Bisection search for optimal |lambda| | 245 float power_bot, power_top; |
hlundin-webrtc
2015/06/30 14:00:51
Premature declaration of variables. Declare them w
ekm
2015/07/01 23:48:25
Done.
| |
243 | 246 SolveForGainsGivenLambda(kLambdaTop, start_freq_, gains_eq_.get()); |
244 float lambda_bot = -1.0f, lambda_top = -10e-18f, lambda; | |
245 float power_bot, power_top, power; | |
246 SolveForGainsGivenLambda(lambda_top, start_freq_, gains_eq_.get()); | |
247 power_top = | 247 power_top = |
248 DotProduct(gains_eq_.get(), filtered_clear_var_.get(), bank_size_); | 248 DotProduct(gains_eq_.get(), filtered_clear_var_.get(), bank_size_); |
249 SolveForGainsGivenLambda(lambda_bot, start_freq_, gains_eq_.get()); | 249 SolveForGainsGivenLambda(kLambdaBot, start_freq_, gains_eq_.get()); |
250 power_bot = | 250 power_bot = |
251 DotProduct(gains_eq_.get(), filtered_clear_var_.get(), bank_size_); | 251 DotProduct(gains_eq_.get(), filtered_clear_var_.get(), bank_size_); |
252 DCHECK(power_target >= power_bot && power_target <= power_top); | 252 if(power_target >= power_bot && power_target <= power_top) { |
253 SolveForLambda(power_target, power_bot, power_top); | |
254 UpdateErbGains(); | |
255 } // Else experiencing variance underflow, so do nothing. | |
256 } | |
253 | 257 |
258 void IntelligibilityEnhancer::SolveForLambda(float power_target, | |
259 float power_bot, | |
260 float power_top) { | |
261 float lambda_bot = kLambdaBot; | |
262 float lambda_top = kLambdaTop; | |
263 float lambda, power; | |
hlundin-webrtc
2015/06/30 14:00:52
Skip declaration of lambda and power here and decl
ekm
2015/07/01 23:48:25
Done.
| |
254 float power_ratio = 2.0f; // Ratio of achieved power to target power. | 264 float power_ratio = 2.0f; // Ratio of achieved power to target power. |
255 const float kConvergeThresh = 0.001f; // TODO(ekmeyerson): Find best values | 265 const float kConvergeThresh = 0.001f; // TODO(ekmeyerson): Find best values |
256 const int kMaxIters = 100; // for these, based on experiments. | 266 const int kMaxIters = 100; // for these, based on experiments. |
257 int iters = 0; | 267 int iters = 0; |
258 while (fabs(power_ratio - 1.0f) > kConvergeThresh && iters <= kMaxIters) { | 268 while (fabs(power_ratio - 1.0f) > kConvergeThresh && iters <= kMaxIters) { |
259 lambda = lambda_bot + (lambda_top - lambda_bot) / 2.0f; | 269 lambda = lambda_bot + (lambda_top - lambda_bot) / 2.0f; |
260 SolveForGainsGivenLambda(lambda, start_freq_, gains_eq_.get()); | 270 SolveForGainsGivenLambda(lambda, start_freq_, gains_eq_.get()); |
261 power = DotProduct(gains_eq_.get(), filtered_clear_var_.get(), bank_size_); | 271 power = DotProduct(gains_eq_.get(), filtered_clear_var_.get(), bank_size_); |
262 if (power < power_target) { | 272 if (power < power_target) { |
263 lambda_bot = lambda; | 273 lambda_bot = lambda; |
264 } else { | 274 } else { |
265 lambda_top = lambda; | 275 lambda_top = lambda; |
266 } | 276 } |
267 power_ratio = fabs(power / power_target); | 277 power_ratio = fabs(power / power_target); |
268 ++iters; | 278 ++iters; |
269 } | 279 } |
280 } | |
270 | 281 |
282 void IntelligibilityEnhancer::UpdateErbGains() { | |
271 // (ERB gain) = filterbank' * (freq gain) | 283 // (ERB gain) = filterbank' * (freq gain) |
272 float* gains = gain_applier_.target(); | 284 float* gains = gain_applier_.target(); |
273 for (int i = 0; i < freqs_; ++i) { | 285 for (int i = 0; i < freqs_; ++i) { |
274 gains[i] = 0.0f; | 286 gains[i] = 0.0f; |
275 for (int j = 0; j < bank_size_; ++j) { | 287 for (int j = 0; j < bank_size_; ++j) { |
276 gains[i] = fmaf(filter_bank_[j][i], gains_eq_[j], gains[i]); | 288 gains[i] = fmaf(filter_bank_[j][i], gains_eq_[j], gains[i]); |
277 } | 289 } |
278 } | 290 } |
279 } | 291 } |
280 | 292 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 int length) { | 409 int length) { |
398 float ret = 0.0f; | 410 float ret = 0.0f; |
399 | 411 |
400 for (int i = 0; i < length; ++i) { | 412 for (int i = 0; i < length; ++i) { |
401 ret = fmaf(a[i], b[i], ret); | 413 ret = fmaf(a[i], b[i], ret); |
402 } | 414 } |
403 return ret; | 415 return ret; |
404 } | 416 } |
405 | 417 |
406 } // namespace webrtc | 418 } // namespace webrtc |
OLD | NEW |