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 |
11 #include "webrtc/modules/audio_processing/aec3/subtractor.h" | 11 #include "webrtc/modules/audio_processing/aec3/subtractor.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
15 #include "webrtc/base/array_view.h" | 15 #include "webrtc/base/array_view.h" |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/safe_minmax.h" |
17 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | 18 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" |
18 | 19 |
19 namespace webrtc { | 20 namespace webrtc { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 void PredictionError(const Aec3Fft& fft, | 24 void PredictionError(const Aec3Fft& fft, |
24 const FftData& S, | 25 const FftData& S, |
25 rtc::ArrayView<const float> y, | 26 rtc::ArrayView<const float> y, |
26 std::array<float, kBlockSize>* e, | 27 std::array<float, kBlockSize>* e, |
27 FftData* E) { | 28 FftData* E) { |
28 std::array<float, kFftLength> s; | 29 std::array<float, kFftLength> s; |
29 fft.Ifft(S, &s); | 30 fft.Ifft(S, &s); |
30 constexpr float kScale = 1.0f / kFftLengthBy2; | 31 constexpr float kScale = 1.0f / kFftLengthBy2; |
31 std::transform(y.begin(), y.end(), s.begin() + kFftLengthBy2, e->begin(), | 32 std::transform(y.begin(), y.end(), s.begin() + kFftLengthBy2, e->begin(), |
32 [&](float a, float b) { return a - b * kScale; }); | 33 [&](float a, float b) { return a - b * kScale; }); |
33 std::for_each(e->begin(), e->end(), [](float& a) { | 34 std::for_each(e->begin(), e->end(), |
34 a = std::max(std::min(a, 32767.0f), -32768.0f); | 35 [](float& a) { a = rtc::SafeClamp(a, -32768.f, 32767.f); }); |
35 }); | |
36 fft.ZeroPaddedFft(*e, E); | 36 fft.ZeroPaddedFft(*e, E); |
37 } | 37 } |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 Subtractor::Subtractor(ApmDataDumper* data_dumper, | 40 Subtractor::Subtractor(ApmDataDumper* data_dumper, |
41 Aec3Optimization optimization) | 41 Aec3Optimization optimization) |
42 : fft_(), | 42 : fft_(), |
43 data_dumper_(data_dumper), | 43 data_dumper_(data_dumper), |
44 optimization_(optimization), | 44 optimization_(optimization), |
45 main_filter_(kAdaptiveFilterLength, optimization, data_dumper_), | 45 main_filter_(kAdaptiveFilterLength, optimization, data_dumper_), |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 shadow_filter_.Adapt(render_buffer, G); | 100 shadow_filter_.Adapt(render_buffer, G); |
101 | 101 |
102 data_dumper_->DumpRaw("aec3_subtractor_G_shadow", G.re); | 102 data_dumper_->DumpRaw("aec3_subtractor_G_shadow", G.re); |
103 data_dumper_->DumpRaw("aec3_subtractor_G_shadow", G.im); | 103 data_dumper_->DumpRaw("aec3_subtractor_G_shadow", G.im); |
104 | 104 |
105 main_filter_.DumpFilter("aec3_subtractor_H_main"); | 105 main_filter_.DumpFilter("aec3_subtractor_H_main"); |
106 shadow_filter_.DumpFilter("aec3_subtractor_H_shadow"); | 106 shadow_filter_.DumpFilter("aec3_subtractor_H_shadow"); |
107 } | 107 } |
108 | 108 |
109 } // namespace webrtc | 109 } // namespace webrtc |
OLD | NEW |