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/erl_estimator.h" | |
12 | |
13 #include <algorithm> | |
14 | |
15 namespace webrtc { | |
16 | |
17 namespace { | |
18 | |
19 constexpr float kMinErl = 0.01f; | |
20 constexpr float kMaxErl = 1000.f; | |
21 | |
22 } // namespace | |
23 | |
24 ErlEstimator::ErlEstimator() { | |
25 erl_.fill(kMaxErl); | |
26 hold_counters_.fill(0); | |
27 } | |
28 | |
29 ErlEstimator::~ErlEstimator() = default; | |
30 | |
31 void ErlEstimator::Update( | |
32 const std::array<float, kFftLengthBy2Plus1>& render_spectrum, | |
33 const std::array<float, kFftLengthBy2Plus1>& capture_spectrum) { | |
34 const auto& X2 = render_spectrum; | |
35 const auto& Y2 = capture_spectrum; | |
36 | |
37 // Corresponds of WGN of power -46 dBFS. | |
ivoc
2017/02/21 17:26:01
Corresponds to
peah-webrtc
2017/02/21 23:00:40
Done.
| |
38 const float kX2Min = 44015068.0f; | |
39 | |
40 // Update the estimates in a maximum statistics manner. | |
41 for (size_t k = 1; k < kFftLengthBy2; ++k) { | |
42 if (X2[k] > kX2Min) { | |
43 const float new_erl = Y2[k] / X2[k]; | |
44 if (new_erl < erl_[k]) { | |
45 hold_counters_[k - 1] = 1000; | |
46 erl_[k] += 0.1 * (new_erl - erl_[k]); | |
47 erl_[k] = std::max(erl_[k], kMinErl); | |
48 } | |
49 } | |
50 } | |
51 | |
52 std::for_each(hold_counters_.begin(), hold_counters_.end(), | |
53 [](int& a) { --a; }); | |
54 std::transform(hold_counters_.begin(), hold_counters_.end(), erl_.begin() + 1, | |
55 erl_.begin() + 1, [](int a, float b) { | |
56 return a > 0 ? b : std::min(kMaxErl, 2.f * b); | |
57 }); | |
58 | |
59 erl_[0] = erl_[1]; | |
60 erl_[kFftLengthBy2] = erl_[kFftLengthBy2 - 1]; | |
61 } | |
62 | |
63 } // namespace webrtc | |
OLD | NEW |