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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-late-start.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>
4 <title>
5 audiobuffersource-late-start.html
6 </title>
7 <script src="../../resources/testharness.js"></script>
8 <script src="../../resources/testharnessreport.js"></script>
9 <script src="../resources/audit-util.js"></script>
10 <script src="../resources/audit.js"></script>
11 </head>
12 <body>
13 <script id="layout-test-code">
14 let renderQuantum = 128;
3 15
4 <head> 16 let sampleRate = 44100;
5 <script src="../../resources/testharness.js"></script> 17 let renderDuration = 0.25;
6 <script src="../../resources/testharnessreport.js"></script> 18 let startTime = 0.5 * renderDuration;
7 <script src="../resources/audit-util.js"></script>
8 <script src="../resources/audit.js"></script>
9 </head>
10 19
11 <body> 20 let audit = Audit.createTaskRunner();
12 <script>
13 21
14 var renderQuantum = 128; 22 // Calculate the index for actual start time.
23 function getStartIndex(time) {
24 let startIndex = time * sampleRate;
25 return startIndex -= (startIndex) % renderQuantum;
26 }
15 27
16 var sampleRate = 44100; 28 // Get the index of value change.
17 var renderDuration = 0.25; 29 function getValueChangeIndex(array, targetValue) {
18 var startTime = 0.5 * renderDuration; 30 return array.findIndex(function(element, index) {
31 if (element === targetValue)
32 return true;
33 });
34 }
19 35
20 var audit = Audit.createTaskRunner(); 36 audit.define('test-late-start', (task, should) => {
37 let context =
38 new OfflineAudioContext(1, renderDuration * sampleRate, sampleRate);
39 let dcOffsetbuffer = createConstantBuffer(context, 1, 1.0);
40 let source = context.createBufferSource();
41 source.buffer = dcOffsetbuffer;
42 source.loop = true;
43 source.connect(context.destination);
21 44
22 // Calculate the index for actual start time. 45 // Schedule source.start(0) at 0.01 second. The specified timing of
23 function getStartIndex(time) { 46 // start() call is already passed in terms of the context time. So the
24 var startIndex = time * sampleRate; 47 // argument |0| will be clamped to the current context time.
25 return startIndex -= (startIndex) % renderQuantum; 48 //
26 } 49 // With the sample rate of 44100, 0.01 second is 441 samples. Rounding
50 // it down to the render quantum gives 384 samples. This is clearly
51 // larger than a single render quantum.
52 //
53 // See issue: crbug.com/462167
54 context.suspend(startTime).then(function() {
55 source.start(0);
56 context.resume();
57 });
27 58
28 // Get the index of value change. 59 // Start rendering and verify result: this verifies if 1) the rendered
29 function getValueChangeIndex(array, targetValue) { 60 // buffer contains at least one non-zero value and 2) the non-zero value
30 return array.findIndex(function (element, index) { 61 // is found later than the first output sample.
31 if (element === targetValue) 62 context.startRendering()
32 return true; 63 .then(function(buffer) {
33 });
34 }
35 64
36 audit.define('test-late-start', (task, should) => { 65 let channelData = buffer.getChannelData(0);
37 var context = new OfflineAudioContext(1, renderDuration * sampleRate, samp leRate); 66 let startIndex = getStartIndex(startTime);
38 var dcOffsetbuffer = createConstantBuffer(context, 1, 1.0); 67 let nonZeroValueIndex = getValueChangeIndex(channelData, 1.0);
39 var source = context.createBufferSource();
40 source.buffer = dcOffsetbuffer;
41 source.loop = true;
42 source.connect(context.destination);
43 68
44 // Schedule source.start(0) at 0.01 second. The specified timing of 69 should(channelData, 'The output').containValues([0, 1]);
45 // start() call is already passed in terms of the context time. So the 70 should(nonZeroValueIndex, 'The index of value change')
46 // argument |0| will be clamped to the current context time. 71 .beEqualTo(startIndex);
47 // 72
48 // With the sample rate of 44100, 0.01 second is 441 samples. Rounding 73 should(
49 // it down to the render quantum gives 384 samples. This is clearly larger 74 nonZeroValueIndex, 'The index of the first non-zero sample')
50 // than a single render quantum. 75 .notBeEqualTo(0)
51 // 76
52 // See issue: crbug.com/462167 77 })
53 context.suspend(startTime).then(function () { 78 .then(() => task.done());
54 source.start(0);
55 context.resume();
56 }); 79 });
57 80
58 // Start rendering and verify result: this verifies if 1) the rendered 81 audit.run();
59 // buffer contains at least one non-zero value and 2) the non-zero value i s 82 </script>
60 // found later than the first output sample. 83 </body>
61 context.startRendering().then(function (buffer) {
62
63 var channelData = buffer.getChannelData(0);
64 var startIndex = getStartIndex(startTime);
65 var nonZeroValueIndex = getValueChangeIndex(channelData, 1.0);
66
67 should(channelData, 'The output').containValues([0, 1]);
68 should(nonZeroValueIndex, 'The index of value change')
69 .beEqualTo(startIndex);
70
71 should(nonZeroValueIndex, 'The index of the first non-zero sample')
72 .notBeEqualTo(0)
73
74 }).then(() => task.done());
75 });
76
77 audit.run();
78 </script>
79 </body>
80
81 </html> 84 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698