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"
|
2018-07-13 00:22:54 +02:00
|
|
|
#include "modules/audio_processing/aec3/subtractor_output.h"
|
2017-10-25 02:59:45 +02:00
|
|
|
#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-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;
|
2018-08-27 14:19:35 +02:00
|
|
|
std::array<float, kFftLengthBy2Plus1> S2;
|
2017-02-23 05:16:26 -08:00
|
|
|
std::array<float, kFftLengthBy2Plus1> N2;
|
2018-04-24 12:44:29 +02:00
|
|
|
FftData E;
|
|
|
|
|
FftData Y;
|
2017-04-06 15:45:32 -07:00
|
|
|
E2.fill(0.f);
|
|
|
|
|
R2.fill(0.f);
|
2018-08-27 14:19:35 +02:00
|
|
|
S2.fill(0.1f);
|
2017-04-06 15:45:32 -07:00
|
|
|
N2.fill(0.f);
|
2018-04-24 12:44:29 +02:00
|
|
|
E.re.fill(0.f);
|
|
|
|
|
E.im.fill(0.f);
|
|
|
|
|
Y.re.fill(0.f);
|
|
|
|
|
Y.im.fill(0.f);
|
|
|
|
|
|
2017-04-06 15:45:32 -07:00
|
|
|
float high_bands_gain;
|
2017-10-25 02:59:45 +02:00
|
|
|
AecState aec_state(EchoCanceller3Config{});
|
2018-03-14 23:23:47 +01:00
|
|
|
EXPECT_DEATH(
|
2018-04-24 12:44:29 +02:00
|
|
|
SuppressionGain(EchoCanceller3Config{}, DetectOptimization(), 16000)
|
2018-09-24 12:48:28 +02:00
|
|
|
.GetGain(E2, E2, S2, R2, N2, E, Y,
|
2018-04-24 12:44:29 +02:00
|
|
|
RenderSignalAnalyzer((EchoCanceller3Config{})), aec_state,
|
2018-03-14 23:23:47 +01:00
|
|
|
std::vector<std::vector<float>>(
|
|
|
|
|
3, std::vector<float>(kBlockSize, 0.f)),
|
|
|
|
|
&high_bands_gain, nullptr),
|
|
|
|
|
"");
|
2017-02-23 05:16:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Does a sanity check that the gains are correctly computed.
|
|
|
|
|
TEST(SuppressionGain, BasicGainComputation) {
|
2018-04-24 12:44:29 +02:00
|
|
|
SuppressionGain suppression_gain(EchoCanceller3Config(), DetectOptimization(),
|
|
|
|
|
16000);
|
2018-03-14 23:23:47 +01:00
|
|
|
RenderSignalAnalyzer analyzer(EchoCanceller3Config{});
|
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;
|
2018-08-27 14:19:35 +02:00
|
|
|
std::array<float, kFftLengthBy2Plus1> S2;
|
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;
|
2018-07-13 00:22:54 +02:00
|
|
|
SubtractorOutput output;
|
|
|
|
|
std::array<float, kBlockSize> y;
|
2018-04-24 12:44:29 +02:00
|
|
|
FftData E;
|
|
|
|
|
FftData Y;
|
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);
|
2017-12-11 22:28:45 +01:00
|
|
|
Subtractor subtractor(config, &data_dumper, DetectOptimization());
|
2017-12-01 23:01:44 +01:00
|
|
|
std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
|
2018-10-15 13:40:29 +02:00
|
|
|
RenderDelayBuffer::Create2(config, 3));
|
2018-06-19 10:50:11 +02:00
|
|
|
absl::optional<DelayEstimate> delay_estimate;
|
2017-10-25 02:59:45 +02:00
|
|
|
|
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);
|
2018-08-27 14:19:35 +02:00
|
|
|
S2.fill(0.1f);
|
2017-02-23 05:16:26 -08:00
|
|
|
N2.fill(100.f);
|
2018-07-13 00:22:54 +02:00
|
|
|
output.Reset();
|
|
|
|
|
y.fill(0.f);
|
2018-04-24 12:44:29 +02:00
|
|
|
E.re.fill(sqrtf(E2[0]));
|
|
|
|
|
E.im.fill(0.f);
|
|
|
|
|
Y.re.fill(sqrtf(Y2[0]));
|
|
|
|
|
Y.im.fill(0.f);
|
2018-02-20 22:18:27 +01:00
|
|
|
|
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) {
|
2018-02-21 08:46:03 +01:00
|
|
|
aec_state.Update(delay_estimate, subtractor.FilterFrequencyResponse(),
|
2017-12-20 22:19:56 +01:00
|
|
|
subtractor.FilterImpulseResponse(),
|
2018-07-13 00:22:54 +02:00
|
|
|
*render_delay_buffer->GetRenderBuffer(), E2, Y2, output,
|
|
|
|
|
y);
|
2017-10-25 02:59:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int k = 0; k < 100; ++k) {
|
2018-02-21 08:46:03 +01:00
|
|
|
aec_state.Update(delay_estimate, subtractor.FilterFrequencyResponse(),
|
2017-12-20 22:19:56 +01:00
|
|
|
subtractor.FilterImpulseResponse(),
|
2018-07-13 00:22:54 +02:00
|
|
|
*render_delay_buffer->GetRenderBuffer(), E2, Y2, output,
|
|
|
|
|
y);
|
2018-09-24 12:48:28 +02:00
|
|
|
suppression_gain.GetGain(E2, E2, S2, R2, N2, E, Y, 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);
|
2018-08-27 14:19:35 +02:00
|
|
|
S2.fill(0.1f);
|
2017-02-23 05:16:26 -08:00
|
|
|
N2.fill(0.f);
|
2018-04-24 12:44:29 +02:00
|
|
|
E.re.fill(sqrtf(E2[0]));
|
|
|
|
|
Y.re.fill(sqrtf(Y2[0]));
|
|
|
|
|
|
2017-10-25 02:59:45 +02:00
|
|
|
for (int k = 0; k < 100; ++k) {
|
2018-02-21 08:46:03 +01:00
|
|
|
aec_state.Update(delay_estimate, subtractor.FilterFrequencyResponse(),
|
2017-12-20 22:19:56 +01:00
|
|
|
subtractor.FilterImpulseResponse(),
|
2018-07-13 00:22:54 +02:00
|
|
|
*render_delay_buffer->GetRenderBuffer(), E2, Y2, output,
|
|
|
|
|
y);
|
2018-09-24 12:48:28 +02:00
|
|
|
suppression_gain.GetGain(E2, E2, S2, R2, N2, E, Y, 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);
|
2018-04-24 12:44:29 +02:00
|
|
|
E.re.fill(sqrtf(E2[0]));
|
|
|
|
|
|
2017-02-23 05:16:26 -08:00
|
|
|
for (int k = 0; k < 10; ++k) {
|
2018-09-24 12:48:28 +02:00
|
|
|
suppression_gain.GetGain(E2, E2, S2, R2, N2, E, Y, 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); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace aec3
|
|
|
|
|
} // namespace webrtc
|