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

Side by Side 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 unified diff | Download patch
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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 if (!values || !(numberOfValues >= 1)) 394 if (!values || !(numberOfValues >= 1))
395 return defaultValue; 395 return defaultValue;
396 396
397 // Return default value if there are no events matching the desired time ran ge. 397 // Return default value if there are no events matching the desired time ran ge.
398 if (!m_events.size() || (endFrame / sampleRate <= m_events[0].time())) { 398 if (!m_events.size() || (endFrame / sampleRate <= m_events[0].time())) {
399 for (unsigned i = 0; i < numberOfValues; ++i) 399 for (unsigned i = 0; i < numberOfValues; ++i)
400 values[i] = defaultValue; 400 values[i] = defaultValue;
401 return defaultValue; 401 return defaultValue;
402 } 402 }
403 403
404 // Optimize the case where the last event is in the past.
405 if (m_events.size() > 0) {
406 ParamEvent& lastEvent = m_events[m_events.size() - 1];
407 ParamEvent::Type lastEventType = lastEvent.getType();
408 double lastEventTime = lastEvent.time();
409 double currentTime = startFrame / sampleRate;
410
411 // If the last event is in the past and the event has ended, then we can
412 // just propagate the same value. Except for SetTarget which lasts
413 // "forever". SetValueCurve also has an explicit SetValue at the end of
414 // the curve, so we don't need to worry that SetValueCurve time is a
415 // start time, not an end time.
416 if (lastEventTime < currentTime && lastEventType != ParamEvent::SetTarge t) {
417 // The event has finished, so just copy the default value out.
418 // Since all events are now also in the past, we can just remove all
419 // timeline events too because |defaultValue| has the expected
420 // value.
421 for (unsigned i = 0; i < numberOfValues; ++i)
422 values[i] = defaultValue;
423 m_smoothedValue = defaultValue;
424 m_events.clear();
425 return defaultValue;
426 }
427 }
428
404 // Maintain a running time (frame) and index for writing the values buffer. 429 // Maintain a running time (frame) and index for writing the values buffer.
405 size_t currentFrame = startFrame; 430 size_t currentFrame = startFrame;
406 unsigned writeIndex = 0; 431 unsigned writeIndex = 0;
407 432
408 // If first event is after startFrame then fill initial part of values buffe r with defaultValue 433 // If first event is after startFrame then fill initial part of values buffe r with defaultValue
409 // until we reach the first event time. 434 // until we reach the first event time.
410 double firstEventTime = m_events[0].time(); 435 double firstEventTime = m_events[0].time();
411 if (firstEventTime > startFrame / sampleRate) { 436 if (firstEventTime > startFrame / sampleRate) {
412 // |fillToFrame| is an exclusive upper bound, so use ceil() to compute t he bound from the 437 // |fillToFrame| is an exclusive upper bound, so use ceil() to compute t he bound from the
413 // firstEventTime. 438 // firstEventTime.
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 for (; writeIndex < numberOfValues; ++writeIndex) 941 for (; writeIndex < numberOfValues; ++writeIndex)
917 values[writeIndex] = value; 942 values[writeIndex] = value;
918 943
919 // This value is used to set the .value attribute of the AudioParam. it sho uld be the last 944 // This value is used to set the .value attribute of the AudioParam. it sho uld be the last
920 // computed value. 945 // computed value.
921 return values[numberOfValues - 1]; 946 return values[numberOfValues - 1];
922 } 947 }
923 948
924 } // namespace blink 949 } // namespace blink
925 950
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698