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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/ScriptProcessor/scriptprocessor-offlineaudiocontext.html

Issue 2862413003: Convert ScriptProcessorNode tests to us new Audit (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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/ScriptProcessor/scriptprocessornode-0-output-channels.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <title>ScriptProcessorNode on OfflineAudioContext</title> 4 <title>ScriptProcessorNode on OfflineAudioContext</title>
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 </head> 9 </head>
10 <body> 10 <body>
11 <script> 11 <script>
12 var audit = Audit.createTaskRunner(); 12 var audit = Audit.createTaskRunner();
13 13
14 14
15 // Fill the output of script processor with a constant value. 15 // Fill the output of script processor with a constant value.
16 audit.defineTask('simple-output', function (taskDone) { 16 audit.define('simple-output', (task, should) => {
17 var sampleRate = 44100; 17 var sampleRate = 44100;
18 var scriptBufferSize = 256; 18 var scriptBufferSize = 256;
19 var renderLength = 1; 19 var renderLength = 1;
20 var PI = Math.fround(Math.PI); 20 var PI = Math.fround(Math.PI);
21 21
22 var context = new OfflineAudioContext( 22 var context =
23 1, renderLength * sampleRate, sampleRate); 23 new OfflineAudioContext(1, renderLength * sampleRate, sampleRate);
24 24
25 var scriptNode = context.createScriptProcessor(scriptBufferSize, 1, 1); 25 var scriptNode = context.createScriptProcessor(scriptBufferSize, 1, 1);
26 scriptNode.onaudioprocess = function (event) { 26 scriptNode.onaudioprocess = function(event) {
27 var outputChannel = event.outputBuffer.getChannelData(0); 27 var outputChannel = event.outputBuffer.getChannelData(0);
28 outputChannel.fill(PI); 28 outputChannel.fill(PI);
29 }; 29 };
30 scriptNode.connect(context.destination); 30 scriptNode.connect(context.destination);
31 31
32 context.startRendering().then(function (buffer) { 32 context.startRendering().then(function(buffer) {
33 var channel = buffer.getChannelData(0); 33 var channel = buffer.getChannelData(0);
34 var initialDelay = channel.subarray(0, 2 * scriptBufferSize); 34 var initialDelay = channel.subarray(0, 2 * scriptBufferSize);
35 var actualContent = channel.subarray(2 * scriptBufferSize); 35 var actualContent = channel.subarray(2 * scriptBufferSize);
36 36
37 // There is the initial delay (2 x buffer size) which is silent. 37 // There is the initial delay (2 x buffer size) which is silent.
38 Should('The initial delay contains zeros.', initialDelay) 38 should(initialDelay, 'The initial delay contains zeros.')
39 .beConstantValueOf(0); 39 .beConstantValueOf(0);
40 40
41 // After the initial delay, we must get |PI|. 41 // After the initial delay, we must get |PI|.
42 Should('The actual content contains ' + PI, actualContent) 42 should(actualContent, 'The actual content contains ' + PI)
43 .beConstantValueOf(PI); 43 .beConstantValueOf(PI);
44 44
45 taskDone(); 45 task.done();
46 });
46 }); 47 });
47 });
48 48
49 49
50 // Pass through an oscillator via a script processor. Sum with the 50 // Pass through an oscillator via a script processor. Sum with the
51 // phase-inverted oscillator with the delayed start time. Verify the 51 // phase-inverted oscillator with the delayed start time. Verify the
52 // rendered buffer is completely silent. 52 // rendered buffer is completely silent.
53 audit.defineTask('oscillator-output', function (taskDone) { 53 audit.define('oscillator-output', (task, should) => {
54 var sampleRate = 44100; 54 var sampleRate = 44100;
55 var scriptBufferSize = 256; 55 var scriptBufferSize = 256;
56 var renderLength = 1; 56 var renderLength = 1;
57 57
58 var context = new OfflineAudioContext( 58 var context =
59 1, renderLength * sampleRate, sampleRate); 59 new OfflineAudioContext(1, renderLength * sampleRate, sampleRate);
60 60
61 var osc1 = context.createOscillator(); 61 var osc1 = context.createOscillator();
62 var osc2 = context.createOscillator(); 62 var osc2 = context.createOscillator();
63 var inverter = context.createGain(); 63 var inverter = context.createGain();
64 var scriptNode = context.createScriptProcessor(scriptBufferSize, 1, 1); 64 var scriptNode = context.createScriptProcessor(scriptBufferSize, 1, 1);
65 scriptNode.onaudioprocess = function (event) { 65 scriptNode.onaudioprocess = function(event) {
66 var inputChannel = event.inputBuffer.getChannelData(0); 66 var inputChannel = event.inputBuffer.getChannelData(0);
67 var outputChannel = event.outputBuffer.getChannelData(0); 67 var outputChannel = event.outputBuffer.getChannelData(0);
68 outputChannel.set(inputChannel); 68 outputChannel.set(inputChannel);
69 }; 69 };
70 70
71 inverter.gain.value = -1; 71 inverter.gain.value = -1;
72 72
73 osc1.connect(inverter).connect(context.destination); 73 osc1.connect(inverter).connect(context.destination);
74 osc2.connect(scriptNode).connect(context.destination); 74 osc2.connect(scriptNode).connect(context.destination);
75 75
76 // The delayed start for |osc1|. 76 // The delayed start for |osc1|.
77 osc1.start((2 * scriptBufferSize) / sampleRate); 77 osc1.start((2 * scriptBufferSize) / sampleRate);
78 osc2.start(); 78 osc2.start();
79 79
80 context.startRendering().then(function (buffer) { 80 context.startRendering().then(function(buffer) {
81 var channel = buffer.getChannelData(0); 81 var channel = buffer.getChannelData(0);
82
83 // The rendered buffer must be silent.
84 Should('The rendered buffer', channel)
85 .beConstantValueOf(0);
86 82
87 taskDone(); 83 // The rendered buffer must be silent.
84 should(channel, 'The rendered buffer').beConstantValueOf(0);
85
86 task.done();
87 });
88 }); 88 });
89 });
90 89
91 90 audit.run();
92 audit.runTasks();
93 </script> 91 </script>
94 </body> 92 </body>
95 </html> 93 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/ScriptProcessor/scriptprocessornode-0-output-channels.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698