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

Unified Diff: media/filters/wsola_internals.cc

Issue 217553004: Handle near-colinear case in WSOLAS QuadraticInterpolation better. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify cases handled. Created 6 years, 9 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 | « media/filters/wsola_internals.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/wsola_internals.cc
diff --git a/media/filters/wsola_internals.cc b/media/filters/wsola_internals.cc
index 45cdd8ffad5de606c74a9165eb2dfd0d720b8816..9ce1f0d966d189d92f1df9e74d61f3d2fd995edd 100644
--- a/media/filters/wsola_internals.cc
+++ b/media/filters/wsola_internals.cc
@@ -84,19 +84,25 @@ void MultiChannelMovingBlockEnergies(const AudioBus* input,
}
// Fit the curve f(x) = a * x^2 + b * x + c such that
-// f(-1) = |y[0]|
-// f(0) = |y[1]|
-// f(1) = |y[2]|.
-void CubicInterpolation(const float* y_values,
- float* extremum,
- float* extremum_value) {
+// f(-1) = y[0]
+// f(0) = y[1]
+// f(1) = y[2]
+// and return the maximum, assuming that y[0] <= y[1] >= y[2].
+void QuadraticInterpolation(const float* y_values,
+ float* extremum,
+ float* extremum_value) {
float a = 0.5f * (y_values[2] + y_values[0]) - y_values[1];
float b = 0.5f * (y_values[2] - y_values[0]);
float c = y_values[1];
- DCHECK_NE(a, 0);
- *extremum = -b / (2.f * a);
- *extremum_value = a * (*extremum) * (*extremum) + b * (*extremum) + c;
+ if (a == 0.f) {
+ // The coordinates are colinear (within floating-point error).
+ *extremum = 0;
+ *extremum_value = y_values[1];
+ } else {
+ *extremum = -b / (2.f * a);
+ *extremum_value = a * (*extremum) * (*extremum) + b * (*extremum) + c;
+ }
}
int DecimatedSearch(int decimation,
@@ -154,8 +160,8 @@ int DecimatedSearch(int decimation,
// estimate of candidate maximum.
float normalized_candidate_index;
float candidate_similarity;
- CubicInterpolation(similarity, &normalized_candidate_index,
- &candidate_similarity);
+ QuadraticInterpolation(similarity, &normalized_candidate_index,
+ &candidate_similarity);
int candidate_index = n - decimation + static_cast<int>(
normalized_candidate_index * decimation + 0.5f);
« no previous file with comments | « media/filters/wsola_internals.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698