Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(816)

Unified Diff: webrtc/modules/audio_processing/aec/aec_core.cc

Issue 1581183005: Cleaning up AEC metrics. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: improve the calculation Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/audio_processing/aec/aec_core.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f9604ec5199d21587cf20d371389b9994607e3b8 100644
--- a/webrtc/modules/audio_processing/aec/aec_core.cc
+++ b/webrtc/modules/audio_processing/aec/aec_core.cc
@@ -38,6 +38,7 @@ extern "C" {
extern "C" {
#include "webrtc/modules/audio_processing/utility/delay_estimator_wrapper.h"
}
+#include "webrtc/base/checks.h"
#include "webrtc/system_wrappers/include/cpu_features_wrapper.h"
#include "webrtc/typedefs.h"
@@ -369,6 +370,41 @@ static int PartitionDelay(const AecCore* aec) {
return delay;
}
+// Update metric with 10 * log10(numerator / denominator),
+static void UpdateMetric(Stats* metric, float numerator, float denominator) {
peah-webrtc 2016/04/19 07:03:37 Did you consider changing the name of the method t
peah-webrtc 2016/04/19 07:03:37 The roles of the numerator/denominator input varia
+ RTC_DCHECK(metric);
+ RTC_CHECK(numerator >= 0);
+ RTC_CHECK(denominator >= 0);
+
+ const float log_numerator = log10(numerator + 1e-10);
+ const float log_denominator = log10(denominator + 1e-10);
+ metric->instant = 10.0 * (log_numerator - log_denominator);
peah-webrtc 2016/04/19 07:03:37 I don't see why we cannot treat the case of the de
minyue-webrtc 2016/04/19 07:21:06 log(a) - log(b) does not only solve denominator be
peah-webrtc 2016/04/19 10:48:34 That is definitely true. Let's keep it like this.
+
+ // Max.
+ if (metric->instant > metric->max)
+ metric->max = metric->instant;
+
+ // Min.
+ if (metric->instant < metric->min)
+ metric->min = metric->instant;
+
+ // Average.
+ metric->counter++;
+ // This is to protect overflow, which should almost never happen.
+ RTC_CHECK_NE(0u, metric->counter);
+ metric->sum += metric->instant;
+ metric->average = metric->sum / metric->counter;
+
+ // Upper mean.
+ if (metric->instant > metric->average) {
+ metric->hicounter++;
+ // This is to protect overflow, which should almost never happen.
+ RTC_CHECK_NE(0u, 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 +678,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 +710,21 @@ static void UpdateMetrics(AecCore* aec) {
(aec->farlevel.framelevel.EndOfBlock()) &&
(far_average_level > (actThreshold * aec->farlevel.minlevel))) {
+ // ERL
peah-webrtc 2016/04/19 07:03:37 The terminating period in the comment is still mis
const float near_average_level =
aec->nearlevel.averagelevel.GetLatestMean();
- // 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/19 07:03:37 The terminating period in the comment is still mis
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/19 07:03:37 The terminating period in the comment is still mis
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;
« no previous file with comments | « webrtc/modules/audio_processing/aec/aec_core.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698