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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/StereoPanner/stereopannernode-no-glitch.html

Issue 2788793004: Convert StereoPanner tests to use new Audit (Closed)
Patch Set: Remove commented-out code 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/StereoPanner/stereopannernode-panning.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 3
4 <head> 4 <head>
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 10
11 <body> 11 <body>
12 <script> 12 <script>
13 var sampleRate = 44100; 13 var sampleRate = 44100;
14 var renderDuration = 0.5; 14 var renderDuration = 0.5;
15 15
16 // The threshold for glitch detection. This was experimentally determined. 16 // The threshold for glitch detection. This was experimentally determined.
17 var GLITCH_THRESHOLD = 0.0005; 17 var GLITCH_THRESHOLD = 0.0005;
18 18
19 // The maximum threshold for the error between the actual and the expected 19 // The maximum threshold for the error between the actual and the expected
20 // sample values. Experimentally determined. 20 // sample values. Experimentally determined.
21 var MAX_ERROR_ALLOWED = 0.0000001; 21 var MAX_ERROR_ALLOWED = 0.0000001;
22 22
23 // Option for |Should| test util. The number of array elements to be printed 23 // Option for |Should| test util. The number of array elements to be printed
24 // out is arbitrary. 24 // out is arbitrary.
25 var SHOULD_OPTS = { 25 var SHOULD_OPTS = {
26 numberOfArrayLog: 2 26 numberOfArrayLog: 2
27 }; 27 };
28 28
29 var audit = Audit.createTaskRunner(); 29 var audit = Audit.createTaskRunner();
30 30
31 // Extract a transitional region from the AudioBuffer. If no transition 31 // Extract a transitional region from the AudioBuffer. If no transition
32 // found, fail this test. 32 // found, fail this test.
33 function extractPanningTransition(input, prefix) { 33 function extractPanningTransition(should, input, prefix) {
34 var chanL = input.getChannelData(0); 34 var chanL = input.getChannelData(0);
35 var chanR = input.getChannelData(1); 35 var chanR = input.getChannelData(1);
36 var start, end; 36 var start, end;
37 var index = 1; 37 var index = 1;
38 38
39 // Find transition by comparing two consecutive samples. If two consecutiv e 39 // Find transition by comparing two consecutive samples. If two consecutiv e
40 // samples are identical, the transition has not started. 40 // samples are identical, the transition has not started.
41 while (chanL[index-1] === chanL[index] || chanR[index-1] === chanR[index]) { 41 while (chanL[index-1] === chanL[index] || chanR[index-1] === chanR[index]) {
42 if (++index >= input.length) { 42 if (++index >= input.length) {
43 Should(false, prefix + ': Transition in the channel data') 43 should(false, prefix + ': Transition in the channel data')
44 .summarize('found', 'not found'); 44 .summarize('found', 'not found');
45 return null; 45 return null;
46 } 46 }
47 } 47 }
48 start = index - 1; 48 start = index - 1;
49 49
50 // Find the end of transition. If two consecutive samples are not equal, 50 // Find the end of transition. If two consecutive samples are not equal,
51 // the transition is still ongoing. 51 // the transition is still ongoing.
52 while (chanL[index-1] !== chanL[index] || chanR[index-1] !== chanR[index]) { 52 while (chanL[index-1] !== chanL[index] || chanR[index-1] !== chanR[index]) {
53 if (++index >= input.length) { 53 if (++index >= input.length) {
54 Should(false, 'Transition found') 54 should(false, 'Transition found')
55 .summarize('', 'but the buffer ended prematurely'); 55 .summarize('', 'but the buffer ended prematurely');
56 return null; 56 return null;
57 } 57 }
58 } 58 }
59 end = index; 59 end = index;
60 60
61 Should(prefix + ': Transition found between sample #' + start + ' and #' + end,
62 true)
63 .summarize('correctly', 'incorrectly');
64
65 return { 61 return {
66 left: chanL.subarray(start, end), 62 left: chanL.subarray(start, end),
67 right: chanR.subarray(start, end), 63 right: chanR.subarray(start, end),
68 length: end - start 64 length: end - start
69 }; 65 };
70 } 66 }
71 67
72 // JS implementation of stereo equal power panning. 68 // JS implementation of stereo equal power panning.
73 function panStereoEqualPower(pan, inputL, inputR) { 69 function panStereoEqualPower(pan, inputL, inputR) {
74 pan = Math.min(1.0, Math.max(-1.0, pan)); 70 pan = Math.min(1.0, Math.max(-1.0, pan));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 109 }
114 110
115 return { 111 return {
116 left: outputL, 112 left: outputL,
117 right: outputR 113 right: outputR
118 }; 114 };
119 } 115 }
120 116
121 // Build audio graph and render. Change the pan parameter in the middle of 117 // Build audio graph and render. Change the pan parameter in the middle of
122 // rendering. 118 // rendering.
123 function panAndVerify(options, done) { 119 function panAndVerify(should, options) {
124 var context = new OfflineAudioContext(2, renderDuration * sampleRate, samp leRate); 120 var context = new OfflineAudioContext(2, renderDuration * sampleRate, samp leRate);
125 var source = context.createBufferSource(); 121 var source = context.createBufferSource();
126 var panner = context.createStereoPanner(); 122 var panner = context.createStereoPanner();
127 var stereoBuffer = createConstantBuffer(context, renderDuration * sampleRa te, [1.0, 1.0]); 123 var stereoBuffer = createConstantBuffer(context, renderDuration * sampleRa te, [1.0, 1.0]);
128 124
129 source.buffer = stereoBuffer; 125 source.buffer = stereoBuffer;
130 126
131 panner.pan.value = options.startPanValue; 127 panner.pan.value = options.startPanValue;
132 128
133 source.connect(panner); 129 source.connect(panner);
134 panner.connect(context.destination); 130 panner.connect(context.destination);
135 source.start(); 131 source.start();
136 132
137 // Schedule the parameter transition by the setter at 1/10 of the render 133 // Schedule the parameter transition by the setter at 1/10 of the render
138 // duration. 134 // duration.
139 context.suspend(0.1 * renderDuration).then(function () { 135 context.suspend(0.1 * renderDuration).then(function () {
140 panner.pan.value = options.endPanValue; 136 panner.pan.value = options.endPanValue;
141 context.resume(); 137 context.resume();
142 }); 138 });
143 139
144 context.startRendering().then(function (buffer) { 140 return context.startRendering().then(function (buffer) {
145 var actual = extractPanningTransition(buffer, options.message); 141 var actual = extractPanningTransition(should, buffer, options.message);
146 var expected = generateStereoEqualPanningResult(stereoBuffer, 142 var expected = generateStereoEqualPanningResult(stereoBuffer,
147 options.startPanValue, options.endPanValue, actual.length); 143 options.startPanValue, options.endPanValue, actual.length);
148 144
149 // |notGlitch| tests are redundant if the actual and expected results 145 // |notGlitch| tests are redundant if the actual and expected results
150 // match and if the expected results themselves don't glitch. 146 // match and if the expected results themselves don't glitch.
151 Should(options.message + ': Channel #0', actual.left).notGlitch(GLITCH_T HRESHOLD); 147 should(actual.left, options.message + ': Channel #0').notGlitch(GLITCH_T HRESHOLD);
152 Should(options.message + ': Channel #1', actual.right).notGlitch(GLITCH_ THRESHOLD); 148 should(actual.right, options.message + ': Channel #1').notGlitch(GLITCH_ THRESHOLD);
153 149
154 Should(options.message + ': Channel #0', actual.left, SHOULD_OPTS) 150 should(actual.left, options.message + ': Channel #0', SHOULD_OPTS)
155 .beCloseToArray(expected.left, MAX_ERROR_ALLOWED); 151 .beCloseToArray(expected.left, {absoluteThreshold: MAX_ERROR_ALLOWED}) ;
156 Should(options.message + ': Channel #1', actual.right, SHOULD_OPTS) 152 should(actual.right, options.message + ': Channel #1', SHOULD_OPTS)
157 .beCloseToArray(expected.right, MAX_ERROR_ALLOWED); 153 .beCloseToArray(expected.right, {absoluteThreshold: MAX_ERROR_ALLOWED} );
158 }).then(done); 154 });
159 } 155 }
160 156
161 // Task: move pan from negative (-0.1) to positive (0.1) value to check if 157 // Task: move pan from negative (-0.1) to positive (0.1) value to check if
162 // there is a glitch during the transition. See crbug.com/470559. 158 // there is a glitch during the transition. See crbug.com/470559.
163 audit.defineTask('negative-to-positive', function (done) { 159 audit.define('negative-to-positive', (task, should) => {
164 panAndVerify({ startPanValue: -0.1, endPanValue: 0.1, message: "L->R" }, d one); 160 panAndVerify(should, { startPanValue: -0.1, endPanValue: 0.1, message: "L- >R" })
161 .then(() => task.done());
165 }); 162 });
166 163
167 164
168 // Task: move pan from positive (0.1) to negative (-0.1) value to check if 165 // Task: move pan from positive (0.1) to negative (-0.1) value to check if
169 // there is a glitch during the transition. 166 // there is a glitch during the transition.
170 audit.defineTask('positive-to-negative', function (done) { 167 audit.define('positive-to-negative', (task, should) => {
171 panAndVerify({ startPanValue: 0.1, endPanValue: -0.1, message: "R->L" }, d one); 168 panAndVerify(should, { startPanValue: 0.1, endPanValue: -0.1, message: "R- >L" })
169 .then(() => task.done());
172 }); 170 });
173 171
174 audit.defineTask('finish-test', function (done) { 172 audit.run();
175 done();
176 });
177
178 audit.runTasks(
179 'negative-to-positive',
180 'positive-to-negative',
181 'finish-test'
182 );
183 </script> 173 </script>
184 </body> 174 </body>
185 175
186 </html> 176 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/StereoPanner/stereopannernode-panning.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698