| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 #include "modules/webaudio/AudioParamTimeline.h" | 30 #include "modules/webaudio/AudioParamTimeline.h" |
| 31 | 31 |
| 32 #include "bindings/v8/ExceptionState.h" | 32 #include "bindings/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 using namespace std; | |
| 40 | |
| 41 namespace WebCore { | 39 namespace WebCore { |
| 42 | 40 |
| 43 void AudioParamTimeline::setValueAtTime(float value, double time) | 41 void AudioParamTimeline::setValueAtTime(float value, double time) |
| 44 { | 42 { |
| 45 insertEvent(ParamEvent(ParamEvent::SetValue, value, time, 0, 0, nullptr)); | 43 insertEvent(ParamEvent(ParamEvent::SetValue, value, time, 0, 0, nullptr)); |
| 46 } | 44 } |
| 47 | 45 |
| 48 void AudioParamTimeline::linearRampToValueAtTime(float value, double time) | 46 void AudioParamTimeline::linearRampToValueAtTime(float value, double time) |
| 49 { | 47 { |
| 50 insertEvent(ParamEvent(ParamEvent::LinearRampToValue, value, time, 0, 0, nul
lptr)); | 48 insertEvent(ParamEvent(ParamEvent::LinearRampToValue, value, time, 0, 0, nul
lptr)); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 190 } |
| 193 | 191 |
| 194 // Maintain a running time and index for writing the values buffer. | 192 // Maintain a running time and index for writing the values buffer. |
| 195 double currentTime = startTime; | 193 double currentTime = startTime; |
| 196 unsigned writeIndex = 0; | 194 unsigned writeIndex = 0; |
| 197 | 195 |
| 198 // If first event is after startTime then fill initial part of values buffer
with defaultValue | 196 // If first event is after startTime then fill initial part of values buffer
with defaultValue |
| 199 // until we reach the first event time. | 197 // until we reach the first event time. |
| 200 double firstEventTime = m_events[0].time(); | 198 double firstEventTime = m_events[0].time(); |
| 201 if (firstEventTime > startTime) { | 199 if (firstEventTime > startTime) { |
| 202 double fillToTime = min(endTime, firstEventTime); | 200 double fillToTime = std::min(endTime, firstEventTime); |
| 203 unsigned fillToFrame = AudioUtilities::timeToSampleFrame(fillToTime - st
artTime, sampleRate); | 201 unsigned fillToFrame = AudioUtilities::timeToSampleFrame(fillToTime - st
artTime, sampleRate); |
| 204 fillToFrame = min(fillToFrame, numberOfValues); | 202 fillToFrame = std::min(fillToFrame, numberOfValues); |
| 205 for (; writeIndex < fillToFrame; ++writeIndex) | 203 for (; writeIndex < fillToFrame; ++writeIndex) |
| 206 values[writeIndex] = defaultValue; | 204 values[writeIndex] = defaultValue; |
| 207 | 205 |
| 208 currentTime = fillToTime; | 206 currentTime = fillToTime; |
| 209 } | 207 } |
| 210 | 208 |
| 211 float value = defaultValue; | 209 float value = defaultValue; |
| 212 | 210 |
| 213 // Go through each event and render the value buffer where the times overlap
, | 211 // Go through each event and render the value buffer where the times overlap
, |
| 214 // stopping when we've rendered all the requested values. | 212 // stopping when we've rendered all the requested values. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 225 | 223 |
| 226 float value1 = event.value(); | 224 float value1 = event.value(); |
| 227 double time1 = event.time(); | 225 double time1 = event.time(); |
| 228 float value2 = nextEvent ? nextEvent->value() : value1; | 226 float value2 = nextEvent ? nextEvent->value() : value1; |
| 229 double time2 = nextEvent ? nextEvent->time() : endTime + 1; | 227 double time2 = nextEvent ? nextEvent->time() : endTime + 1; |
| 230 | 228 |
| 231 double deltaTime = time2 - time1; | 229 double deltaTime = time2 - time1; |
| 232 float k = deltaTime > 0 ? 1 / deltaTime : 0; | 230 float k = deltaTime > 0 ? 1 / deltaTime : 0; |
| 233 double sampleFrameTimeIncr = 1 / sampleRate; | 231 double sampleFrameTimeIncr = 1 / sampleRate; |
| 234 | 232 |
| 235 double fillToTime = min(endTime, time2); | 233 double fillToTime = std::min(endTime, time2); |
| 236 unsigned fillToFrame = AudioUtilities::timeToSampleFrame(fillToTime - st
artTime, sampleRate); | 234 unsigned fillToFrame = AudioUtilities::timeToSampleFrame(fillToTime - st
artTime, sampleRate); |
| 237 fillToFrame = min(fillToFrame, numberOfValues); | 235 fillToFrame = std::min(fillToFrame, numberOfValues); |
| 238 | 236 |
| 239 ParamEvent::Type nextEventType = nextEvent ? static_cast<ParamEvent::Typ
e>(nextEvent->type()) : ParamEvent::LastType /* unknown */; | 237 ParamEvent::Type nextEventType = nextEvent ? static_cast<ParamEvent::Typ
e>(nextEvent->type()) : ParamEvent::LastType /* unknown */; |
| 240 | 238 |
| 241 // First handle linear and exponential ramps which require looking ahead
to the next event. | 239 // First handle linear and exponential ramps which require looking ahead
to the next event. |
| 242 if (nextEventType == ParamEvent::LinearRampToValue) { | 240 if (nextEventType == ParamEvent::LinearRampToValue) { |
| 243 for (; writeIndex < fillToFrame; ++writeIndex) { | 241 for (; writeIndex < fillToFrame; ++writeIndex) { |
| 244 float x = (currentTime - time1) * k; | 242 float x = (currentTime - time1) * k; |
| 245 value = (1 - x) * value1 + x * value2; | 243 value = (1 - x) * value1 + x * value2; |
| 246 values[writeIndex] = value; | 244 values[writeIndex] = value; |
| 247 currentTime += sampleFrameTimeIncr; | 245 currentTime += sampleFrameTimeIncr; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 currentTime = fillToTime; | 317 currentTime = fillToTime; |
| 320 for (; writeIndex < fillToFrame; ++writeIndex) | 318 for (; writeIndex < fillToFrame; ++writeIndex) |
| 321 values[writeIndex] = value; | 319 values[writeIndex] = value; |
| 322 break; | 320 break; |
| 323 } | 321 } |
| 324 | 322 |
| 325 // Save old values and recalculate information based on the
curve's duration | 323 // Save old values and recalculate information based on the
curve's duration |
| 326 // instead of the next event time. | 324 // instead of the next event time. |
| 327 unsigned nextEventFillToFrame = fillToFrame; | 325 unsigned nextEventFillToFrame = fillToFrame; |
| 328 float nextEventFillToTime = fillToTime; | 326 float nextEventFillToTime = fillToTime; |
| 329 fillToTime = min(endTime, time1 + duration); | 327 fillToTime = std::min(endTime, time1 + duration); |
| 330 fillToFrame = AudioUtilities::timeToSampleFrame(fillToTime -
startTime, sampleRate); | 328 fillToFrame = AudioUtilities::timeToSampleFrame(fillToTime -
startTime, sampleRate); |
| 331 fillToFrame = min(fillToFrame, numberOfValues); | 329 fillToFrame = std::min(fillToFrame, numberOfValues); |
| 332 | 330 |
| 333 // Index into the curve data using a floating-point value. | 331 // Index into the curve data using a floating-point value. |
| 334 // We're scaling the number of curve points by the duration
(see curvePointsPerFrame). | 332 // We're scaling the number of curve points by the duration
(see curvePointsPerFrame). |
| 335 float curveVirtualIndex = 0; | 333 float curveVirtualIndex = 0; |
| 336 if (time1 < currentTime) { | 334 if (time1 < currentTime) { |
| 337 // Index somewhere in the middle of the curve data. | 335 // Index somewhere in the middle of the curve data. |
| 338 // Don't use timeToSampleFrame() since we want the exact
floating-point frame. | 336 // Don't use timeToSampleFrame() since we want the exact
floating-point frame. |
| 339 float frameOffset = (currentTime - time1) * sampleRate; | 337 float frameOffset = (currentTime - time1) * sampleRate; |
| 340 curveVirtualIndex = curvePointsPerFrame * frameOffset; | 338 curveVirtualIndex = curvePointsPerFrame * frameOffset; |
| 341 } | 339 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 // to the end of the values buffer. | 372 // to the end of the values buffer. |
| 375 for (; writeIndex < numberOfValues; ++writeIndex) | 373 for (; writeIndex < numberOfValues; ++writeIndex) |
| 376 values[writeIndex] = value; | 374 values[writeIndex] = value; |
| 377 | 375 |
| 378 return value; | 376 return value; |
| 379 } | 377 } |
| 380 | 378 |
| 381 } // namespace WebCore | 379 } // namespace WebCore |
| 382 | 380 |
| 383 #endif // ENABLE(WEB_AUDIO) | 381 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |