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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/audioparam-sampling.html

Issue 1377903002: Use frames instead of time for running AudioParam timelines. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <script src="resources/compatibility.js"></script>
5 <script src="resources/audio-testing.js"></script>
6 <script src="resources/audioparam-testing.js"></script>
7 <script src="../resources/js-test.js"></script>
8 <title>Test Sampling of LinearRampToValueAtTime</title>
9 </head>
10
11 <body>
12 <div id="description"></div>
13 <div id="console"></div>
14
15 <script>
16 description("Test Sampling of LinearRampToValueAtTime");
17
18 window.jsTestIsAsync = true;
19 var sampleRate = 12800;
20 var context;
21
22 var audit = Audit.createTaskRunner();
23
24 function runTest(config) {
25 // Create a short context with a constant signal source connected to a g ain node that will
26 // be automated.
27 context = new OfflineAudioContext(1, 256, sampleRate);
28
29 // Create a constant unit amplitude source.
30 var source = context.createBufferSource();
31 var b = createConstantBuffer(context, 1, 1);
32 source.buffer = b;
33 source.loop = true;
34
35 // Gain node that is to be automated.
36 var gain = context.createGain();
37 gain.gain.value = 0;
38 gain.gain.setValueAtTime(config.startValue, config.startTime);
39 config.automationFunction(gain);
40
41 source.connect(gain);
42 gain.connect(context.destination);
43
44 source.start();
45
46 return context.startRendering().then(function (resultBuffer) {
47 // Check that the automation has the correct sampling.
48 var resultData = resultBuffer.getChannelData(0);
49
50 // The automation has starts at config.startTime, so the frame just af ter this should have
51 // the automation applied.
52 var startFrame = Math.ceil(config.startTime * sampleRate);
53
54 // The automation ends at config.endTime so the frame just before this should have the
55 // automation applied.
56 var endFrame = Math.floor(config.endTime * sampleRate);
57
58 // Use the true automation to find the expected values.
59 var expectedStart = config.expectedFunction(startFrame / sampleRate);
60 var expectedEnd = config.expectedFunction(endFrame / sampleRate);
61
62 var success = Should(config.desc + ": Sample " + startFrame,
63 resultData[startFrame]).beCloseTo(expectedStart, config.startValueTh reshold, 7);
64 success = Should(config.desc + ": Sample " + endFrame,
65 resultData[endFrame]).beCloseTo(expectedEnd, config.endValueThreshol d, 7) && success;
66
67 if (success)
68 testPassed(config.desc + " passed.\n");
69 else
70 testFailed(config.desc + " failed.\n");
71 });
72 }
73
74 function expectedLinear(t) {
75 var slope = (this.endValue - this.startValue) / (this.endTime - this.sta rtTime);
76 return this.startValue + slope * (t - this.startTime);
77 };
78
79 function expectedExponential(t) {
80 var ratio = this.endValue / this.startValue;
81 var exponent = (t - this.startTime) / (this.endTime - this.startTime);
82 return this.startValue * Math.pow(ratio, exponent);
83 };
84
85 function linearAutomation(g) {
86 g.gain.linearRampToValueAtTime(this.endValue, this.endTime);
87 }
88
89 function exponentialAutomation(g) {
90 g.gain.exponentialRampToValueAtTime(this.endValue, this.endTime);
91 }
92
93 // Basically want to test that if neither the start time nor end time is o n a frame boundary
94 // that we sample the automation curve correctly. The start times and end times are mostly
95 // arbitrary, except that they cannot be on a frame boundary.
96 var testConfigs = [{
97 desc: "linearRamp",
98 startTime: .1 / sampleRate,
99 endTime: 128.1 / sampleRate,
100 startValue: 1,
101 endValue: 0,
102 startValueThreshold: 1.201e-8,
103 endValueThreshold: 1.526e-5,
104 automationFunction: linearAutomation,
105 expectedFunction: expectedLinear
106 }, {
107 desc: "linearRamp:short",
108 startTime: .1 / sampleRate,
109 endTime: 5.1 / sampleRate,
110 startValue: 1,
111 endValue: 0,
112 startValueThreshold: 8.723e-9,
113 endValueThreshold: 9.537e-7,
114 automationFunction: linearAutomation,
115 expectedFunction: expectedLinear
116 }, {
117 desc: "linearRamp:long",
118 startTime: .1 / sampleRate,
119 endTime: 200.1 / sampleRate,
120 startValue: 1,
121 endValue: 0,
122 startValueThreshold: 2.827e-8,
123 endValueThreshold: 4.674e-5,
124 automationFunction: linearAutomation,
125 expectedFunction: expectedLinear
126 }, {
127 desc: "exponentialRamp",
128 startTime: .1 / sampleRate,
129 endTime: 128.1 / sampleRate,
130 startValue: 1,
131 endValue: 1e-5,
132 startValueThreshold: 2.505e-8,
133 endValueThreshold: 1.484e-7,
134 automationFunction: exponentialAutomation,
135 expectedFunction: expectedExponential
136 }, {
137 desc: "exponentialRamp:short",
138 startTime: .1 / sampleRate,
139 endTime: 5.1 / sampleRate,
140 startValue: 1,
141 endValue: 1e-5,
142 startValueThreshold: 5.027e-8,
143 endValueThreshold: 3.821e-7,
144 automationFunction: exponentialAutomation,
145 expectedFunction: expectedExponential
146 }, {
147 desc: "exponentialRamp:long",
148 startTime: .1 / sampleRate,
149 endTime: 200.1 / sampleRate,
150 startValue: 1,
151 endValue: 1e-5,
152 startValueThreshold: 8.035e-9,
153 endValueThreshold: 1.337e-6,
154 automationFunction: exponentialAutomation,
155 expectedFunction: expectedExponential
156 },
157 ];
158
159 function createTaskFunction(config) {
160 return function (done) {
161 runTest(config).then(done);
162 };
163 }
164
165 // Create all of the tasks from the test configs
166 for (var k = 0; k < testConfigs.length; ++k) {
167 var config = testConfigs[k];
168 var taskName = config.desc + ":task" + k;
169 audit.defineTask(taskName, createTaskFunction(config));
170 }
171
172 audit.defineTask("finish", function (done) {
173 finishJSTest();
174 done();
175 }); audit.runTasks();
hongchan 2015/09/30 22:14:18 Add a line break here.
Raymond Toy 2015/10/01 18:05:55 Done.
176 successfullyParsed = true;
177 </script>
178 </body>
179 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698