| 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/render_signal_analyzer.h" | 11 #include "webrtc/modules/audio_processing/aec3/render_signal_analyzer.h" |
| 12 | 12 |
| 13 // TODO(peah): Reactivate once the next CL has landed. | |
| 14 #if 0 | |
| 15 | |
| 16 #include <math.h> | 13 #include <math.h> |
| 17 #include <array> | 14 #include <array> |
| 18 #include <vector> | 15 #include <vector> |
| 19 | 16 |
| 20 #include "webrtc/base/array_view.h" | 17 #include "webrtc/base/array_view.h" |
| 21 #include "webrtc/base/random.h" | 18 #include "webrtc/base/random.h" |
| 22 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" | 19 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" |
| 23 #include "webrtc/modules/audio_processing/aec3/aec3_fft.h" | 20 #include "webrtc/modules/audio_processing/aec3/aec3_fft.h" |
| 24 #include "webrtc/modules/audio_processing/aec3/fft_buffer.h" | |
| 25 #include "webrtc/modules/audio_processing/aec3/fft_data.h" | 21 #include "webrtc/modules/audio_processing/aec3/fft_data.h" |
| 22 #include "webrtc/modules/audio_processing/aec3/render_buffer.h" |
| 26 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" | 23 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" |
| 27 #include "webrtc/test/gtest.h" | 24 #include "webrtc/test/gtest.h" |
| 28 | 25 |
| 29 namespace webrtc { | 26 namespace webrtc { |
| 30 namespace { | 27 namespace { |
| 31 | 28 |
| 32 constexpr float kPi = 3.141592f; | 29 constexpr float kPi = 3.141592f; |
| 33 | 30 |
| 34 void ProduceSinusoid(int sample_rate_hz, | 31 void ProduceSinusoid(int sample_rate_hz, |
| 35 float sinusoidal_frequency_hz, | 32 float sinusoidal_frequency_hz, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 52 RenderSignalAnalyzer analyzer; | 49 RenderSignalAnalyzer analyzer; |
| 53 EXPECT_DEATH(analyzer.MaskRegionsAroundNarrowBands(nullptr), ""); | 50 EXPECT_DEATH(analyzer.MaskRegionsAroundNarrowBands(nullptr), ""); |
| 54 } | 51 } |
| 55 | 52 |
| 56 #endif | 53 #endif |
| 57 | 54 |
| 58 // Verify that no narrow bands are detected in a Gaussian noise signal. | 55 // Verify that no narrow bands are detected in a Gaussian noise signal. |
| 59 TEST(RenderSignalAnalyzer, NoFalseDetectionOfNarrowBands) { | 56 TEST(RenderSignalAnalyzer, NoFalseDetectionOfNarrowBands) { |
| 60 RenderSignalAnalyzer analyzer; | 57 RenderSignalAnalyzer analyzer; |
| 61 Random random_generator(42U); | 58 Random random_generator(42U); |
| 62 std::vector<float> x(kBlockSize, 0.f); | 59 std::vector<std::vector<float>> x(3, std::vector<float>(kBlockSize, 0.f)); |
| 63 std::array<float, kBlockSize> x_old; | 60 std::array<float, kBlockSize> x_old; |
| 64 FftData X; | 61 FftData X; |
| 65 Aec3Fft fft; | 62 Aec3Fft fft; |
| 66 FftBuffer X_buffer(Aec3Optimization::kNone, 1, std::vector<size_t>(1, 1)); | 63 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, 1, |
| 64 std::vector<size_t>(1, 1)); |
| 67 std::array<float, kFftLengthBy2Plus1> mask; | 65 std::array<float, kFftLengthBy2Plus1> mask; |
| 68 x_old.fill(0.f); | 66 x_old.fill(0.f); |
| 69 | 67 |
| 70 for (size_t k = 0; k < 100; ++k) { | 68 for (size_t k = 0; k < 100; ++k) { |
| 71 RandomizeSampleVector(&random_generator, x); | 69 RandomizeSampleVector(&random_generator, x[0]); |
| 72 fft.PaddedFft(x, x_old, &X); | 70 fft.PaddedFft(x[0], x_old, &X); |
| 73 X_buffer.Insert(X); | 71 render_buffer.Insert(x); |
| 74 analyzer.Update(X_buffer, rtc::Optional<size_t>(0)); | 72 analyzer.Update(render_buffer, rtc::Optional<size_t>(0)); |
| 75 } | 73 } |
| 76 | 74 |
| 77 mask.fill(1.f); | 75 mask.fill(1.f); |
| 78 analyzer.MaskRegionsAroundNarrowBands(&mask); | 76 analyzer.MaskRegionsAroundNarrowBands(&mask); |
| 79 EXPECT_TRUE( | 77 EXPECT_TRUE( |
| 80 std::all_of(mask.begin(), mask.end(), [](float a) { return a == 1.f; })); | 78 std::all_of(mask.begin(), mask.end(), [](float a) { return a == 1.f; })); |
| 81 EXPECT_FALSE(analyzer.PoorSignalExcitation()); | 79 EXPECT_FALSE(analyzer.PoorSignalExcitation()); |
| 82 } | 80 } |
| 83 | 81 |
| 84 // Verify that a sinusiod signal is detected as narrow bands. | 82 // Verify that a sinusiod signal is detected as narrow bands. |
| 85 TEST(RenderSignalAnalyzer, NarrowBandDetection) { | 83 TEST(RenderSignalAnalyzer, NarrowBandDetection) { |
| 86 RenderSignalAnalyzer analyzer; | 84 RenderSignalAnalyzer analyzer; |
| 87 Random random_generator(42U); | 85 Random random_generator(42U); |
| 88 std::vector<float> x(kBlockSize, 0.f); | 86 std::vector<std::vector<float>> x(3, std::vector<float>(kBlockSize, 0.f)); |
| 89 std::array<float, kBlockSize> x_old; | 87 std::array<float, kBlockSize> x_old; |
| 90 FftData X; | |
| 91 Aec3Fft fft; | 88 Aec3Fft fft; |
| 92 FftBuffer X_buffer(Aec3Optimization::kNone, 1, std::vector<size_t>(1, 1)); | 89 RenderBuffer render_buffer(Aec3Optimization::kNone, 3, 1, |
| 90 std::vector<size_t>(1, 1)); |
| 93 std::array<float, kFftLengthBy2Plus1> mask; | 91 std::array<float, kFftLengthBy2Plus1> mask; |
| 94 x_old.fill(0.f); | 92 x_old.fill(0.f); |
| 95 constexpr int kSinusFrequencyBin = 32; | 93 constexpr int kSinusFrequencyBin = 32; |
| 96 | 94 |
| 97 auto generate_sinusoid_test = [&](bool known_delay) { | 95 auto generate_sinusoid_test = [&](bool known_delay) { |
| 98 size_t sample_counter = 0; | 96 size_t sample_counter = 0; |
| 99 for (size_t k = 0; k < 100; ++k) { | 97 for (size_t k = 0; k < 100; ++k) { |
| 100 ProduceSinusoid(16000, 16000 / 2 * kSinusFrequencyBin / kFftLengthBy2, | 98 ProduceSinusoid(16000, 16000 / 2 * kSinusFrequencyBin / kFftLengthBy2, |
| 101 &sample_counter, x); | 99 &sample_counter, x[0]); |
| 102 fft.PaddedFft(x, x_old, &X); | 100 render_buffer.Insert(x); |
| 103 X_buffer.Insert(X); | 101 analyzer.Update(render_buffer, known_delay ? rtc::Optional<size_t>(0) |
| 104 analyzer.Update( | 102 : rtc::Optional<size_t>()); |
| 105 X_buffer, | |
| 106 known_delay ? rtc::Optional<size_t>(0) : rtc::Optional<size_t>()); | |
| 107 } | 103 } |
| 108 }; | 104 }; |
| 109 | 105 |
| 110 generate_sinusoid_test(true); | 106 generate_sinusoid_test(true); |
| 111 mask.fill(1.f); | 107 mask.fill(1.f); |
| 112 analyzer.MaskRegionsAroundNarrowBands(&mask); | 108 analyzer.MaskRegionsAroundNarrowBands(&mask); |
| 113 for (int k = 0; k < static_cast<int>(mask.size()); ++k) { | 109 for (int k = 0; k < static_cast<int>(mask.size()); ++k) { |
| 114 EXPECT_EQ(abs(k - kSinusFrequencyBin) <= 2 ? 0.f : 1.f, mask[k]); | 110 EXPECT_EQ(abs(k - kSinusFrequencyBin) <= 2 ? 0.f : 1.f, mask[k]); |
| 115 } | 111 } |
| 116 EXPECT_TRUE(analyzer.PoorSignalExcitation()); | 112 EXPECT_TRUE(analyzer.PoorSignalExcitation()); |
| 117 | 113 |
| 118 // Verify that no bands are detected as narrow when the delay is unknown. | 114 // Verify that no bands are detected as narrow when the delay is unknown. |
| 119 generate_sinusoid_test(false); | 115 generate_sinusoid_test(false); |
| 120 mask.fill(1.f); | 116 mask.fill(1.f); |
| 121 analyzer.MaskRegionsAroundNarrowBands(&mask); | 117 analyzer.MaskRegionsAroundNarrowBands(&mask); |
| 122 std::for_each(mask.begin(), mask.end(), [](float a) { EXPECT_EQ(1.f, a); }); | 118 std::for_each(mask.begin(), mask.end(), [](float a) { EXPECT_EQ(1.f, a); }); |
| 123 EXPECT_FALSE(analyzer.PoorSignalExcitation()); | 119 EXPECT_FALSE(analyzer.PoorSignalExcitation()); |
| 124 } | 120 } |
| 125 | 121 |
| 126 } // namespace webrtc | 122 } // namespace webrtc |
| 127 | |
| 128 #endif | |
| OLD | NEW |