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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-premature-loop-stop.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 Test AudioBufferSourceNode premature loop stop
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 // Reasonably low sample rate for the optimum test speed.
15 let sampleRate = 4096;
3 16
4 <head> 17 let audit = Audit.createTaskRunner();
5 <title>Test AudioBufferSourceNode premature loop stop</title>
6 <script src="../../resources/testharness.js"></script>
7 <script src="../../resources/testharnessreport.js"></script>
8 <script src="../resources/audit-util.js"></script>
9 <script src="../resources/audit.js"></script>
10 </head>
11 18
12 <body> 19 // Task: Create a buffer with 3 regions filled with constant value of [1,
13 <script> 20 // 2, 3]. Then set a loop range over the second region. Start the loop and
21 // disable it in the middle of looping. Verify the rendered buffer has the
22 // entire content including the looped region.
23 audit.define('premature-loop-stop', (task, should) => {
24 let regionValues = [1, 2, 3];
14 25
15 // Reasonably low sample rate for the optimum test speed. 26 // The region length is 2 * render quantum size to be able to suspend
16 var sampleRate = 4096; 27 // the rendering at the half of the region.
28 let regionLength = 256;
17 29
18 var audit = Audit.createTaskRunner(); 30 // The test will repeat the second region 3 times, thus the rendered
31 // audio have the length of 5 * regionLength.
32 let context = new OfflineAudioContext(1, 5 * regionLength, sampleRate);
19 33
20 // Task: Create a buffer with 3 regions filled with constant value of [1, 2, 34 // Create 3 constant buffers of [1, 2, 3] and concatenate them together:
21 // 3]. Then set a loop range over the second region. Start the loop and 35 // | 1 | 2 | 3 |
22 // disable it in the middle of looping. Verify the rendered buffer has the 36 let testBuffer = context.createBuffer(1, 3 * regionLength, sampleRate);
23 // entire content including the looped region. 37 let testChannel = testBuffer.getChannelData(0);
24 audit.define('premature-loop-stop', (task, should) => { 38 for (let i = 0; i < regionValues.length; i++) {
25 var regionValues = [1, 2, 3]; 39 let region =
40 createConstantBuffer(context, regionLength, regionValues[i]);
41 testChannel.set(region.getChannelData(0), regionLength * i);
42 ;
43 }
26 44
27 // The region length is 2 * render quantum size to be able to suspend the 45 let source = context.createBufferSource();
28 // rendering at the half of the region. 46 source.connect(context.destination);
29 var regionLength = 256;
30 47
31 // The test will repeat the second region 3 times, thus the rendered audio 48 source.buffer = testBuffer;
32 // have the length of 5 * regionLength. 49 source.loop = true;
33 var context = new OfflineAudioContext(1, 5 * regionLength, sampleRate);
34 50
35 // Create 3 constant buffers of [1, 2, 3] and concatenate them together: 51 // Set loop points over the region 2.
36 // | 1 | 2 | 3 | 52 source.loopStart = regionLength / sampleRate;
37 var testBuffer = context.createBuffer(1, 3 * regionLength, sampleRate); 53 source.loopEnd = 2 * regionLength / sampleRate;
38 var testChannel = testBuffer.getChannelData(0);
39 for (var i = 0; i < regionValues.length; i++) {
40 var region = createConstantBuffer(context, regionLength, regionValues[i] );
41 testChannel.set(region.getChannelData(0), regionLength * i);;
42 }
43 54
44 var source = context.createBufferSource(); 55 source.start();
45 source.connect(context.destination);
46 56
47 source.buffer = testBuffer; 57 // Disengage the loop at |3.5 * regionLength / sampleRate| which is the
48 source.loop = true; 58 // end of 7th rendering quantum and also the half of the third iteration
59 // of region #2.
60 context.suspend(3.5 * regionLength / sampleRate).then(function() {
61 source.loop = false;
62 context.resume();
63 });
49 64
50 // Set loop points over the region 2. 65 context.startRendering()
51 source.loopStart = regionLength/sampleRate; 66 .then(function(renderedBuffer) {
52 source.loopEnd = 2 * regionLength/sampleRate; 67 let channel = renderedBuffer.getChannelData(0);
53 68
54 source.start(); 69 // Verify if the rendered buffer has the following structure:
70 // | 1 | 2 | 2 | 2 | 3 |
71 let region1 = channel.subarray(0, regionLength - 1);
72 let region2 =
73 channel.subarray(regionLength, 4 * regionLength - 1);
74 let region3 =
75 channel.subarray(4 * regionLength, 5 * regionLength - 1);
55 76
56 // Disengage the loop at |3.5 * regionLength / sampleRate| which is the 77 should(region1, 'Region #1').beConstantValueOf(1);
57 // end of 7th rendering quantum and also the half of the third iteration 78 should(region2, 'Region #2 (looped)').beConstantValueOf(2);
58 // of region #2. 79 should(region3, 'Region #3').beConstantValueOf(3);
59 context.suspend(3.5 * regionLength/sampleRate).then(function () { 80 })
60 source.loop = false; 81 .then(() => task.done());
61 context.resume();
62 }); 82 });
63 83
64 context.startRendering().then(function (renderedBuffer) { 84 audit.run();
65 var channel = renderedBuffer.getChannelData(0); 85 </script>
66 86 </body>
67 // Verify if the rendered buffer has the following structure:
68 // | 1 | 2 | 2 | 2 | 3 |
69 var region1 = channel.subarray(0, regionLength - 1);
70 var region2 = channel.subarray(regionLength, 4 * regionLength - 1);
71 var region3 = channel.subarray(4 * regionLength, 5 * regionLength - 1);
72
73 should(region1, 'Region #1').beConstantValueOf(1);
74 should(region2, 'Region #2 (looped)').beConstantValueOf(2);
75 should(region3, 'Region #3').beConstantValueOf(3);
76 }).then(() => task.done());
77 });
78
79 audit.run();
80 </script>
81 </body>
82
83 </html> 87 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698