Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Unified Diff: third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp

Issue 2033503004: Avoid slow AudioParam automation path when possible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp b/third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp
index 804538f4b180589659861bd69a8d2dfcc24321a2..e22ce2f9ab55713320e80131e2a530554c447d7c 100644
--- a/third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp
@@ -409,6 +409,31 @@ float AudioParamTimeline::valuesForFrameRangeImpl(
return defaultValue;
}
+ // Optimize the case where the last event is in the past.
+ if (m_events.size() > 0) {
+ ParamEvent& lastEvent = m_events[m_events.size() - 1];
+ ParamEvent::Type lastEventType = lastEvent.getType();
+ double lastEventTime = lastEvent.time();
+ double currentTime = startFrame / sampleRate;
+
+ // If the last event is in the past and the event has ended, then we can
+ // just propagate the same value. Except for SetTarget which lasts
+ // "forever". SetValueCurve also has an explicit SetValue at the end of
+ // the curve, so we don't need to worry that SetValueCurve time is a
+ // start time, not an end time.
+ if (lastEventTime < currentTime && lastEventType != ParamEvent::SetTarget) {
+ // The event has finished, so just copy the default value out.
+ // Since all events are now also in the past, we can just remove all
+ // timeline events too because |defaultValue| has the expected
+ // value.
+ for (unsigned i = 0; i < numberOfValues; ++i)
+ values[i] = defaultValue;
+ m_smoothedValue = defaultValue;
+ m_events.clear();
+ return defaultValue;
+ }
+ }
+
// Maintain a running time (frame) and index for writing the values buffer.
size_t currentFrame = startFrame;
unsigned writeIndex = 0;

Powered by Google App Engine
This is Rietveld 408576698