OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/audio_processing/aec3/erle_estimator.h" | |
12 | |
13 #include <algorithm> | |
14 | |
15 namespace webrtc { | |
16 | |
17 namespace { | |
18 | |
19 constexpr float kMinErle = 1.f; | |
hlundin-webrtc
2017/02/22 15:24:06
In dB?
peah-webrtc
2017/02/22 23:51:38
No, it is linear.
| |
20 constexpr float kMaxErle = 8.f; | |
21 | |
22 } // namespace | |
23 | |
24 ErleEstimator::ErleEstimator() { | |
25 erle_.fill(kMinErle); | |
26 hold_counters_.fill(0); | |
27 } | |
28 | |
29 ErleEstimator::~ErleEstimator() = default; | |
30 | |
31 void ErleEstimator::Update( | |
32 const std::array<float, kFftLengthBy2Plus1>& render_spectrum, | |
33 const std::array<float, kFftLengthBy2Plus1>& capture_spectrum, | |
34 const std::array<float, kFftLengthBy2Plus1>& subtractor_spectrum) { | |
35 const auto& X2 = render_spectrum; | |
36 const auto& Y2 = capture_spectrum; | |
37 const auto& E2 = subtractor_spectrum; | |
38 | |
39 // Corresponds of WGN of power -46 dBFS. | |
40 const float kX2Min = 44015068.0f; | |
hlundin-webrtc
2017/02/22 15:24:06
constexpr
peah-webrtc
2017/02/22 23:51:38
Done.
| |
41 | |
42 // Update the estimates in a clamped minimum statistics manner. | |
43 for (size_t k = 1; k < kFftLengthBy2; ++k) { | |
44 if (X2[k] > kX2Min && E2[k] > 0.f) { | |
45 const float new_erle = Y2[k] / E2[k]; | |
46 if (new_erle > erle_[k]) { | |
47 hold_counters_[k - 1] = 100; | |
48 erle_[k] += 0.1f * (new_erle - erle_[k]); | |
49 erle_[k] = std::max(kMinErle, std::min(erle_[k], kMaxErle)); | |
50 } | |
51 } | |
52 } | |
53 | |
54 std::for_each(hold_counters_.begin(), hold_counters_.end(), | |
55 [](int& a) { --a; }); | |
56 std::transform(hold_counters_.begin(), hold_counters_.end(), | |
57 erle_.begin() + 1, erle_.begin() + 1, [](int a, float b) { | |
58 return a > 0 ? b : std::max(kMinErle, 0.97f * b); | |
59 }); | |
60 | |
61 erle_[0] = erle_[1]; | |
62 erle_[kFftLengthBy2] = erle_[kFftLengthBy2 - 1]; | |
63 } | |
64 | |
65 } // namespace webrtc | |
OLD | NEW |