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 #include "webrtc/modules/audio_processing/aec3/power_echo_model.h" | 10 #include "webrtc/modules/audio_processing/aec3/power_echo_model.h" |
11 | 11 |
12 #include <string.h> | 12 #include <string.h> |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
15 #include "webrtc/base/optional.h" | 15 #include "webrtc/base/optional.h" |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Computes the spectral power over that last 20 frames. | 20 // Computes the spectral power over that last 20 frames. |
21 void RecentMaximum(const FftBuffer& X_buffer, | 21 void RecentMaximum(const RenderBuffer& X_buffer, |
22 std::array<float, kFftLengthBy2Plus1>* R2) { | 22 std::array<float, kFftLengthBy2Plus1>* R2) { |
23 R2->fill(0.f); | 23 R2->fill(0.f); |
24 for (size_t j = 0; j < 20; ++j) { | 24 for (size_t j = 0; j < 20; ++j) { |
25 std::transform(R2->begin(), R2->end(), X_buffer.Spectrum(j).begin(), | 25 std::transform(R2->begin(), R2->end(), X_buffer.Spectrum(j).begin(), |
26 R2->begin(), | 26 R2->begin(), |
27 [](float a, float b) { return std::max(a, b); }); | 27 [](float a, float b) { return std::max(a, b); }); |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 constexpr float kHInitial = 10.f; | 31 constexpr float kHInitial = 10.f; |
32 constexpr int kUpdateCounterInitial = 300; | 32 constexpr int kUpdateCounterInitial = 300; |
33 | 33 |
34 } // namespace | 34 } // namespace |
35 | 35 |
36 PowerEchoModel::PowerEchoModel() { | 36 PowerEchoModel::PowerEchoModel() { |
37 H2_.fill(CountedFloat(kHInitial, kUpdateCounterInitial)); | 37 H2_.fill(CountedFloat(kHInitial, kUpdateCounterInitial)); |
38 } | 38 } |
39 | 39 |
40 PowerEchoModel::~PowerEchoModel() = default; | 40 PowerEchoModel::~PowerEchoModel() = default; |
41 | 41 |
42 void PowerEchoModel::HandleEchoPathChange( | 42 void PowerEchoModel::HandleEchoPathChange( |
43 const EchoPathVariability& variability) { | 43 const EchoPathVariability& variability) { |
44 if (variability.gain_change) { | 44 if (variability.gain_change) { |
45 H2_.fill(CountedFloat(kHInitial, kUpdateCounterInitial)); | 45 H2_.fill(CountedFloat(kHInitial, kUpdateCounterInitial)); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 void PowerEchoModel::EstimateEcho( | 49 void PowerEchoModel::EstimateEcho( |
50 const FftBuffer& render_buffer, | 50 const RenderBuffer& render_buffer, |
51 const std::array<float, kFftLengthBy2Plus1>& capture_spectrum, | 51 const std::array<float, kFftLengthBy2Plus1>& capture_spectrum, |
52 const AecState& aec_state, | 52 const AecState& aec_state, |
53 std::array<float, kFftLengthBy2Plus1>* echo_spectrum) { | 53 std::array<float, kFftLengthBy2Plus1>* echo_spectrum) { |
54 RTC_DCHECK(echo_spectrum); | 54 RTC_DCHECK(echo_spectrum); |
55 | 55 |
56 const FftBuffer& X_buffer = render_buffer; | 56 const RenderBuffer& X_buffer = render_buffer; |
57 const auto& Y2 = capture_spectrum; | 57 const auto& Y2 = capture_spectrum; |
58 std::array<float, kFftLengthBy2Plus1>* S2 = echo_spectrum; | 58 std::array<float, kFftLengthBy2Plus1>* S2 = echo_spectrum; |
59 | 59 |
60 // Choose delay to use. | 60 // Choose delay to use. |
61 const rtc::Optional<size_t> delay = | 61 const rtc::Optional<size_t> delay = |
62 aec_state.FilterDelay() | 62 aec_state.FilterDelay() |
63 ? aec_state.FilterDelay() | 63 ? aec_state.FilterDelay() |
64 : (aec_state.ExternalDelay() ? rtc::Optional<size_t>(std::min<size_t>( | 64 : (aec_state.ExternalDelay() ? rtc::Optional<size_t>(std::min<size_t>( |
65 *aec_state.ExternalDelay(), | 65 *aec_state.ExternalDelay(), |
66 X_buffer.Buffer().size() - 1)) | 66 X_buffer.Buffer().size() - 1)) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 std::transform(new_H2.begin(), new_H2.end(), H2_.begin(), H2_.begin(), | 102 std::transform(new_H2.begin(), new_H2.end(), H2_.begin(), H2_.begin(), |
103 H2_updater); | 103 H2_updater); |
104 } | 104 } |
105 | 105 |
106 // S2 = H2*X2_active. | 106 // S2 = H2*X2_active. |
107 std::transform(H2_.begin(), H2_.end(), X2_active.begin(), S2->begin(), | 107 std::transform(H2_.begin(), H2_.end(), X2_active.begin(), S2->begin(), |
108 [](CountedFloat a, float b) { return a.value * b; }); | 108 [](CountedFloat a, float b) { return a.value * b; }); |
109 } | 109 } |
110 | 110 |
111 } // namespace webrtc | 111 } // namespace webrtc |
OLD | NEW |