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

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

Issue 2426893003: Allow timeConstant=0 for setTargetAtTime (Closed)
Patch Set: Created 4 years, 2 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 float initialValue, 157 float initialValue,
158 double callTime) { 158 double callTime) {
159 return ParamEvent(ParamEvent::ExponentialRampToValue, value, time, 0, 0, 159 return ParamEvent(ParamEvent::ExponentialRampToValue, value, time, 0, 0,
160 nullptr, initialValue, callTime); 160 nullptr, initialValue, callTime);
161 } 161 }
162 162
163 AudioParamTimeline::ParamEvent 163 AudioParamTimeline::ParamEvent
164 AudioParamTimeline::ParamEvent::createSetTargetEvent(float value, 164 AudioParamTimeline::ParamEvent::createSetTargetEvent(float value,
165 double time, 165 double time,
166 double timeConstant) { 166 double timeConstant) {
167 // The time line code does not expect a timeConstant of 0. (IT
hongchan 2016/10/31 20:50:43 typo: "(IT" -> "It"
168 // returns NaN or Infinity due to division by zero. The caller
169 // should have converted this to a SetValueEvent.
170 DCHECK_NE(timeConstant, 0);
167 return ParamEvent(ParamEvent::SetTarget, value, time, timeConstant, 0, 171 return ParamEvent(ParamEvent::SetTarget, value, time, timeConstant, 0,
168 nullptr); 172 nullptr);
169 } 173 }
170 174
171 AudioParamTimeline::ParamEvent 175 AudioParamTimeline::ParamEvent
172 AudioParamTimeline::ParamEvent::createSetValueCurveEvent( 176 AudioParamTimeline::ParamEvent::createSetValueCurveEvent(
173 const DOMFloat32Array* curve, 177 const DOMFloat32Array* curve,
174 double time, 178 double time,
175 double duration) { 179 double duration) {
176 return ParamEvent(ParamEvent::SetValueCurve, 0, time, 0, duration, curve); 180 return ParamEvent(ParamEvent::SetValueCurve, 0, time, 0, duration, curve);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 exceptionState); 233 exceptionState);
230 } 234 }
231 235
232 void AudioParamTimeline::setTargetAtTime(float target, 236 void AudioParamTimeline::setTargetAtTime(float target,
233 double time, 237 double time,
234 double timeConstant, 238 double timeConstant,
235 ExceptionState& exceptionState) { 239 ExceptionState& exceptionState) {
236 DCHECK(isMainThread()); 240 DCHECK(isMainThread());
237 241
238 if (!isNonNegativeAudioParamTime(time, exceptionState) || 242 if (!isNonNegativeAudioParamTime(time, exceptionState) ||
239 !isPositiveAudioParamTime(timeConstant, exceptionState, "Time constant")) 243 !isNonNegativeAudioParamTime(timeConstant, exceptionState,
244 "Time constant"))
240 return; 245 return;
241 246
242 insertEvent(ParamEvent::createSetTargetEvent(target, time, timeConstant), 247 // If timeConstant = 0, we instantly jump to the target value, so
243 exceptionState); 248 // insert a SetValueEvent instead of SetTargetEvent.
249 if (timeConstant == 0) {
250 insertEvent(ParamEvent::createSetValueEvent(target, time), exceptionState);
251 } else {
252 insertEvent(ParamEvent::createSetTargetEvent(target, time, timeConstant),
253 exceptionState);
254 }
244 } 255 }
245 256
246 void AudioParamTimeline::setValueCurveAtTime(DOMFloat32Array* curve, 257 void AudioParamTimeline::setValueCurveAtTime(DOMFloat32Array* curve,
247 double time, 258 double time,
248 double duration, 259 double duration,
249 ExceptionState& exceptionState) { 260 ExceptionState& exceptionState) {
250 DCHECK(isMainThread()); 261 DCHECK(isMainThread());
251 DCHECK(curve); 262 DCHECK(curve);
252 263
253 if (!isNonNegativeAudioParamTime(time, exceptionState) || 264 if (!isNonNegativeAudioParamTime(time, exceptionState) ||
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 // propagate the last value to the end of the values buffer. 1058 // propagate the last value to the end of the values buffer.
1048 for (; writeIndex < numberOfValues; ++writeIndex) 1059 for (; writeIndex < numberOfValues; ++writeIndex)
1049 values[writeIndex] = value; 1060 values[writeIndex] = value;
1050 1061
1051 // This value is used to set the .value attribute of the AudioParam. it 1062 // This value is used to set the .value attribute of the AudioParam. it
1052 // should be the last computed value. 1063 // should be the last computed value.
1053 return values[numberOfValues - 1]; 1064 return values[numberOfValues - 1];
1054 } 1065 }
1055 1066
1056 } // namespace blink 1067 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698