| 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 #ifndef AudioParamTimeline_h | 29 #ifndef AudioParamTimeline_h |
| 30 #define AudioParamTimeline_h | 30 #define AudioParamTimeline_h |
| 31 | 31 |
| 32 #include "core/dom/DOMTypedArray.h" | 32 #include "core/dom/DOMTypedArray.h" |
| 33 #include "modules/webaudio/AudioDestinationNode.h" | 33 #include "modules/webaudio/AudioDestinationNode.h" |
| 34 #include "modules/webaudio/BaseAudioContext.h" | 34 #include "modules/webaudio/BaseAudioContext.h" |
| 35 #include "wtf/Forward.h" | 35 #include "wtf/Forward.h" |
| 36 #include "wtf/Threading.h" | 36 #include "wtf/Threading.h" |
| 37 #include "wtf/Vector.h" | 37 #include "wtf/Vector.h" |
| 38 | 38 |
| 39 #include <tuple> |
| 40 |
| 39 namespace blink { | 41 namespace blink { |
| 40 | 42 |
| 41 class AudioParamTimeline { | 43 class AudioParamTimeline { |
| 42 DISALLOW_NEW(); | 44 DISALLOW_NEW(); |
| 43 | 45 |
| 44 public: | 46 public: |
| 45 AudioParamTimeline() {} | 47 AudioParamTimeline() {} |
| 46 | 48 |
| 47 void setValueAtTime(float value, double time, ExceptionState&); | 49 void setValueAtTime(float value, double time, ExceptionState&); |
| 48 void linearRampToValueAtTime(float value, | 50 void linearRampToValueAtTime(float value, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 const std::unique_ptr<ParamEvent>& b) { | 153 const std::unique_ptr<ParamEvent>& b) { |
| 152 return a->time() < b->time(); | 154 return a->time() < b->time(); |
| 153 } | 155 } |
| 154 | 156 |
| 155 Type getType() const { return m_type; } | 157 Type getType() const { return m_type; } |
| 156 float value() const { return m_value; } | 158 float value() const { return m_value; } |
| 157 double time() const { return m_time; } | 159 double time() const { return m_time; } |
| 158 void setTime(double newTime) { m_time = newTime; } | 160 void setTime(double newTime) { m_time = newTime; } |
| 159 double timeConstant() const { return m_timeConstant; } | 161 double timeConstant() const { return m_timeConstant; } |
| 160 double duration() const { return m_duration; } | 162 double duration() const { return m_duration; } |
| 163 const Vector<float>& curve() const { return m_curve; } |
| 161 Vector<float>& curve() { return m_curve; } | 164 Vector<float>& curve() { return m_curve; } |
| 162 float initialValue() const { return m_initialValue; } | 165 float initialValue() const { return m_initialValue; } |
| 163 double callTime() const { return m_callTime; } | 166 double callTime() const { return m_callTime; } |
| 164 bool needsTimeClampCheck() const { return m_needsTimeClampCheck; } | 167 bool needsTimeClampCheck() const { return m_needsTimeClampCheck; } |
| 165 void clearTimeClampCheck() { m_needsTimeClampCheck = false; } | 168 void clearTimeClampCheck() { m_needsTimeClampCheck = false; } |
| 166 | 169 |
| 167 double curvePointsPerSecond() const { return m_curvePointsPerSecond; } | 170 double curvePointsPerSecond() const { return m_curvePointsPerSecond; } |
| 168 float curveEndValue() const { return m_curveEndValue; } | 171 float curveEndValue() const { return m_curveEndValue; } |
| 169 | 172 |
| 170 // For CancelValues events. Not valid for any other event. | 173 // For CancelValues events. Not valid for any other event. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 std::unique_ptr<ParamEvent> m_savedEvent; | 257 std::unique_ptr<ParamEvent> m_savedEvent; |
| 255 | 258 |
| 256 // True if the start time needs to be checked against current time | 259 // True if the start time needs to be checked against current time |
| 257 // to implement clamping. | 260 // to implement clamping. |
| 258 bool m_needsTimeClampCheck; | 261 bool m_needsTimeClampCheck; |
| 259 | 262 |
| 260 // True if a default value has been assigned to the CancelValues event. | 263 // True if a default value has been assigned to the CancelValues event. |
| 261 bool m_hasDefaultCancelledValue; | 264 bool m_hasDefaultCancelledValue; |
| 262 }; | 265 }; |
| 263 | 266 |
| 267 // State of the timeline for the current event. |
| 268 struct AutomationState { |
| 269 // Parameters for the current automation request. Number of |
| 270 // values to be computed for the automation request |
| 271 const unsigned numberOfValues; |
| 272 // Start and end frames for this automation request |
| 273 const size_t startFrame; |
| 274 const size_t endFrame; |
| 275 |
| 276 // Sample rate and control rate for this request |
| 277 const double sampleRate; |
| 278 const double controlRate; |
| 279 |
| 280 // Parameters needed for processing the current event. |
| 281 const size_t fillToFrame; |
| 282 const size_t fillToEndFrame; |
| 283 |
| 284 // Value and time for the current event |
| 285 const float value1; |
| 286 const double time1; |
| 287 |
| 288 // Value and time for the next event, if any. |
| 289 const float value2; |
| 290 const double time2; |
| 291 |
| 292 // The current event, and it's index in the event vector. |
| 293 const ParamEvent* event; |
| 294 const int eventIndex; |
| 295 }; |
| 296 |
| 264 void insertEvent(std::unique_ptr<ParamEvent>, ExceptionState&); | 297 void insertEvent(std::unique_ptr<ParamEvent>, ExceptionState&); |
| 265 float valuesForFrameRangeImpl(size_t startFrame, | 298 float valuesForFrameRangeImpl(size_t startFrame, |
| 266 size_t endFrame, | 299 size_t endFrame, |
| 267 float defaultValue, | 300 float defaultValue, |
| 268 float* values, | 301 float* values, |
| 269 unsigned numberOfValues, | 302 unsigned numberOfValues, |
| 270 double sampleRate, | 303 double sampleRate, |
| 271 double controlRate); | 304 double controlRate); |
| 272 | 305 |
| 273 // Produce a nice string describing the event in human-readable form. | 306 // Produce a nice string describing the event in human-readable form. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 289 float value1, | 322 float value1, |
| 290 double time1, | 323 double time1, |
| 291 float value2, | 324 float value2, |
| 292 float timeConstant); | 325 float timeConstant); |
| 293 float valueCurveAtTime(double t, | 326 float valueCurveAtTime(double t, |
| 294 double time1, | 327 double time1, |
| 295 double duration, | 328 double duration, |
| 296 const float* curveData, | 329 const float* curveData, |
| 297 unsigned curveLength); | 330 unsigned curveLength); |
| 298 | 331 |
| 332 // Handles the special case where the first event in the timeline |
| 333 // starts after |startFrame|. These initial values are filled using |
| 334 // |defaultValue|. The updated |currentFrame| and |writeIndex| is |
| 335 // returned. |
| 336 std::tuple<size_t, unsigned> handleFirstEvent(float* values, |
| 337 float defaultValue, |
| 338 unsigned numberOfValues, |
| 339 size_t startFrame, |
| 340 size_t endFrame, |
| 341 double sampleRate, |
| 342 size_t currentFrame, |
| 343 unsigned writeIndex); |
| 344 |
| 345 // Return true if |currentEvent| starts after |currentFrame|, but |
| 346 // also takes into account the |nextEvent| if any. |
| 347 bool isEventCurrent(const ParamEvent* currentEvent, |
| 348 const ParamEvent* nextEvent, |
| 349 size_t currentFrame, |
| 350 double sampleRate); |
| 351 |
| 352 // Clamp event times to current time, if needed. |
| 353 void clampToCurrentTime(int numberOfEvents, |
| 354 size_t startFrame, |
| 355 double sampleRate); |
| 356 |
| 357 // Handle the case where the last event in the timeline is in the |
| 358 // past. Returns false if any event is not in the past. Otherwise, |
| 359 // return true and also fill in |values| with |defaultValue|. |
| 360 bool handleAllEventsInThePast(double currentTime, |
| 361 double sampleRate, |
| 362 float defaultValue, |
| 363 unsigned numberOfValues, |
| 364 float* values); |
| 365 |
| 366 // Handle processing of CancelValue event. If cancellation happens, value2, |
| 367 // time2, and nextEventType will be updated with the new value due to |
| 368 // cancellation. The |
| 369 std::tuple<float, double, ParamEvent::Type> handleCancelValues( |
| 370 const ParamEvent* currentEvent, |
| 371 ParamEvent* nextEvent, |
| 372 float value2, |
| 373 double time2); |
| 374 |
| 375 // Process a SetTarget event and the next event is a |
| 376 // LinearRampToValue or ExponentialRampToValue event. This requires |
| 377 // special handling because the ramp should start at whatever value |
| 378 // the SetTarget event has reached at this time, instead of using |
| 379 // the value of the SetTarget event. |
| 380 void processSetTargetFollowedByRamp(int eventIndex, |
| 381 ParamEvent*& currentEvent, |
| 382 ParamEvent::Type nextEventType, |
| 383 size_t currentFrame, |
| 384 double sampleRate, |
| 385 double controlRate, |
| 386 float& value); |
| 387 |
| 388 // Handle processing of linearRampEvent, writing the appropriate |
| 389 // values to |values|. Returns the updated |currentFrame|, last |
| 390 // computed |value|, and the updated |writeIndex|. |
| 391 std::tuple<size_t, float, unsigned> processLinearRamp( |
| 392 const AutomationState& currentState, |
| 393 float* values, |
| 394 size_t currentFrame, |
| 395 float value, |
| 396 unsigned writeIndex); |
| 397 |
| 398 // Handle processing of exponentialRampEvent, writing the appropriate |
| 399 // values to |values|. Returns the updated |currentFrame|, last |
| 400 // computed |value|, and the updated |writeIndex|. |
| 401 std::tuple<size_t, float, unsigned> processExponentialRamp( |
| 402 const AutomationState& currentState, |
| 403 float* values, |
| 404 size_t currentFrame, |
| 405 float value, |
| 406 unsigned writeIndex); |
| 407 |
| 408 // Handle processing of SetTargetEvent, writing the appropriate |
| 409 // values to |values|. Returns the updated |currentFrame|, last |
| 410 // computed |value|, and the updated |writeIndex|. |
| 411 std::tuple<size_t, float, unsigned> processSetTarget( |
| 412 const AutomationState& currentState, |
| 413 float* values, |
| 414 size_t currentFrame, |
| 415 float value, |
| 416 unsigned writeIndex); |
| 417 |
| 418 // Handle processing of SetValueCurveEvent, writing the appropriate |
| 419 // values to |values|. Returns the updated |currentFrame|, last |
| 420 // computed |value|, and the updated |writeIndex|. |
| 421 std::tuple<size_t, float, unsigned> processSetValueCurve( |
| 422 const AutomationState& currentState, |
| 423 float* values, |
| 424 size_t currentFrame, |
| 425 float value, |
| 426 unsigned writeIndex); |
| 427 |
| 428 // Handle processing of CancelValuesEvent, writing the appropriate |
| 429 // values to |values|. Returns the updated |currentFrame|, last |
| 430 // computed |value|, and the updated |writeIndex|. |
| 431 std::tuple<size_t, float, unsigned> processCancelValues( |
| 432 const AutomationState& currentState, |
| 433 float* values, |
| 434 size_t currentFrame, |
| 435 float value, |
| 436 unsigned writeIndex); |
| 437 |
| 438 // Fill the output vector |values| with the value |defaultValue|, |
| 439 // starting at |writeIndex| and continuing up to |endFrame| |
| 440 // (exclusive). |writeIndex| is updated with the new index. |
| 441 unsigned fillWithDefault(float* values, |
| 442 float defaultValue, |
| 443 size_t endFrame, |
| 444 unsigned writeIndex); |
| 445 |
| 299 // Vector of all automation events for the AudioParam. Access must | 446 // Vector of all automation events for the AudioParam. Access must |
| 300 // be locked via m_eventsLock. | 447 // be locked via m_eventsLock. |
| 301 Vector<std::unique_ptr<ParamEvent>> m_events; | 448 Vector<std::unique_ptr<ParamEvent>> m_events; |
| 302 | 449 |
| 303 mutable Mutex m_eventsLock; | 450 mutable Mutex m_eventsLock; |
| 304 | 451 |
| 305 // Smoothing (de-zippering) | 452 // Smoothing (de-zippering) |
| 306 float m_smoothedValue; | 453 float m_smoothedValue; |
| 307 }; | 454 }; |
| 308 | 455 |
| 309 } // namespace blink | 456 } // namespace blink |
| 310 | 457 |
| 311 #endif // AudioParamTimeline_h | 458 #endif // AudioParamTimeline_h |
| OLD | NEW |