Reset Agc2 on analog gain changes.

Agc2 applies a digital gain to the nearend signal.
When the analog level changes, the digital gain calculation is no
longer valid. Therefore Agc2 should be notified to analog gain
changes.

This CL also allow audioproc_f to chain AGC1 and AGC2. In a dependent
CL we will allow using AGC1 for analog gain and AGC2 for digital
gain.

Bug: webrtc:7494
Change-Id: Id75b3728fbf2de1d84b7fba005e4670c7a2985d9
Reviewed-on: https://webrtc-review.googlesource.com/89387
Commit-Queue: Alex Loiko <aleloi@webrtc.org>
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24231}
This commit is contained in:
Alex Loiko 2018-08-06 16:32:12 +02:00 committed by Commit Bot
parent 436d036b62
commit a837dd790d
8 changed files with 25 additions and 16 deletions

View file

@ -30,14 +30,6 @@ AdaptiveAgc::AdaptiveAgc(ApmDataDumper* apm_data_dumper)
AdaptiveAgc::~AdaptiveAgc() = default; AdaptiveAgc::~AdaptiveAgc() = default;
void AdaptiveAgc::Process(AudioFrameView<float> float_frame) { void AdaptiveAgc::Process(AudioFrameView<float> float_frame) {
// TODO(webrtc:7494): Remove this loop. Remove the vectors from
// VadWithData after we move to a VAD that outputs an estimate every
// kFrameDurationMs ms.
//
// Some VADs are 'bursty'. They return several estimates for some
// frames, and no estimates for other frames. We want to feed all to
// the level estimator, but only care about the last level it
// produces.
const VadWithLevel::LevelAndProbability vad_result = const VadWithLevel::LevelAndProbability vad_result =
vad_.AnalyzeFrame(float_frame); vad_.AnalyzeFrame(float_frame);
apm_data_dumper_->DumpRaw("agc2_vad_probability", apm_data_dumper_->DumpRaw("agc2_vad_probability",
@ -58,4 +50,8 @@ void AdaptiveAgc::Process(AudioFrameView<float> float_frame) {
float_frame); float_frame);
} }
void AdaptiveAgc::Reset() {
speech_level_estimator_.Reset();
}
} // namespace webrtc } // namespace webrtc

View file

@ -25,9 +25,11 @@ class ApmDataDumper;
class AdaptiveAgc { class AdaptiveAgc {
public: public:
explicit AdaptiveAgc(ApmDataDumper* apm_data_dumper); explicit AdaptiveAgc(ApmDataDumper* apm_data_dumper);
void Process(AudioFrameView<float> float_frame);
~AdaptiveAgc(); ~AdaptiveAgc();
void Process(AudioFrameView<float> float_frame);
void Reset();
private: private:
AdaptiveModeLevelEstimator speech_level_estimator_; AdaptiveModeLevelEstimator speech_level_estimator_;
VadWithLevel vad_; VadWithLevel vad_;

View file

@ -1334,6 +1334,8 @@ int AudioProcessingImpl::ProcessCaptureStreamLocked() {
} }
if (config_.gain_controller2.enabled) { if (config_.gain_controller2.enabled) {
private_submodules_->gain_controller2->NotifyAnalogLevel(
gain_control()->stream_analog_level());
private_submodules_->gain_controller2->Process(capture_buffer); private_submodules_->gain_controller2->Process(capture_buffer);
} }

View file

@ -43,14 +43,18 @@ int GainControlForExperimentalAgc::set_stream_analog_level(int level) {
rtc::CritScope cs_capture(crit_capture_); rtc::CritScope cs_capture(crit_capture_);
data_dumper_->DumpRaw("experimental_gain_control_set_stream_analog_level", 1, data_dumper_->DumpRaw("experimental_gain_control_set_stream_analog_level", 1,
&level); &level);
do_log_level_ = true;
volume_ = level; volume_ = level;
return AudioProcessing::kNoError; return AudioProcessing::kNoError;
} }
int GainControlForExperimentalAgc::stream_analog_level() { int GainControlForExperimentalAgc::stream_analog_level() {
rtc::CritScope cs_capture(crit_capture_); rtc::CritScope cs_capture(crit_capture_);
data_dumper_->DumpRaw("experimental_gain_control_stream_analog_level", 1, if (do_log_level_) {
&volume_); data_dumper_->DumpRaw("experimental_gain_control_stream_analog_level", 1,
&volume_);
do_log_level_ = false;
}
return volume_; return volume_;
} }

View file

@ -68,6 +68,7 @@ class GainControlForExperimentalAgc : public GainControl,
GainControl* real_gain_control_; GainControl* real_gain_control_;
int volume_; int volume_;
rtc::CriticalSection* crit_capture_; rtc::CriticalSection* crit_capture_;
bool do_log_level_ = true;
static int instance_counter_; static int instance_counter_;
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(GainControlForExperimentalAgc); RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(GainControlForExperimentalAgc);
}; };

View file

@ -45,6 +45,13 @@ void GainController2::Process(AudioBuffer* audio) {
fixed_gain_controller_.Process(float_frame); fixed_gain_controller_.Process(float_frame);
} }
void GainController2::NotifyAnalogLevel(int level) {
if (analog_level_ != level) {
adaptive_agc_.Reset();
}
analog_level_ = level;
}
void GainController2::ApplyConfig( void GainController2::ApplyConfig(
const AudioProcessing::Config::GainController2& config) { const AudioProcessing::Config::GainController2& config) {
RTC_DCHECK(Validate(config)); RTC_DCHECK(Validate(config));

View file

@ -33,6 +33,7 @@ class GainController2 {
void Initialize(int sample_rate_hz); void Initialize(int sample_rate_hz);
void Process(AudioBuffer* audio); void Process(AudioBuffer* audio);
void NotifyAnalogLevel(int level);
void ApplyConfig(const AudioProcessing::Config::GainController2& config); void ApplyConfig(const AudioProcessing::Config::GainController2& config);
static bool Validate(const AudioProcessing::Config::GainController2& config); static bool Validate(const AudioProcessing::Config::GainController2& config);
@ -45,6 +46,7 @@ class GainController2 {
FixedGainController fixed_gain_controller_; FixedGainController fixed_gain_controller_;
AudioProcessing::Config::GainController2 config_; AudioProcessing::Config::GainController2 config_;
AdaptiveAgc adaptive_agc_; AdaptiveAgc adaptive_agc_;
int analog_level_ = -1;
RTC_DISALLOW_COPY_AND_ASSIGN(GainController2); RTC_DISALLOW_COPY_AND_ASSIGN(GainController2);
}; };

View file

@ -378,11 +378,6 @@ void PerformBasicParameterSanityChecks(const SimulationSettings& settings) {
(*settings.agc_compression_gain) > 90), (*settings.agc_compression_gain) > 90),
"Error: --agc_compression_gain must be specified between 0 and 90.\n"); "Error: --agc_compression_gain must be specified between 0 and 90.\n");
ReportConditionalErrorAndExit(
settings.use_agc && *settings.use_agc && settings.use_agc2 &&
*settings.use_agc2,
"Error: --agc and --agc2 cannot be both active.\n");
ReportConditionalErrorAndExit( ReportConditionalErrorAndExit(
settings.use_agc2 && *settings.use_agc2 && settings.use_agc2 && *settings.use_agc2 &&
((settings.agc2_fixed_gain_db) < 0 || ((settings.agc2_fixed_gain_db) < 0 ||