mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-20 00:57:49 +01:00

In order to eliminate the WebRTC Subtree mirror in Chromium, WebRTC is moving the content of the src/webrtc directory up to the src/ directory. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true TBR=tommi@webrtc.org Bug: chromium:611808 Change-Id: Iac59c5b51b950f174119565bac87955a7994bc38 Reviewed-on: https://webrtc-review.googlesource.com/1560 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Henrik Kjellander <kjellander@webrtc.org> Cr-Commit-Position: refs/heads/master@{#19845}
96 lines
3.4 KiB
C++
96 lines
3.4 KiB
C++
/*
|
|
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "webrtc/modules/audio_processing/aec3/suppression_gain.h"
|
|
|
|
#include "webrtc/rtc_base/checks.h"
|
|
#include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
|
|
#include "webrtc/test/gtest.h"
|
|
#include "webrtc/typedefs.h"
|
|
|
|
namespace webrtc {
|
|
namespace aec3 {
|
|
|
|
#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
|
|
|
|
// Verifies that the check for non-null output gains works.
|
|
TEST(SuppressionGain, NullOutputGains) {
|
|
std::array<float, kFftLengthBy2Plus1> E2;
|
|
std::array<float, kFftLengthBy2Plus1> R2;
|
|
std::array<float, kFftLengthBy2Plus1> N2;
|
|
E2.fill(0.f);
|
|
R2.fill(0.f);
|
|
N2.fill(0.f);
|
|
float high_bands_gain;
|
|
EXPECT_DEATH(SuppressionGain(AudioProcessing::Config::EchoCanceller3{},
|
|
DetectOptimization())
|
|
.GetGain(E2, R2, N2, RenderSignalAnalyzer(), false,
|
|
std::vector<std::vector<float>>(
|
|
3, std::vector<float>(kBlockSize, 0.f)),
|
|
false, &high_bands_gain, nullptr),
|
|
"");
|
|
}
|
|
|
|
#endif
|
|
|
|
// Does a sanity check that the gains are correctly computed.
|
|
TEST(SuppressionGain, BasicGainComputation) {
|
|
SuppressionGain suppression_gain(AudioProcessing::Config::EchoCanceller3(),
|
|
DetectOptimization());
|
|
RenderSignalAnalyzer analyzer;
|
|
float high_bands_gain;
|
|
std::array<float, kFftLengthBy2Plus1> E2;
|
|
std::array<float, kFftLengthBy2Plus1> R2;
|
|
std::array<float, kFftLengthBy2Plus1> N2;
|
|
std::array<float, kFftLengthBy2Plus1> g;
|
|
std::vector<std::vector<float>> x(1, std::vector<float>(kBlockSize, 0.f));
|
|
|
|
// Ensure that a strong noise is detected to mask any echoes.
|
|
E2.fill(10.f);
|
|
R2.fill(0.1f);
|
|
N2.fill(100.f);
|
|
for (int k = 0; k < 10; ++k) {
|
|
suppression_gain.GetGain(E2, R2, N2, analyzer, false, x, false,
|
|
&high_bands_gain, &g);
|
|
}
|
|
std::for_each(g.begin(), g.end(),
|
|
[](float a) { EXPECT_NEAR(1.f, a, 0.001); });
|
|
|
|
// Ensure that a strong nearend is detected to mask any echoes.
|
|
E2.fill(100.f);
|
|
R2.fill(0.1f);
|
|
N2.fill(0.f);
|
|
for (int k = 0; k < 10; ++k) {
|
|
suppression_gain.GetGain(E2, R2, N2, analyzer, false, x, false,
|
|
&high_bands_gain, &g);
|
|
}
|
|
std::for_each(g.begin(), g.end(),
|
|
[](float a) { EXPECT_NEAR(1.f, a, 0.001); });
|
|
|
|
// Ensure that a strong echo is suppressed.
|
|
E2.fill(1000000000.f);
|
|
R2.fill(10000000000000.f);
|
|
N2.fill(0.f);
|
|
for (int k = 0; k < 10; ++k) {
|
|
suppression_gain.GetGain(E2, R2, N2, analyzer, false, x, false,
|
|
&high_bands_gain, &g);
|
|
}
|
|
std::for_each(g.begin(), g.end(),
|
|
[](float a) { EXPECT_NEAR(0.f, a, 0.001); });
|
|
|
|
// Verify the functionality for forcing a zero gain.
|
|
suppression_gain.GetGain(E2, R2, N2, analyzer, false, x, true,
|
|
&high_bands_gain, &g);
|
|
std::for_each(g.begin(), g.end(), [](float a) { EXPECT_FLOAT_EQ(0.f, a); });
|
|
EXPECT_FLOAT_EQ(0.f, high_bands_gain);
|
|
}
|
|
|
|
} // namespace aec3
|
|
} // namespace webrtc
|