OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 const std::array<float, kFftLengthBy2Plus1>& capture_spectrum, | 34 const std::array<float, kFftLengthBy2Plus1>& capture_spectrum, |
35 const std::array<float, kFftLengthBy2Plus1>& subtractor_spectrum) { | 35 const std::array<float, kFftLengthBy2Plus1>& subtractor_spectrum) { |
36 const auto& X2 = render_spectrum; | 36 const auto& X2 = render_spectrum; |
37 const auto& Y2 = capture_spectrum; | 37 const auto& Y2 = capture_spectrum; |
38 const auto& E2 = subtractor_spectrum; | 38 const auto& E2 = subtractor_spectrum; |
39 | 39 |
40 // Corresponds of WGN of power -46 dBFS. | 40 // Corresponds of WGN of power -46 dBFS. |
41 constexpr float kX2Min = 44015068.0f; | 41 constexpr float kX2Min = 44015068.0f; |
42 | 42 |
43 // Update the estimates in a clamped minimum statistics manner. | 43 // Update the estimates in a clamped minimum statistics manner. |
44 size_t k = 1; | 44 auto erle_update = [&](size_t start, size_t stop, float max_erle) { |
45 size_t band_limit = kFftLengthBy2 / 2; | 45 for (size_t k = start; k < stop; ++k) { |
46 float max_erle = kMaxLfErle; | |
47 for (int j = 0; j < 2; ++j) { | |
48 for (; k < band_limit; ++k) { | |
49 if (X2[k] > kX2Min && E2[k] > 0.f) { | 46 if (X2[k] > kX2Min && E2[k] > 0.f) { |
50 const float new_erle = Y2[k] / E2[k]; | 47 const float new_erle = Y2[k] / E2[k]; |
51 if (new_erle > erle_[k]) { | 48 if (new_erle > erle_[k]) { |
52 hold_counters_[k - 1] = 100; | 49 hold_counters_[k - 1] = 100; |
53 erle_[k] += 0.1f * (new_erle - erle_[k]); | 50 erle_[k] += 0.1f * (new_erle - erle_[k]); |
54 erle_[k] = std::max(kMinErle, std::min(erle_[k], max_erle)); | 51 erle_[k] = std::max(kMinErle, std::min(erle_[k], max_erle)); |
55 } | 52 } |
56 } | 53 } |
57 } | 54 } |
58 band_limit = kFftLengthBy2; | 55 }; |
59 max_erle = kMaxHfErle; | 56 erle_update(1, kFftLengthBy2 / 2, kMaxLfErle); |
60 } | 57 erle_update(kFftLengthBy2 / 2, kFftLengthBy2, kMaxHfErle); |
61 | 58 |
62 std::for_each(hold_counters_.begin(), hold_counters_.end(), | 59 std::for_each(hold_counters_.begin(), hold_counters_.end(), |
63 [](int& a) { --a; }); | 60 [](int& a) { --a; }); |
64 std::transform(hold_counters_.begin(), hold_counters_.end(), | 61 std::transform(hold_counters_.begin(), hold_counters_.end(), |
65 erle_.begin() + 1, erle_.begin() + 1, [](int a, float b) { | 62 erle_.begin() + 1, erle_.begin() + 1, [](int a, float b) { |
66 return a > 0 ? b : std::max(kMinErle, 0.97f * b); | 63 return a > 0 ? b : std::max(kMinErle, 0.97f * b); |
67 }); | 64 }); |
68 | 65 |
69 erle_[0] = erle_[1]; | 66 erle_[0] = erle_[1]; |
70 erle_[kFftLengthBy2] = erle_[kFftLengthBy2 - 1]; | 67 erle_[kFftLengthBy2] = erle_[kFftLengthBy2 - 1]; |
71 } | 68 } |
72 | 69 |
73 } // namespace webrtc | 70 } // namespace webrtc |
OLD | NEW |