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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp

Issue 2028773002: setValueCurveAtTime has implicit setValueAtTime at end (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/audioparam-setValueCurve-exceptions-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 void AudioParamTimeline::setValueCurveAtTime(DOMFloat32Array* curve, double time , double duration, ExceptionState& exceptionState) 188 void AudioParamTimeline::setValueCurveAtTime(DOMFloat32Array* curve, double time , double duration, ExceptionState& exceptionState)
189 { 189 {
190 ASSERT(isMainThread()); 190 ASSERT(isMainThread());
191 ASSERT(curve); 191 ASSERT(curve);
192 192
193 if (!isNonNegativeAudioParamTime(time, exceptionState) 193 if (!isNonNegativeAudioParamTime(time, exceptionState)
194 || !isPositiveAudioParamTime(duration, exceptionState, "Duration")) 194 || !isPositiveAudioParamTime(duration, exceptionState, "Duration"))
195 return; 195 return;
196 196
197 insertEvent(ParamEvent::createSetValueCurveEvent(curve, time, duration), exc eptionState); 197 insertEvent(ParamEvent::createSetValueCurveEvent(curve, time, duration), exc eptionState);
198
199 // Insert a setValueAtTime event too to establish an event so that all
200 // following events will process from the end of the curve instead of the
201 // beginning.
202 insertEvent(ParamEvent::createSetValueEvent(curve->data()[curve->length() - 1], time + duration), exceptionState);
hongchan 2016/06/03 17:15:47 I understand the logic and it does a reasonable th
Raymond Toy 2016/06/03 17:34:25 I think so. The spec (now) says that setValueCurv
hongchan 2016/06/03 17:39:30 Acknowledged.
198 } 203 }
199 204
200 void AudioParamTimeline::insertEvent(const ParamEvent& event, ExceptionState& ex ceptionState) 205 void AudioParamTimeline::insertEvent(const ParamEvent& event, ExceptionState& ex ceptionState)
201 { 206 {
202 ASSERT(isMainThread()); 207 ASSERT(isMainThread());
203 208
204 // Sanity check the event. Be super careful we're not getting infected with NaN or Inf. These 209 // Sanity check the event. Be super careful we're not getting infected with NaN or Inf. These
205 // should have been handled by the caller. 210 // should have been handled by the caller.
206 bool isValid = event.getType() < ParamEvent::LastType 211 bool isValid = event.getType() < ParamEvent::LastType
207 && std::isfinite(event.value()) 212 && std::isfinite(event.value())
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // Go through each event and render the value buffer where the times overlap , 400 // Go through each event and render the value buffer where the times overlap ,
396 // stopping when we've rendered all the requested values. 401 // stopping when we've rendered all the requested values.
397 // FIXME: could try to optimize by avoiding having to iterate starting from the very first event 402 // FIXME: could try to optimize by avoiding having to iterate starting from the very first event
398 // and keeping track of a "current" event index. 403 // and keeping track of a "current" event index.
399 int n = m_events.size(); 404 int n = m_events.size();
400 for (int i = 0; i < n && writeIndex < numberOfValues; ++i) { 405 for (int i = 0; i < n && writeIndex < numberOfValues; ++i) {
401 ParamEvent& event = m_events[i]; 406 ParamEvent& event = m_events[i];
402 ParamEvent* nextEvent = i < n - 1 ? &(m_events[i + 1]) : 0; 407 ParamEvent* nextEvent = i < n - 1 ? &(m_events[i + 1]) : 0;
403 408
404 // Wait until we get a more recent event. 409 // Wait until we get a more recent event.
410 //
411 // WARNING: due to round-off it might happen that nextEvent->time() is
412 // just less than currentFrame/sampleRate. This means that we will end
413 // up running the event again. The code below had better be prepared
414 // for this case! What should happen is the fillToFrame should be 0 so
415 // that while the event is actually run again, nothing actually gets
416 // computed, and we move on to the next event.
hongchan 2016/06/03 17:15:47 What is the purpose of this comment? Is this a TOD
Raymond Toy 2016/06/03 17:34:25 A note. I'm not sure what a TODO should say. I th
hongchan 2016/06/09 16:26:09 Do you still think this needs to be expanded someh
Raymond Toy 2016/06/13 16:36:49 Done. PTAL.
405 if (nextEvent && nextEvent->time() < currentFrame / sampleRate) { 417 if (nextEvent && nextEvent->time() < currentFrame / sampleRate) {
406 // But if the current event is a SetValue event and the event time i s between 418 // But if the current event is a SetValue event and the event time i s between
407 // currentFrame - 1 and curentFrame (in time). we don't want to skip it. If we do skip 419 // currentFrame - 1 and curentFrame (in time). we don't want to skip it. If we do skip
408 // it, the SetValue event is completely skipped and not applied, whi ch is wrong. Other 420 // it, the SetValue event is completely skipped and not applied, whi ch is wrong. Other
409 // events don't have this problem. (Because currentFrame is unsigne d, we do the time 421 // events don't have this problem. (Because currentFrame is unsigne d, we do the time
410 // check in this funny, but equivalent way.) 422 // check in this funny, but equivalent way.)
411 double eventFrame = event.time() * sampleRate; 423 double eventFrame = event.time() * sampleRate;
412 424
413 // Condition is currentFrame - 1 < eventFrame <= currentFrame, but c urrentFrame is 425 // Condition is currentFrame - 1 < eventFrame <= currentFrame, but c urrentFrame is
414 // unsigned and could be 0, so use currentFrame < eventFrame + 1 ins tead. 426 // unsigned and could be 0, so use currentFrame < eventFrame + 1 ins tead.
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 } 845 }
834 846
835 // If there's any time left after the duration of this event and the start 847 // If there's any time left after the duration of this event and the start
836 // of the next, then just propagate the last value of the cu rveData. 848 // of the next, then just propagate the last value of the cu rveData.
837 if (writeIndex < nextEventFillToFrame) 849 if (writeIndex < nextEventFillToFrame)
838 value = curveData[numberOfCurvePoints - 1]; 850 value = curveData[numberOfCurvePoints - 1];
839 for (; writeIndex < nextEventFillToFrame; ++writeIndex) 851 for (; writeIndex < nextEventFillToFrame; ++writeIndex)
840 values[writeIndex] = value; 852 values[writeIndex] = value;
841 853
842 // Re-adjust current time 854 // Re-adjust current time
843 currentFrame = nextEventFillToFrame; 855 currentFrame += nextEventFillToFrame;
hongchan 2016/06/03 17:15:47 Why are we accumulating this?
Raymond Toy 2016/06/03 17:34:25 This is a bug in the original code. If you look c
hongchan 2016/06/03 17:39:30 Wow, it is surprising that this hasn't come up so
hongchan 2016/06/09 16:26:09 Can we edit the description of this CL to reflect
844 856
845 break; 857 break;
846 } 858 }
847 case ParamEvent::LastType: 859 case ParamEvent::LastType:
848 ASSERT_NOT_REACHED(); 860 ASSERT_NOT_REACHED();
849 break; 861 break;
850 } 862 }
851 } 863 }
852 } 864 }
853 865
854 // If there's any time left after processing the last event then just propag ate the last value 866 // If there's any time left after processing the last event then just propag ate the last value
855 // to the end of the values buffer. 867 // to the end of the values buffer.
856 for (; writeIndex < numberOfValues; ++writeIndex) 868 for (; writeIndex < numberOfValues; ++writeIndex)
857 values[writeIndex] = value; 869 values[writeIndex] = value;
858 870
859 // This value is used to set the .value attribute of the AudioParam. it sho uld be the last 871 // This value is used to set the .value attribute of the AudioParam. it sho uld be the last
860 // computed value. 872 // computed value.
861 return values[numberOfValues - 1]; 873 return values[numberOfValues - 1];
862 } 874 }
863 875
864 } // namespace blink 876 } // namespace blink
865 877
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/audioparam-setValueCurve-exceptions-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698