| 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 // TODO(peah): Reactivate once the next CL has landed. | |
| 14 #if 0 | |
| 15 #include <algorithm> | 13 #include <algorithm> |
| 16 #include <numeric> | 14 #include <numeric> |
| 17 #include <string> | 15 #include <string> |
| 18 | 16 |
| 19 #include "webrtc/base/random.h" | 17 #include "webrtc/base/random.h" |
| 20 #include "webrtc/modules/audio_processing/aec3/aec_state.h" | 18 #include "webrtc/modules/audio_processing/aec3/aec_state.h" |
| 21 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" | 19 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" |
| 22 #include "webrtc/test/gtest.h" | 20 #include "webrtc/test/gtest.h" |
| 23 | 21 |
| 24 namespace webrtc { | 22 namespace webrtc { |
| 25 namespace { | 23 namespace { |
| 26 | 24 |
| 27 float RunSubtractorTest(int num_blocks_to_process, | 25 float RunSubtractorTest(int num_blocks_to_process, |
| 28 int delay_samples, | 26 int delay_samples, |
| 29 bool uncorrelated_inputs, | 27 bool uncorrelated_inputs, |
| 30 const std::vector<int>& blocks_with_echo_path_changes) { | 28 const std::vector<int>& blocks_with_echo_path_changes) { |
| 31 ApmDataDumper data_dumper(42); | 29 ApmDataDumper data_dumper(42); |
| 32 Subtractor subtractor(&data_dumper, DetectOptimization()); | 30 Subtractor subtractor(&data_dumper, DetectOptimization()); |
| 33 std::vector<float> x(kBlockSize, 0.f); | 31 std::vector<std::vector<float>> x(3, std::vector<float>(kBlockSize, 0.f)); |
| 34 std::vector<float> y(kBlockSize, 0.f); | 32 std::vector<float> y(kBlockSize, 0.f); |
| 35 std::array<float, kBlockSize> x_old; | 33 std::array<float, kBlockSize> x_old; |
| 36 SubtractorOutput output; | 34 SubtractorOutput output; |
| 37 FftBuffer X_buffer( | 35 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, kAdaptiveFilterLength, |
| 38 Aec3Optimization::kNone, subtractor.MinFarendBufferLength(), | 36 std::vector<size_t>(1, kAdaptiveFilterLength)); |
| 39 std::vector<size_t>(1, subtractor.MinFarendBufferLength())); | |
| 40 RenderSignalAnalyzer render_signal_analyzer; | 37 RenderSignalAnalyzer render_signal_analyzer; |
| 41 Random random_generator(42U); | 38 Random random_generator(42U); |
| 42 Aec3Fft fft; | 39 Aec3Fft fft; |
| 43 FftData X; | |
| 44 std::array<float, kFftLengthBy2Plus1> Y2; | 40 std::array<float, kFftLengthBy2Plus1> Y2; |
| 45 std::array<float, kFftLengthBy2Plus1> E2_main; | 41 std::array<float, kFftLengthBy2Plus1> E2_main; |
| 46 std::array<float, kFftLengthBy2Plus1> E2_shadow; | 42 std::array<float, kFftLengthBy2Plus1> E2_shadow; |
| 47 AecState aec_state; | 43 AecState aec_state; |
| 48 x_old.fill(0.f); | 44 x_old.fill(0.f); |
| 49 Y2.fill(0.f); | 45 Y2.fill(0.f); |
| 50 E2_main.fill(0.f); | 46 E2_main.fill(0.f); |
| 51 E2_shadow.fill(0.f); | 47 E2_shadow.fill(0.f); |
| 52 | 48 |
| 53 DelayBuffer<float> delay_buffer(delay_samples); | 49 DelayBuffer<float> delay_buffer(delay_samples); |
| 54 for (int k = 0; k < num_blocks_to_process; ++k) { | 50 for (int k = 0; k < num_blocks_to_process; ++k) { |
| 55 RandomizeSampleVector(&random_generator, x); | 51 RandomizeSampleVector(&random_generator, x[0]); |
| 56 if (uncorrelated_inputs) { | 52 if (uncorrelated_inputs) { |
| 57 RandomizeSampleVector(&random_generator, y); | 53 RandomizeSampleVector(&random_generator, y); |
| 58 } else { | 54 } else { |
| 59 delay_buffer.Delay(x, y); | 55 delay_buffer.Delay(x[0], y); |
| 60 } | 56 } |
| 61 fft.PaddedFft(x, x_old, &X); | 57 render_buffer.Insert(x); |
| 62 X_buffer.Insert(X); | 58 render_signal_analyzer.Update(render_buffer, aec_state.FilterDelay()); |
| 63 render_signal_analyzer.Update(X_buffer, aec_state.FilterDelay()); | |
| 64 | 59 |
| 65 // Handle echo path changes. | 60 // Handle echo path changes. |
| 66 if (std::find(blocks_with_echo_path_changes.begin(), | 61 if (std::find(blocks_with_echo_path_changes.begin(), |
| 67 blocks_with_echo_path_changes.end(), | 62 blocks_with_echo_path_changes.end(), |
| 68 k) != blocks_with_echo_path_changes.end()) { | 63 k) != blocks_with_echo_path_changes.end()) { |
| 69 subtractor.HandleEchoPathChange(EchoPathVariability(true, true)); | 64 subtractor.HandleEchoPathChange(EchoPathVariability(true, true)); |
| 70 } | 65 } |
| 71 subtractor.Process(X_buffer, y, render_signal_analyzer, false, &output); | 66 subtractor.Process(render_buffer, y, render_signal_analyzer, aec_state, |
| 67 &output); |
| 72 | 68 |
| 69 aec_state.HandleEchoPathChange(EchoPathVariability(false, false)); |
| 73 aec_state.Update(subtractor.FilterFrequencyResponse(), | 70 aec_state.Update(subtractor.FilterFrequencyResponse(), |
| 74 rtc::Optional<size_t>(delay_samples / kBlockSize), | 71 rtc::Optional<size_t>(delay_samples / kBlockSize), |
| 75 X_buffer, E2_main, E2_shadow, Y2, x, | 72 render_buffer, E2_main, Y2, x[0], false); |
| 76 EchoPathVariability(false, false), false); | |
| 77 } | 73 } |
| 78 | 74 |
| 79 const float output_power = std::inner_product( | 75 const float output_power = std::inner_product( |
| 80 output.e_main.begin(), output.e_main.end(), output.e_main.begin(), 0.f); | 76 output.e_main.begin(), output.e_main.end(), output.e_main.begin(), 0.f); |
| 81 const float y_power = std::inner_product(y.begin(), y.end(), y.begin(), 0.f); | 77 const float y_power = std::inner_product(y.begin(), y.end(), y.begin(), 0.f); |
| 82 if (y_power == 0.f) { | 78 if (y_power == 0.f) { |
| 83 ADD_FAILURE(); | 79 ADD_FAILURE(); |
| 84 return -1.0; | 80 return -1.0; |
| 85 } | 81 } |
| 86 return output_power / y_power; | 82 return output_power / y_power; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 100 TEST(Subtractor, NullDataDumper) { | 96 TEST(Subtractor, NullDataDumper) { |
| 101 EXPECT_DEATH(Subtractor(nullptr, DetectOptimization()), ""); | 97 EXPECT_DEATH(Subtractor(nullptr, DetectOptimization()), ""); |
| 102 } | 98 } |
| 103 | 99 |
| 104 // Verifies the check for null subtractor output. | 100 // Verifies the check for null subtractor output. |
| 105 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH | 101 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH |
| 106 // tests on test bots has been fixed. | 102 // tests on test bots has been fixed. |
| 107 TEST(Subtractor, DISABLED_NullOutput) { | 103 TEST(Subtractor, DISABLED_NullOutput) { |
| 108 ApmDataDumper data_dumper(42); | 104 ApmDataDumper data_dumper(42); |
| 109 Subtractor subtractor(&data_dumper, DetectOptimization()); | 105 Subtractor subtractor(&data_dumper, DetectOptimization()); |
| 110 FftBuffer X_buffer( | 106 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, kAdaptiveFilterLength, |
| 111 Aec3Optimization::kNone, subtractor.MinFarendBufferLength(), | 107 std::vector<size_t>(1, kAdaptiveFilterLength)); |
| 112 std::vector<size_t>(1, subtractor.MinFarendBufferLength())); | |
| 113 RenderSignalAnalyzer render_signal_analyzer; | 108 RenderSignalAnalyzer render_signal_analyzer; |
| 114 std::vector<float> y(kBlockSize, 0.f); | 109 std::vector<float> y(kBlockSize, 0.f); |
| 115 | 110 |
| 116 EXPECT_DEATH( | 111 EXPECT_DEATH(subtractor.Process(render_buffer, y, render_signal_analyzer, |
| 117 subtractor.Process(X_buffer, y, render_signal_analyzer, false, nullptr), | 112 AecState(), nullptr), |
| 118 ""); | 113 ""); |
| 119 } | 114 } |
| 120 | 115 |
| 121 // Verifies the check for the capture signal size. | 116 // Verifies the check for the capture signal size. |
| 122 TEST(Subtractor, WrongCaptureSize) { | 117 TEST(Subtractor, WrongCaptureSize) { |
| 123 ApmDataDumper data_dumper(42); | 118 ApmDataDumper data_dumper(42); |
| 124 Subtractor subtractor(&data_dumper, DetectOptimization()); | 119 Subtractor subtractor(&data_dumper, DetectOptimization()); |
| 125 FftBuffer X_buffer( | 120 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, kAdaptiveFilterLength, |
| 126 Aec3Optimization::kNone, subtractor.MinFarendBufferLength(), | 121 std::vector<size_t>(1, kAdaptiveFilterLength)); |
| 127 std::vector<size_t>(1, subtractor.MinFarendBufferLength())); | |
| 128 RenderSignalAnalyzer render_signal_analyzer; | 122 RenderSignalAnalyzer render_signal_analyzer; |
| 129 std::vector<float> y(kBlockSize - 1, 0.f); | 123 std::vector<float> y(kBlockSize - 1, 0.f); |
| 130 SubtractorOutput output; | 124 SubtractorOutput output; |
| 131 | 125 |
| 132 EXPECT_DEATH( | 126 EXPECT_DEATH(subtractor.Process(render_buffer, y, render_signal_analyzer, |
| 133 subtractor.Process(X_buffer, y, render_signal_analyzer, false, &output), | 127 AecState(), &output), |
| 134 ""); | 128 ""); |
| 135 } | 129 } |
| 136 | 130 |
| 137 #endif | 131 #endif |
| 138 | 132 |
| 139 // Verifies that the subtractor is able to converge on correlated data. | 133 // Verifies that the subtractor is able to converge on correlated data. |
| 140 TEST(Subtractor, Convergence) { | 134 TEST(Subtractor, Convergence) { |
| 141 std::vector<int> blocks_with_echo_path_changes; | 135 std::vector<int> blocks_with_echo_path_changes; |
| 142 for (size_t delay_samples : {0, 64, 150, 200, 301}) { | 136 for (size_t delay_samples : {0, 64, 150, 200, 301}) { |
| 143 SCOPED_TRACE(ProduceDebugText(delay_samples)); | 137 SCOPED_TRACE(ProduceDebugText(delay_samples)); |
| 144 | 138 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 168 for (size_t delay_samples : {0, 64, 150, 200, 301}) { | 162 for (size_t delay_samples : {0, 64, 150, 200, 301}) { |
| 169 SCOPED_TRACE(ProduceDebugText(delay_samples)); | 163 SCOPED_TRACE(ProduceDebugText(delay_samples)); |
| 170 | 164 |
| 171 float echo_to_nearend_power = RunSubtractorTest( | 165 float echo_to_nearend_power = RunSubtractorTest( |
| 172 100, delay_samples, false, blocks_with_echo_path_changes); | 166 100, delay_samples, false, blocks_with_echo_path_changes); |
| 173 EXPECT_NEAR(1.f, echo_to_nearend_power, 0.0000001f); | 167 EXPECT_NEAR(1.f, echo_to_nearend_power, 0.0000001f); |
| 174 } | 168 } |
| 175 } | 169 } |
| 176 | 170 |
| 177 } // namespace webrtc | 171 } // namespace webrtc |
| 178 | |
| 179 #endif | |
| OLD | NEW |