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

Unified Diff: third_party/WebKit/Source/platform/audio/Distance.cpp

Issue 2859143004: Correctly clamp in distance formulas (Closed)
Patch Set: Address review comments. Created 3 years, 7 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 | « third_party/WebKit/LayoutTests/webaudio/resources/panner-formulas.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/audio/Distance.cpp
diff --git a/third_party/WebKit/Source/platform/audio/Distance.cpp b/third_party/WebKit/Source/platform/audio/Distance.cpp
index 99c5a0221aa10008546f78f776b8f3ca13309ed5..1984eb7dcb3e89dafc5e5e2cf46da2ee4299ac0d 100644
--- a/third_party/WebKit/Source/platform/audio/Distance.cpp
+++ b/third_party/WebKit/Source/platform/audio/Distance.cpp
@@ -42,10 +42,6 @@ DistanceEffect::DistanceEffect()
rolloff_factor_(1.0) {}
double DistanceEffect::Gain(double distance) {
- // Don't get closer than the reference distance or go beyond the maximum
- // distance.
- distance = clampTo(distance, ref_distance_, max_distance_);
-
switch (model_) {
case kModelLinear:
return LinearGain(distance);
@@ -59,17 +55,27 @@ double DistanceEffect::Gain(double distance) {
}
double DistanceEffect::LinearGain(double distance) {
+ // Clamp refDistance and distance according to the spec.
+ double dref = std::min(ref_distance_, max_distance_);
+ double dmax = std::max(ref_distance_, max_distance_);
+ distance = clampTo(distance, dref, dmax);
+
+ if (dref == dmax)
+ return 1 - rolloff_factor_;
+
// We want a gain that decreases linearly from m_refDistance to
// m_maxDistance. The gain is 1 at m_refDistance.
- return (1.0 - clampTo(rolloff_factor_, 0.0, 1.0) *
- (distance - ref_distance_) /
- (max_distance_ - ref_distance_));
+ return (1.0 - clampTo(rolloff_factor_, 0.0, 1.0) * (distance - dref) /
+ (dmax - dref));
}
double DistanceEffect::InverseGain(double distance) {
if (ref_distance_ == 0)
return 0;
+ // Clamp distance according to spec
+ distance = clampTo(distance, ref_distance_);
+
return ref_distance_ / (ref_distance_ + clampTo(rolloff_factor_, 0.0) *
(distance - ref_distance_));
}
@@ -78,6 +84,9 @@ double DistanceEffect::ExponentialGain(double distance) {
if (ref_distance_ == 0)
return 0;
+ // Clamp distance according to spec
+ distance = clampTo(distance, ref_distance_);
+
return pow(distance / ref_distance_, -clampTo(rolloff_factor_, 0.0));
}
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/resources/panner-formulas.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698