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 13 matching lines...) Expand all Loading... | |
24 namespace webrtc { | 24 namespace webrtc { |
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) { | |
35 return std::isfinite(c.real()) && std::isfinite(c.imag()); | |
36 } | |
37 | |
38 bool cplxnormal(complex<float> c) { | |
39 return std::isnormal(c.real()) && std::isnormal(c.imag()); | |
40 } | |
41 | |
42 complex<float> zerofudge(complex<float> c) { | 34 complex<float> zerofudge(complex<float> c) { |
43 const static complex<float> fudge[7] = {{0.001f, 0.002f}, | 35 const static complex<float> fudge[7] = {{0.001f, 0.002f}, |
44 {0.008f, 0.001f}, | 36 {0.008f, 0.001f}, |
45 {0.003f, 0.008f}, | 37 {0.003f, 0.008f}, |
46 {0.0006f, 0.0009f}, | 38 {0.0006f, 0.0009f}, |
47 {0.001f, 0.004f}, | 39 {0.001f, 0.004f}, |
48 {0.003f, 0.004f}, | 40 {0.003f, 0.004f}, |
49 {0.002f, 0.009f}}; | 41 {0.002f, 0.009f}}; |
50 static int fudge_index = 0; | 42 static int fudge_index = 0; |
Andrew MacDonald
2015/07/22 22:17:07
Ahh, non-const static!
Do we really need this zer
ekm
2015/07/22 22:45:25
I think that's saying the |skip_fudge| flag can be
Andrew MacDonald
2015/07/22 23:34:59
Got it. Is there any benefit to adding this dither
ekm
2015/07/23 00:06:26
That's a good question. I think we want the dither
| |
51 if (cplxfinite(c) && !cplxnormal(c)) { | 43 if (c.real() == 0.f || c.imag() == 0.f) { |
52 fudge_index = (fudge_index + 1) % 7; | 44 fudge_index = (fudge_index + 1) % 7; |
53 return c + fudge[fudge_index]; | 45 return c + fudge[fudge_index]; |
54 } | 46 } |
55 return c; | 47 return c; |
56 } | 48 } |
57 | 49 |
58 complex<float> NewMean(complex<float> mean, complex<float> data, int count) { | 50 complex<float> NewMean(complex<float> mean, complex<float> data, int count) { |
59 return mean + (data - mean) / static_cast<float>(count); | 51 return mean + (data - mean) / static_cast<float>(count); |
60 } | 52 } |
61 | 53 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 } else { | 122 } else { |
131 float old_sum = conj_sum_[i]; | 123 float old_sum = conj_sum_[i]; |
132 complex<float> old_mean = running_mean_[i]; | 124 complex<float> old_mean = running_mean_[i]; |
133 running_mean_[i] = | 125 running_mean_[i] = |
134 old_mean + (sample - old_mean) / static_cast<float>(count_); | 126 old_mean + (sample - old_mean) / static_cast<float>(count_); |
135 conj_sum_[i] = | 127 conj_sum_[i] = |
136 (old_sum + std::conj(sample - old_mean) * (sample - running_mean_[i])) | 128 (old_sum + std::conj(sample - old_mean) * (sample - running_mean_[i])) |
137 .real(); | 129 .real(); |
138 variance_[i] = | 130 variance_[i] = |
139 conj_sum_[i] / (count_ - 1); // + fudge[fudge_index].real(); | 131 conj_sum_[i] / (count_ - 1); // + fudge[fudge_index].real(); |
140 if (skip_fudge && false) { | 132 if (skip_fudge && false) { |
Andrew MacDonald
2015/07/22 22:17:07
Can you remove these three lines?
ekm
2015/07/22 22:45:25
Done.
| |
141 // variance_[i] -= fudge[fudge_index].real(); | 133 // variance_[i] -= fudge[fudge_index].real(); |
142 } | 134 } |
143 } | 135 } |
144 array_mean_ += (variance_[i] - array_mean_) / (i + 1); | 136 array_mean_ += (variance_[i] - array_mean_) / (i + 1); |
145 } | 137 } |
146 } | 138 } |
147 | 139 |
148 // Compute the variance from the beginning, with exponential decaying of the | 140 // Compute the variance from the beginning, with exponential decaying of the |
149 // series data. | 141 // series data. |
150 void VarianceArray::DecayStep(const complex<float>* data, bool /*dummy*/) { | 142 void VarianceArray::DecayStep(const complex<float>* data, bool /*dummy*/) { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 factor = 1.0f; | 317 factor = 1.0f; |
326 } | 318 } |
327 out_block[i] = factor * in_block[i]; | 319 out_block[i] = factor * in_block[i]; |
328 current_[i] = UpdateFactor(target_[i], current_[i], change_limit_); | 320 current_[i] = UpdateFactor(target_[i], current_[i], change_limit_); |
329 } | 321 } |
330 } | 322 } |
331 | 323 |
332 } // namespace intelligibility | 324 } // namespace intelligibility |
333 | 325 |
334 } // namespace webrtc | 326 } // namespace webrtc |
OLD | NEW |