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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-detune-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-detune-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 detune 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 detune of 0, the duration of impulse buffer should be 4
12 <script> 22 // samples (which means the interval between impulses is 4). Increasing
23 // detune to 1200 (1 octave) 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 detune 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 detune of 0, the duration of impulse buffer should be 4
22 // samples (which means the interval between impulses is 4). Increasing
23 // detune to 1200 (1 octave) 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, 1200] for modulating 38 // Create a DC offset buffer with 2 values [0, 1200] for modulating
39 // detune. The first half of buffer is 0 and the rest is 1200. 39 // detune. The first half of buffer is 0 and the rest is 1200.
40 dcOffsetBuffer = context.createBuffer(1, renderLength, 40 dcOffsetBuffer = context.createBuffer(1, renderLength, sampleRate);
41 sampleRate); 41 let dcOffsetArray = dcOffsetBuffer.getChannelData(0);
42 var dcOffsetArray = dcOffsetBuffer.getChannelData(0);
43 for (i = 0; i < dcOffsetArray.length; i++) { 42 for (i = 0; i < dcOffsetArray.length; i++) {
44
45 // Note that these values will be added to the detune AudioParam 43 // Note that these values will be added to the detune AudioParam
46 // value. For example, 1 DC offset value will result detune of 1200. 44 // value. For example, 1 DC offset value will result detune of 1200.
47 dcOffsetArray[i] = i < half ? 0 : 1200; 45 dcOffsetArray[i] = i < half ? 0 : 1200;
48 } 46 }
49 }, "Creation of impulse buffers") 47 }, 'Creation of impulse buffers').notThrow();
50 .notThrow();
51 48
52 task.done(); 49 task.done();
53 }); 50 });
54 51
55 52
56 // Task: Render the actual buffer and compare with the reference. 53 // Task: Render the actual buffer and compare with the reference.
57 audit.define('synthesize-verify', (task, should) => { 54 audit.define('synthesize-verify', (task, should) => {
58 var impulse = context.createBufferSource(); 55 let impulse = context.createBufferSource();
59 var dcOffset = context.createBufferSource(); 56 let dcOffset = context.createBufferSource();
60 57
61 impulse.buffer = impulseBuffer; 58 impulse.buffer = impulseBuffer;
62 dcOffset.buffer = dcOffsetBuffer; 59 dcOffset.buffer = dcOffsetBuffer;
63 impulse.loop = true; 60 impulse.loop = true;
64 61
65 impulse.connect(context.destination); 62 impulse.connect(context.destination);
66 dcOffset.connect(impulse.detune); 63 dcOffset.connect(impulse.detune);
67 64
68 impulse.start(); 65 impulse.start();
69 dcOffset.start(); 66 dcOffset.start();
70 67
71 context.startRendering().then(function (renderedBuffer) { 68 context.startRendering()
72 var data = renderedBuffer.getChannelData(0); 69 .then(function(renderedBuffer) {
73 var passed = true, i = 0; 70 let data = renderedBuffer.getChannelData(0);
74 var nextImpulseIndex = 0; 71 let passed = true, i = 0;
72 let nextImpulseIndex = 0;
75 73
76 while (i < renderLength) { 74 while (i < renderLength) {
77 if (i === nextImpulseIndex && data[i] === 1) { 75 if (i === nextImpulseIndex && data[i] === 1) {
78 // From 0 to 127th element, the interval between impulses is 4. On t he other 76 // From 0 to 127th element, the interval between impulses is
79 // hand, the interval is 2 between 128th and 255th element. 77 // 4. On the other hand, the interval is 2 between 128th and
80 nextImpulseIndex += (i < half) ? impulseLength : impulseLength / 2; 78 // 255th element.
81 } else if (data[i] !== 0) { 79 nextImpulseIndex +=
82 // If a value is neither 0 or 1, break the loop and fail the test. 80 (i < half) ? impulseLength : impulseLength / 2;
83 passed = false; 81 } else if (data[i] !== 0) {
84 break; 82 // If a value is neither 0 or 1, break the loop and fail the
85 } 83 // test.
84 passed = false;
85 break;
86 }
86 87
87 i++; 88 i++;
88 } 89 }
89 90
90 should(passed, 'Increasing detune') 91 should(passed, 'Increasing detune')
91 .message( 92 .message(
92 'to 1200 decreased the interval between impulses to half', 93 'to 1200 decreased the interval between impulses to half',
93 'produced the incorrect result' + 'at the index ' + i); 94 'produced the incorrect result' +
94 }).then(() => task.done()); 95 'at the index ' + i);
95 }); 96 })
97 .then(() => task.done());
98 });
96 99
97 audit.run(); 100 audit.run();
98 </script> 101 </script>
99 </body> 102 </body>
100
101 </html> 103 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698