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

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

Issue 2391893005: Implement clamping of AudioParam time. (Closed)
Patch Set: Rebase and fix typo in comment. Created 4 years, 2 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 35731182aa8088b21deb7f47a87c1c8cdf21436e..55b8026734d208f797cbd2ba4063ecee33a6fd4a 100644
--- a/third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp
@@ -128,7 +128,8 @@ AudioParamTimeline::ParamEvent::ParamEvent(Type type,
m_timeConstant(timeConstant),
m_duration(duration),
m_initialValue(initialValue),
- m_callTime(callTime) {
+ m_callTime(callTime),
+ m_needsClampCheck(true) {
if (curve) {
// Copy the curve data
unsigned curveLength = curve->length();
@@ -456,12 +457,33 @@ float AudioParamTimeline::valuesForFrameRangeImpl(size_t startFrame,
return defaultValue;
}
- // Optimize the case where the last event is in the past.
+ int n = m_events.size();
hongchan 2016/10/18 17:34:59 n => numberOfEvents ?
Raymond Toy 2016/10/18 20:33:18 Done.
+
if (m_events.size() > 0) {
hongchan 2016/10/18 17:34:59 Can we use |numberOfEvents| here?
Raymond Toy 2016/10/18 20:33:18 Done.
+ double currentTime = startFrame / sampleRate;
+
+ // Look at all the events in the timeline and check to see if any needs
+ // to clamp the start time to the current time.
+ for (int k = 0; k < n; ++k) {
+ ParamEvent& event = m_events[k];
+
+ // We're examining the event for the first time and the event time is
+ // in the past so clamp the event time to the current time (start of
+ // the rendering quantum).
+ if (event.needsClampCheck()) {
+ if (event.time() < currentTime)
+ event.setTime(currentTime);
+
+ // In all cases, we can clear the flag because the event is either
+ // in the future, or we've already checked it (just now).
+ event.clearClampCheck();
+ }
+ }
+
+ // Optimize the case where the last event is in the past.
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
@@ -509,7 +531,6 @@ float AudioParamTimeline::valuesForFrameRangeImpl(size_t startFrame,
// Go through each event and render the value buffer where the times overlap,
// stopping when we've rendered all the requested values.
- int n = m_events.size();
int lastSkippedEventIndex = 0;
for (int i = 0; i < n && writeIndex < numberOfValues; ++i) {
ParamEvent& event = m_events[i];
@@ -600,8 +621,12 @@ float AudioParamTimeline::valuesForFrameRangeImpl(size_t startFrame,
event.timeConstant(), controlRate));
value += (event.value() - value) * discreteTimeConstant;
}
+
+ // Insert a SetValueEvent to mark the starting value and time.
+ // Clear the clamp check because this doesn't need it.
m_events[i] =
ParamEvent::createSetValueEvent(value, currentFrame / sampleRate);
+ m_events[i].clearClampCheck();
}
float value1 = event.value();

Powered by Google App Engine
This is Rietveld 408576698