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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-setValueCurve-end.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>Test Automation Following setValueCurveAtTime Automations</title> 4 <title>
5 Test Automation Following setValueCurveAtTime Automations
6 </title>
5 <script src="../../resources/testharness.js"></script> 7 <script src="../../resources/testharness.js"></script>
6 <script src="../../resources/testharnessreport.js"></script> 8 <script src="../../resources/testharnessreport.js"></script>
7 <script src="../resources/audit-util.js"></script> 9 <script src="../resources/audit-util.js"></script>
8 <script src="../resources/audit.js"></script> 10 <script src="../resources/audit.js"></script>
9 <script src="../resources/audio-param.js"></script> 11 <script src="../resources/audio-param.js"></script>
10 </head> 12 </head>
13 <body>
14 <script id="layout-test-code">
15 let sampleRate = 12800;
16 // Some short duration because we don't need to run the test for very
17 // long.
18 let testDurationFrames = 256;
19 let testDurationSec = testDurationFrames / sampleRate;
20 let curveDuration = testDurationSec / 2;
11 21
12 <body> 22 let audit = Audit.createTaskRunner();
13 <script>
14
15 var sampleRate = 12800;
16 // Some short duration because we don't need to run the test for very long .
17 var testDurationFrames = 256;
18 var testDurationSec = testDurationFrames / sampleRate;
19 var curveDuration = testDurationSec / 2;
20
21 var audit = Audit.createTaskRunner();
22 23
23 // Configuration for each test. 24 // Configuration for each test.
24 // 25 //
25 // Required options: 26 // Required options:
26 // automation - Name of automation method to test 27 // automation - Name of automation method to test
27 // time - Time for the automation method. 28 // time - Time for the automation method.
28 // Optional options: 29 // Optional options:
29 // extraDuration - extra time for the duration of the setValueCurve 30 // extraDuration - extra time for the duration of the setValueCurve
30 // duration. Default is 0. This should not be on a 31 // duration. Default is 0. This should not be on a
31 // sample frame boundary. This is for testing that 32 // sample frame boundary. This is for testing that
32 // curves that don't end on a frame boundary are handled 33 // curves that don't end on a frame boundary are handled
33 // correctly. 34 // correctly.
34 // threshold - Error threshold for the test; default is 0. 35 // threshold - Error threshold for the test; default is 0.
35 var testConfigs = [{ 36 let testConfigs = [
36 automation: "linearRampToValueAtTime", 37 {
37 time: testDurationSec, 38 automation: 'linearRampToValueAtTime',
38 threshold: 3.9737e-8 39 time: testDurationSec,
39 }, { 40 threshold: 3.9737e-8
40 automation: "linearRampToValueAtTime", 41 },
41 time: testDurationSec, 42 {
42 extraDuration: 0.5 / sampleRate, 43 automation: 'linearRampToValueAtTime',
43 threshold: 1.8141e-8 44 time: testDurationSec,
44 }, { 45 extraDuration: 0.5 / sampleRate,
45 automation: "exponentialRampToValueAtTime", 46 threshold: 1.8141e-8
46 time: testDurationSec, 47 },
47 threshold: 3.9737e-8 48 {
48 }, { 49 automation: 'exponentialRampToValueAtTime',
49 automation: "exponentialRampToValueAtTime", 50 time: testDurationSec,
50 time: testDurationSec, 51 threshold: 3.9737e-8
51 extraDuration: 0.5 / sampleRate, 52 },
52 threshold: 2.0312e-8 53 {
53 }, { 54 automation: 'exponentialRampToValueAtTime',
54 automation: "setTargetAtTime", 55 time: testDurationSec,
55 time: curveDuration, 56 extraDuration: 0.5 / sampleRate,
56 threshold: 1.5895e-7 57 threshold: 2.0312e-8
57 }, { 58 },
58 automation: "setTargetAtTime", 59 {
59 time: curveDuration + 0.5 / sampleRate, 60 automation: 'setTargetAtTime',
60 extraDuration: 0.5 / sampleRate, 61 time: curveDuration,
61 threshold: 1.3278e-7 62 threshold: 1.5895e-7
62 }]; 63 },
64 {
65 automation: 'setTargetAtTime',
66 time: curveDuration + 0.5 / sampleRate,
67 extraDuration: 0.5 / sampleRate,
68 threshold: 1.3278e-7
69 }
70 ];
63 71
64 // Define tests from the configs 72 // Define tests from the configs
65 for (k in testConfigs) { 73 for (k in testConfigs) {
66 audit.define(k + ": " + testConfigs[k].automation, (function (config) { 74 audit.define(k + ': ' + testConfigs[k].automation, (function(config) {
67 return (task, should) => { 75 return (task, should) => {
68 runTest(should, config).then(() => task.done()); 76 runTest(should, config).then(() => task.done());
69 }; 77 };
70 })(testConfigs[k])); 78 })(testConfigs[k]));
71 } 79 }
72 80
73 audit.run(); 81 audit.run();
74 82
75 function runTest(should, options) { 83 function runTest(should, options) {
76 // For the test, use a gain node with a constant input to test the 84 // For the test, use a gain node with a constant input to test the
77 // automations. 85 // automations.
78 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ; 86 let context =
79 var source = context.createBufferSource(); 87 new OfflineAudioContext(1, testDurationFrames, sampleRate);
88 let source = context.createBufferSource();
80 source.buffer = createConstantBuffer(context, 1, 1); 89 source.buffer = createConstantBuffer(context, 1, 1);
81 source.loop = true; 90 source.loop = true;
82 91
83 var gain = context.createGain(); 92 let gain = context.createGain();
84 93
85 // Any valid curve is ok. We only use the last value for testing. 94 // Any valid curve is ok. We only use the last value for testing.
86 var curve = [0, 2, 0.3]; 95 let curve = [0, 2, 0.3];
87 var actualDuration = curveDuration + (options.extraDuration || 0); 96 let actualDuration = curveDuration + (options.extraDuration || 0);
88 gain.gain.setValueCurveAtTime(Float32Array.from(curve), 0, actualDuratio n); 97 gain.gain.setValueCurveAtTime(
98 Float32Array.from(curve), 0, actualDuration);
89 99
90 // Run the desired test automation. The extra parameter (0.01) is only 100 // Run the desired test automation. The extra parameter (0.01) is only
91 // used for setTargetAtTime tests; it's ignored for other tests. 101 // used for setTargetAtTime tests; it's ignored for other tests.
92 var automationValue = 2; 102 let automationValue = 2;
93 gain.gain[options.automation](automationValue, options.time, 0.01); 103 gain.gain[options.automation](automationValue, options.time, 0.01);
94 104
95 source.connect(gain); 105 source.connect(gain);
96 gain.connect(context.destination); 106 gain.connect(context.destination);
97 107
98 source.start(); 108 source.start();
99 109
100 return context.startRendering().then(function (resultBuffer) { 110 return context.startRendering().then(function(resultBuffer) {
101 var result = resultBuffer.getChannelData(0); 111 let result = resultBuffer.getChannelData(0);
102 112
103 // Only need to verify that the ramp started at the right 113 // Only need to verify that the ramp started at the right
104 // value. Figure the nearest sample frame to the end curve. 114 // value. Figure the nearest sample frame to the end curve.
105 var curveEndFrame = Math.ceil(actualDuration * sampleRate); 115 let curveEndFrame = Math.ceil(actualDuration * sampleRate);
106 116
107 var expectedResult = curve[curve.length - 1]; 117 let expectedResult = curve[curve.length - 1];
108 118
109 // Determine the expected value after the end of the setValueCurve eve nt. 119 // Determine the expected value after the end of the setValueCurve
110 if (options.automation == "linearRampToValueAtTime") { 120 // event.
121 if (options.automation == 'linearRampToValueAtTime') {
111 expectedResult = audioParamLinearRamp( 122 expectedResult = audioParamLinearRamp(
112 curveEndFrame / sampleRate, 123 curveEndFrame / sampleRate, curve[curve.length - 1],
113 curve[curve.length - 1], actualDuration, 124 actualDuration, automationValue, testDurationSec);
114 automationValue, testDurationSec); 125 } else if (options.automation == 'exponentialRampToValueAtTime') {
115 } else if (options.automation == "exponentialRampToValueAtTime") {
116 expectedResult = audioParamExponentialRamp( 126 expectedResult = audioParamExponentialRamp(
117 curveEndFrame / sampleRate, 127 curveEndFrame / sampleRate, curve[curve.length - 1],
118 curve[curve.length - 1], actualDuration, 128 actualDuration, automationValue, testDurationSec);
119 automationValue, testDurationSec); 129 } else if (options.automation == 'setTargetAtTime') {
120 } else if (options.automation == "setTargetAtTime") {
121 expectedResult = audioParamSetTarget( 130 expectedResult = audioParamSetTarget(
122 curveEndFrame / sampleRate, 131 curveEndFrame / sampleRate, curve[curve.length - 1],
123 curve[curve.length - 1], actualDuration, 132 actualDuration, automationValue, 0.01);
124 automationValue, 0.01);
125 } 133 }
126 134
127 var message = "setValueCurve(..., " + 0 + ", " + actualDuration + 135 let message = 'setValueCurve(..., ' + 0 + ', ' + actualDuration +
128 ")." + options.automation + 136 ').' + options.automation + '(2, ' + testDurationSec;
129 "(2, " + testDurationSec;
130 137
131 if (options.automation == "setTargetAtTime") 138 if (options.automation == 'setTargetAtTime')
132 message += ", 0.01"; 139 message += ', 0.01';
133 message += ")"; 140 message += ')';
134 141
135 should(result[curveEndFrame], 142 should(
136 message + ": value at time " + curveEndFrame / sampleRate) 143 result[curveEndFrame],
137 .beCloseTo(expectedResult, { 144 message + ': value at time ' + curveEndFrame / sampleRate)
138 threshold: options.threshold || 0 145 .beCloseTo(expectedResult, {threshold: options.threshold || 0});
139 });
140 }); 146 });
141 } 147 }
142 148
143 function linearRampValue(t, t0, v0, t1, v1) { 149 function linearRampValue(t, t0, v0, t1, v1) {
144 return v0 + (v1 - v0) * (t - t0) / (t1 - t0); 150 return v0 + (v1 - v0) * (t - t0) / (t1 - t0);
145 } 151 }
146 152
147 function exponentialRampValue(t, t0, v0, t1, v1) { 153 function exponentialRampValue(t, t0, v0, t1, v1) {
148 return v0 * Math.pow(v1 / v0, (t - t0) / (t1 - t0)); 154 return v0 * Math.pow(v1 / v0, (t - t0) / (t1 - t0));
149 } 155 }
150 156
151 function setTargetValue(t, t0, v0, v1, timeConstant) { 157 function setTargetValue(t, t0, v0, v1, timeConstant) {
152 return v1 + (v0 - v1) * Math.exp(-(t - t0) / timeConstant) 158 return v1 + (v0 - v1) * Math.exp(-(t - t0) / timeConstant)
153 } 159 }
154 </script> 160 </script>
155 </body> 161 </body>
156 </html> 162 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698