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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-playbackrate-modulated-impulse.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-playbackrate-modulated-impulse.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 sampleRate = 44100;
3 15
4 <head> 16 // To get an observable change on playbackRate modulation, the minimum
5 <script src="../../resources/testharness.js"></script> 17 // rendering length should greater than the rendering quantum.
6 <script src="../../resources/testharnessreport.js"></script> 18 let renderLength = 256;
7 <script src="../resources/audit-util.js"></script> 19 let half = renderLength / 2;
8 <script src="../resources/audit.js"></script>
9 </head>
10 20
11 <body> 21 // With the playbackRate of 1, the duration of impulse buffer should be 4
12 <script> 22 // samples (which means the interval between impulses is 4). Doubling
23 // playback speed decrease the interval to 2 samples.
24 let impulseLength = 4;
13 25
14 var sampleRate = 44100; 26 let context = new OfflineAudioContext(1, renderLength, sampleRate);
27 let impulseBuffer, dcOffsetBuffer;
15 28
16 // To get an observable change on playbackRate modulation, the minimum 29 let audit = Audit.createTaskRunner();
17 // rendering length should greater than the rendering quantum.
18 var renderLength = 256;
19 var half = renderLength / 2;
20
21 // With the playbackRate of 1, the duration of impulse buffer should be 4
22 // samples (which means the interval between impulses is 4). Doubling
23 // playback speed decrease the interval to 2 samples.
24 var impulseLength = 4;
25
26 var context = new OfflineAudioContext(1, renderLength, sampleRate);
27 var impulseBuffer, dcOffsetBuffer;
28
29 var audit = Audit.createTaskRunner();
30 30
31 31
32 // Task: build an impulse and DC-offset buffers for testing. 32 // Task: build an impulse and DC-offset buffers for testing.
33 audit.define('build-buffers', (task, should) => { 33 audit.define('build-buffers', (task, should) => {
34 should(() => { 34 should(() => {
35 // 4-sample impulse sample. 35 // 4-sample impulse sample.
36 impulseBuffer = createImpulseBuffer(context, impulseLength); 36 impulseBuffer = createImpulseBuffer(context, impulseLength);
37 37
38 // Create a DC offset buffer with 2 values [0, 1] for modulating 38 // Create a DC offset buffer with 2 values [0, 1] for modulating
39 // playbackRate. The first half of buffer is 0 and the rest is 1. 39 // playbackRate. The first half of buffer is 0 and the rest is 1.
40 dcOffsetBuffer = context.createBuffer(1, renderLength, sampleRate); 40 dcOffsetBuffer = context.createBuffer(1, renderLength, sampleRate);
41 var dcOffsetArray = dcOffsetBuffer.getChannelData(0); 41 let dcOffsetArray = dcOffsetBuffer.getChannelData(0);
42 for (i = 0; i < dcOffsetArray.length; i++) { 42 for (i = 0; i < dcOffsetArray.length; i++) {
43 43 // Note that these values will be added to the playbackRate
44 // Note that these values will be added to the playbackRate AudioPar am 44 // AudioParam value. For example, 0 DC offset value will result
45 // value. For example, 0 DC offset value will result playbackRate of 1 45 // playbackRate of 1 because the default playbackRate value is 1.
46 // because the default playbackRate value is 1.
47 dcOffsetArray[i] = i < half ? 0 : 1; 46 dcOffsetArray[i] = i < half ? 0 : 1;
48 } 47 }
49 }, "Build buffers") 48 }, 'Build buffers').notThrow();
50 .notThrow();
51 49
52 task.done(); 50 task.done();
53 }); 51 });
54 52
55 53
56 // Task: Render the actual buffer and compare with the reference. 54 // Task: Render the actual buffer and compare with the reference.
57 audit.define('synthesize-verify', (task, should) => { 55 audit.define('synthesize-verify', (task, should) => {
58 var impulse = context.createBufferSource(); 56 let impulse = context.createBufferSource();
59 var dcOffset = context.createBufferSource(); 57 let dcOffset = context.createBufferSource();
60 58
61 impulse.buffer = impulseBuffer; 59 impulse.buffer = impulseBuffer;
62 dcOffset.buffer = dcOffsetBuffer; 60 dcOffset.buffer = dcOffsetBuffer;
63 impulse.loop = true; 61 impulse.loop = true;
64 62
65 impulse.connect(context.destination); 63 impulse.connect(context.destination);
66 dcOffset.connect(impulse.playbackRate); 64 dcOffset.connect(impulse.playbackRate);
67 65
68 impulse.start(); 66 impulse.start();
69 dcOffset.start(); 67 dcOffset.start();
70 68
71 context.startRendering().then(function (renderedBuffer) { 69 context.startRendering()
72 var data = renderedBuffer.getChannelData(0); 70 .then(function(renderedBuffer) {
73 var passed = true, i = 0; 71 let data = renderedBuffer.getChannelData(0);
74 var nextImpulseIndex = 0; 72 let passed = true, i = 0;
73 let nextImpulseIndex = 0;
75 74
76 while (i < renderLength) { 75 while (i < renderLength) {
77 if (i === nextImpulseIndex && data[i] === 1) { 76 if (i === nextImpulseIndex && data[i] === 1) {
78 // From 0 to 127th element, the interval between impulses is 4. On t he other 77 // From 0 to 127th element, the interval between impulses is
79 // hand, the interval is 2 between 128th and 255th element. 78 // 4. On the other hand, the interval is 2 between 128th and
80 nextImpulseIndex += (i < half) ? impulseLength : impulseLength / 2; 79 // 255th element.
81 } else if (data[i] !== 0) { 80 nextImpulseIndex +=
82 // If a value is neither 0 or 1, break the loop and fail the test. 81 (i < half) ? impulseLength : impulseLength / 2;
83 passed = false; 82 } else if (data[i] !== 0) {
84 break; 83 // If a value is neither 0 or 1, break the loop and fail the
85 } 84 // test.
85 passed = false;
86 break;
87 }
86 88
87 i++; 89 i++;
88 } 90 }
89 91
90 should(passed, 'Doubling playbackRate') 92 should(passed, 'Doubling playbackRate')
91 .message( 93 .message(
92 'decreased the interval between impulses to half', 94 'decreased the interval between impulses to half',
93 'produced the incorrect result' + 'at the index ' + i) 95 'produced the incorrect result' +
94 }).then(() => task.done()); 96 'at the index ' + i)
95 }); 97 })
98 .then(() => task.done());
99 });
96 100
97 audit.run(); 101 audit.run();
98 102
99 successfullyParsed = true; 103 successfullyParsed = true;
100 </script> 104 </script>
101 </body> 105 </body>
102
103 </html> 106 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698