| 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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 // range. | 464 // range. |
| 465 if (!m_events.size() || (endFrame / sampleRate <= m_events[0].time())) { | 465 if (!m_events.size() || (endFrame / sampleRate <= m_events[0].time())) { |
| 466 for (unsigned i = 0; i < numberOfValues; ++i) | 466 for (unsigned i = 0; i < numberOfValues; ++i) |
| 467 values[i] = defaultValue; | 467 values[i] = defaultValue; |
| 468 return defaultValue; | 468 return defaultValue; |
| 469 } | 469 } |
| 470 | 470 |
| 471 int numberOfEvents = m_events.size(); | 471 int numberOfEvents = m_events.size(); |
| 472 | 472 |
| 473 if (numberOfEvents > 0) { | 473 if (numberOfEvents > 0) { |
| 474 bool clampedSomeEventTime = false; |
| 474 double currentTime = startFrame / sampleRate; | 475 double currentTime = startFrame / sampleRate; |
| 475 | 476 |
| 476 // Look at all the events in the timeline and check to see if any needs | 477 // Look at all the events in the timeline and check to see if any needs |
| 477 // to clamp the start time to the current time. | 478 // to clamp the start time to the current time. |
| 478 for (int k = 0; k < numberOfEvents; ++k) { | 479 for (int k = 0; k < numberOfEvents; ++k) { |
| 479 ParamEvent& event = m_events[k]; | 480 ParamEvent& event = m_events[k]; |
| 480 | 481 |
| 481 // We're examining the event for the first time and the event time is | 482 // We're examining the event for the first time and the event time is |
| 482 // in the past so clamp the event time to the current time (start of | 483 // in the past so clamp the event time to the current time (start of |
| 483 // the rendering quantum). | 484 // the rendering quantum). |
| 484 if (event.needsTimeClampCheck()) { | 485 if (event.needsTimeClampCheck()) { |
| 485 if (event.time() < currentTime) | 486 if (event.time() < currentTime) { |
| 486 event.setTime(currentTime); | 487 event.setTime(currentTime); |
| 488 clampedSomeEventTime = true; |
| 489 } |
| 487 | 490 |
| 488 // In all cases, we can clear the flag because the event is either | 491 // In all cases, we can clear the flag because the event is either |
| 489 // in the future, or we've already checked it (just now). | 492 // in the future, or we've already checked it (just now). |
| 490 event.clearTimeClampCheck(); | 493 event.clearTimeClampCheck(); |
| 491 } | 494 } |
| 492 } | 495 } |
| 493 | 496 |
| 497 if (clampedSomeEventTime) { |
| 498 // If we clamped some event time to current time, we need to |
| 499 // sort the event list in time order again, but it must be |
| 500 // stable! |
| 501 std::stable_sort(m_events.begin(), m_events.end(), |
| 502 ParamEvent::eventPreceeds); |
| 503 } |
| 504 |
| 494 // Optimize the case where the last event is in the past. | 505 // Optimize the case where the last event is in the past. |
| 495 ParamEvent& lastEvent = m_events[m_events.size() - 1]; | 506 ParamEvent& lastEvent = m_events[m_events.size() - 1]; |
| 496 ParamEvent::Type lastEventType = lastEvent.getType(); | 507 ParamEvent::Type lastEventType = lastEvent.getType(); |
| 497 double lastEventTime = lastEvent.time(); | 508 double lastEventTime = lastEvent.time(); |
| 498 | 509 |
| 499 // If the last event is in the past and the event has ended, then we can | 510 // If the last event is in the past and the event has ended, then we can |
| 500 // just propagate the same value. Except for SetTarget which lasts | 511 // just propagate the same value. Except for SetTarget which lasts |
| 501 // "forever". SetValueCurve also has an explicit SetValue at the end of | 512 // "forever". SetValueCurve also has an explicit SetValue at the end of |
| 502 // the curve, so we don't need to worry that SetValueCurve time is a | 513 // the curve, so we don't need to worry that SetValueCurve time is a |
| 503 // start time, not an end time. | 514 // start time, not an end time. |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 ParamEvent::createSetValueEvent(value, currentFrame / sampleRate); | 650 ParamEvent::createSetValueEvent(value, currentFrame / sampleRate); |
| 640 m_events[i].clearTimeClampCheck(); | 651 m_events[i].clearTimeClampCheck(); |
| 641 } | 652 } |
| 642 | 653 |
| 643 float value1 = event.value(); | 654 float value1 = event.value(); |
| 644 double time1 = event.time(); | 655 double time1 = event.time(); |
| 645 | 656 |
| 646 float value2 = nextEvent ? nextEvent->value() : value1; | 657 float value2 = nextEvent ? nextEvent->value() : value1; |
| 647 double time2 = nextEvent ? nextEvent->time() : endFrame / sampleRate + 1; | 658 double time2 = nextEvent ? nextEvent->time() : endFrame / sampleRate + 1; |
| 648 | 659 |
| 660 DCHECK_GE(time2, time1); |
| 649 double deltaTime = time2 - time1; | 661 double deltaTime = time2 - time1; |
| 650 float k = deltaTime > 0 ? 1 / deltaTime : 0; | 662 float k = deltaTime > 0 ? 1 / deltaTime : 0; |
| 651 | 663 |
| 652 // |fillToEndFrame| is the exclusive upper bound of the last frame to be | 664 // |fillToEndFrame| is the exclusive upper bound of the last frame to be |
| 653 // computed for this event. It's either the last desired frame (|endFrame|) | 665 // computed for this event. It's either the last desired frame (|endFrame|) |
| 654 // or derived from the end time of the next event (time2). We compute | 666 // or derived from the end time of the next event (time2). We compute |
| 655 // ceil(time2*sampleRate) because fillToEndFrame is the exclusive upper | 667 // ceil(time2*sampleRate) because fillToEndFrame is the exclusive upper |
| 656 // bound. Consider the case where |startFrame| = 128 and time2 = 128.1 | 668 // bound. Consider the case where |startFrame| = 128 and time2 = 128.1 |
| 657 // (assuming sampleRate = 1). Since time2 is greater than 128, we want to | 669 // (assuming sampleRate = 1). Since time2 is greater than 128, we want to |
| 658 // output a value for frame 128. This requires that fillToEndFrame be at | 670 // output a value for frame 128. This requires that fillToEndFrame be at |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 // propagate the last value to the end of the values buffer. | 1108 // propagate the last value to the end of the values buffer. |
| 1097 for (; writeIndex < numberOfValues; ++writeIndex) | 1109 for (; writeIndex < numberOfValues; ++writeIndex) |
| 1098 values[writeIndex] = value; | 1110 values[writeIndex] = value; |
| 1099 | 1111 |
| 1100 // This value is used to set the .value attribute of the AudioParam. it | 1112 // This value is used to set the .value attribute of the AudioParam. it |
| 1101 // should be the last computed value. | 1113 // should be the last computed value. |
| 1102 return values[numberOfValues - 1]; | 1114 return values[numberOfValues - 1]; |
| 1103 } | 1115 } |
| 1104 | 1116 |
| 1105 } // namespace blink | 1117 } // namespace blink |
| OLD | NEW |