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 |
11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
13 * | 13 * |
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "modules/webaudio/AudioParam.h" | 26 #include "modules/webaudio/AudioParam.h" |
27 | |
28 #include "core/inspector/ConsoleMessage.h" | |
27 #include "modules/webaudio/AudioNode.h" | 29 #include "modules/webaudio/AudioNode.h" |
28 #include "modules/webaudio/AudioNodeOutput.h" | 30 #include "modules/webaudio/AudioNodeOutput.h" |
29 #include "platform/FloatConversion.h" | 31 #include "platform/FloatConversion.h" |
30 #include "platform/audio/AudioUtilities.h" | 32 #include "platform/audio/AudioUtilities.h" |
33 #include "platform/v8_inspector/public/ConsoleTypes.h" | |
31 #include "wtf/MathExtras.h" | 34 #include "wtf/MathExtras.h" |
32 | 35 |
33 namespace blink { | 36 namespace blink { |
34 | 37 |
35 const double AudioParamHandler::DefaultSmoothingConstant = 0.05; | 38 const double AudioParamHandler::DefaultSmoothingConstant = 0.05; |
36 const double AudioParamHandler::SnapThreshold = 0.001; | 39 const double AudioParamHandler::SnapThreshold = 0.001; |
37 | 40 |
38 AudioParamHandler::AudioParamHandler(AbstractAudioContext& context, AudioParamTy pe paramType, double defaultValue) | 41 AudioParamHandler::AudioParamHandler(AbstractAudioContext& context, AudioParamTy pe paramType, double defaultValue, float minValue, float maxValue) |
39 : AudioSummingJunction(context.deferredTaskHandler()) | 42 : AudioSummingJunction(context.deferredTaskHandler()) |
40 , m_paramType(paramType) | 43 , m_paramType(paramType) |
41 , m_intrinsicValue(defaultValue) | 44 , m_intrinsicValue(defaultValue) |
42 , m_defaultValue(defaultValue) | 45 , m_defaultValue(defaultValue) |
46 , m_minValue(minValue) | |
47 , m_maxValue(maxValue) | |
43 , m_smoothedValue(defaultValue) | 48 , m_smoothedValue(defaultValue) |
44 { | 49 { |
45 // The destination MUST exist because we need the destination handler for th e AudioParam. | 50 // The destination MUST exist because we need the destination handler for th e AudioParam. |
46 RELEASE_ASSERT(context.destination()); | 51 RELEASE_ASSERT(context.destination()); |
47 | 52 |
48 m_destinationHandler = &context.destination()->audioDestinationHandler(); | 53 m_destinationHandler = &context.destination()->audioDestinationHandler(); |
49 } | 54 } |
50 | 55 |
51 AudioDestinationHandler& AudioParamHandler::destinationHandler() const | 56 AudioDestinationHandler& AudioParamHandler::destinationHandler() const |
52 { | 57 { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 float timelineValue = m_timeline.valueForContextTime(destinationHandler( ), v, hasValue); | 110 float timelineValue = m_timeline.valueForContextTime(destinationHandler( ), v, hasValue); |
106 | 111 |
107 if (hasValue) | 112 if (hasValue) |
108 v = timelineValue; | 113 v = timelineValue; |
109 } | 114 } |
110 | 115 |
111 setIntrinsicValue(v); | 116 setIntrinsicValue(v); |
112 return v; | 117 return v; |
113 } | 118 } |
114 | 119 |
120 void AudioParamHandler::setIntrinsicValue(float newValue) | |
121 { | |
122 newValue = clampTo(newValue, m_minValue, m_maxValue); | |
123 noBarrierStore(&m_intrinsicValue, newValue); | |
124 } | |
125 | |
115 void AudioParamHandler::setValue(float value) | 126 void AudioParamHandler::setValue(float value) |
116 { | 127 { |
117 setIntrinsicValue(value); | 128 setIntrinsicValue(value); |
118 } | 129 } |
119 | 130 |
120 float AudioParamHandler::smoothedValue() | 131 float AudioParamHandler::smoothedValue() |
121 { | 132 { |
122 return m_smoothedValue; | 133 return m_smoothedValue; |
123 } | 134 } |
124 | 135 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 | 253 |
243 if (m_outputs.contains(&output)) { | 254 if (m_outputs.contains(&output)) { |
244 m_outputs.remove(&output); | 255 m_outputs.remove(&output); |
245 changedOutputs(); | 256 changedOutputs(); |
246 output.removeParam(*this); | 257 output.removeParam(*this); |
247 } | 258 } |
248 } | 259 } |
249 | 260 |
250 // ---------------------------------------------------------------- | 261 // ---------------------------------------------------------------- |
251 | 262 |
252 AudioParam::AudioParam(AbstractAudioContext& context, AudioParamType paramType, double defaultValue) | 263 AudioParam::AudioParam(AbstractAudioContext& context, AudioParamType paramType, double defaultValue, float minValue, float maxValue) |
253 : m_handler(AudioParamHandler::create(context, paramType, defaultValue)) | 264 : m_handler(AudioParamHandler::create(context, paramType, defaultValue, minV alue, maxValue)) |
254 , m_context(context) | 265 , m_context(context) |
255 { | 266 { |
256 } | 267 } |
257 | 268 |
258 AudioParam* AudioParam::create(AbstractAudioContext& context, AudioParamType par amType, double defaultValue) | 269 AudioParam* AudioParam::create(AbstractAudioContext& context, AudioParamType par amType, double defaultValue) |
259 { | 270 { |
260 return new AudioParam(context, paramType, defaultValue); | 271 // Default nominal range is most negative float to most positive. This basi cally means any |
272 // value is valid, except that floating-point infinities are excluded. | |
273 float limit = std::numeric_limits<float>::max(); | |
274 return new AudioParam(context, paramType, defaultValue, -limit, limit); | |
275 } | |
276 | |
277 AudioParam* AudioParam::create(AbstractAudioContext& context, AudioParamType par amType, double defaultValue, | |
278 float min, float max) | |
hongchan
2016/05/13 01:30:15
Here as well.
Raymond Toy
2016/05/13 18:40:32
Done.
| |
279 { | |
280 DCHECK(min <= max); | |
281 return new AudioParam(context, paramType, defaultValue, min, max); | |
261 } | 282 } |
262 | 283 |
263 DEFINE_TRACE(AudioParam) | 284 DEFINE_TRACE(AudioParam) |
264 { | 285 { |
265 visitor->trace(m_context); | 286 visitor->trace(m_context); |
266 } | 287 } |
267 | 288 |
268 float AudioParam::value() const | 289 float AudioParam::value() const |
269 { | 290 { |
270 return handler().value(); | 291 return handler().value(); |
271 } | 292 } |
272 | 293 |
294 void AudioParam::warnIfOutsideRange(float value, float minValue, float maxValue) | |
295 { | |
296 if (value < minValue || value > maxValue) { | |
297 context()->getExecutionContext()->addConsoleMessage( | |
298 ConsoleMessage::create( | |
299 JSMessageSource, | |
300 WarningMessageLevel, | |
301 handler().getParamName() | |
302 + " value " | |
303 + String::number(value) | |
304 + " outside nominal range [" | |
305 + String::number(minValue) + ", " + String::number(maxValue) | |
306 + "]; value will be clamped.")); | |
307 } | |
308 } | |
309 | |
273 void AudioParam::setValue(float value) | 310 void AudioParam::setValue(float value) |
274 { | 311 { |
312 warnIfOutsideRange(value, minValue(), maxValue()); | |
275 handler().setValue(value); | 313 handler().setValue(value); |
276 } | 314 } |
277 | 315 |
278 float AudioParam::defaultValue() const | 316 float AudioParam::defaultValue() const |
279 { | 317 { |
280 return handler().defaultValue(); | 318 return handler().defaultValue(); |
281 } | 319 } |
282 | 320 |
321 float AudioParam::minValue() const | |
322 { | |
323 return handler().minValue(); | |
324 } | |
325 | |
326 float AudioParam::maxValue() const | |
327 { | |
328 return handler().maxValue(); | |
329 } | |
330 | |
283 AudioParam* AudioParam::setValueAtTime(float value, double time, ExceptionState& exceptionState) | 331 AudioParam* AudioParam::setValueAtTime(float value, double time, ExceptionState& exceptionState) |
284 { | 332 { |
285 handler().timeline().setValueAtTime(value, time, exceptionState); | 333 handler().timeline().setValueAtTime(value, time, exceptionState); |
286 return this; | 334 return this; |
287 } | 335 } |
288 | 336 |
289 AudioParam* AudioParam::linearRampToValueAtTime(float value, double time, Except ionState& exceptionState) | 337 AudioParam* AudioParam::linearRampToValueAtTime(float value, double time, Except ionState& exceptionState) |
290 { | 338 { |
291 handler().timeline().linearRampToValueAtTime( | 339 handler().timeline().linearRampToValueAtTime( |
292 value, time, handler().intrinsicValue(), context()->currentTime(), excep tionState); | 340 value, time, handler().intrinsicValue(), context()->currentTime(), excep tionState); |
(...skipping 19 matching lines...) Expand all Loading... | |
312 } | 360 } |
313 | 361 |
314 AudioParam* AudioParam::cancelScheduledValues(double startTime, ExceptionState& exceptionState) | 362 AudioParam* AudioParam::cancelScheduledValues(double startTime, ExceptionState& exceptionState) |
315 { | 363 { |
316 handler().timeline().cancelScheduledValues(startTime, exceptionState); | 364 handler().timeline().cancelScheduledValues(startTime, exceptionState); |
317 return this; | 365 return this; |
318 } | 366 } |
319 | 367 |
320 } // namespace blink | 368 } // namespace blink |
321 | 369 |
OLD | NEW |