Chromium Code Reviews| 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 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 namespace intelligibility { | 26 namespace intelligibility { |
| 27 | 27 |
| 28 float UpdateFactor(float target, float current, float limit) { | 28 float UpdateFactor(float target, float current, float limit) { |
| 29 float delta = fabsf(target - current); | 29 float delta = fabsf(target - current); |
| 30 float sign = copysign(1.0f, target - current); | 30 float sign = copysign(1.0f, target - current); |
| 31 return current + sign * fminf(delta, limit); | 31 return current + sign * fminf(delta, limit); |
| 32 } | 32 } |
| 33 | 33 |
| 34 bool cplxfinite(complex<float> c) { | 34 bool cplxfinite(complex<float> c) { |
| 35 return std::isfinite(c.real()) && std::isfinite(c.imag()); | 35 return std::isfinite(c.real()) && std::isfinite(c.imag()); |
|
Andrew MacDonald
2015/07/22 19:41:30
This is also C++11 standard library...
jdduke (slow)
2015/07/22 19:51:00
Ah, the joys and quirks of stlport. They seem to h
| |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool cplxnormal(complex<float> c) { | 38 bool cplxnormal(complex<float> c) { |
| 39 return std::isnormal(c.real()) && std::isnormal(c.imag()); | 39 return isnormal(c.real()) && isnormal(c.imag()); |
|
Andrew MacDonald
2015/07/22 19:41:30
Actually this is failing for me on Linux ("use of
jdduke (slow)
2015/07/22 19:51:00
Done.
| |
| 40 } | 40 } |
| 41 | 41 |
| 42 complex<float> zerofudge(complex<float> c) { | 42 complex<float> zerofudge(complex<float> c) { |
| 43 const static complex<float> fudge[7] = {{0.001f, 0.002f}, | 43 const static complex<float> fudge[7] = {{0.001f, 0.002f}, |
| 44 {0.008f, 0.001f}, | 44 {0.008f, 0.001f}, |
| 45 {0.003f, 0.008f}, | 45 {0.003f, 0.008f}, |
| 46 {0.0006f, 0.0009f}, | 46 {0.0006f, 0.0009f}, |
| 47 {0.001f, 0.004f}, | 47 {0.001f, 0.004f}, |
| 48 {0.003f, 0.004f}, | 48 {0.003f, 0.004f}, |
| 49 {0.002f, 0.009f}}; | 49 {0.002f, 0.009f}}; |
| 50 static int fudge_index = 0; | 50 static int fudge_index = 0; |
| 51 if (cplxfinite(c) && !cplxnormal(c)) { | 51 if (cplxfinite(c) && !cplxnormal(c)) { |
|
ekm
2015/07/22 21:26:37
The C++11 stuff is overkill. I think we can just c
| |
| 52 fudge_index = (fudge_index + 1) % 7; | 52 fudge_index = (fudge_index + 1) % 7; |
| 53 return c + fudge[fudge_index]; | 53 return c + fudge[fudge_index]; |
| 54 } | 54 } |
| 55 return c; | 55 return c; |
| 56 } | 56 } |
| 57 | 57 |
| 58 complex<float> NewMean(complex<float> mean, complex<float> data, int count) { | 58 complex<float> NewMean(complex<float> mean, complex<float> data, int count) { |
| 59 return mean + (data - mean) / static_cast<float>(count); | 59 return mean + (data - mean) / static_cast<float>(count); |
| 60 } | 60 } |
| 61 | 61 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 for (int i = 0; i < freqs; ++i) { | 314 for (int i = 0; i < freqs; ++i) { |
| 315 target_[i] = 1.0f; | 315 target_[i] = 1.0f; |
| 316 current_[i] = 1.0f; | 316 current_[i] = 1.0f; |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 | 319 |
| 320 void GainApplier::Apply(const complex<float>* in_block, | 320 void GainApplier::Apply(const complex<float>* in_block, |
| 321 complex<float>* out_block) { | 321 complex<float>* out_block) { |
| 322 for (int i = 0; i < freqs_; ++i) { | 322 for (int i = 0; i < freqs_; ++i) { |
| 323 float factor = sqrtf(fabsf(current_[i])); | 323 float factor = sqrtf(fabsf(current_[i])); |
| 324 if (!std::isnormal(factor)) { | 324 if (!isnormal(factor)) { |
| 325 factor = 1.0f; | 325 factor = 1.0f; |
| 326 } | 326 } |
| 327 out_block[i] = factor * in_block[i]; | 327 out_block[i] = factor * in_block[i]; |
| 328 current_[i] = UpdateFactor(target_[i], current_[i], change_limit_); | 328 current_[i] = UpdateFactor(target_[i], current_[i], change_limit_); |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 } // namespace intelligibility | 332 } // namespace intelligibility |
| 333 | 333 |
| 334 } // namespace webrtc | 334 } // namespace webrtc |
| OLD | NEW |