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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/audio-param.js

Issue 1695573002: Update the AudioParam value attribute correctly from timelines. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and reduce printed precision some more Created 4 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
(Empty)
1 // Define functions that implement the formulas for AudioParam automations.
2
3 // AudioParam linearRamp value at time t for a linear ramp between (t0, v0) and (t1, v1). It is
4 // assumed that t0 <= t. Results are undefined otherwise.
5 function audioParamLinearRamp(t, v0, t0, v1, t1)
6 {
7 if (t >= t1)
8 return v1;
9 return (v0 + (v1 - v0) * (t - t0) / (t1 - t0))
10 }
11
12 // AudioParam exponentialRamp value at time t for an exponential ramp between (t 0, v0) and (t1, v1).
13 // It is assumed that t0 <= t. Results are undefined otherwise.
14 function audioParamExponentialRamp(t, v0, t0, v1, t1)
15 {
16 if (t >= t1)
17 return v1;
18 return v0 * Math.pow(v1 / v0, (t - t0) / (t1 - t0));
19 }
20
21 // AudioParam setTarget value at time t for a setTarget curve starting at (t0, v 0) with a final
22 // value of vFainal and a time constant of timeConstant. It is assumed that t0 <= t. Results are
23 // undefined otherwise.
24 function audioParamSetTarget(t, v0, t0, vFinal, timeConstant)
25 {
26 return vFinal + (v0 - vFinal) * Math.exp(-(t - t0) / timeConstant);
27 }
28
29 // AudioParam setValueCurve value at time t for a setValueCurve starting at time t0 with curve,
30 // curve, and duration duration. The sample rate is sampleRate. It is assumed that t0 <= t.
31 function audioParamSetValueCurve(t, curve, t0, duration)
32 {
33 if (t > t0 + duration)
34 return curve[curve.length - 1];
35
36 var curvePointsPerSecond = (curve.length - 1) / duration;
37
38 var virtualIndex = (t - t0) * curvePointsPerSecond;
39 var index = Math.floor(virtualIndex);
40
41 var delta = virtualIndex - index;
42
43 var c0 = curve[index];
44 var c1 = curve[Math.min(index + 1, curve.length - 1)];
45 return c0 + (c1 - c0) * delta;
46 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698