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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-setTargetAtTime-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 for SetTargetAtTime
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 for SetTargetAtTime</title>
10 </head> 12 </head>
13 <body>
14 <script id="layout-test-code">
15 // Some slow sample rate, but otherwise arbitrary.
16 let sampleRate = 12800;
11 17
12 <body> 18 // Time constant for setTargetValue. Make it short, but is otherwise
13 <script> 19 // arbitrary.
14 20 let timeConstant = 10 / sampleRate;
15 // Some slow sample rate, but otherwise arbitrary.
16 var sampleRate = 12800;
17 21
18 // Time constant for setTargetValue. Make it short, but is otherwise arbit rary. 22 // Defaut initial gain for test. Arbitrary, but we want it large so the
19 var timeConstant = 10 / sampleRate; 23 // changes look large, even if the relative change isn't.
24 let initialGain = 10000;
20 25
21 // Defaut initial gain for test. Arbitrary, but we want it large so the c hanges look large, 26 let audit = Audit.createTaskRunner();
22 // even if the relative change isn't.
23 var initialGain = 10000;
24 27
25 var audit = Audit.createTaskRunner(); 28 // Test sampling of setTargetAtTime that starts at |startFrame|. A gain
26 29 // node is used for testing. |initializeGainFunction| initializes the
27 // Test sampling of setTargetAtTime that starts at |startFrame|. A gain n ode is used for 30 // gain value.
28 // testing. |initializeGainFunction| initializes the gain value. 31 function doTest(
29 function doTest(should, message, startFrame, threshold, initializeGainFunc tion) { 32 should, message, startFrame, threshold, initializeGainFunction) {
30 var context = new OfflineAudioContext(1, 256, sampleRate); 33 let context = new OfflineAudioContext(1, 256, sampleRate);
31 var source = context.createBufferSource(); 34 let source = context.createBufferSource();
32 var b = context.createBuffer(1, 1, sampleRate); 35 let b = context.createBuffer(1, 1, sampleRate);
33 b.getChannelData(0)[0] = 1; 36 b.getChannelData(0)[0] = 1;
34 source.buffer = b; 37 source.buffer = b;
35 source.loop = true; 38 source.loop = true;
36 39
37 var gain = context.createGain(); 40 let gain = context.createGain();
38 // Initialize the value of the gain node appropriately. 41 // Initialize the value of the gain node appropriately.
39 initializeGainFunction(gain); 42 initializeGainFunction(gain);
40 gain.gain.setTargetAtTime(0, startFrame / sampleRate, timeConstant); 43 gain.gain.setTargetAtTime(0, startFrame / sampleRate, timeConstant);
41 44
42 source.connect(gain); 45 source.connect(gain);
43 gain.connect(context.destination); 46 gain.connect(context.destination);
44 47
45 source.start(); 48 source.start();
46 49
47 return context.startRendering().then(function (resultBuffer) { 50 return context.startRendering().then(function(resultBuffer) {
48 // Verify that the sampling of the setTargetAtTime automation was done correctly. We just 51 // Verify that the sampling of the setTargetAtTime automation was done
49 // look at the sample just past the start of the automation. 52 // correctly. We just look at the sample just past the start of the
50 var resultData = resultBuffer.getChannelData(0); 53 // automation.
51 // Compute the true result at the frame just past startFrame and verif y that the actual 54 let resultData = resultBuffer.getChannelData(0);
52 // rendered result is within |threshold| of the expected value. 55 // Compute the true result at the frame just past startFrame and
53 var frame = Math.ceil(startFrame); 56 // verify that the actual rendered result is within |threshold| of the
54 var v = 10000 * Math.exp(-(frame / sampleRate - startFrame / sampleRat e) / timeConstant); 57 // expected value.
55 should(resultData[frame], message + ": Target value at frame " + 58 let frame = Math.ceil(startFrame);
56 frame).beCloseTo(v, { 59 let v = 10000 *
57 threshold: threshold 60 Math.exp(
58 }); 61 -(frame / sampleRate - startFrame / sampleRate) /
62 timeConstant);
63 should(
64 resultData[frame], message + ': Target value at frame ' + frame)
65 .beCloseTo(v, {threshold: threshold});
59 }); 66 });
60 } 67 }
61 68
62 function initializeGainBySetter (g) { 69 function initializeGainBySetter(g) {
63 g.gain.value = initialGain; 70 g.gain.value = initialGain;
64 } 71 }
65 72
66 function initializeGainBySetValue (g) { 73 function initializeGainBySetValue(g) {
67 g.gain.setValueAtTime(initialGain, 0); 74 g.gain.setValueAtTime(initialGain, 0);
68 } 75 }
69 76
70 audit.define("setValue;128.1", (task, should) => { 77 audit.define('setValue;128.1', (task, should) => {
71 doTest(should, "Initialize by setValueAtTime", 128.1, 3.6029e-8, 78 doTest(
79 should, 'Initialize by setValueAtTime', 128.1, 3.6029e-8,
72 initializeGainBySetValue) 80 initializeGainBySetValue)
73 .then(() => task.done()); 81 .then(() => task.done());
74 }); 82 });
75 83
76 audit.define("setValue;0.1", (task, should) => { 84 audit.define('setValue;0.1', (task, should) => {
77 doTest(should, "Initialize by setValueAtTime", 0.1, 3.6029e-8, 85 doTest(
86 should, 'Initialize by setValueAtTime', 0.1, 3.6029e-8,
78 initializeGainBySetValue) 87 initializeGainBySetValue)
79 .then(() => task.done()); 88 .then(() => task.done());
80 }); 89 });
81 90
82 audit.define("setValue;0.0", (task, should) => { 91 audit.define('setValue;0.0', (task, should) => {
83 doTest(should, "Initialize by setValueAtTime", 0, 3.6029e-8, 92 doTest(
93 should, 'Initialize by setValueAtTime', 0, 3.6029e-8,
84 initializeGainBySetValue) 94 initializeGainBySetValue)
85 .then(() => task.done()); 95 .then(() => task.done());
86 }); 96 });
87 97
88 audit.define("setter;128.1", (task, should) => { 98 audit.define('setter;128.1', (task, should) => {
89 doTest(should, "Initialize by setter", 128.1, 3.6029e-8, 99 doTest(
100 should, 'Initialize by setter', 128.1, 3.6029e-8,
90 initializeGainBySetter) 101 initializeGainBySetter)
91 .then(() => task.done()); 102 .then(() => task.done());
92 }); 103 });
93 104
94 audit.define("setter;0.1", (task, should) => { 105 audit.define('setter;0.1', (task, should) => {
95 doTest(should, "Initialize by setter", 0.1, 3.6029e-8, 106 doTest(
107 should, 'Initialize by setter', 0.1, 3.6029e-8,
96 initializeGainBySetter) 108 initializeGainBySetter)
97 .then(() => task.done()); 109 .then(() => task.done());
98 }); 110 });
99 111
100 audit.define("setter;0.0", (task, should) => { 112 audit.define('setter;0.0', (task, should) => {
101 doTest(should, "Initialize by setter", 0, 0, initializeGainBySetter) 113 doTest(should, 'Initialize by setter', 0, 0, initializeGainBySetter)
102 .then(() => task.done()); 114 .then(() => task.done());
103 }); 115 });
104 116
105 audit.run(); 117 audit.run();
106 </script> 118 </script>
107 </body> 119 </body>
108 </html> 120 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698