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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/note-grain-on-play.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> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <title>
5 note-grain-on-play.html
6 </title>
4 <script src="../../resources/testharness.js"></script> 7 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script> 8 <script src="../../resources/testharnessreport.js"></script>
6 <script src="../resources/audit-util.js"></script> 9 <script src="../resources/audit-util.js"></script>
7 <script src="../resources/audit.js"></script> 10 <script src="../resources/audit.js"></script>
8 <script src="../resources/note-grain-on-testing.js"></script> 11 <script src="../resources/note-grain-on-testing.js"></script>
9 </head> 12 </head>
10
11 <body> 13 <body>
12 <div id="description"></div> 14 <div id="description"></div>
13 <div id="console"></div> 15 <div id="console"></div>
14 16 <script id="layout-test-code">
15 <script>
16 let audit = Audit.createTaskRunner(); 17 let audit = Audit.createTaskRunner();
17 18
18 // To test noteGrainOn, a single ramp signal is created. 19 // To test noteGrainOn, a single ramp signal is created.
19 // Various sections of the ramp are rendered by noteGrainOn() at 20 // Various sections of the ramp are rendered by noteGrainOn() at
20 // different times, and we verify that the actual output 21 // different times, and we verify that the actual output
21 // consists of the correct section of the ramp at the correct 22 // consists of the correct section of the ramp at the correct
22 // time. 23 // time.
23 24
24 let linearRampBuffer; 25 let linearRampBuffer;
25 26
26 // Array of the grain offset used for each ramp played. 27 // Array of the grain offset used for each ramp played.
27 let grainOffsetTime = []; 28 let grainOffsetTime = [];
28 29
29 // Verify the received signal is a ramp from the correct section 30 // Verify the received signal is a ramp from the correct section
30 // of our ramp signal. 31 // of our ramp signal.
31 function verifyGrain(renderedData, startFrame, endFrame, grainIndex) { 32 function verifyGrain(renderedData, startFrame, endFrame, grainIndex) {
32 let grainOffsetFrame = timeToSampleFrame(grainOffsetTime[ 33 let grainOffsetFrame =
33 grainIndex], sampleRate); 34 timeToSampleFrame(grainOffsetTime[grainIndex], sampleRate);
34 let grainFrameLength = endFrame - startFrame; 35 let grainFrameLength = endFrame - startFrame;
35 let ramp = linearRampBuffer.getChannelData(0); 36 let ramp = linearRampBuffer.getChannelData(0);
36 let isCorrect = true; 37 let isCorrect = true;
37 38
38 let expected; 39 let expected;
39 let actual; 40 let actual;
40 let frame; 41 let frame;
41 42
42 for (let k = 0; k < grainFrameLength; ++k) { 43 for (let k = 0; k < grainFrameLength; ++k) {
43 if (renderedData[startFrame + k] != ramp[grainOffsetFrame + 44 if (renderedData[startFrame + k] != ramp[grainOffsetFrame + k]) {
44 k]) { 45 expected = ramp[grainOffsetFrame + k];
45 expected = ramp[grainOffsetFrame + k]; 46 actual = renderedData[startFrame + k];
46 actual = renderedData[startFrame + k]; 47 frame = startFrame + k;
47 frame = startFrame + k; 48 isCorrect = false;
48 isCorrect = false; 49 break;
49 break;
50 }
51 } 50 }
52 return { 51 }
53 verified: isCorrect, 52 return {
54 expected: expected, 53 verified: isCorrect,
55 actual: actual, 54 expected: expected,
56 frame: frame 55 actual: actual,
57 }; 56 frame: frame
57 };
58 } 58 }
59 59
60 function checkResult(buffer, should) { 60 function checkResult(buffer, should) {
61 renderedData = buffer.getChannelData(0); 61 renderedData = buffer.getChannelData(0);
62 let nSamples = renderedData.length; 62 let nSamples = renderedData.length;
63 63
64 // Number of grains that we found that have incorrect data. 64 // Number of grains that we found that have incorrect data.
65 let invalidGrainDataCount = 0; 65 let invalidGrainDataCount = 0;
66 66
67 let startEndFrames = findStartAndEndSamples(renderedData); 67 let startEndFrames = findStartAndEndSamples(renderedData);
68 68
69 // Verify the start and stop times. Not strictly needed for 69 // Verify the start and stop times. Not strictly needed for
70 // this test, but it's useful to know that if the ramp data 70 // this test, but it's useful to know that if the ramp data
71 // appears to be incorrect. 71 // appears to be incorrect.
72 verifyStartAndEndFrames(startEndFrames, should); 72 verifyStartAndEndFrames(startEndFrames, should);
73 73
74 // Loop through each of the rendered grains and check that 74 // Loop through each of the rendered grains and check that
75 // each grain contains our expected ramp. 75 // each grain contains our expected ramp.
76 for (let k = 0; k < startEndFrames.start.length; ++k) { 76 for (let k = 0; k < startEndFrames.start.length; ++k) {
77 // Verify that the rendered data matches the expected 77 // Verify that the rendered data matches the expected
78 // section of our ramp signal. 78 // section of our ramp signal.
79 let result = verifyGrain(renderedData, startEndFrames.start[ 79 let result = verifyGrain(
80 k], startEndFrames.end[k], k); 80 renderedData, startEndFrames.start[k], startEndFrames.end[k], k);
81 should(result.verified, "Pulse " + k + 81 should(result.verified, 'Pulse ' + k + ' contained the expected data')
82 " contained the expected data")
83 .beTrue(); 82 .beTrue();
84 } 83 }
85 should(invalidGrainDataCount, 84 should(
86 "Number of grains that did not contain the expected data") 85 invalidGrainDataCount,
86 'Number of grains that did not contain the expected data')
87 .beEqualTo(0); 87 .beEqualTo(0);
88 } 88 }
89 89
90 audit.define({ 90 audit.define(
91 label: "note-grain-on-play", 91 {
92 description: "Test noteGrainOn offset rendering" 92 label: 'note-grain-on-play',
93 }, function(task, should) { 93 description: 'Test noteGrainOn offset rendering'
94 // Create offline audio context. 94 },
95 context = new OfflineAudioContext(2, sampleRate * 95 function(task, should) {
96 renderTime, sampleRate); 96 // Create offline audio context.
97 context =
98 new OfflineAudioContext(2, sampleRate * renderTime, sampleRate);
97 99
98 // Create a linear ramp for testing noteGrainOn. 100 // Create a linear ramp for testing noteGrainOn.
99 linearRampBuffer = createSignalBuffer(context, 101 linearRampBuffer = createSignalBuffer(context, function(k) {
100 function(k) { 102 // Want the ramp to start
101 // Want the ramp to start 103 // with 1, not 0.
102 // with 1, not 0. 104 return k + 1;
103 return k + 1; 105 });
104 });
105 106
106 let grainInfo = playAllGrains(context, linearRampBuffer, 107 let grainInfo =
107 numberOfTests); 108 playAllGrains(context, linearRampBuffer, numberOfTests);
108 109
109 grainOffsetTime = grainInfo.grainOffsetTimes; 110 grainOffsetTime = grainInfo.grainOffsetTimes;
110 111
111 context.startRendering() 112 context.startRendering().then(function(audioBuffer) {
112 .then(function(audioBuffer) { 113 checkResult(audioBuffer, should);
113 checkResult(audioBuffer, should); 114 task.done();
114 task.done(); 115 });
115 }); 116 });
116 }); 117
117
118 audit.run(); 118 audit.run();
119 </script> 119 </script>
120 </body> 120 </body>
121 </html> 121 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698