Chromium Code Reviews| 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..1a77747581dc62082eda2ab115380ad2ede8793c 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)); |
|
hongchan
2017/05/05 18:07:58
Can we align this line somehow?
Raymond Toy
2017/05/05 18:18:28
clang-format did that. :-(
|
| } |
| 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,12 @@ double DistanceEffect::ExponentialGain(double distance) { |
| if (ref_distance_ == 0) |
| return 0; |
| + // Clamp distance according to spec |
| + distance = clampTo(distance, ref_distance_); |
| + |
| + if (ref_distance_ == 0) |
| + return 0; |
|
hongchan
2017/05/05 18:07:58
L.90~91 is identical to L84~L85.
Raymond Toy
2017/05/05 18:18:29
90-91 removed.
|
| + |
| return pow(distance / ref_distance_, -clampTo(rolloff_factor_, 0.0)); |
| } |