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/adaptive_fir_filter.h" | 11 #include "webrtc/modules/audio_processing/aec3/adaptive_fir_filter.h" |
12 | 12 |
13 #include <math.h> | 13 #include <math.h> |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <numeric> | 15 #include <numeric> |
16 #include <string> | 16 #include <string> |
17 #include "webrtc/typedefs.h" | 17 #include "webrtc/typedefs.h" |
18 #if defined(WEBRTC_ARCH_X86_FAMILY) | 18 #if defined(WEBRTC_ARCH_X86_FAMILY) |
19 #include <emmintrin.h> | 19 #include <emmintrin.h> |
20 #endif | 20 #endif |
21 #include "webrtc/base/arraysize.h" | 21 #include "webrtc/base/arraysize.h" |
22 #include "webrtc/base/random.h" | 22 #include "webrtc/base/random.h" |
| 23 #include "webrtc/base/safe_minmax.h" |
23 #include "webrtc/modules/audio_processing/aec3/aec3_fft.h" | 24 #include "webrtc/modules/audio_processing/aec3/aec3_fft.h" |
24 #include "webrtc/modules/audio_processing/aec3/aec_state.h" | 25 #include "webrtc/modules/audio_processing/aec3/aec_state.h" |
25 #include "webrtc/modules/audio_processing/aec3/cascaded_biquad_filter.h" | 26 #include "webrtc/modules/audio_processing/aec3/cascaded_biquad_filter.h" |
26 #include "webrtc/modules/audio_processing/aec3/render_signal_analyzer.h" | 27 #include "webrtc/modules/audio_processing/aec3/render_signal_analyzer.h" |
27 #include "webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.h" | 28 #include "webrtc/modules/audio_processing/aec3/shadow_filter_update_gain.h" |
28 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | 29 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" |
29 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" | 30 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" |
30 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" | 31 #include "webrtc/system_wrappers/include/cpu_features_wrapper.h" |
31 #include "webrtc/test/gtest.h" | 32 #include "webrtc/test/gtest.h" |
32 | 33 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 x_hp_filter.Process(x[0]); | 344 x_hp_filter.Process(x[0]); |
344 y_hp_filter.Process(y); | 345 y_hp_filter.Process(y); |
345 | 346 |
346 render_buffer.Insert(x); | 347 render_buffer.Insert(x); |
347 render_signal_analyzer.Update(render_buffer, aec_state.FilterDelay()); | 348 render_signal_analyzer.Update(render_buffer, aec_state.FilterDelay()); |
348 | 349 |
349 filter.Filter(render_buffer, &S); | 350 filter.Filter(render_buffer, &S); |
350 fft.Ifft(S, &s); | 351 fft.Ifft(S, &s); |
351 std::transform(y.begin(), y.end(), s.begin() + kFftLengthBy2, e.begin(), | 352 std::transform(y.begin(), y.end(), s.begin() + kFftLengthBy2, e.begin(), |
352 [&](float a, float b) { return a - b * kScale; }); | 353 [&](float a, float b) { return a - b * kScale; }); |
353 std::for_each(e.begin(), e.end(), [](float& a) { | 354 std::for_each(e.begin(), e.end(), |
354 a = std::max(std::min(a, 32767.0f), -32768.0f); | 355 [](float& a) { a = rtc::SafeClamp(a, -32768.f, 32767.f); }); |
355 }); | |
356 fft.ZeroPaddedFft(e, &E); | 356 fft.ZeroPaddedFft(e, &E); |
357 | 357 |
358 gain.Compute(render_buffer, render_signal_analyzer, E, | 358 gain.Compute(render_buffer, render_signal_analyzer, E, |
359 filter.SizePartitions(), false, &G); | 359 filter.SizePartitions(), false, &G); |
360 filter.Adapt(render_buffer, G); | 360 filter.Adapt(render_buffer, G); |
361 aec_state.HandleEchoPathChange(EchoPathVariability(false, false)); | 361 aec_state.HandleEchoPathChange(EchoPathVariability(false, false)); |
362 aec_state.Update(filter.FilterFrequencyResponse(), | 362 aec_state.Update(filter.FilterFrequencyResponse(), |
363 rtc::Optional<size_t>(), render_buffer, E2_main, Y2, | 363 rtc::Optional<size_t>(), render_buffer, E2_main, Y2, |
364 x[0], false); | 364 x[0], false); |
365 } | 365 } |
366 // Verify that the filter is able to perform well. | 366 // Verify that the filter is able to perform well. |
367 EXPECT_LT(1000 * std::inner_product(e.begin(), e.end(), e.begin(), 0.f), | 367 EXPECT_LT(1000 * std::inner_product(e.begin(), e.end(), e.begin(), 0.f), |
368 std::inner_product(y.begin(), y.end(), y.begin(), 0.f)); | 368 std::inner_product(y.begin(), y.end(), y.begin(), 0.f)); |
369 ASSERT_TRUE(aec_state.FilterDelay()); | 369 ASSERT_TRUE(aec_state.FilterDelay()); |
370 EXPECT_EQ(delay_samples / kBlockSize, *aec_state.FilterDelay()); | 370 EXPECT_EQ(delay_samples / kBlockSize, *aec_state.FilterDelay()); |
371 } | 371 } |
372 } | 372 } |
373 } // namespace aec3 | 373 } // namespace aec3 |
374 } // namespace webrtc | 374 } // namespace webrtc |
OLD | NEW |