2017-02-23 05:16:26 -08:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/aec3/suppression_gain.h"
|
2017-02-23 05:16:26 -08:00
|
|
|
|
2017-10-25 02:59:45 +02:00
|
|
|
#include "modules/audio_processing/aec3/aec_state.h"
|
2017-12-01 23:01:44 +01:00
|
|
|
#include "modules/audio_processing/aec3/render_delay_buffer.h"
|
2017-10-25 02:59:45 +02:00
|
|
|
#include "modules/audio_processing/aec3/subtractor.h"
|
|
|
|
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "system_wrappers/include/cpu_features_wrapper.h"
|
|
|
|
|
#include "test/gtest.h"
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "typedefs.h" // NOLINT(build/include)
|
2017-02-23 05:16:26 -08:00
|
|
|
|
|
|
|
|
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;
|
2017-04-06 15:45:32 -07:00
|
|
|
E2.fill(0.f);
|
|
|
|
|
R2.fill(0.f);
|
|
|
|
|
N2.fill(0.f);
|
|
|
|
|
float high_bands_gain;
|
2017-10-25 02:59:45 +02:00
|
|
|
AecState aec_state(EchoCanceller3Config{});
|
2017-10-18 12:32:42 +02:00
|
|
|
EXPECT_DEATH(SuppressionGain(EchoCanceller3Config{}, DetectOptimization())
|
2017-10-25 02:59:45 +02:00
|
|
|
.GetGain(E2, R2, N2, RenderSignalAnalyzer(), aec_state,
|
2017-04-06 15:45:32 -07:00
|
|
|
std::vector<std::vector<float>>(
|
|
|
|
|
3, std::vector<float>(kBlockSize, 0.f)),
|
2017-10-25 02:59:45 +02:00
|
|
|
&high_bands_gain, nullptr),
|
2017-04-06 15:45:32 -07:00
|
|
|
"");
|
2017-02-23 05:16:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Does a sanity check that the gains are correctly computed.
|
|
|
|
|
TEST(SuppressionGain, BasicGainComputation) {
|
2017-10-18 12:32:42 +02:00
|
|
|
SuppressionGain suppression_gain(EchoCanceller3Config(),
|
2017-08-24 22:36:53 -07:00
|
|
|
DetectOptimization());
|
2017-07-11 06:13:43 -07:00
|
|
|
RenderSignalAnalyzer analyzer;
|
2017-04-06 15:45:32 -07:00
|
|
|
float high_bands_gain;
|
2017-02-23 05:16:26 -08:00
|
|
|
std::array<float, kFftLengthBy2Plus1> E2;
|
2017-10-25 02:59:45 +02:00
|
|
|
std::array<float, kFftLengthBy2Plus1> Y2;
|
2017-02-23 05:16:26 -08:00
|
|
|
std::array<float, kFftLengthBy2Plus1> R2;
|
|
|
|
|
std::array<float, kFftLengthBy2Plus1> N2;
|
|
|
|
|
std::array<float, kFftLengthBy2Plus1> g;
|
2017-10-25 02:59:45 +02:00
|
|
|
std::array<float, kBlockSize> s;
|
2017-04-06 15:45:32 -07:00
|
|
|
std::vector<std::vector<float>> x(1, std::vector<float>(kBlockSize, 0.f));
|
2017-12-01 23:01:44 +01:00
|
|
|
EchoCanceller3Config config;
|
|
|
|
|
AecState aec_state(config);
|
2017-10-25 02:59:45 +02:00
|
|
|
ApmDataDumper data_dumper(42);
|
|
|
|
|
Subtractor subtractor(&data_dumper, DetectOptimization());
|
2017-12-01 23:01:44 +01:00
|
|
|
std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
|
|
|
|
|
RenderDelayBuffer::Create(config, 3));
|
2017-10-25 02:59:45 +02:00
|
|
|
|
|
|
|
|
// Verify the functionality for forcing a zero gain.
|
|
|
|
|
E2.fill(1000000000.f);
|
|
|
|
|
R2.fill(10000000000000.f);
|
|
|
|
|
N2.fill(0.f);
|
|
|
|
|
s.fill(10.f);
|
2017-11-17 14:34:48 +01:00
|
|
|
aec_state.Update(
|
|
|
|
|
subtractor.FilterFrequencyResponse(), subtractor.FilterImpulseResponse(),
|
2017-12-11 21:34:19 +01:00
|
|
|
subtractor.ConvergedFilter(), 10, *render_delay_buffer->GetRenderBuffer(),
|
2017-12-01 23:01:44 +01:00
|
|
|
E2, Y2, x[0], s, false);
|
2017-10-25 02:59:45 +02:00
|
|
|
suppression_gain.GetGain(E2, R2, N2, analyzer, aec_state, x, &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);
|
2017-02-23 05:16:26 -08:00
|
|
|
|
|
|
|
|
// Ensure that a strong noise is detected to mask any echoes.
|
|
|
|
|
E2.fill(10.f);
|
2017-10-25 02:59:45 +02:00
|
|
|
Y2.fill(10.f);
|
2017-02-23 05:16:26 -08:00
|
|
|
R2.fill(0.1f);
|
|
|
|
|
N2.fill(100.f);
|
2017-10-25 02:59:45 +02:00
|
|
|
// Ensure that the gain is no longer forced to zero.
|
|
|
|
|
for (int k = 0; k <= kNumBlocksPerSecond / 5 + 1; ++k) {
|
2017-12-01 23:01:44 +01:00
|
|
|
aec_state.Update(
|
|
|
|
|
subtractor.FilterFrequencyResponse(),
|
|
|
|
|
subtractor.FilterImpulseResponse(), subtractor.ConvergedFilter(), 10,
|
2017-12-11 21:34:19 +01:00
|
|
|
*render_delay_buffer->GetRenderBuffer(), E2, Y2, x[0], s, false);
|
2017-10-25 02:59:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int k = 0; k < 100; ++k) {
|
2017-12-01 23:01:44 +01:00
|
|
|
aec_state.Update(
|
|
|
|
|
subtractor.FilterFrequencyResponse(),
|
|
|
|
|
subtractor.FilterImpulseResponse(), subtractor.ConvergedFilter(), 10,
|
2017-12-11 21:34:19 +01:00
|
|
|
*render_delay_buffer->GetRenderBuffer(), E2, Y2, x[0], s, false);
|
2017-10-25 02:59:45 +02:00
|
|
|
suppression_gain.GetGain(E2, R2, N2, analyzer, aec_state, x,
|
2017-07-11 06:13:43 -07:00
|
|
|
&high_bands_gain, &g);
|
2017-02-23 05:16:26 -08:00
|
|
|
}
|
|
|
|
|
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);
|
2017-10-25 02:59:45 +02:00
|
|
|
Y2.fill(100.f);
|
2017-02-23 05:16:26 -08:00
|
|
|
R2.fill(0.1f);
|
|
|
|
|
N2.fill(0.f);
|
2017-10-25 02:59:45 +02:00
|
|
|
for (int k = 0; k < 100; ++k) {
|
2017-12-01 23:01:44 +01:00
|
|
|
aec_state.Update(
|
|
|
|
|
subtractor.FilterFrequencyResponse(),
|
|
|
|
|
subtractor.FilterImpulseResponse(), subtractor.ConvergedFilter(), 10,
|
2017-12-11 21:34:19 +01:00
|
|
|
*render_delay_buffer->GetRenderBuffer(), E2, Y2, x[0], s, false);
|
2017-10-25 02:59:45 +02:00
|
|
|
suppression_gain.GetGain(E2, R2, N2, analyzer, aec_state, x,
|
2017-07-11 06:13:43 -07:00
|
|
|
&high_bands_gain, &g);
|
2017-02-23 05:16:26 -08:00
|
|
|
}
|
|
|
|
|
std::for_each(g.begin(), g.end(),
|
|
|
|
|
[](float a) { EXPECT_NEAR(1.f, a, 0.001); });
|
|
|
|
|
|
|
|
|
|
// Ensure that a strong echo is suppressed.
|
2017-05-23 04:07:10 -07:00
|
|
|
E2.fill(1000000000.f);
|
|
|
|
|
R2.fill(10000000000000.f);
|
2017-02-23 05:16:26 -08:00
|
|
|
N2.fill(0.f);
|
|
|
|
|
for (int k = 0; k < 10; ++k) {
|
2017-10-25 02:59:45 +02:00
|
|
|
suppression_gain.GetGain(E2, R2, N2, analyzer, aec_state, x,
|
2017-07-11 06:13:43 -07:00
|
|
|
&high_bands_gain, &g);
|
2017-02-23 05:16:26 -08:00
|
|
|
}
|
|
|
|
|
std::for_each(g.begin(), g.end(),
|
|
|
|
|
[](float a) { EXPECT_NEAR(0.f, a, 0.001); });
|
2017-04-10 13:52:14 -07:00
|
|
|
|
2017-02-23 05:16:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace aec3
|
|
|
|
|
} // namespace webrtc
|