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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-initial-event.html

Issue 2780433005: Convert AudioParam tests to new Audit (Closed)
Patch Set: Address review comments Created 3 years, 8 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 <!doctype html> 1 <!doctype html>
2 <html> 2 <html>
3 3
4 <head> 4 <head>
5 <script src="../../resources/testharness.js"></script> 5 <script src="../../resources/testharness.js"></script>
6 <script src="../../resources/testharnessreport.js"></script> 6 <script src="../../resources/testharnessreport.js"></script>
7 <script src="../resources/audit-util.js"></script> 7 <script src="../resources/audit-util.js"></script>
8 <script src="../resources/audio-testing.js"></script> 8 <script src="../resources/audit.js"></script>
9 <script src="../resources/audioparam-testing.js"></script> 9 <script src="../resources/audioparam-testing.js"></script>
10 <title>AudioParam Initial Events </title> 10 <title>AudioParam Initial Events </title>
11 </head> 11 </head>
12 12
13 <body> 13 <body>
14 <script> 14 <script>
15 15
16 var sampleRate = 48000; 16 var sampleRate = 48000;
17 // Number of frames in a rendering quantum. 17 // Number of frames in a rendering quantum.
18 var quantumFrames = 128; 18 var quantumFrames = 128;
19 // Test doesn't need to run for very long. 19 // Test doesn't need to run for very long.
20 var renderDuration = 0.2; 20 var renderDuration = 0.2;
21 var renderFrames = renderDuration * sampleRate; 21 var renderFrames = renderDuration * sampleRate;
22 var automationEndTime = 0.1; 22 var automationEndTime = 0.1;
23 23
24 var audit = Audit.createTaskRunner(); 24 var audit = Audit.createTaskRunner();
25 25
26 // The following tests start a ramp automation without an initial event. Th is should cause an 26 // The following tests start a ramp automation without an initial event. Th is should cause an
27 // initial event to be added implicitly to give a starting point. 27 // initial event to be added implicitly to give a starting point.
28 audit.defineTask("linear-ramp", function (done) { 28 audit.define("linear-ramp", (task, should) => {
29 runTest("Linear ramp", { 29 runTest("Linear ramp", should, {
30 automationFunction: function (node, value, time) { 30 automationFunction: function (node, value, time) {
31 node.gain.linearRampToValueAtTime(value, time); 31 node.gain.linearRampToValueAtTime(value, time);
32 }, 32 },
33 referenceFunction: linearRamp, 33 referenceFunction: linearRamp,
34 // Experimentally determined threshold 34 // Experimentally determined threshold
35 threshold: 6.0003e-8, 35 threshold: { absoluteThreshold: 6.0003e-8 },
36 // The starting value of the gain node 36 // The starting value of the gain node
37 v0: 0.5, 37 v0: 0.5,
38 // The target value of the automation 38 // The target value of the automation
39 v1: 0, 39 v1: 0,
40 }) 40 })
41 .then(done); 41 .then(() => task.done());
42 }); 42 });
43 43
44 audit.defineTask("exponential-ramp", function (done) { 44 audit.define("exponential-ramp", (task, should) => {
45 runTest("Exponential ramp", { 45 runTest("Exponential ramp", should, {
46 automationFunction: function (node, value, time) { 46 automationFunction: function (node, value, time) {
47 node.gain.exponentialRampToValueAtTime(value, time); 47 node.gain.exponentialRampToValueAtTime(value, time);
48 }, 48 },
49 referenceFunction: exponentialRamp, 49 referenceFunction: exponentialRamp,
50 threshold: 2.3842e-6, 50 threshold: { absoluteThreshold: 2.3842e-6 },
51 v0: 0.5, 51 v0: 0.5,
52 v1: 2, 52 v1: 2,
53 }) 53 })
54 .then(done); 54 .then(() => task.done());
55 }); 55 });
56 56
57 // Same tests as above, but we delay the call to the automation function. Th is is to verify that 57 // Same tests as above, but we delay the call to the automation function. Th is is to verify that
58 // the we still do the right thing after the context has started. 58 // the we still do the right thing after the context has started.
59 audit.defineTask("delayed-linear-ramp", function (done) { 59 audit.define("delayed-linear-ramp", (task, should) => {
60 runTest("Delayed linear ramp", { 60 runTest("Delayed linear ramp", should, {
61 automationFunction: function (node, value, time) { 61 automationFunction: function (node, value, time) {
62 node.gain.linearRampToValueAtTime(value, time); 62 node.gain.linearRampToValueAtTime(value, time);
63 }, 63 },
64 referenceFunction: linearRamp, 64 referenceFunction: linearRamp,
65 // Experimentally determined threshold 65 // Experimentally determined threshold
66 threshold: 9.87968e-8, 66 threshold: { absoluteThreshold: 9.87968e-8 },
67 // The starting value of the gain node 67 // The starting value of the gain node
68 v0: 0.5, 68 v0: 0.5,
69 // The target value of the automation 69 // The target value of the automation
70 v1: 0, 70 v1: 0,
71 delay: quantumFrames / sampleRate 71 delay: quantumFrames / sampleRate
72 }) 72 })
73 .then(done); 73 .then(() => task.done());
74 }); 74 });
75 75
76 audit.defineTask("delayed-exponential-ramp", function (done) { 76 audit.define("delayed-exponential-ramp", (task, should) => {
77 runTest("Delayed exponential ramp", { 77 runTest("Delayed exponential ramp", should, {
78 automationFunction: function (node, value, time) { 78 automationFunction: function (node, value, time) {
79 node.gain.exponentialRampToValueAtTime(value, time); 79 node.gain.exponentialRampToValueAtTime(value, time);
80 }, 80 },
81 referenceFunction: exponentialRamp, 81 referenceFunction: exponentialRamp,
82 // Experimentally determined threshold 82 // Experimentally determined threshold
83 threshold: 1.3948e-5, 83 threshold: { absoluteThreshold: 1.3948e-5 },
84 // The starting value of the gain node 84 // The starting value of the gain node
85 v0: 0.5, 85 v0: 0.5,
86 // The target value of the automation 86 // The target value of the automation
87 v1: 2, 87 v1: 2,
88 delay: quantumFrames / sampleRate 88 delay: quantumFrames / sampleRate
89 }) 89 })
90 .then(done); 90 .then(() => task.done());
91 }); 91 });
92 92
93 audit.defineTask("finish", function (done) { 93 audit.run();
94 done();
95 });
96
97 audit.runTasks();
98 94
99 // Generate the expected waveform for a linear ramp starting from the value |v0|, ramping to 95 // Generate the expected waveform for a linear ramp starting from the value |v0|, ramping to
100 // |v1| at time |endTime|. The time of |v0| is assumed to be 0. |nFrames| is how many frames 96 // |v1| at time |endTime|. The time of |v0| is assumed to be 0. |nFrames| is how many frames
101 // to generate. 97 // to generate.
102 function linearRamp(v0, v1, startTime, endTime, nFrames) { 98 function linearRamp(v0, v1, startTime, endTime, nFrames) {
103 var expected = createLinearRampArray(startTime, endTime, v0, v1, sampleRat e); 99 var expected = createLinearRampArray(startTime, endTime, v0, v1, sampleRat e);
104 var preFiller = new Array(Math.floor(startTime * sampleRate)); 100 var preFiller = new Array(Math.floor(startTime * sampleRate));
105 var postFiller = new Array(nFrames - Math.ceil(endTime * sampleRate)); 101 var postFiller = new Array(nFrames - Math.ceil(endTime * sampleRate));
106 preFiller.fill(v0); 102 preFiller.fill(v0);
107 return preFiller.concat(expected.concat(postFiller.fill(v1))); 103 return preFiller.concat(expected.concat(postFiller.fill(v1)));
(...skipping 11 matching lines...) Expand all
119 } 115 }
120 116
121 // Run an automation test. |message| is the message to use for printing the results. |options| 117 // Run an automation test. |message| is the message to use for printing the results. |options|
122 // is a property bag containing the configuration of the test including the following: 118 // is a property bag containing the configuration of the test including the following:
123 // 119 //
124 // automationFunction - automation function to use, 120 // automationFunction - automation function to use,
125 // referenceFunction - function generating the expected result 121 // referenceFunction - function generating the expected result
126 // threshold - comparison threshold 122 // threshold - comparison threshold
127 // v0 - starting value 123 // v0 - starting value
128 // v1 - end value for automation 124 // v1 - end value for automation
129 function runTest(message, options) { 125 function runTest(message, should, options) {
130 var automationFunction = options.automationFunction; 126 var automationFunction = options.automationFunction;
131 var referenceFunction = options.referenceFunction; 127 var referenceFunction = options.referenceFunction;
132 var threshold = options.threshold; 128 var threshold = options.threshold;
133 var v0 = options.v0; 129 var v0 = options.v0;
134 var v1 = options.v1; 130 var v1 = options.v1;
135 var delay = options.delay; 131 var delay = options.delay;
136 132
137 var context = new OfflineAudioContext(1, renderFrames, sampleRate); 133 var context = new OfflineAudioContext(1, renderFrames, sampleRate);
138 134
139 // A constant source of amplitude 1. 135 // A constant source of amplitude 1.
(...skipping 17 matching lines...) Expand all
157 153
158 source.connect(gain); 154 source.connect(gain);
159 gain.connect(context.destination); 155 gain.connect(context.destination);
160 156
161 source.start(); 157 source.start();
162 158
163 return context.startRendering() 159 return context.startRendering()
164 .then(function (resultBuffer) { 160 .then(function (resultBuffer) {
165 var result = resultBuffer.getChannelData(0); 161 var result = resultBuffer.getChannelData(0);
166 var expected = referenceFunction(v0, v1, delay ? delay : 0, automation EndTime, renderFrames); 162 var expected = referenceFunction(v0, v1, delay ? delay : 0, automation EndTime, renderFrames);
167 Should(message, result).beCloseToArray(expected, threshold); 163 should(result, message).beCloseToArray(expected, threshold);
168 }); 164 });
169 } 165 }
170 </script> 166 </script>
171 </body> 167 </body>
172 168
173 </html> 169 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698