| 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));
|
| }
|
|
|
|
|