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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/ScriptProcessor/scriptprocessor-offlineaudiocontext.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>ScriptProcessorNode on OfflineAudioContext</title> 4 <title>
5 <script src="../../resources/testharness.js"></script> 5 ScriptProcessorNode on OfflineAudioContext
6 <script src="../../resources/testharnessreport.js"></script> 6 </title>
7 <script src="../resources/audit-util.js"></script> 7 <script src="../../resources/testharness.js"></script>
8 <script src="../resources/audit.js"></script> 8 <script src="../../resources/testharnessreport.js"></script>
9 </head> 9 <script src="../resources/audit-util.js"></script>
10 <body> 10 <script src="../resources/audit.js"></script>
11 <script> 11 </head>
12 var audit = Audit.createTaskRunner(); 12 <body>
13 <script id="layout-test-code">
14 let audit = Audit.createTaskRunner();
13 15
14 16
15 // Fill the output of script processor with a constant value. 17 // Fill the output of script processor with a constant value.
16 audit.define('simple-output', (task, should) => { 18 audit.define('simple-output', (task, should) => {
17 var sampleRate = 44100; 19 let sampleRate = 44100;
18 var scriptBufferSize = 256; 20 let scriptBufferSize = 256;
19 var renderLength = 1; 21 let renderLength = 1;
20 var PI = Math.fround(Math.PI); 22 let PI = Math.fround(Math.PI);
21 23
22 var context = 24 let context =
23 new OfflineAudioContext(1, renderLength * sampleRate, sampleRate); 25 new OfflineAudioContext(1, renderLength * sampleRate, sampleRate);
24 26
25 var scriptNode = context.createScriptProcessor(scriptBufferSize, 1, 1); 27 let scriptNode = context.createScriptProcessor(scriptBufferSize, 1, 1);
26 scriptNode.onaudioprocess = function(event) { 28 scriptNode.onaudioprocess = function(event) {
27 var outputChannel = event.outputBuffer.getChannelData(0); 29 let outputChannel = event.outputBuffer.getChannelData(0);
28 outputChannel.fill(PI); 30 outputChannel.fill(PI);
29 }; 31 };
30 scriptNode.connect(context.destination); 32 scriptNode.connect(context.destination);
31 33
32 context.startRendering().then(function(buffer) { 34 context.startRendering().then(function(buffer) {
33 var channel = buffer.getChannelData(0); 35 let channel = buffer.getChannelData(0);
34 var initialDelay = channel.subarray(0, 2 * scriptBufferSize); 36 let initialDelay = channel.subarray(0, 2 * scriptBufferSize);
35 var actualContent = channel.subarray(2 * scriptBufferSize); 37 let actualContent = channel.subarray(2 * scriptBufferSize);
36 38
37 // There is the initial delay (2 x buffer size) which is silent. 39 // There is the initial delay (2 x buffer size) which is silent.
38 should(initialDelay, 'The initial delay contains zeros.') 40 should(initialDelay, 'The initial delay contains zeros.')
39 .beConstantValueOf(0); 41 .beConstantValueOf(0);
40 42
41 // After the initial delay, we must get |PI|. 43 // After the initial delay, we must get |PI|.
42 should(actualContent, 'The actual content contains ' + PI) 44 should(actualContent, 'The actual content contains ' + PI)
43 .beConstantValueOf(PI); 45 .beConstantValueOf(PI);
44 46
45 task.done(); 47 task.done();
46 }); 48 });
47 }); 49 });
48 50
49 51
50 // Pass through an oscillator via a script processor. Sum with the 52 // Pass through an oscillator via a script processor. Sum with the
51 // phase-inverted oscillator with the delayed start time. Verify the 53 // phase-inverted oscillator with the delayed start time. Verify the
52 // rendered buffer is completely silent. 54 // rendered buffer is completely silent.
53 audit.define('oscillator-output', (task, should) => { 55 audit.define('oscillator-output', (task, should) => {
54 var sampleRate = 44100; 56 let sampleRate = 44100;
55 var scriptBufferSize = 256; 57 let scriptBufferSize = 256;
56 var renderLength = 1; 58 let renderLength = 1;
57 59
58 var context = 60 let context =
59 new OfflineAudioContext(1, renderLength * sampleRate, sampleRate); 61 new OfflineAudioContext(1, renderLength * sampleRate, sampleRate);
60 62
61 var osc1 = context.createOscillator(); 63 let osc1 = context.createOscillator();
62 var osc2 = context.createOscillator(); 64 let osc2 = context.createOscillator();
63 var inverter = context.createGain(); 65 let inverter = context.createGain();
64 var scriptNode = context.createScriptProcessor(scriptBufferSize, 1, 1); 66 let scriptNode = context.createScriptProcessor(scriptBufferSize, 1, 1);
65 scriptNode.onaudioprocess = function(event) { 67 scriptNode.onaudioprocess = function(event) {
66 var inputChannel = event.inputBuffer.getChannelData(0); 68 let inputChannel = event.inputBuffer.getChannelData(0);
67 var outputChannel = event.outputBuffer.getChannelData(0); 69 let outputChannel = event.outputBuffer.getChannelData(0);
68 outputChannel.set(inputChannel); 70 outputChannel.set(inputChannel);
69 }; 71 };
70 72
71 inverter.gain.value = -1; 73 inverter.gain.value = -1;
72 74
73 osc1.connect(inverter).connect(context.destination); 75 osc1.connect(inverter).connect(context.destination);
74 osc2.connect(scriptNode).connect(context.destination); 76 osc2.connect(scriptNode).connect(context.destination);
75 77
76 // The delayed start for |osc1|. 78 // The delayed start for |osc1|.
77 osc1.start((2 * scriptBufferSize) / sampleRate); 79 osc1.start((2 * scriptBufferSize) / sampleRate);
78 osc2.start(); 80 osc2.start();
79 81
80 context.startRendering().then(function(buffer) { 82 context.startRendering().then(function(buffer) {
81 var channel = buffer.getChannelData(0); 83 let channel = buffer.getChannelData(0);
82 84
83 // The rendered buffer must be silent. 85 // The rendered buffer must be silent.
84 should(channel, 'The rendered buffer').beConstantValueOf(0); 86 should(channel, 'The rendered buffer').beConstantValueOf(0);
85 87
86 task.done(); 88 task.done();
87 }); 89 });
88 }); 90 });
89 91
90 audit.run(); 92 audit.run();
91 </script> 93 </script>
92 </body> 94 </body>
93 </html> 95 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698