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 1b5f03fec4e7a255f25c681218bbb7470ebc0770..436a1b2458a3a5d574898e593662284ba922a5df 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 int subCountLen = 4; |
static const int countLen = 50; |
static const int kDelayMetricsAggregationWindow = 1250; // 5 seconds at 16 kHz. |
+// Diverge metric is based on audio level, which gets updated which every |
+// |subCountLen + 1| * 10 milliseconds. Diverge metric takes the statistics of |
+// |kDivergeMetricAggregationWindow| samples. Current value corresponds to 0.5 |
+// seconds at 16 kHz. |
+static const int kDivergeMetricAggregationWindow = 25; |
+ |
// 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 |
@@ -556,6 +562,8 @@ static void InitMetrics(AecCore* self) { |
InitStats(&self->erle); |
InitStats(&self->aNlp); |
InitStats(&self->rerl); |
+ |
+ self->fraction_filter_divergent->Flush(); |
} |
static float CalculatePower(const float* in, size_t num_samples) { |
@@ -613,6 +621,16 @@ static void UpdateMetrics(AecCore* aec) { |
aec->stateCounter++; |
} |
+ if (aec->linoutlevel.sfrcounter == 0) { |
+ const float level_increase = |
peah-webrtc
2016/03/14 09:12:53
What about renaming level_increase to level_differ
minyue-webrtc
2016/03/14 14:51:41
I thought about it, "increase" gives a direction:
peah-webrtc
2016/03/15 09:18:40
Ok.
(I think it sounds weird with a negative incre
|
+ aec->linoutlevel.framelevel - aec->nearlevel.framelevel; |
+ // Level increase should be, in principle, negative, when the filter |
+ // does not diverge. Here we allow some margin (0.001 * near end level) and |
+ // numerical error (1.0). |
+ aec->fraction_filter_divergent->AddSample(level_increase > |
peah-webrtc
2016/03/14 09:12:53
Is a sliding window average measure really needed
minyue-webrtc
2016/03/14 14:51:41
I wrote a new MeanCalculator, with the hope that i
peah-webrtc
2016/03/15 09:18:40
If you foresee future uses of the class I think yo
peah-webrtc
2016/03/15 09:18:40
What do you mean by that the update frequency is d
peah-webrtc
2016/03/15 09:18:40
I think that one thing that is missing is that the
minyue-webrtc
2016/04/03 21:42:05
Better to add in a follow up CL IMO (and it is dra
minyue-webrtc
2016/04/03 21:42:05
Ok. I'd remove MeanCalculator
minyue-webrtc
2016/04/03 21:42:05
as we offline discussed
|
+ std::max(0.001 * aec->nearlevel.framelevel, 1.0) ? 1.0 : 0.0); |
+ } |
+ |
if (aec->farlevel.frcounter == 0) { |
if (aec->farlevel.minlevel < noisyPower) { |
actThreshold = actThresholdClean; |
@@ -1365,7 +1383,7 @@ static void ProcessBlock(AecCore* aec) { |
AecCore* WebRtcAec_CreateAec() { |
int i; |
- AecCore* aec = reinterpret_cast<AecCore*>(malloc(sizeof(AecCore))); |
+ AecCore* aec = new AecCore; |
if (!aec) { |
return NULL; |
} |
@@ -1429,6 +1447,14 @@ AecCore* WebRtcAec_CreateAec() { |
WebRtcAec_FreeAec(aec); |
return NULL; |
} |
+ |
+ aec->fraction_filter_divergent.reset( |
peah-webrtc
2016/03/14 09:12:53
Does this need to be dynamically allocated? Since
minyue-webrtc
2016/03/14 14:51:41
Problem is |aec| does not have a constructor (unle
peah-webrtc
2016/03/15 09:18:40
Acknowledged.
|
+ new webrtc::MeanCalculator(kDivergeMetricAggregationWindow)); |
+ if (aec->fraction_filter_divergent.get() == nullptr) { |
+ WebRtcAec_FreeAec(aec); |
+ return NULL; |
+ } |
+ |
#ifdef WEBRTC_ANDROID |
aec->delay_agnostic_enabled = 1; // DA-AEC enabled by default. |
// DA-AEC assumes the system is causal from the beginning and will self adjust |