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

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: Move m_smoothedValue from AudioParam to AudioParamTimeline. 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 85ee0a196b442aba014fa2485fb74cea182f3525..e89dc6975ec1dce9def928b7ef6667fa1c716ae1 100644
--- a/third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp
@@ -401,6 +401,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