Index: webrtc/modules/audio_processing/aec/aec_core.cc |
diff --git a/webrtc/modules/audio_processing/aec/aec_core.cc b/webrtc/modules/audio_processing/aec/aec_core.cc |
index e23a79312b05beb9c7904c103c605a5d454b3e69..3235ee439cc66297eaa8c21c2bedd6dcb0803cf8 100644 |
--- a/webrtc/modules/audio_processing/aec/aec_core.cc |
+++ b/webrtc/modules/audio_processing/aec/aec_core.cc |
@@ -50,6 +50,12 @@ static const size_t kSubCountLen = 4; |
static const size_t kCountLen = 50; |
static const int kDelayMetricsAggregationWindow = 1250; // 5 seconds at 16 kHz. |
+// Divergence metric is based on audio level, which gets updated every |
+// |kCountLen + 1| * 10 milliseconds. Divergence metric takes the statistics of |
+// |kDivergeMetricAggregationWindow| samples. Current value corresponds to 0.5 |
+// seconds at 16 kHz. |
+static const int kDivergeMetricAggregationWindow = 25; |
peah-webrtc
2016/04/06 11:01:10
This should probably be called kDivergeMetricAggre
minyue-webrtc
2016/04/06 13:35:37
Done.
|
+ |
// Quantities to control H band scaling for SWB input |
static const float cnScaleHband = 0.4f; // scale for comfort noise in H band. |
// Initial bin for averaging nlp gain in low band |
@@ -150,16 +156,18 @@ __inline static float MulIm(float aRe, float aIm, float bRe, float bIm) { |
return aRe * bIm + aIm * bRe; |
} |
-PowerLevel::PowerLevel() |
// TODO(minyue): Due to a legacy bug, |framelevel| and |averagelevel| use a |
-// window, of which the length is 1 unit longer than indicated. Remove "+1" |
-// when the code is refactored. |
-: framelevel(kSubCountLen + 1), |
- averagelevel(kCountLen + 1) { |
+// window, of which the length is 1 unit longer than indicated. Remove "+1" when |
+// the code is refactored. |
+PowerLevel::PowerLevel() |
+ : framelevel(kSubCountLen + 1), |
+ averagelevel(kCountLen + 1) { |
} |
// TODO(minyue): Moving some initialization from WebRtcAec_CreateAec() to ctor. |
-AecCore::AecCore() = default; |
+AecCore::AecCore() |
+ : divergent_filter_fraction(kDivergeMetricAggregationWindow) { |
+} |
static int CmpFloat(const void* a, const void* b) { |
const float* da = (const float*)a; |
@@ -562,6 +570,8 @@ static void InitMetrics(AecCore* self) { |
InitStats(&self->erle); |
InitStats(&self->aNlp); |
InitStats(&self->rerl); |
+ |
+ self->divergent_filter_fraction.Reset(); |
} |
static float CalculatePower(const float* in, size_t num_samples) { |
@@ -605,6 +615,21 @@ static void UpdateMetrics(AecCore* aec) { |
aec->stateCounter++; |
} |
+ if (aec->linoutlevel.framelevel.EndOfBlock()) { |
+ const float near_level = aec->nearlevel.framelevel.GetLatestMean(); |
+ const float level_increase = |
+ aec->linoutlevel.framelevel.GetLatestMean() - near_level; |
+ const bool output_signal_active = |
+ aec->nlpoutlevel.framelevel.GetLatestMean() > |
+ actThresholdClean * aec->nlpoutlevel.minlevel; |
+ // Level increase should be, in principle, negative, when the filter |
+ // does not diverge. Here we allow some margin (0.01 * near end level) and |
+ // numerical error (1.0). We count divergence only when the AEC output |
+ // signal is active. |
+ aec->divergent_filter_fraction.AddObservation(output_signal_active && |
+ level_increase > std::max(0.01 * near_level, 1.0)); |
peah-webrtc
2016/04/06 11:01:10
If this would be a general and common task maybe a
minyue-webrtc
2016/04/06 13:35:37
Done.
|
+ } |
+ |
if (aec->farlevel.averagelevel.EndOfBlock()) { |
if (aec->farlevel.minlevel < noisyPower) { |
actThreshold = actThresholdClean; |