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

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

Issue 2651253004: Convert non-Audit AudioParam tests to testharness (Closed)
Patch Set: Reindent Created 3 years, 10 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/AudioParam/audioparam-connect-audioratesignal-expected.txt » ('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 2
3 <!-- 3 <!--
4 Tests that an audio-rate signal (AudioNode output) can be connected to an AudioP aram. 4 Tests that an audio-rate signal (AudioNode output) can be connected to an
5 Specifically, this tests that an audio-rate signal coming from an AudioBufferSou rceNode 5 AudioParam. Specifically, this tests that an audio-rate signal coming from an
6 playing an AudioBuffer containing a specific curve can be connected to an AudioG ainNode's 6 AudioBufferSourceNode playing an AudioBuffer containing a specific curve can be
7 .gain attribute (an AudioParam). Another AudioBufferSourceNode will be the audi o source 7 connected to an AudioGainNode's .gain attribute (an AudioParam). Another
8 having its gain changed. We load this one with an AudioBuffer containing a cons tant value of 1. 8 AudioBufferSourceNode will be the audio source having its gain changed. We load
9 Thus it's easy to check that the resultant signal should be equal to the gain-sc aling curve. 9 this one with an AudioBuffer containing a constant value of 1. Thus it's easy
10 to check that the resultant signal should be equal to the gain-scaling curve.
10 --> 11 -->
11 12
12 <html> 13 <html>
13 <head> 14 <head>
14 <script src="../../resources/js-test.js"></script> 15 <script src="../../resources/testharness.js"></script>
16 <script src="../../resources/testharnessreport.js"></script>
15 <script src="../resources/audit-util.js"></script> 17 <script src="../resources/audit-util.js"></script>
16 <script src="../resources/audio-testing.js"></script> 18 <script src="../resources/audit.js"></script>
17 19
18 </head> 20 </head>
19 <body> 21 <body>
20 22
21 <script> 23 <script>
24 let audit = Audit.createTaskRunner();
22 25
23 var sampleRate = 44100.0; 26 let sampleRate = 44100.0;
24 var lengthInSeconds = 1; 27 let lengthInSeconds = 1;
25 28
26 var context = 0; 29 let context = 0;
27 var constantOneBuffer = 0; 30 let constantOneBuffer = 0;
28 var linearRampBuffer = 0; 31 let linearRampBuffer = 0;
29 32
30 function checkResult(event) { 33 function checkResult(renderedBuffer, should) {
31 var renderedBuffer = event.renderedBuffer; 34 let renderedData = renderedBuffer.getChannelData(0);
32 var renderedData = renderedBuffer.getChannelData(0); 35 let expectedData = linearRampBuffer.getChannelData(0);
33 var expectedData = linearRampBuffer.getChannelData(0); 36 let n = renderedBuffer.length;
34 var n = renderedBuffer.length;
35 37
36 if (n == linearRampBuffer.length) { 38 should(n, 'Rendered signal length').beEqualTo(linearRampBuffer.length);
37 testPassed("Rendered signal is of correct length."); 39
38 } else { 40 // Check that the rendered result exactly matches the buffer used to control
39 testFailed("Rendered signal is not of correct length."); 41 // gain. This is because we're changing the gain of a signal having constant
42 // value 1.
43 let success = true;
44 for (let i = 0; i < n; ++i) {
45 if (renderedData[i] != expectedData[i]) {
46 success = false;
47 break;
40 } 48 }
49 }
41 50
42 // Check that the rendered result exactly matches the buffer used to control gain. 51 should(
43 // This is because we're changing the gain of a signal having constant value 1. 52 success,
44 var success = true; 53 'Rendered signal exactly matches the audio-rate gain changing signal')
45 for (var i = 0; i < n; ++i) { 54 .beTrue();
46 if (renderedData[i] != expectedData[i]) {
47 success = false;
48 break;
49 }
50 }
51
52 if (success) {
53 testPassed("Rendered signal exactly matches the audio-rate gain changing signal.");
54 } else {
55 testFailed("Rendered signal differs from the audio-rate gain changing si gnal.");
56 }
57
58 finishJSTest();
59 } 55 }
60 56
61 function runTest() { 57 audit.define('test', function(task, should) {
62 if (window.testRunner) { 58 let sampleFrameLength = sampleRate * lengthInSeconds;
63 testRunner.dumpAsText();
64 testRunner.waitUntilDone();
65 }
66 59
67 window.jsTestIsAsync = true; 60 // Create offline audio context.
61 context = new OfflineAudioContext(1, sampleFrameLength, sampleRate);
68 62
69 var sampleFrameLength = sampleRate * lengthInSeconds; 63 // Create buffer used by the source which will have its gain controlled.
64 constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1);
70 65
71 // Create offline audio context. 66 // Create buffer used to control gain.
72 context = new OfflineAudioContext(1, sampleFrameLength, sampleRate); 67 linearRampBuffer = createLinearRampBuffer(context, sampleFrameLength);
73 68
74 // Create buffer used by the source which will have its gain controlled. 69 // Create the two sources.
75 constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1);
76 70
77 // Create buffer used to control gain. 71 let constantSource = context.createBufferSource();
78 linearRampBuffer = createLinearRampBuffer(context, sampleFrameLength); 72 constantSource.buffer = constantOneBuffer;
79 73
80 // Create the two sources. 74 let gainChangingSource = context.createBufferSource();
75 gainChangingSource.buffer = linearRampBuffer;
81 76
82 var constantSource = context.createBufferSource(); 77 // Create a gain node controlling the gain of constantSource and make the
83 constantSource.buffer = constantOneBuffer; 78 // connections.
79 let gainNode = context.createGain();
84 80
85 var gainChangingSource = context.createBufferSource(); 81 // Intrinsic baseline gain of zero.
86 gainChangingSource.buffer = linearRampBuffer; 82 gainNode.gain.value = 0;
87 83
88 // Create a gain node controlling the gain of constantSource and make the co nnections. 84 constantSource.connect(gainNode);
89 var gainNode = context.createGain(); 85 gainNode.connect(context.destination);
90 86
91 // Intrinsic baseline gain of zero. 87 // Connect an audio-rate signal to control the .gain AudioParam.
92 gainNode.gain.value = 0; 88 // This is the heart of what is being tested.
89 gainChangingSource.connect(gainNode.gain);
93 90
94 constantSource.connect(gainNode); 91 // Start both sources at time 0.
95 gainNode.connect(context.destination); 92 constantSource.start(0);
93 gainChangingSource.start(0);
96 94
97 // Connect an audio-rate signal to control the .gain AudioParam. 95 context.startRendering().then(buffer => {
98 // This is the heart of what is being tested. 96 checkResult(buffer, should);
99 gainChangingSource.connect(gainNode.gain); 97 task.done();
98 });
99 });
100 100
101 // Start both sources at time 0. 101 audit.run();
102 constantSource.start(0);
103 gainChangingSource.start(0);
104
105 context.oncomplete = checkResult;
106 context.startRendering();
107 }
108
109 runTest();
110 successfullyParsed = true;
111 102
112 </script> 103 </script>
113 104
114 </body> 105 </body>
115 </html> 106 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-connect-audioratesignal-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698