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 c4379c617104cd12f622bc1631908b37620fd887..b51101fd3b2e7e84c3b56629ee456c55ab5e615f 100644 |
--- a/webrtc/modules/audio_processing/aec/aec_core.cc |
+++ b/webrtc/modules/audio_processing/aec/aec_core.cc |
@@ -369,6 +369,37 @@ static int PartitionDelay(const AecCore* aec) { |
return delay; |
} |
+// Update metric with 10 * log10(nomin / denom), |
+static void UpdateMetric(Stats* metric, float nomin, float denom) { |
tlegrand-webrtc
2016/04/13 14:33:31
How do we test this function, to make sure it hand
peah-webrtc
2016/04/14 13:46:10
Since it is local within aec_core.cc, I think a DC
peah-webrtc
2016/04/14 13:46:10
Breaking out the computation of the metric in a se
minyue-webrtc
2016/04/14 14:11:12
Yes, it is good to sanity check on |metric|, added
peah-webrtc
2016/04/15 10:46:37
Would it be possible to change the names of nomin
peah-webrtc
2016/04/15 10:46:37
Maybe it is ok and a good solution, but to me it f
minyue-webrtc
2016/04/18 10:56:25
I think one reason for inf is that we calculate di
minyue-webrtc
2016/04/18 10:56:25
Done.
|
+ const float temp = nomin / denom; |
tlegrand-webrtc
2016/04/13 14:33:31
Is division with 0 allowed for float?
peah-webrtc
2016/04/14 13:46:10
Please rename this variable to what is is, as it i
peah-webrtc
2016/04/14 13:46:10
No, we should never do that. (If happening on the
minyue-webrtc
2016/04/14 14:11:12
For float, denom = 0 will not crash.
peah-webrtc
2016/04/15 10:46:37
Ah, you are right, I did not know that.
But I sti
minyue-webrtc
2016/04/18 10:56:25
Done.
|
+ if (!std::isfinite(temp)) |
peah-webrtc
2016/04/14 13:46:10
I think it is better to check for denom being zero
|
+ return; |
+ |
+ // Instant. |
+ // Adding 1e-10 to set the lower bound to -100. |
+ metric->instant = 10.0 * log10(temp + 1e-10); |
+ |
+ // Max. |
+ if (metric->instant > metric->max) |
+ metric->max = metric->instant; |
+ |
+ // Min. |
+ if (metric->instant < metric->min) |
+ metric->min = metric->instant; |
+ |
+ // Average. |
+ metric->counter++; |
tlegrand-webrtc
2016/04/13 14:33:31
Do we ever reset these counters? I realize you did
peah-webrtc
2016/04/14 13:46:10
I think it is nice to have a controlled wraparound
minyue-webrtc
2016/04/14 14:11:12
Very good point. I am not fully sure what we would
minyue-webrtc
2016/04/14 14:11:12
After 391, I added a RTC_CHECK_NE(0u, metric->coun
peah-webrtc
2016/04/15 10:46:37
Acknowledged.
|
+ metric->sum += metric->instant; |
+ metric->average = metric->sum / metric->counter; |
+ |
+ // Upper mean. |
+ if (metric->instant > metric->average) { |
+ metric->hicounter++; |
+ metric->hisum += metric->instant; |
+ metric->himean = metric->hisum / metric->hicounter; |
+ } |
+} |
+ |
// Threshold to protect against the ill-effects of a zero far-end. |
const float WebRtcAec_kMinFarendPSD = 15; |
@@ -642,16 +673,12 @@ static void UpdateLevel(PowerLevel* level, float power) { |
} |
static void UpdateMetrics(AecCore* aec) { |
- float dtmp; |
- |
const float actThresholdNoisy = 8.0f; |
const float actThresholdClean = 40.0f; |
- const float safety = 0.99995f; |
const float noisyPower = 300000.0f; |
float actThreshold; |
- float echo, suppressedEcho; |
if (aec->echoState) { // Check if echo is likely present |
aec->stateCounter++; |
@@ -678,95 +705,21 @@ static void UpdateMetrics(AecCore* aec) { |
(aec->farlevel.framelevel.EndOfBlock()) && |
(far_average_level > (actThreshold * aec->farlevel.minlevel))) { |
+ // ERL |
peah-webrtc
2016/04/14 13:46:10
Comment should be terminated with a period. Furthe
minyue-webrtc
2016/04/18 10:56:25
Done.
|
const float near_average_level = |
aec->nearlevel.averagelevel.GetLatestMean(); |
peah-webrtc
2016/04/14 13:46:10
To be consistent with how it is done below, I thin
minyue-webrtc
2016/04/18 10:56:25
Done.
|
- // Subtract noise power |
- echo = near_average_level - safety * aec->nearlevel.minlevel; |
- |
- // ERL |
- dtmp = 10 * static_cast<float>(log10(far_average_level / |
- near_average_level + 1e-10f)); |
- |
- aec->erl.instant = dtmp; |
- if (dtmp > aec->erl.max) { |
- aec->erl.max = dtmp; |
- } |
- |
- if (dtmp < aec->erl.min) { |
- aec->erl.min = dtmp; |
- } |
- |
- aec->erl.counter++; |
- aec->erl.sum += dtmp; |
- aec->erl.average = aec->erl.sum / aec->erl.counter; |
- |
- // Upper mean |
- if (dtmp > aec->erl.average) { |
- aec->erl.hicounter++; |
- aec->erl.hisum += dtmp; |
- aec->erl.himean = aec->erl.hisum / aec->erl.hicounter; |
- } |
+ UpdateMetric(&aec->erl, far_average_level, near_average_level); |
// A_NLP |
peah-webrtc
2016/04/14 13:46:10
See comment above.
minyue-webrtc
2016/04/18 10:56:25
done, although I am not sure if I name it properly
|
const float linout_average_level = |
aec->linoutlevel.averagelevel.GetLatestMean(); |
- dtmp = 10 * static_cast<float>(log10(near_average_level / |
- linout_average_level + 1e-10f)); |
- |
- // subtract noise power |
- suppressedEcho = |
- linout_average_level - safety * aec->linoutlevel.minlevel; |
- |
- aec->aNlp.instant = |
- 10 * static_cast<float>(log10(echo / suppressedEcho + 1e-10f)); |
- |
- if (dtmp > aec->aNlp.max) { |
- aec->aNlp.max = dtmp; |
- } |
- |
- if (dtmp < aec->aNlp.min) { |
- aec->aNlp.min = dtmp; |
- } |
- |
- aec->aNlp.counter++; |
- aec->aNlp.sum += dtmp; |
- aec->aNlp.average = aec->aNlp.sum / aec->aNlp.counter; |
- |
- // Upper mean |
- if (dtmp > aec->aNlp.average) { |
- aec->aNlp.hicounter++; |
- aec->aNlp.hisum += dtmp; |
- aec->aNlp.himean = aec->aNlp.hisum / aec->aNlp.hicounter; |
- } |
+ UpdateMetric(&aec->aNlp, near_average_level, linout_average_level); |
// ERLE |
peah-webrtc
2016/04/14 13:46:10
See comment above.
minyue-webrtc
2016/04/18 10:56:25
Done.
|
const float nlpout_average_level = |
aec->nlpoutlevel.averagelevel.GetLatestMean(); |
- // subtract noise power |
- suppressedEcho = |
- nlpout_average_level - safety * aec->nlpoutlevel.minlevel; |
- dtmp = 10 * static_cast<float>(log10(echo / suppressedEcho + 1e-10f)); |
- |
- aec->erle.instant = dtmp; |
- if (dtmp > aec->erle.max) { |
- aec->erle.max = dtmp; |
- } |
- |
- if (dtmp < aec->erle.min) { |
- aec->erle.min = dtmp; |
- } |
- |
- aec->erle.counter++; |
- aec->erle.sum += dtmp; |
- aec->erle.average = aec->erle.sum / aec->erle.counter; |
- |
- // Upper mean |
- if (dtmp > aec->erle.average) { |
- aec->erle.hicounter++; |
- aec->erle.hisum += dtmp; |
- aec->erle.himean = aec->erle.hisum / aec->erle.hicounter; |
- } |
+ UpdateMetric(&aec->erle, near_average_level, nlpout_average_level); |
} |
aec->stateCounter = 0; |