Set a positive initial gain in the Adaptive Digital GC.

If the adaptive gain is too low, we raise it slowly and only during
speech.

The CL gives better behavior at the start of a call. If the gain is too
high, the fixed-digital limits it. The gain is also quickly reduced by
the AdaptiveGainApplier.

Bug: webrtc:7494
Change-Id: I683f1e3e463cddec2d91f6c7f15c73e744430034
Reviewed-on: https://webrtc-review.googlesource.com/71484
Commit-Queue: Alex Loiko <aleloi@webrtc.org>
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23053}
This commit is contained in:
Alex Loiko 2018-04-20 15:28:45 +02:00 committed by Commit Bot
parent d4043f69ae
commit 95141d91d8
5 changed files with 16 additions and 16 deletions

View File

@ -68,8 +68,7 @@ float ComputeGainChangeThisFrameDb(float target_gain_db,
AdaptiveDigitalGainApplier::AdaptiveDigitalGainApplier( AdaptiveDigitalGainApplier::AdaptiveDigitalGainApplier(
ApmDataDumper* apm_data_dumper) ApmDataDumper* apm_data_dumper)
: gain_applier_(false, 1.f), // Initial gain is 1, and we do not : gain_applier_(false, DbToRatio(last_gain_db_)),
// clip after gain.
apm_data_dumper_(apm_data_dumper) {} apm_data_dumper_(apm_data_dumper) {}
void AdaptiveDigitalGainApplier::Process( void AdaptiveDigitalGainApplier::Process(

View File

@ -11,6 +11,7 @@
#ifndef MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_DIGITAL_GAIN_APPLIER_H_ #ifndef MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_DIGITAL_GAIN_APPLIER_H_
#define MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_DIGITAL_GAIN_APPLIER_H_ #define MODULES_AUDIO_PROCESSING_AGC2_ADAPTIVE_DIGITAL_GAIN_APPLIER_H_
#include "modules/audio_processing/agc2/agc2_common.h"
#include "modules/audio_processing/agc2/gain_applier.h" #include "modules/audio_processing/agc2/gain_applier.h"
#include "modules/audio_processing/include/audio_frame_view.h" #include "modules/audio_processing/include/audio_frame_view.h"
#include "modules/audio_processing/vad/vad_with_level.h" #include "modules/audio_processing/vad/vad_with_level.h"
@ -30,7 +31,7 @@ class AdaptiveDigitalGainApplier {
AudioFrameView<float> float_frame); AudioFrameView<float> float_frame);
private: private:
float last_gain_db_ = 0.f; float last_gain_db_ = kInitialAdaptiveDigitalGainDb;
GainApplier gain_applier_; GainApplier gain_applier_;
// For some combinations of noise and speech probability, increasing // For some combinations of noise and speech probability, increasing

View File

@ -145,7 +145,7 @@ TEST(AutomaticGainController2AdaptiveGainApplier, GainIsRampedInAFrame) {
rtc::ArrayView<const VadWithLevel::LevelAndProbability>(&kVadSpeech, 1), rtc::ArrayView<const VadWithLevel::LevelAndProbability>(&kVadSpeech, 1),
fake_audio.float_frame_view()); fake_audio.float_frame_view());
float maximal_difference = 0.f; float maximal_difference = 0.f;
float current_value = 1.f; float current_value = 1.f * DbToRatio(kInitialAdaptiveDigitalGainDb);
for (const auto& x : fake_audio.float_frame_view().channel(0)) { for (const auto& x : fake_audio.float_frame_view().channel(0)) {
const float difference = std::abs(x - current_value); const float difference = std::abs(x - current_value);
maximal_difference = std::max(maximal_difference, difference); maximal_difference = std::max(maximal_difference, difference);
@ -164,17 +164,21 @@ TEST(AutomaticGainController2AdaptiveGainApplier, NoiseLimitsGain) {
constexpr float initial_level_dbfs = -25.f; constexpr float initial_level_dbfs = -25.f;
constexpr int num_samples = 480; constexpr int num_samples = 480;
constexpr int num_frames = 100; constexpr int num_initial_frames =
kInitialAdaptiveDigitalGainDb / kMaxGainChangePerFrameDb;
constexpr int num_frames = 50;
ASSERT_GT(kWithNoiseDbfs, kMaxNoiseLevelDbfs) << "kWithNoiseDbfs is too low"; ASSERT_GT(kWithNoiseDbfs, kMaxNoiseLevelDbfs) << "kWithNoiseDbfs is too low";
for (int i = 0; i < num_frames; ++i) { for (int i = 0; i < num_initial_frames + num_frames; ++i) {
VectorFloatFrame fake_audio(1, num_samples, 1.f); VectorFloatFrame fake_audio(1, num_samples, 1.f);
gain_applier.Process( gain_applier.Process(
initial_level_dbfs, kWithNoiseDbfs, initial_level_dbfs, kWithNoiseDbfs,
rtc::ArrayView<const VadWithLevel::LevelAndProbability>(&kVadSpeech, 1), rtc::ArrayView<const VadWithLevel::LevelAndProbability>(&kVadSpeech, 1),
fake_audio.float_frame_view()); fake_audio.float_frame_view());
// Wait so that the adaptive gain applier has time to lower the gain.
if (i > num_initial_frames) {
const float maximal_ratio = const float maximal_ratio =
*std::max_element(fake_audio.float_frame_view().channel(0).begin(), *std::max_element(fake_audio.float_frame_view().channel(0).begin(),
fake_audio.float_frame_view().channel(0).end()); fake_audio.float_frame_view().channel(0).end());
@ -182,4 +186,5 @@ TEST(AutomaticGainController2AdaptiveGainApplier, NoiseLimitsGain) {
EXPECT_NEAR(maximal_ratio, 1.f, 0.001f); EXPECT_NEAR(maximal_ratio, 1.f, 0.001f);
} }
} }
}
} // namespace webrtc } // namespace webrtc

View File

@ -33,6 +33,7 @@ constexpr float kMaxGainChangePerFrameDb =
kMaxGainChangePerSecondDb * kFrameDurationMs / 1000.f; kMaxGainChangePerSecondDb * kFrameDurationMs / 1000.f;
constexpr float kHeadroomDbfs = 1.f; constexpr float kHeadroomDbfs = 1.f;
constexpr float kMaxGainDb = 30.f; constexpr float kMaxGainDb = 30.f;
constexpr float kInitialAdaptiveDigitalGainDb = 8.f;
// This parameter must be tuned together with the noise estimator. // This parameter must be tuned together with the noise estimator.
constexpr float kMaxNoiseLevelDbfs = -50.f; constexpr float kMaxNoiseLevelDbfs = -50.f;

View File

@ -80,12 +80,6 @@ TEST(GainController2, Usage) {
SetAudioBufferSamples(sample_value, &ab); SetAudioBufferSamples(sample_value, &ab);
AudioProcessing::Config::GainController2 config; AudioProcessing::Config::GainController2 config;
// Check that samples are not modified when the fixed gain is 0 dB.
config.fixed_gain_db = 0.f;
gain_controller2->ApplyConfig(config);
gain_controller2->Process(&ab);
EXPECT_EQ(ab.channels_f()[0][0], sample_value);
// Check that samples are amplified when the fixed gain is greater than 0 dB. // Check that samples are amplified when the fixed gain is greater than 0 dB.
config.fixed_gain_db = 5.f; config.fixed_gain_db = 5.f;
gain_controller2->ApplyConfig(config); gain_controller2->ApplyConfig(config);