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

Unified Diff: webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc

Issue 1207353002: Add new variance update option and unittests for intelligibility (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 6 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
Index: webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc
diff --git a/webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc b/webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc
index 145cc0872866db4effc4715000b979e54d5e723e..5426c444068f87965b05699c98de96dada565283 100644
--- a/webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc
+++ b/webrtc/modules/audio_processing/intelligibility/intelligibility_utils.cc
@@ -96,7 +96,8 @@ VarianceArray::VarianceArray(int freqs,
decay_(decay),
history_cursor_(0),
count_(0),
- array_mean_(0.0f) {
+ array_mean_(0.0f),
+ buffer_full_(false) {
history_.reset(new rtc::scoped_ptr<complex<float>[]>[freqs_]());
for (int i = 0; i < freqs_; ++i) {
history_[i].reset(new complex<float>[window_size_]());
@@ -122,6 +123,9 @@ VarianceArray::VarianceArray(int freqs,
case kStepBlocked:
step_func_ = &VarianceArray::BlockedStep;
break;
+ case kStepBlockBasedMovingAverage:
+ step_func_ = &VarianceArray::BlockBasedMovingAverage;
+ break;
}
}
@@ -223,7 +227,7 @@ void VarianceArray::WindowedStep(const complex<float>* data, bool /*dummy*/) {
// history window and a new block is started. The variances for the window
// are recomputed from scratch at each of these transitions.
void VarianceArray::BlockedStep(const complex<float>* data, bool /*dummy*/) {
- int blocks = min(window_size_, history_cursor_);
+ int blocks = min(window_size_, history_cursor_ + 1);
for (int i = 0; i < freqs_; ++i) {
AddToMean(data[i], count_ + 1, &sub_running_mean_[i]);
AddToMean(data[i] * std::conj(data[i]), count_ + 1,
@@ -242,8 +246,8 @@ void VarianceArray::BlockedStep(const complex<float>* data, bool /*dummy*/) {
running_mean_[i] = complex<float>(0.0f, 0.0f);
running_mean_sq_[i] = complex<float>(0.0f, 0.0f);
for (int j = 0; j < min(window_size_, history_cursor_); ++j) {
- AddToMean(subhistory_[i][j], j, &running_mean_[i]);
- AddToMean(subhistory_sq_[i][j], j, &running_mean_sq_[i]);
+ AddToMean(subhistory_[i][j], j + 1, &running_mean_[i]);
+ AddToMean(subhistory_sq_[i][j], j + 1, &running_mean_sq_[i]);
}
++history_cursor_;
}
@@ -254,6 +258,47 @@ void VarianceArray::BlockedStep(const complex<float>* data, bool /*dummy*/) {
}
}
+// Recomputes variances from scratch each window based on previous window.
+void VarianceArray::BlockBasedMovingAverage(
turaj 2015/06/26 00:32:58 There is a concern, which is not proven, that keep
ekm 2015/06/26 19:07:09 Interesting. This is just do to floating point err
turaj 2015/06/29 17:33:35 Something like that, but I'm not sure.
+ const std::complex<float>* data, bool /*dummy*/) {
+ for (int i = 0; i < freqs_; ++i) {
+ sub_running_mean_[i] += data[i];
+ sub_running_mean_sq_[i] += data[i] * std::conj(data[i]);
+ }
+ ++count_;
+
+ // TODO(ekmeyerson) make kWindowBlockSize nonconstant to allow
+ // experimentation with different block size,window size pairs.
+ if (count_ >= kWindowBlockSize) {
+ count_ = 0;
+
+ for (int i = 0; i < freqs_; ++i) {
+ running_mean_[i] -= subhistory_[i][history_cursor_];
+ running_mean_sq_[i] -= subhistory_sq_[i][history_cursor_];
+
+ float scale = 1.f / kWindowBlockSize;
+ subhistory_[i][history_cursor_] = sub_running_mean_[i] * scale;
+ subhistory_sq_[i][history_cursor_] = sub_running_mean_sq_[i] * scale;
+
+ sub_running_mean_[i] = std::complex<float>(0.0f, 0.0f);
+ sub_running_mean_sq_[i] = std::complex<float>(0.0f, 0.0f);
+
+ running_mean_[i] += subhistory_[i][history_cursor_];
+ running_mean_sq_[i] += subhistory_sq_[i][history_cursor_];
+
+ scale = 1.f / (buffer_full_ ? window_size_ : history_cursor_ + 1);
+ variance_[i] = std::real(running_mean_sq_[i] * scale - running_mean_[i] *
+ scale * std::conj(running_mean_[i]) * scale);
+ }
+
+ ++history_cursor_;
+ if (history_cursor_ >= window_size_) {
+ buffer_full_ = true;
+ history_cursor_ = 0;
+ }
+ }
+}
+
void VarianceArray::Clear() {
memset(running_mean_.get(), 0, sizeof(*running_mean_.get()) * freqs_);
memset(running_mean_sq_.get(), 0, sizeof(*running_mean_sq_.get()) * freqs_);

Powered by Google App Engine
This is Rietveld 408576698