| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "platform/audio/Distance.h" | 29 #include "platform/audio/Distance.h" |
| 30 #include "wtf/Assertions.h" | 30 #include "wtf/Assertions.h" |
| 31 #include "wtf/MathExtras.h" |
| 31 #include <math.h> | 32 #include <math.h> |
| 32 #include <algorithm> | 33 #include <algorithm> |
| 33 | 34 |
| 34 namespace blink { | 35 namespace blink { |
| 35 | 36 |
| 36 DistanceEffect::DistanceEffect() | 37 DistanceEffect::DistanceEffect() |
| 37 : m_model(ModelInverse), | 38 : m_model(ModelInverse), |
| 38 m_isClamped(true), | 39 m_isClamped(true), |
| 39 m_refDistance(1.0), | 40 m_refDistance(1.0), |
| 40 m_maxDistance(10000.0), | 41 m_maxDistance(10000.0), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 57 return exponentialGain(distance); | 58 return exponentialGain(distance); |
| 58 } | 59 } |
| 59 ASSERT_NOT_REACHED(); | 60 ASSERT_NOT_REACHED(); |
| 60 return 0.0; | 61 return 0.0; |
| 61 } | 62 } |
| 62 | 63 |
| 63 double DistanceEffect::linearGain(double distance) { | 64 double DistanceEffect::linearGain(double distance) { |
| 64 // We want a gain that decreases linearly from m_refDistance to | 65 // We want a gain that decreases linearly from m_refDistance to |
| 65 // m_maxDistance. The gain is 1 at m_refDistance. | 66 // m_maxDistance. The gain is 1 at m_refDistance. |
| 66 return (1.0 - | 67 return (1.0 - |
| 67 m_rolloffFactor * (distance - m_refDistance) / | 68 clampTo(m_rolloffFactor, 0.0, 1.0) * (distance - m_refDistance) / |
| 68 (m_maxDistance - m_refDistance)); | 69 (m_maxDistance - m_refDistance)); |
| 69 } | 70 } |
| 70 | 71 |
| 71 double DistanceEffect::inverseGain(double distance) { | 72 double DistanceEffect::inverseGain(double distance) { |
| 72 return m_refDistance / | 73 return m_refDistance / |
| 73 (m_refDistance + m_rolloffFactor * (distance - m_refDistance)); | 74 (m_refDistance + |
| 75 clampTo(m_rolloffFactor, 0.0) * (distance - m_refDistance)); |
| 74 } | 76 } |
| 75 | 77 |
| 76 double DistanceEffect::exponentialGain(double distance) { | 78 double DistanceEffect::exponentialGain(double distance) { |
| 77 return pow(distance / m_refDistance, -m_rolloffFactor); | 79 return pow(distance / m_refDistance, -clampTo(m_rolloffFactor, 0.0)); |
| 78 } | 80 } |
| 79 | 81 |
| 80 } // namespace blink | 82 } // namespace blink |
| OLD | NEW |