OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 // This type is not exposed to Javascript. It's meant to handle the | |
110 // cancelValuesAndHoldAtTime() API. | |
hongchan
2016/12/22 18:41:37
Just a thought: how about renaming this variable t
Raymond Toy
2016/12/22 19:06:23
Actually, the comment is kind of wrong. None of th
| |
111 CancelValues, | |
108 LastType | 112 LastType |
109 }; | 113 }; |
110 | 114 |
111 static ParamEvent createLinearRampEvent(float value, | 115 static std::unique_ptr<ParamEvent> createLinearRampEvent(float value, |
112 double time, | 116 double time, |
113 float initialValue, | 117 float initialValue, |
114 double callTime); | 118 double callTime); |
115 static ParamEvent createExponentialRampEvent(float value, | 119 static std::unique_ptr<ParamEvent> createExponentialRampEvent( |
116 double time, | 120 float value, |
117 float initialValue, | 121 double time, |
118 double callTime); | 122 float initialValue, |
119 static ParamEvent createSetValueEvent(float value, double time); | 123 double callTime); |
120 static ParamEvent createSetTargetEvent(float value, | 124 static std::unique_ptr<ParamEvent> createSetValueEvent(float value, |
121 double time, | 125 double time); |
122 double timeConstant); | 126 static std::unique_ptr<ParamEvent> |
123 static ParamEvent createSetValueCurveEvent(const DOMFloat32Array* curve, | 127 createSetTargetEvent(float value, double time, double timeConstant); |
124 double time, | 128 static std::unique_ptr<ParamEvent> createSetValueCurveEvent( |
125 double duration); | 129 const DOMFloat32Array* curve, |
130 double time, | |
131 double duration); | |
132 static std::unique_ptr<ParamEvent> createCancelValuesEvent( | |
133 double time, | |
134 std::unique_ptr<ParamEvent> savedEvent); | |
135 static std::unique_ptr<ParamEvent> createGeneralEvent( | |
hongchan
2016/12/22 18:41:37
Can we have a comment why this method is needed? P
Raymond Toy
2016/12/22 19:06:23
It's needed to create a saved event (which is basi
| |
136 Type, | |
137 float value, | |
138 double time, | |
139 float initialValue, | |
140 double callTime, | |
141 double timeConstant, | |
142 double duration, | |
143 Vector<float>& curve, | |
144 double curvePointsPerSecond, | |
145 float curveEndValue, | |
146 std::unique_ptr<ParamEvent> savedEvent); | |
126 | 147 |
127 Type getType() const { return m_type; } | 148 Type getType() const { return m_type; } |
128 float value() const { return m_value; } | 149 float value() const { return m_value; } |
129 double time() const { return m_time; } | 150 double time() const { return m_time; } |
130 void setTime(double newTime) { m_time = newTime; } | 151 void setTime(double newTime) { m_time = newTime; } |
131 double timeConstant() const { return m_timeConstant; } | 152 double timeConstant() const { return m_timeConstant; } |
132 double duration() const { return m_duration; } | 153 double duration() const { return m_duration; } |
133 Vector<float>& curve() { return m_curve; } | 154 Vector<float>& curve() { return m_curve; } |
134 float initialValue() const { return m_initialValue; } | 155 float initialValue() const { return m_initialValue; } |
135 double callTime() const { return m_callTime; } | 156 double callTime() const { return m_callTime; } |
136 bool needsTimeClampCheck() const { return m_needsTimeClampCheck; } | 157 bool needsTimeClampCheck() const { return m_needsTimeClampCheck; } |
137 void clearTimeClampCheck() { m_needsTimeClampCheck = false; } | 158 void clearTimeClampCheck() { m_needsTimeClampCheck = false; } |
138 | 159 |
160 double curvePointsPerSecond() const { return m_curvePointsPerSecond; } | |
161 float curveEndValue() const { return m_curveEndValue; } | |
162 | |
163 // For CancelValues events. Not valid for any other event | |
hongchan
2016/12/22 18:41:37
nit: a missing period. Also there is a couple of m
Raymond Toy
2016/12/22 19:21:34
Done.
| |
164 ParamEvent* savedEvent() const; | |
165 bool hasDefaultCancelledValue() const; | |
166 void setCancelledValue(float); | |
167 | |
139 private: | 168 private: |
169 // General event | |
140 ParamEvent(Type type, | 170 ParamEvent(Type type, |
141 float value, | 171 float value, |
142 double time, | 172 double time, |
173 float initialValue, | |
174 double callTime, | |
143 double timeConstant, | 175 double timeConstant, |
144 double duration, | 176 double duration, |
177 Vector<float>& curve, | |
178 double curvePointsPerSecond, | |
179 float curveEndValue, | |
180 std::unique_ptr<ParamEvent> savedEvent); | |
181 | |
182 // Create simplest event needing just a value and time, like setValueAtTime | |
hongchan
2016/12/22 18:41:37
nit: a missing period.
Raymond Toy
2016/12/22 19:21:34
Done.
| |
183 ParamEvent(Type, float value, double time); | |
184 | |
185 // Create a linear or exponential ramp that requires an initial value and | |
186 // time in case | |
hongchan
2016/12/22 18:41:37
nit: the line breaks at the wrong position?
Raymond Toy
2016/12/22 19:21:34
Done.
| |
187 // there is no actual event that preceeds this event. | |
188 ParamEvent(Type, | |
189 float value, | |
190 double time, | |
191 float initialValue, | |
192 double callTime); | |
193 | |
194 // Create an event needing a time constant (setTargetAtTime) | |
195 ParamEvent(Type, float value, double time, double timeConstant); | |
196 | |
197 // Create a setValueCurve event | |
198 ParamEvent(Type, | |
199 double time, | |
200 double duration, | |
145 const DOMFloat32Array* curve, | 201 const DOMFloat32Array* curve, |
146 float initialValue = 0, | 202 double curvePointsPerSecond, |
147 double callTime = 0); | 203 float curveEndValue); |
204 | |
205 // Create CancelValues event | |
206 ParamEvent(Type, double time, std::unique_ptr<ParamEvent> savedEvent); | |
148 | 207 |
149 Type m_type; | 208 Type m_type; |
209 | |
210 // The value for the event. The interpretation of this depends on | |
211 // the event type. Not used for SetValueCurve. For CancelValues, | |
212 // it is the end value to use when cancelling a LinearRampToValue | |
213 // or ExponentialRampToValue event. | |
150 float m_value; | 214 float m_value; |
215 | |
216 // The time for the event. The interpretation of this depends on | |
217 // the event type. | |
151 double m_time; | 218 double m_time; |
152 // Only used for SetTarget events | 219 |
153 double m_timeConstant; | |
154 // Only used for SetValueCurve events. | |
155 double m_duration; | |
156 Vector<float> m_curve; | |
157 // Initial value and time to use for linear and exponential ramps that don't | 220 // Initial value and time to use for linear and exponential ramps that don't |
158 // have a preceding event. | 221 // have a preceding event. |
159 float m_initialValue; | 222 float m_initialValue; |
160 double m_callTime; | 223 double m_callTime; |
224 | |
225 // Only used for SetTarget events | |
226 double m_timeConstant; | |
227 | |
228 // The following items are only used for SetValueCurve events | |
hongchan
2016/12/22 18:41:37
nit: perhaps a colon at the end?
| |
229 // | |
230 // m_duration is the duration of the curve. | |
231 // m_curve is the array of curve poitns. | |
232 // m_curvePointsPerSecond is the number of curve points per second. it | |
233 // is used to compute the curve index step when running the | |
234 // automation. | |
235 // m_curveEndValue is the default value to use at the end of the | |
236 // curve. Normally it's the last entry in m_curve, but cancelling a | |
237 // SetValueCurve will set this to a new value. // Only used for | |
238 // SetValueCurve events. | |
hongchan
2016/12/22 18:41:37
These comments should be located just above each v
Raymond Toy
2016/12/22 19:21:34
Done.
| |
239 double m_duration; | |
240 Vector<float> m_curve; | |
241 double m_curvePointsPerSecond; | |
242 float m_curveEndValue; | |
243 | |
244 // For CancelValues. If CancelValues is in the middle of an event, this | |
245 // holds the event that is being cancelled, so that processing can | |
246 // continue as if the event still existed up until we reach the actual | |
247 // scheduled cancel time. | |
248 std::unique_ptr<ParamEvent> m_savedEvent; | |
249 | |
161 // True if the start time needs to be checked against current time | 250 // True if the start time needs to be checked against current time |
162 // to implement clamping. | 251 // to implement clamping. |
163 bool m_needsTimeClampCheck; | 252 bool m_needsTimeClampCheck; |
253 | |
254 // True if a default value has been assigned to the CancelValues event. | |
255 bool m_hasDefaultCancelledValue; | |
164 }; | 256 }; |
165 | 257 |
166 void insertEvent(const ParamEvent&, ExceptionState&); | 258 void insertEvent(std::unique_ptr<ParamEvent>, ExceptionState&); |
167 float valuesForFrameRangeImpl(size_t startFrame, | 259 float valuesForFrameRangeImpl(size_t startFrame, |
168 size_t endFrame, | 260 size_t endFrame, |
169 float defaultValue, | 261 float defaultValue, |
170 float* values, | 262 float* values, |
171 unsigned numberOfValues, | 263 unsigned numberOfValues, |
172 double sampleRate, | 264 double sampleRate, |
173 double controlRate); | 265 double controlRate); |
174 | 266 |
175 // Produce a nice string describing the event in human-readable form. | 267 // Produce a nice string describing the event in human-readable form. |
176 String eventToString(const ParamEvent&); | 268 String eventToString(const ParamEvent&); |
177 Vector<ParamEvent> m_events; | 269 |
270 // Automation functions that compute the vlaue of the specified | |
271 // automation at the specified time. | |
272 float linearRampAtTime(double t, | |
273 float value1, | |
274 double time1, | |
275 float value2, | |
276 double time2); | |
277 float exponentialRampAtTime(double t, | |
278 float value1, | |
279 double time1, | |
280 float value2, | |
281 double time2); | |
282 float targetValueAtTime(double t, | |
283 float value1, | |
284 double time1, | |
285 float value2, | |
286 float timeConstant); | |
287 float valueCurveAtTime(double t, | |
288 double time1, | |
289 double duration, | |
290 const float* curveData, | |
291 unsigned curveLength); | |
292 | |
293 // Vector of all automation events for the AudioParam. Access must | |
294 // be locked via m_eventsLock. | |
295 Vector<std::unique_ptr<ParamEvent>> m_events; | |
178 | 296 |
179 mutable Mutex m_eventsLock; | 297 mutable Mutex m_eventsLock; |
180 | 298 |
181 // Smoothing (de-zippering) | 299 // Smoothing (de-zippering) |
182 float m_smoothedValue; | 300 float m_smoothedValue; |
183 }; | 301 }; |
184 | 302 |
185 } // namespace blink | 303 } // namespace blink |
186 | 304 |
187 #endif // AudioParamTimeline_h | 305 #endif // AudioParamTimeline_h |
OLD | NEW |