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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-summingjunction.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
3 <!-- 2 <!--
4 Tests that multiple audio-rate signals (AudioNode outputs) can be connected to a n AudioParam 3 Tests that multiple audio-rate signals (AudioNode outputs) can be connected to a n AudioParam
5 and that these signals are summed, along with the AudioParams intrinsic value. 4 and that these signals are summed, along with the AudioParams intrinsic value.
6 --> 5 -->
6 <html>
7 <head>
8 <title>
9 audioparam-summingjunction.html
10 </title>
11 <script src="../../resources/testharness.js"></script>
12 <script src="../../resources/testharnessreport.js"></script>
13 <script src="../resources/audit-util.js"></script>
14 <script src="../resources/audit.js"></script>
15 <script src="../resources/mix-testing.js"></script>
16 </head>
17 <body>
18 <script id="layout-test-code">
19 let audit = Audit.createTaskRunner();
7 20
8 <html> 21 let sampleRate = 44100.0;
9 <head> 22 let lengthInSeconds = 1;
10 <script src="../../resources/testharness.js"></script>
11 <script src="../../resources/testharnessreport.js"></script>
12 <script src="../resources/audit-util.js"></script>
13 <script src="../resources/audit.js"></script>
14 <script src="../resources/mix-testing.js"></script>
15 23
16 </head> 24 let context = 0;
17 <body>
18 25
19 <script> 26 // Buffers used by the two gain controlling sources.
20 let audit = Audit.createTaskRunner(); 27 let linearRampBuffer;
28 let toneBuffer;
29 let toneFrequency = 440;
21 30
22 let sampleRate = 44100.0; 31 // Arbitrary non-zero value.
23 let lengthInSeconds = 1; 32 let baselineGain = 5;
24 33
25 let context = 0; 34 // Allow for a small round-off error.
35 let maxAllowedError = 1e-6;
26 36
27 // Buffers used by the two gain controlling sources. 37 function checkResult(renderedBuffer, should) {
28 let linearRampBuffer; 38 let renderedData = renderedBuffer.getChannelData(0);
29 let toneBuffer;
30 let toneFrequency = 440;
31 39
32 // Arbitrary non-zero value. 40 // Get buffer data from the two sources used to control gain.
33 let baselineGain = 5; 41 let linearRampData = linearRampBuffer.getChannelData(0);
42 let toneData = toneBuffer.getChannelData(0);
34 43
35 // Allow for a small round-off error. 44 let n = renderedBuffer.length;
36 let maxAllowedError = 1e-6;
37 45
38 function checkResult(renderedBuffer, should) { 46 should(n, 'Rendered signal length').beEqualTo(linearRampBuffer.length);
39 let renderedData = renderedBuffer.getChannelData(0);
40 47
41 // Get buffer data from the two sources used to control gain. 48 // Check that the rendered result exactly matches the sum of the
42 let linearRampData = linearRampBuffer.getChannelData(0); 49 // intrinsic gain plus the two sources used to control gain. This is
43 let toneData = toneBuffer.getChannelData(0); 50 // because we're changing the gain of a signal having constant value 1.
51 let success = true;
52 for (let i = 0; i < n; ++i) {
53 let expectedValue = baselineGain + linearRampData[i] + toneData[i];
54 let error = Math.abs(expectedValue - renderedData[i]);
44 55
45 let n = renderedBuffer.length; 56 if (error > maxAllowedError) {
57 success = false;
58 break;
59 }
60 }
46 61
47 should(n, 'Rendered signal length').beEqualTo(linearRampBuffer.length); 62 should(
63 success,
64 'Rendered signal matches sum of two audio-rate gain changing signals plus baseline gain')
65 .beTrue();
66 }
48 67
49 // Check that the rendered result exactly matches the sum of the intrinsic 68 audit.define('test', function(task, should) {
50 // gain plus the two sources used to control gain. 69 let sampleFrameLength = sampleRate * lengthInSeconds;
51 // This is because we're changing the gain of a signal having constant value
52 // 1.
53 let success = true;
54 for (let i = 0; i < n; ++i) {
55 let expectedValue = baselineGain + linearRampData[i] + toneData[i];
56 let error = Math.abs(expectedValue - renderedData[i]);
57 70
58 if (error > maxAllowedError) { 71 // Create offline audio context.
59 success = false; 72 context = new OfflineAudioContext(1, sampleFrameLength, sampleRate);
60 break;
61 }
62 }
63 73
64 should( 74 // Create buffer used by the source which will have its gain controlled.
65 success, 75 let constantOneBuffer =
66 'Rendered signal matches sum of two audio-rate gain changing signals plus baseline gain') 76 createConstantBuffer(context, sampleFrameLength, 1);
67 .beTrue(); 77 let constantSource = context.createBufferSource();
68 } 78 constantSource.buffer = constantOneBuffer;
69 79
70 audit.define('test', function(task, should) { 80 // Create 1st buffer used to control gain (a linear ramp).
71 let sampleFrameLength = sampleRate * lengthInSeconds; 81 linearRampBuffer = createLinearRampBuffer(context, sampleFrameLength);
82 let gainSource1 = context.createBufferSource();
83 gainSource1.buffer = linearRampBuffer;
72 84
73 // Create offline audio context. 85 // Create 2st buffer used to control gain (a simple sine wave tone).
74 context = new OfflineAudioContext(1, sampleFrameLength, sampleRate); 86 toneBuffer =
87 createToneBuffer(context, toneFrequency, lengthInSeconds, 1);
88 let gainSource2 = context.createBufferSource();
89 gainSource2.buffer = toneBuffer;
75 90
76 // Create buffer used by the source which will have its gain controlled. 91 // Create a gain node controlling the gain of constantSource and make
77 let constantOneBuffer = createConstantBuffer(context, sampleFrameLength, 1); 92 // the connections.
78 let constantSource = context.createBufferSource(); 93 let gainNode = context.createGain();
79 constantSource.buffer = constantOneBuffer;
80 94
81 // Create 1st buffer used to control gain (a linear ramp). 95 // Intrinsic baseline gain.
82 linearRampBuffer = createLinearRampBuffer(context, sampleFrameLength); 96 // This gain value should be summed with gainSource1 and gainSource2.
83 let gainSource1 = context.createBufferSource(); 97 gainNode.gain.value = baselineGain;
84 gainSource1.buffer = linearRampBuffer;
85 98
86 // Create 2st buffer used to control gain (a simple sine wave tone). 99 constantSource.connect(gainNode);
87 toneBuffer = createToneBuffer(context, toneFrequency, lengthInSeconds, 1); 100 gainNode.connect(context.destination);
88 let gainSource2 = context.createBufferSource();
89 gainSource2.buffer = toneBuffer;
90 101
91 // Create a gain node controlling the gain of constantSource and make the 102 // Connect two audio-rate signals to control the .gain AudioParam.
92 // connections. 103 gainSource1.connect(gainNode.gain);
93 let gainNode = context.createGain(); 104 gainSource2.connect(gainNode.gain);
94 105
95 // Intrinsic baseline gain. 106 // Start all sources at time 0.
96 // This gain value should be summed with gainSource1 and gainSource2. 107 constantSource.start(0);
97 gainNode.gain.value = baselineGain; 108 gainSource1.start(0);
109 gainSource2.start(0);
98 110
99 constantSource.connect(gainNode); 111 context.startRendering().then(buffer => {
100 gainNode.connect(context.destination); 112 checkResult(buffer, should);
113 task.done();
114 });
115 });
101 116
102 // Connect two audio-rate signals to control the .gain AudioParam. 117 audit.run();
103 gainSource1.connect(gainNode.gain); 118 </script>
104 gainSource2.connect(gainNode.gain); 119 </body>
105
106 // Start all sources at time 0.
107 constantSource.start(0);
108 gainSource1.start(0);
109 gainSource2.start(0);
110
111 context.startRendering().then(buffer => {
112 checkResult(buffer, should);
113 task.done();
114 });
115 });
116
117 audit.run();
118 </script>
119
120 </body>
121 </html> 120 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698