AGC2 AdaptiveModeLevelEstimator: minor code improvements
- State -> LevelEstimatorState - Mark two methods as const - Call DumpDebugData() in one place - DumpDebugData: don't check if data dumper is provided - Add LevelEstimatorState::operator== The changes will reduce clutter in follow up CL. Note: this CL breaks the chain of 3 CLs titled "AGC2 AdaptiveModeLevelEstimator min consecutive speech frames". Bug: webrtc:7494 Change-Id: If39ce4b787069bef4af910d718cdfae3af1784a4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/185811 Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Jakob Ivarsson <jakobi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32247}
This commit is contained in:
parent
f5e261aaf6
commit
9cf3ea0ab2
@ -49,7 +49,15 @@ float GetLevel(const VadLevelAnalyzer::Result& vad_level,
|
||||
|
||||
} // namespace
|
||||
|
||||
float AdaptiveModeLevelEstimator::State::Ratio::GetRatio() const {
|
||||
bool AdaptiveModeLevelEstimator::LevelEstimatorState::operator==(
|
||||
const AdaptiveModeLevelEstimator::LevelEstimatorState& b) const {
|
||||
return time_to_full_buffer_ms == b.time_to_full_buffer_ms &&
|
||||
level_dbfs.numerator == b.level_dbfs.numerator &&
|
||||
level_dbfs.denominator == b.level_dbfs.denominator &&
|
||||
saturation_protector == b.saturation_protector;
|
||||
}
|
||||
|
||||
float AdaptiveModeLevelEstimator::LevelEstimatorState::Ratio::GetRatio() const {
|
||||
RTC_DCHECK_NE(denominator, 0.f);
|
||||
return numerator / denominator;
|
||||
}
|
||||
@ -89,6 +97,7 @@ AdaptiveModeLevelEstimator::AdaptiveModeLevelEstimator(
|
||||
use_saturation_protector_,
|
||||
initial_saturation_margin_db_,
|
||||
extra_saturation_margin_db_)) {
|
||||
RTC_DCHECK(apm_data_dumper_);
|
||||
Reset();
|
||||
}
|
||||
|
||||
@ -100,20 +109,19 @@ void AdaptiveModeLevelEstimator::Update(
|
||||
RTC_DCHECK_LT(vad_level.peak_dbfs, 50.f);
|
||||
RTC_DCHECK_GE(vad_level.speech_probability, 0.f);
|
||||
RTC_DCHECK_LE(vad_level.speech_probability, 1.f);
|
||||
DumpDebugData();
|
||||
|
||||
if (vad_level.speech_probability < kVadConfidenceThreshold) {
|
||||
DebugDumpEstimate();
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the state.
|
||||
// Update level estimate.
|
||||
RTC_DCHECK_GE(state_.time_to_full_buffer_ms, 0);
|
||||
const bool buffer_is_full = state_.time_to_full_buffer_ms == 0;
|
||||
if (!buffer_is_full) {
|
||||
state_.time_to_full_buffer_ms -= kFrameDurationMs;
|
||||
}
|
||||
|
||||
// Update level estimation (average level weighted by speech probability).
|
||||
// Weighted average of levels with speech probability as weight.
|
||||
RTC_DCHECK_GT(vad_level.speech_probability, 0.f);
|
||||
const float leak_factor = buffer_is_full ? kFullBufferLeakFactor : 1.f;
|
||||
state_.level_dbfs.numerator =
|
||||
@ -133,8 +141,6 @@ void AdaptiveModeLevelEstimator::Update(
|
||||
level_dbfs_ = ComputeLevelEstimateDbfs(level_dbfs, use_saturation_protector_,
|
||||
state_.saturation_protector.margin_db,
|
||||
extra_saturation_margin_db_);
|
||||
|
||||
DebugDumpEstimate();
|
||||
}
|
||||
|
||||
bool AdaptiveModeLevelEstimator::IsConfident() const {
|
||||
@ -143,13 +149,14 @@ bool AdaptiveModeLevelEstimator::IsConfident() const {
|
||||
}
|
||||
|
||||
void AdaptiveModeLevelEstimator::Reset() {
|
||||
ResetState(state_);
|
||||
ResetLevelEstimatorState(state_);
|
||||
level_dbfs_ = ComputeLevelEstimateDbfs(
|
||||
kInitialSpeechLevelEstimateDbfs, use_saturation_protector_,
|
||||
initial_saturation_margin_db_, extra_saturation_margin_db_);
|
||||
}
|
||||
|
||||
void AdaptiveModeLevelEstimator::ResetState(State& state) {
|
||||
void AdaptiveModeLevelEstimator::ResetLevelEstimatorState(
|
||||
LevelEstimatorState& state) const {
|
||||
state.time_to_full_buffer_ms = kFullBufferSizeMs;
|
||||
state.level_dbfs.numerator = 0.f;
|
||||
state.level_dbfs.denominator = 0.f;
|
||||
@ -157,12 +164,10 @@ void AdaptiveModeLevelEstimator::ResetState(State& state) {
|
||||
state.saturation_protector);
|
||||
}
|
||||
|
||||
void AdaptiveModeLevelEstimator::DebugDumpEstimate() {
|
||||
if (apm_data_dumper_) {
|
||||
apm_data_dumper_->DumpRaw("agc2_adaptive_level_estimate_dbfs", level_dbfs_);
|
||||
apm_data_dumper_->DumpRaw("agc2_adaptive_saturation_margin_db",
|
||||
state_.saturation_protector.margin_db);
|
||||
}
|
||||
void AdaptiveModeLevelEstimator::DumpDebugData() const {
|
||||
apm_data_dumper_->DumpRaw("agc2_adaptive_level_estimate_dbfs", level_dbfs_);
|
||||
apm_data_dumper_->DumpRaw("agc2_adaptive_saturation_margin_db",
|
||||
state_.saturation_protector.margin_db);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -53,7 +53,11 @@ class AdaptiveModeLevelEstimator {
|
||||
|
||||
private:
|
||||
// Part of the level estimator state used for check-pointing and restore ops.
|
||||
struct State {
|
||||
struct LevelEstimatorState {
|
||||
bool operator==(const LevelEstimatorState& s) const;
|
||||
inline bool operator!=(const LevelEstimatorState& s) const {
|
||||
return !(*this == s);
|
||||
}
|
||||
struct Ratio {
|
||||
float numerator;
|
||||
float denominator;
|
||||
@ -64,8 +68,9 @@ class AdaptiveModeLevelEstimator {
|
||||
SaturationProtectorState saturation_protector;
|
||||
};
|
||||
|
||||
void ResetState(State& state);
|
||||
void DebugDumpEstimate();
|
||||
void ResetLevelEstimatorState(LevelEstimatorState& state) const;
|
||||
|
||||
void DumpDebugData() const;
|
||||
|
||||
ApmDataDumper* const apm_data_dumper_;
|
||||
|
||||
@ -75,7 +80,7 @@ class AdaptiveModeLevelEstimator {
|
||||
const float initial_saturation_margin_db_;
|
||||
const float extra_saturation_margin_db_;
|
||||
// TODO(crbug.com/webrtc/7494): Add temporary state.
|
||||
State state_;
|
||||
LevelEstimatorState state_;
|
||||
float level_dbfs_;
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user