mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
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:
parent
436d036b62
commit
a837dd790d
8 changed files with 25 additions and 16 deletions
|
@ -30,14 +30,6 @@ AdaptiveAgc::AdaptiveAgc(ApmDataDumper* apm_data_dumper)
|
|||
AdaptiveAgc::~AdaptiveAgc() = default;
|
||||
|
||||
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 =
|
||||
vad_.AnalyzeFrame(float_frame);
|
||||
apm_data_dumper_->DumpRaw("agc2_vad_probability",
|
||||
|
@ -58,4 +50,8 @@ void AdaptiveAgc::Process(AudioFrameView<float> float_frame) {
|
|||
float_frame);
|
||||
}
|
||||
|
||||
void AdaptiveAgc::Reset() {
|
||||
speech_level_estimator_.Reset();
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
|
@ -25,9 +25,11 @@ class ApmDataDumper;
|
|||
class AdaptiveAgc {
|
||||
public:
|
||||
explicit AdaptiveAgc(ApmDataDumper* apm_data_dumper);
|
||||
void Process(AudioFrameView<float> float_frame);
|
||||
~AdaptiveAgc();
|
||||
|
||||
void Process(AudioFrameView<float> float_frame);
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
AdaptiveModeLevelEstimator speech_level_estimator_;
|
||||
VadWithLevel vad_;
|
||||
|
|
|
@ -1334,6 +1334,8 @@ int AudioProcessingImpl::ProcessCaptureStreamLocked() {
|
|||
}
|
||||
|
||||
if (config_.gain_controller2.enabled) {
|
||||
private_submodules_->gain_controller2->NotifyAnalogLevel(
|
||||
gain_control()->stream_analog_level());
|
||||
private_submodules_->gain_controller2->Process(capture_buffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,14 +43,18 @@ int GainControlForExperimentalAgc::set_stream_analog_level(int level) {
|
|||
rtc::CritScope cs_capture(crit_capture_);
|
||||
data_dumper_->DumpRaw("experimental_gain_control_set_stream_analog_level", 1,
|
||||
&level);
|
||||
do_log_level_ = true;
|
||||
volume_ = level;
|
||||
return AudioProcessing::kNoError;
|
||||
}
|
||||
|
||||
int GainControlForExperimentalAgc::stream_analog_level() {
|
||||
rtc::CritScope cs_capture(crit_capture_);
|
||||
data_dumper_->DumpRaw("experimental_gain_control_stream_analog_level", 1,
|
||||
&volume_);
|
||||
if (do_log_level_) {
|
||||
data_dumper_->DumpRaw("experimental_gain_control_stream_analog_level", 1,
|
||||
&volume_);
|
||||
do_log_level_ = false;
|
||||
}
|
||||
return volume_;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ class GainControlForExperimentalAgc : public GainControl,
|
|||
GainControl* real_gain_control_;
|
||||
int volume_;
|
||||
rtc::CriticalSection* crit_capture_;
|
||||
bool do_log_level_ = true;
|
||||
static int instance_counter_;
|
||||
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(GainControlForExperimentalAgc);
|
||||
};
|
||||
|
|
|
@ -45,6 +45,13 @@ void GainController2::Process(AudioBuffer* audio) {
|
|||
fixed_gain_controller_.Process(float_frame);
|
||||
}
|
||||
|
||||
void GainController2::NotifyAnalogLevel(int level) {
|
||||
if (analog_level_ != level) {
|
||||
adaptive_agc_.Reset();
|
||||
}
|
||||
analog_level_ = level;
|
||||
}
|
||||
|
||||
void GainController2::ApplyConfig(
|
||||
const AudioProcessing::Config::GainController2& config) {
|
||||
RTC_DCHECK(Validate(config));
|
||||
|
|
|
@ -33,6 +33,7 @@ class GainController2 {
|
|||
|
||||
void Initialize(int sample_rate_hz);
|
||||
void Process(AudioBuffer* audio);
|
||||
void NotifyAnalogLevel(int level);
|
||||
|
||||
void ApplyConfig(const AudioProcessing::Config::GainController2& config);
|
||||
static bool Validate(const AudioProcessing::Config::GainController2& config);
|
||||
|
@ -45,6 +46,7 @@ class GainController2 {
|
|||
FixedGainController fixed_gain_controller_;
|
||||
AudioProcessing::Config::GainController2 config_;
|
||||
AdaptiveAgc adaptive_agc_;
|
||||
int analog_level_ = -1;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(GainController2);
|
||||
};
|
||||
|
|
|
@ -378,11 +378,6 @@ void PerformBasicParameterSanityChecks(const SimulationSettings& settings) {
|
|||
(*settings.agc_compression_gain) > 90),
|
||||
"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(
|
||||
settings.use_agc2 && *settings.use_agc2 &&
|
||||
((settings.agc2_fixed_gain_db) < 0 ||
|
||||
|
|
Loading…
Reference in a new issue