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

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

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

Powered by Google App Engine
This is Rietveld 408576698