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

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

Issue 2629463002: Refactor valuesForFrameRangeImpl (Closed)
Patch Set: Make AutomationState const and add documentation Created 3 years, 10 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 18 matching lines...) Expand all
29 #ifndef AudioParamTimeline_h 29 #ifndef AudioParamTimeline_h
30 #define AudioParamTimeline_h 30 #define AudioParamTimeline_h
31 31
32 #include "core/dom/DOMTypedArray.h" 32 #include "core/dom/DOMTypedArray.h"
33 #include "modules/webaudio/AudioDestinationNode.h" 33 #include "modules/webaudio/AudioDestinationNode.h"
34 #include "modules/webaudio/BaseAudioContext.h" 34 #include "modules/webaudio/BaseAudioContext.h"
35 #include "wtf/Forward.h" 35 #include "wtf/Forward.h"
36 #include "wtf/Threading.h" 36 #include "wtf/Threading.h"
37 #include "wtf/Vector.h" 37 #include "wtf/Vector.h"
38 38
39 #include <tuple>
40
39 namespace blink { 41 namespace blink {
40 42
41 class AudioParamTimeline { 43 class AudioParamTimeline {
42 DISALLOW_NEW(); 44 DISALLOW_NEW();
43 45
44 public: 46 public:
45 AudioParamTimeline() {} 47 AudioParamTimeline() {}
46 48
47 void setValueAtTime(float value, double time, ExceptionState&); 49 void setValueAtTime(float value, double time, ExceptionState&);
48 void linearRampToValueAtTime(float value, 50 void linearRampToValueAtTime(float value,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 const std::unique_ptr<ParamEvent>& b) { 153 const std::unique_ptr<ParamEvent>& b) {
152 return a->time() < b->time(); 154 return a->time() < b->time();
153 } 155 }
154 156
155 Type getType() const { return m_type; } 157 Type getType() const { return m_type; }
156 float value() const { return m_value; } 158 float value() const { return m_value; }
157 double time() const { return m_time; } 159 double time() const { return m_time; }
158 void setTime(double newTime) { m_time = newTime; } 160 void setTime(double newTime) { m_time = newTime; }
159 double timeConstant() const { return m_timeConstant; } 161 double timeConstant() const { return m_timeConstant; }
160 double duration() const { return m_duration; } 162 double duration() const { return m_duration; }
163 const Vector<float>& curve() const { return m_curve; }
hongchan 2017/02/10 23:37:29 What is the benefit of this pattern? A const gette
Raymond Toy 2017/02/10 23:52:36 Not sure about the pattern, but a few other bits o
161 Vector<float>& curve() { return m_curve; } 164 Vector<float>& curve() { return m_curve; }
162 float initialValue() const { return m_initialValue; } 165 float initialValue() const { return m_initialValue; }
163 double callTime() const { return m_callTime; } 166 double callTime() const { return m_callTime; }
164 bool needsTimeClampCheck() const { return m_needsTimeClampCheck; } 167 bool needsTimeClampCheck() const { return m_needsTimeClampCheck; }
165 void clearTimeClampCheck() { m_needsTimeClampCheck = false; } 168 void clearTimeClampCheck() { m_needsTimeClampCheck = false; }
166 169
167 double curvePointsPerSecond() const { return m_curvePointsPerSecond; } 170 double curvePointsPerSecond() const { return m_curvePointsPerSecond; }
168 float curveEndValue() const { return m_curveEndValue; } 171 float curveEndValue() const { return m_curveEndValue; }
169 172
170 // For CancelValues events. Not valid for any other event. 173 // For CancelValues events. Not valid for any other event.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 std::unique_ptr<ParamEvent> m_savedEvent; 257 std::unique_ptr<ParamEvent> m_savedEvent;
255 258
256 // True if the start time needs to be checked against current time 259 // True if the start time needs to be checked against current time
257 // to implement clamping. 260 // to implement clamping.
258 bool m_needsTimeClampCheck; 261 bool m_needsTimeClampCheck;
259 262
260 // True if a default value has been assigned to the CancelValues event. 263 // True if a default value has been assigned to the CancelValues event.
261 bool m_hasDefaultCancelledValue; 264 bool m_hasDefaultCancelledValue;
262 }; 265 };
263 266
267 // State of the timeline for the current event.
268 struct AutomationState {
269 // Parameters for the current automation request.
hongchan 2017/02/10 23:37:29 Merge this comment with l.267?
Raymond Toy 2017/02/14 19:55:52 Done.
270
271 // Number of values to be computed for the automation request
272 const unsigned numberOfValues;
273 // Start and end frames for this automation request
274 const size_t startFrame;
275 const size_t endFrame;
276
277 // Sample rate and control rate for this request
278 const double sampleRate;
279 const double controlRate;
280
281 // Parameters needed for processing the current event.
282
hongchan 2017/02/10 23:37:29 An extra empty line.
Raymond Toy 2017/02/14 19:55:52 Done.
283 const size_t fillToFrame;
284 const size_t fillToEndFrame;
285
286 // Value and time for the current event
287 const float value1;
288 const double time1;
289
290 // Value and time for the next event, if any.
291 const float value2;
292 const double time2;
293
294 // The current event, and it's index in the event vector.
295 const ParamEvent* event;
296 const int eventIndex;
297 };
298
264 void insertEvent(std::unique_ptr<ParamEvent>, ExceptionState&); 299 void insertEvent(std::unique_ptr<ParamEvent>, ExceptionState&);
265 float valuesForFrameRangeImpl(size_t startFrame, 300 float valuesForFrameRangeImpl(size_t startFrame,
266 size_t endFrame, 301 size_t endFrame,
267 float defaultValue, 302 float defaultValue,
268 float* values, 303 float* values,
269 unsigned numberOfValues, 304 unsigned numberOfValues,
270 double sampleRate, 305 double sampleRate,
271 double controlRate); 306 double controlRate);
272 307
273 // Produce a nice string describing the event in human-readable form. 308 // Produce a nice string describing the event in human-readable form.
(...skipping 15 matching lines...) Expand all
289 float value1, 324 float value1,
290 double time1, 325 double time1,
291 float value2, 326 float value2,
292 float timeConstant); 327 float timeConstant);
293 float valueCurveAtTime(double t, 328 float valueCurveAtTime(double t,
294 double time1, 329 double time1,
295 double duration, 330 double duration,
296 const float* curveData, 331 const float* curveData,
297 unsigned curveLength); 332 unsigned curveLength);
298 333
334 // Handles the special case where the first event in the timeline
335 // starts after |startFrame|. These initial values are filled using
336 // |defaultValue|. The updated |currentFrame| and |writeIndex| is
337 // returned.
338 std::tuple<size_t, unsigned> handleFirstEvent(float* values,
339 float defaultValue,
340 unsigned numberOfValues,
341 size_t startFrame,
342 size_t endFrame,
343 double sampleRate,
344 size_t currentFrame,
345 unsigned writeIndex);
346
347 // Return true if |currentEvent| starts after |currentFrame|, but
348 // also takes into account the |nextEvent| if any.
349 bool isEventCurrent(const ParamEvent* currentEvent,
350 const ParamEvent* nextEvent,
351 size_t currentFrame,
352 double sampleRate);
353
354 // Clamp event times to current time, if needed.
355 void clampToCurrentTime(int numberOfEvents,
356 size_t startFrame,
357 double sampleRate);
358
359 // Handle the case where the last event in the timeline is in the
360 // past. Returns false if any event is not in the past. Otherwise,
361 // return true and also fill in |values| with |defaultValue|.
362 bool handleAllEventsInThePast(double currentTime,
363 double sampleRate,
364 float defaultValue,
365 unsigned numberOfValues,
366 float* values);
367
368 // Handle processing of CancelValue event. If cancellation happens, value2,
369 // time2, and nextEventType will be updated with the new value due to
370 // cancellation. The
371 std::tuple<float, double, ParamEvent::Type> handleCancelValues(
372 const ParamEvent* currentEvent,
373 ParamEvent* nextEvent,
374 float value2,
375 double time2);
376
377 // Process a SetTarget event and the next event is a
378 // LinearRampToValue or ExponentialRampToValue event. This requires
379 // special handling because the ramp should start at whatever value
380 // the SetTarget event has reached at this time, instead of using
381 // the value of the SetTarget event.
382 void processSetTargetFollowedByRamp(int eventIndex,
383 ParamEvent*& currentEvent,
384 ParamEvent::Type nextEventType,
385 size_t currentFrame,
386 double sampleRate,
387 double controlRate,
388 float& value);
389
390 // Handle processing of linearRampEvent, writing the appropriate
391 // values to |values|. Returns the updated |currentFrame|, last
392 // computed |value|, and the updated \writeIndex|.
hongchan 2017/02/10 23:37:29 \writeIndex| => |writeIndex| + and all the follow
Raymond Toy 2017/02/14 19:55:52 Done.
393 std::tuple<size_t, float, unsigned> processLinearRamp(
394 const AutomationState& currentState,
395 float* values,
396 size_t currentFrame,
397 float value,
398 unsigned writeIndex);
399
400 // Handle processing of exponentialRampEvent, writing the appropriate
401 // values to |values|. Returns the updated |currentFrame|, last
402 // computed |value|, and the updated \writeIndex|.
403 std::tuple<size_t, float, unsigned> processExponentialRamp(
404 const AutomationState& currentState,
405 float* values,
406 size_t currentFrame,
407 float value,
408 unsigned writeIndex);
409
410 // Handle processing of SetTargetEvent, writing the appropriate
411 // values to |values|. Returns the updated |currentFrame|, last
412 // computed |value|, and the updated \writeIndex|.
413 std::tuple<size_t, float, unsigned> processSetTarget(
414 const AutomationState& currentState,
415 float* values,
416 size_t currentFrame,
417 float value,
418 unsigned writeIndex);
419
420 // Handle processing of SetValueCurveEvent, writing the appropriate
421 // values to |values|. Returns the updated |currentFrame|, last
422 // computed |value|, and the updated \writeIndex|.
423 std::tuple<size_t, float, unsigned> processSetValueCurve(
424 const AutomationState& currentState,
425 float* values,
426 size_t currentFrame,
427 float value,
428 unsigned writeIndex);
429
430 // Handle processing of CancelValuesEvent, writing the appropriate
431 // values to |values|. Returns the updated |currentFrame|, last
432 // computed |value|, and the updated \writeIndex|.
433 std::tuple<size_t, float, unsigned> processCancelValues(
434 const AutomationState& currentState,
435 float* values,
436 size_t currentFrame,
437 float value,
438 unsigned writeIndex);
439
440 // Fill the output vector |values| with the value |defaultValue|,
441 // starting at |writeIndex| and continuing up to |endFrame|
442 // (exclusive). |writeIndex| is updated with the new index.
443 unsigned fillWithDefault(float* values,
444 float defaultValue,
445 size_t endFrame,
446 unsigned writeIndex);
447
299 // Vector of all automation events for the AudioParam. Access must 448 // Vector of all automation events for the AudioParam. Access must
300 // be locked via m_eventsLock. 449 // be locked via m_eventsLock.
301 Vector<std::unique_ptr<ParamEvent>> m_events; 450 Vector<std::unique_ptr<ParamEvent>> m_events;
302 451
303 mutable Mutex m_eventsLock; 452 mutable Mutex m_eventsLock;
304 453
305 // Smoothing (de-zippering) 454 // Smoothing (de-zippering)
306 float m_smoothedValue; 455 float m_smoothedValue;
307 }; 456 };
308 457
309 } // namespace blink 458 } // namespace blink
310 459
311 #endif // AudioParamTimeline_h 460 #endif // AudioParamTimeline_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698