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

Side by Side Diff: third_party/WebKit/Source/platform/audio/Distance.cpp

Issue 2807313002: Allow Panner.refDistance to be 0 (Closed)
Patch Set: Adjust test to support cases where 0 is allowed (or not) Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/PannerNode.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 double DistanceEffect::LinearGain(double distance) { 61 double DistanceEffect::LinearGain(double distance) {
62 // We want a gain that decreases linearly from m_refDistance to 62 // We want a gain that decreases linearly from m_refDistance to
63 // m_maxDistance. The gain is 1 at m_refDistance. 63 // m_maxDistance. The gain is 1 at m_refDistance.
64 return (1.0 - clampTo(rolloff_factor_, 0.0, 1.0) * 64 return (1.0 - clampTo(rolloff_factor_, 0.0, 1.0) *
65 (distance - ref_distance_) / 65 (distance - ref_distance_) /
66 (max_distance_ - ref_distance_)); 66 (max_distance_ - ref_distance_));
67 } 67 }
68 68
69 double DistanceEffect::InverseGain(double distance) { 69 double DistanceEffect::InverseGain(double distance) {
70 if (ref_distance_ == 0)
71 return 0;
72
70 return ref_distance_ / (ref_distance_ + clampTo(rolloff_factor_, 0.0) * 73 return ref_distance_ / (ref_distance_ + clampTo(rolloff_factor_, 0.0) *
71 (distance - ref_distance_)); 74 (distance - ref_distance_));
72 } 75 }
73 76
74 double DistanceEffect::ExponentialGain(double distance) { 77 double DistanceEffect::ExponentialGain(double distance) {
78 if (ref_distance_ == 0)
79 return 0;
80
75 return pow(distance / ref_distance_, -clampTo(rolloff_factor_, 0.0)); 81 return pow(distance / ref_distance_, -clampTo(rolloff_factor_, 0.0));
76 } 82 }
77 83
78 } // namespace blink 84 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/PannerNode.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698