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

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: 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 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 if (!values || !(numberOfValues >= 1)) 402 if (!values || !(numberOfValues >= 1))
403 return defaultValue; 403 return defaultValue;
404 404
405 // Return default value if there are no events matching the desired time ran ge. 405 // Return default value if there are no events matching the desired time ran ge.
406 if (!m_events.size() || (endFrame / sampleRate <= m_events[0].time())) { 406 if (!m_events.size() || (endFrame / sampleRate <= m_events[0].time())) {
407 for (unsigned i = 0; i < numberOfValues; ++i) 407 for (unsigned i = 0; i < numberOfValues; ++i)
408 values[i] = defaultValue; 408 values[i] = defaultValue;
409 return defaultValue; 409 return defaultValue;
410 } 410 }
411 411
412 // Optimize the case where the last event is in the past.
413 if (m_events.size() > 0) {
414 ParamEvent& lastEvent = m_events[m_events.size() - 1];
415 ParamEvent::Type lastEventType = lastEvent.getType();
416 double lastEventTime = lastEvent.time();
417 double currentTime = startFrame / sampleRate;
418
419 // If the last event is in the past and the event has ended, then we can
420 // just propagate the same value. Except for SetTarget which lasts
421 // "forever". SetValueCurve also has an explicit SetValue at the end of
422 // the curve, so we don't need to worry that SetValueCurve time is a
423 // start time, not an end time.
424 if (lastEventTime < currentTime && lastEventType != ParamEvent::SetTarge t) {
425 // The event has finished, so just copy the default value out.
426 // Since all events are now also in the past, we can just remove all
427 // timeline events too because |defaultValue| has the expected
428 // value.
429 for (unsigned i = 0; i < numberOfValues; ++i)
430 values[i] = defaultValue;
431 m_smoothedValue = defaultValue;
432 m_events.clear();
433 return defaultValue;
434 }
435 }
436
412 // Maintain a running time (frame) and index for writing the values buffer. 437 // Maintain a running time (frame) and index for writing the values buffer.
413 size_t currentFrame = startFrame; 438 size_t currentFrame = startFrame;
414 unsigned writeIndex = 0; 439 unsigned writeIndex = 0;
415 440
416 // If first event is after startFrame then fill initial part of values buffe r with defaultValue 441 // If first event is after startFrame then fill initial part of values buffe r with defaultValue
417 // until we reach the first event time. 442 // until we reach the first event time.
418 double firstEventTime = m_events[0].time(); 443 double firstEventTime = m_events[0].time();
419 if (firstEventTime > startFrame / sampleRate) { 444 if (firstEventTime > startFrame / sampleRate) {
420 // |fillToFrame| is an exclusive upper bound, so use ceil() to compute t he bound from the 445 // |fillToFrame| is an exclusive upper bound, so use ceil() to compute t he bound from the
421 // firstEventTime. 446 // firstEventTime.
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 for (; writeIndex < numberOfValues; ++writeIndex) 949 for (; writeIndex < numberOfValues; ++writeIndex)
925 values[writeIndex] = value; 950 values[writeIndex] = value;
926 951
927 // This value is used to set the .value attribute of the AudioParam. it sho uld be the last 952 // This value is used to set the .value attribute of the AudioParam. it sho uld be the last
928 // computed value. 953 // computed value.
929 return values[numberOfValues - 1]; 954 return values[numberOfValues - 1];
930 } 955 }
931 956
932 } // namespace blink 957 } // namespace blink
933 958
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698