| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 #include "bindings/core/v8/ExceptionState.h" | 32 #include "bindings/core/v8/ExceptionState.h" |
| 33 #include "core/dom/ExceptionCode.h" | 33 #include "core/dom/ExceptionCode.h" |
| 34 #include "platform/audio/AudioUtilities.h" | 34 #include "platform/audio/AudioUtilities.h" |
| 35 #include "platform/FloatConversion.h" | 35 #include "platform/FloatConversion.h" |
| 36 #include "wtf/MathExtras.h" | 36 #include "wtf/MathExtras.h" |
| 37 #include <algorithm> | 37 #include <algorithm> |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 static bool isValidAudioParamValue(float value, ExceptionState& exceptionState) | 41 static bool isPositiveAudioParamValue(float value, ExceptionState& exceptionStat
e) |
| 42 { | 42 { |
| 43 if (std::isfinite(value)) | 43 if (value > 0) |
| 44 return true; | 44 return true; |
| 45 | 45 |
| 46 exceptionState.throwDOMException( | 46 exceptionState.throwDOMException( |
| 47 InvalidAccessError, | |
| 48 "Target value must be a finite number: " + String::number(value)); | |
| 49 return false; | |
| 50 } | |
| 51 | |
| 52 static bool isPositiveAudioParamValue(float value, ExceptionState& exceptionStat
e) | |
| 53 { | |
| 54 if (std::isfinite(value) && (value > 0)) | |
| 55 return true; | |
| 56 | |
| 57 exceptionState.throwDOMException( | |
| 58 InvalidAccessError, | 47 InvalidAccessError, |
| 59 "Target value must be a finite positive number: " + String::number(value
)); | 48 "Target value must be a finite positive number: " + String::number(value
)); |
| 60 return false; | 49 return false; |
| 61 } | 50 } |
| 62 | 51 |
| 63 static bool isValidAudioParamTime(double time, ExceptionState& exceptionState, S
tring message) | 52 static bool isNonNegativeAudioParamTime(double time, ExceptionState& exceptionSt
ate, String message = "Time") |
| 64 { | 53 { |
| 65 if (std::isfinite(time) && (time >= 0)) | 54 if (time >= 0) |
| 66 return true; | 55 return true; |
| 67 | 56 |
| 68 exceptionState.throwDOMException( | 57 exceptionState.throwDOMException( |
| 69 InvalidAccessError, | 58 InvalidAccessError, |
| 70 message + " must be a finite non-negative number: " + String::number(tim
e)); | 59 message + " must be a finite non-negative number: " + String::number(tim
e)); |
| 71 return false; | 60 return false; |
| 72 } | 61 } |
| 73 | 62 |
| 74 static bool isPositiveAudioParamTime(double time, ExceptionState& exceptionState
, String message) | 63 static bool isPositiveAudioParamTime(double time, ExceptionState& exceptionState
, String message) |
| 75 { | 64 { |
| 76 if (std::isfinite(time) && (time > 0)) | 65 if (time > 0) |
| 77 return true; | 66 return true; |
| 78 | 67 |
| 79 exceptionState.throwDOMException( | 68 exceptionState.throwDOMException( |
| 80 InvalidAccessError, | 69 InvalidAccessError, |
| 81 message + " must be a finite positive number: " + String::number(time)); | 70 message + " must be a finite positive number: " + String::number(time)); |
| 82 return false; | 71 return false; |
| 83 } | 72 } |
| 84 | 73 |
| 85 static bool isValidAudioParamTime(double time, ExceptionState& exceptionState) | |
| 86 { | |
| 87 return isValidAudioParamTime(time, exceptionState, "Time"); | |
| 88 } | |
| 89 | |
| 90 void AudioParamTimeline::setValueAtTime(float value, double time, ExceptionState
& exceptionState) | 74 void AudioParamTimeline::setValueAtTime(float value, double time, ExceptionState
& exceptionState) |
| 91 { | 75 { |
| 92 ASSERT(isMainThread()); | 76 ASSERT(isMainThread()); |
| 93 | 77 |
| 94 if (!isValidAudioParamValue(value, exceptionState) | 78 if (!isNonNegativeAudioParamTime(time, exceptionState)) |
| 95 || !isValidAudioParamTime(time, exceptionState)) | |
| 96 return; | 79 return; |
| 97 | 80 |
| 98 insertEvent(ParamEvent(ParamEvent::SetValue, value, time, 0, 0, nullptr)); | 81 insertEvent(ParamEvent(ParamEvent::SetValue, value, time, 0, 0, nullptr)); |
| 99 } | 82 } |
| 100 | 83 |
| 101 void AudioParamTimeline::linearRampToValueAtTime(float value, double time, Excep
tionState& exceptionState) | 84 void AudioParamTimeline::linearRampToValueAtTime(float value, double time, Excep
tionState& exceptionState) |
| 102 { | 85 { |
| 103 ASSERT(isMainThread()); | 86 ASSERT(isMainThread()); |
| 104 | 87 |
| 105 if (!isValidAudioParamValue(value, exceptionState) | 88 if (!isNonNegativeAudioParamTime(time, exceptionState)) |
| 106 || !isValidAudioParamTime(time, exceptionState)) | |
| 107 return; | 89 return; |
| 108 | 90 |
| 109 insertEvent(ParamEvent(ParamEvent::LinearRampToValue, value, time, 0, 0, nul
lptr)); | 91 insertEvent(ParamEvent(ParamEvent::LinearRampToValue, value, time, 0, 0, nul
lptr)); |
| 110 } | 92 } |
| 111 | 93 |
| 112 void AudioParamTimeline::exponentialRampToValueAtTime(float value, double time,
ExceptionState& exceptionState) | 94 void AudioParamTimeline::exponentialRampToValueAtTime(float value, double time,
ExceptionState& exceptionState) |
| 113 { | 95 { |
| 114 ASSERT(isMainThread()); | 96 ASSERT(isMainThread()); |
| 115 | 97 |
| 116 if (!isPositiveAudioParamValue(value, exceptionState) | 98 if (!isPositiveAudioParamValue(value, exceptionState) |
| 117 || !isValidAudioParamTime(time, exceptionState)) | 99 || !isNonNegativeAudioParamTime(time, exceptionState)) |
| 118 return; | 100 return; |
| 119 | 101 |
| 120 insertEvent(ParamEvent(ParamEvent::ExponentialRampToValue, value, time, 0, 0
, nullptr)); | 102 insertEvent(ParamEvent(ParamEvent::ExponentialRampToValue, value, time, 0, 0
, nullptr)); |
| 121 } | 103 } |
| 122 | 104 |
| 123 void AudioParamTimeline::setTargetAtTime(float target, double time, double timeC
onstant, ExceptionState& exceptionState) | 105 void AudioParamTimeline::setTargetAtTime(float target, double time, double timeC
onstant, ExceptionState& exceptionState) |
| 124 { | 106 { |
| 125 ASSERT(isMainThread()); | 107 ASSERT(isMainThread()); |
| 126 | 108 |
| 127 if (!isValidAudioParamValue(target, exceptionState) | 109 if (!isNonNegativeAudioParamTime(time, exceptionState) |
| 128 || !isValidAudioParamTime(time, exceptionState) | 110 || !isNonNegativeAudioParamTime(timeConstant, exceptionState, "Time cons
tant")) |
| 129 || !isValidAudioParamTime(timeConstant, exceptionState, "Time constant")
) | |
| 130 return; | 111 return; |
| 131 | 112 |
| 132 insertEvent(ParamEvent(ParamEvent::SetTarget, target, time, timeConstant, 0,
nullptr)); | 113 insertEvent(ParamEvent(ParamEvent::SetTarget, target, time, timeConstant, 0,
nullptr)); |
| 133 } | 114 } |
| 134 | 115 |
| 135 void AudioParamTimeline::setValueCurveAtTime(DOMFloat32Array* curve, double time
, double duration, ExceptionState& exceptionState) | 116 void AudioParamTimeline::setValueCurveAtTime(DOMFloat32Array* curve, double time
, double duration, ExceptionState& exceptionState) |
| 136 { | 117 { |
| 137 ASSERT(isMainThread()); | 118 ASSERT(isMainThread()); |
| 138 | 119 |
| 139 if (!isValidAudioParamTime(time, exceptionState) | 120 if (!isNonNegativeAudioParamTime(time, exceptionState) |
| 140 || !isPositiveAudioParamTime(duration, exceptionState, "Duration")) | 121 || !isPositiveAudioParamTime(duration, exceptionState, "Duration")) |
| 141 return; | 122 return; |
| 142 | 123 |
| 143 insertEvent(ParamEvent(ParamEvent::SetValueCurve, 0, time, 0, duration, curv
e)); | 124 insertEvent(ParamEvent(ParamEvent::SetValueCurve, 0, time, 0, duration, curv
e)); |
| 144 } | 125 } |
| 145 | 126 |
| 146 void AudioParamTimeline::insertEvent(const ParamEvent& event) | 127 void AudioParamTimeline::insertEvent(const ParamEvent& event) |
| 147 { | 128 { |
| 148 // Sanity check the event. Be super careful we're not getting infected with
NaN or Inf. These | 129 // Sanity check the event. Be super careful we're not getting infected with
NaN or Inf. These |
| 149 // should have been handled by the caller. | 130 // should have been handled by the caller. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 173 break; | 154 break; |
| 174 } | 155 } |
| 175 | 156 |
| 176 m_events.insert(i, event); | 157 m_events.insert(i, event); |
| 177 } | 158 } |
| 178 | 159 |
| 179 void AudioParamTimeline::cancelScheduledValues(double startTime, ExceptionState&
exceptionState) | 160 void AudioParamTimeline::cancelScheduledValues(double startTime, ExceptionState&
exceptionState) |
| 180 { | 161 { |
| 181 ASSERT(isMainThread()); | 162 ASSERT(isMainThread()); |
| 182 | 163 |
| 183 if (!std::isfinite(startTime)) { | |
| 184 exceptionState.throwDOMException( | |
| 185 InvalidStateError, | |
| 186 "Time must be a finite number: " + String::number(startTime)); | |
| 187 } | |
| 188 | |
| 189 MutexLocker locker(m_eventsLock); | 164 MutexLocker locker(m_eventsLock); |
| 190 | 165 |
| 191 // Remove all events starting at startTime. | 166 // Remove all events starting at startTime. |
| 192 for (unsigned i = 0; i < m_events.size(); ++i) { | 167 for (unsigned i = 0; i < m_events.size(); ++i) { |
| 193 if (m_events[i].time() >= startTime) { | 168 if (m_events[i].time() >= startTime) { |
| 194 m_events.remove(i, m_events.size() - i); | 169 m_events.remove(i, m_events.size() - i); |
| 195 break; | 170 break; |
| 196 } | 171 } |
| 197 } | 172 } |
| 198 } | 173 } |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 // to the end of the values buffer. | 423 // to the end of the values buffer. |
| 449 for (; writeIndex < numberOfValues; ++writeIndex) | 424 for (; writeIndex < numberOfValues; ++writeIndex) |
| 450 values[writeIndex] = value; | 425 values[writeIndex] = value; |
| 451 | 426 |
| 452 return value; | 427 return value; |
| 453 } | 428 } |
| 454 | 429 |
| 455 } // namespace blink | 430 } // namespace blink |
| 456 | 431 |
| 457 #endif // ENABLE(WEB_AUDIO) | 432 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |