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

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

Issue 1533103002: Implement cancelValuesAndHoldAtTime (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 3 years, 11 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 ExceptionState&); 57 ExceptionState&);
58 void setTargetAtTime(float target, 58 void setTargetAtTime(float target,
59 double time, 59 double time,
60 double timeConstant, 60 double timeConstant,
61 ExceptionState&); 61 ExceptionState&);
62 void setValueCurveAtTime(DOMFloat32Array* curve, 62 void setValueCurveAtTime(DOMFloat32Array* curve,
63 double time, 63 double time,
64 double duration, 64 double duration,
65 ExceptionState&); 65 ExceptionState&);
66 void cancelScheduledValues(double startTime, ExceptionState&); 66 void cancelScheduledValues(double startTime, ExceptionState&);
67 void cancelValuesAndHoldAtTime(double cancelTime, ExceptionState&);
67 68
68 // hasValue is set to true if a valid timeline value is returned. 69 // hasValue is set to true if a valid timeline value is returned.
69 // otherwise defaultValue is returned. 70 // otherwise defaultValue is returned.
70 float valueForContextTime(AudioDestinationHandler&, 71 float valueForContextTime(AudioDestinationHandler&,
71 float defaultValue, 72 float defaultValue,
72 bool& hasValue, 73 bool& hasValue,
73 float minValue, 74 float minValue,
74 float maxValue); 75 float maxValue);
75 76
76 // Given the time range in frames, calculates parameter values into the values 77 // Given the time range in frames, calculates parameter values into the values
(...skipping 21 matching lines...) Expand all
98 99
99 private: 100 private:
100 class ParamEvent { 101 class ParamEvent {
101 public: 102 public:
102 enum Type { 103 enum Type {
103 SetValue, 104 SetValue,
104 LinearRampToValue, 105 LinearRampToValue,
105 ExponentialRampToValue, 106 ExponentialRampToValue,
106 SetTarget, 107 SetTarget,
107 SetValueCurve, 108 SetValueCurve,
109 // For cancelValuesAndHold
110 CancelValues,
108 LastType 111 LastType
109 }; 112 };
110 113
111 static ParamEvent createLinearRampEvent(float value, 114 static std::unique_ptr<ParamEvent> createLinearRampEvent(float value,
112 double time, 115 double time,
113 float initialValue, 116 float initialValue,
114 double callTime); 117 double callTime);
115 static ParamEvent createExponentialRampEvent(float value, 118 static std::unique_ptr<ParamEvent> createExponentialRampEvent(
116 double time, 119 float value,
117 float initialValue, 120 double time,
118 double callTime); 121 float initialValue,
119 static ParamEvent createSetValueEvent(float value, double time); 122 double callTime);
120 static ParamEvent createSetTargetEvent(float value, 123 static std::unique_ptr<ParamEvent> createSetValueEvent(float value,
121 double time, 124 double time);
122 double timeConstant); 125 static std::unique_ptr<ParamEvent>
123 static ParamEvent createSetValueCurveEvent(const DOMFloat32Array* curve, 126 createSetTargetEvent(float value, double time, double timeConstant);
124 double time, 127 static std::unique_ptr<ParamEvent> createSetValueCurveEvent(
125 double duration); 128 const DOMFloat32Array* curve,
129 double time,
130 double duration);
131 static std::unique_ptr<ParamEvent> createCancelValuesEvent(
132 double time,
133 std::unique_ptr<ParamEvent> savedEvent);
134 // Needed for creating a saved event where we want to supply all
135 // the possible parameters because we're mostly copying an
136 // existing event.
137 static std::unique_ptr<ParamEvent> createGeneralEvent(
138 Type,
139 float value,
140 double time,
141 float initialValue,
142 double callTime,
143 double timeConstant,
144 double duration,
145 Vector<float>& curve,
146 double curvePointsPerSecond,
147 float curveEndValue,
148 std::unique_ptr<ParamEvent> savedEvent);
126 149
127 static bool eventPreceeds(const ParamEvent& a, const ParamEvent& b) { 150 static bool eventPreceeds(const std::unique_ptr<ParamEvent>& a,
128 return a.time() < b.time(); 151 const std::unique_ptr<ParamEvent>& b) {
152 return a->time() < b->time();
129 } 153 }
130 154
131 Type getType() const { return m_type; } 155 Type getType() const { return m_type; }
132 float value() const { return m_value; } 156 float value() const { return m_value; }
133 double time() const { return m_time; } 157 double time() const { return m_time; }
134 void setTime(double newTime) { m_time = newTime; } 158 void setTime(double newTime) { m_time = newTime; }
135 double timeConstant() const { return m_timeConstant; } 159 double timeConstant() const { return m_timeConstant; }
136 double duration() const { return m_duration; } 160 double duration() const { return m_duration; }
137 Vector<float>& curve() { return m_curve; } 161 Vector<float>& curve() { return m_curve; }
138 float initialValue() const { return m_initialValue; } 162 float initialValue() const { return m_initialValue; }
139 double callTime() const { return m_callTime; } 163 double callTime() const { return m_callTime; }
140 bool needsTimeClampCheck() const { return m_needsTimeClampCheck; } 164 bool needsTimeClampCheck() const { return m_needsTimeClampCheck; }
141 void clearTimeClampCheck() { m_needsTimeClampCheck = false; } 165 void clearTimeClampCheck() { m_needsTimeClampCheck = false; }
142 166
167 double curvePointsPerSecond() const { return m_curvePointsPerSecond; }
168 float curveEndValue() const { return m_curveEndValue; }
169
170 // For CancelValues events. Not valid for any other event.
171 ParamEvent* savedEvent() const;
172 bool hasDefaultCancelledValue() const;
173 void setCancelledValue(float);
174
143 private: 175 private:
176 // General event
144 ParamEvent(Type type, 177 ParamEvent(Type type,
145 float value, 178 float value,
146 double time, 179 double time,
180 float initialValue,
181 double callTime,
147 double timeConstant, 182 double timeConstant,
148 double duration, 183 double duration,
184 Vector<float>& curve,
185 double curvePointsPerSecond,
186 float curveEndValue,
187 std::unique_ptr<ParamEvent> savedEvent);
188
189 // Create simplest event needing just a value and time, like
190 // setValueAtTime.
191 ParamEvent(Type, float value, double time);
192
193 // Create a linear or exponential ramp that requires an initial
194 // value and time in case there is no actual event that preceeds
195 // this event.
196 ParamEvent(Type,
197 float value,
198 double time,
199 float initialValue,
200 double callTime);
201
202 // Create an event needing a time constant (setTargetAtTime)
203 ParamEvent(Type, float value, double time, double timeConstant);
204
205 // Create a setValueCurve event
206 ParamEvent(Type,
207 double time,
208 double duration,
149 const DOMFloat32Array* curve, 209 const DOMFloat32Array* curve,
150 float initialValue = 0, 210 double curvePointsPerSecond,
151 double callTime = 0); 211 float curveEndValue);
212
213 // Create CancelValues event
214 ParamEvent(Type, double time, std::unique_ptr<ParamEvent> savedEvent);
152 215
153 Type m_type; 216 Type m_type;
217
218 // The value for the event. The interpretation of this depends on
219 // the event type. Not used for SetValueCurve. For CancelValues,
220 // it is the end value to use when cancelling a LinearRampToValue
221 // or ExponentialRampToValue event.
154 float m_value; 222 float m_value;
223
224 // The time for the event. The interpretation of this depends on
225 // the event type.
155 double m_time; 226 double m_time;
156 // Only used for SetTarget events 227
157 double m_timeConstant;
158 // Only used for SetValueCurve events.
159 double m_duration;
160 Vector<float> m_curve;
161 // Initial value and time to use for linear and exponential ramps that don't 228 // Initial value and time to use for linear and exponential ramps that don't
162 // have a preceding event. 229 // have a preceding event.
163 float m_initialValue; 230 float m_initialValue;
164 double m_callTime; 231 double m_callTime;
232
233 // Only used for SetTarget events
234 double m_timeConstant;
235
236 // The following items are only used for SetValueCurve events.
237 //
238 // The duration of the curve.
239 double m_duration;
240 // The array of curve points.
241 Vector<float> m_curve;
242 // The number of curve points per second. it is used to compute
243 // the curve index step when running the automation.
244 double m_curvePointsPerSecond;
245 // The default value to use at the end of the curve. Normally
246 // it's the last entry in m_curve, but cancelling a SetValueCurve
247 // will set this to a new value.
248 float m_curveEndValue;
249
250 // For CancelValues. If CancelValues is in the middle of an event, this
251 // holds the event that is being cancelled, so that processing can
252 // continue as if the event still existed up until we reach the actual
253 // scheduled cancel time.
254 std::unique_ptr<ParamEvent> m_savedEvent;
255
165 // True if the start time needs to be checked against current time 256 // True if the start time needs to be checked against current time
166 // to implement clamping. 257 // to implement clamping.
167 bool m_needsTimeClampCheck; 258 bool m_needsTimeClampCheck;
259
260 // True if a default value has been assigned to the CancelValues event.
261 bool m_hasDefaultCancelledValue;
168 }; 262 };
169 263
170 void insertEvent(const ParamEvent&, ExceptionState&); 264 void insertEvent(std::unique_ptr<ParamEvent>, ExceptionState&);
171 float valuesForFrameRangeImpl(size_t startFrame, 265 float valuesForFrameRangeImpl(size_t startFrame,
172 size_t endFrame, 266 size_t endFrame,
173 float defaultValue, 267 float defaultValue,
174 float* values, 268 float* values,
175 unsigned numberOfValues, 269 unsigned numberOfValues,
176 double sampleRate, 270 double sampleRate,
177 double controlRate); 271 double controlRate);
178 272
179 // Produce a nice string describing the event in human-readable form. 273 // Produce a nice string describing the event in human-readable form.
180 String eventToString(const ParamEvent&); 274 String eventToString(const ParamEvent&);
181 Vector<ParamEvent> m_events; 275
276 // Automation functions that compute the vlaue of the specified
277 // automation at the specified time.
278 float linearRampAtTime(double t,
279 float value1,
280 double time1,
281 float value2,
282 double time2);
283 float exponentialRampAtTime(double t,
284 float value1,
285 double time1,
286 float value2,
287 double time2);
288 float targetValueAtTime(double t,
289 float value1,
290 double time1,
291 float value2,
292 float timeConstant);
293 float valueCurveAtTime(double t,
294 double time1,
295 double duration,
296 const float* curveData,
297 unsigned curveLength);
298
299 // Vector of all automation events for the AudioParam. Access must
300 // be locked via m_eventsLock.
301 Vector<std::unique_ptr<ParamEvent>> m_events;
182 302
183 mutable Mutex m_eventsLock; 303 mutable Mutex m_eventsLock;
184 304
185 // Smoothing (de-zippering) 305 // Smoothing (de-zippering)
186 float m_smoothedValue; 306 float m_smoothedValue;
187 }; 307 };
188 308
189 } // namespace blink 309 } // namespace blink
190 310
191 #endif // AudioParamTimeline_h 311 #endif // AudioParamTimeline_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698