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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/sample-accurate-scheduling.html

Issue 2635223004: Convert AudioBufferSource sample-accurate-scheduling to testharness (Closed)
Patch Set: Address review comments Created 3 years, 11 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/sample-accurate-scheduling-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 2
3 <!-- 3 <!--
4 Tests that we are able to schedule a series of notes to playback with sample-acc uracy. 4 Tests that we are able to schedule a series of notes to playback with sample-acc uracy.
5 We use an impulse so we can tell exactly where the rendering is happening. 5 We use an impulse so we can tell exactly where the rendering is happening.
6 --> 6 -->
7 7
8 <html> 8 <html>
9 <head> 9 <head>
10 <script src="../../resources/js-test.js"></script> 10 <script src="../../resources/testharness.js"></script>
11 <script src="../../resources/testharnessreport.js"></script>
11 <script src="../resources/audit-util.js"></script> 12 <script src="../resources/audit-util.js"></script>
12 <script src="../resources/audio-testing.js"></script> 13 <script src="../resources/audit.js"></script>
13 <script type="text/javascript" src="../resources/buffer-loader.js"></script> 14 <script src="../resources/buffer-loader.js"></script>
14 </head> 15 </head>
15 16
16 <body> 17 <body>
17 18
18 <div id="description"></div> 19 <script>
19 <div id="console"></div> 20 let audit = Audit.createTaskRunner();
20 21
21 <script> 22 let sampleRate = 44100.0;
22 description("Tests sample-accurate scheduling."); 23 let lengthInSeconds = 4;
23 24
24 var sampleRate = 44100.0; 25 let context = 0;
25 var lengthInSeconds = 4; 26 let bufferLoader = 0;
26 27 let impulse;
27 var context = 0;
28 var bufferLoader = 0;
29 var impulse;
30 28
31 // See if we can render at exactly these sample offsets. 29 // See if we can render at exactly these sample offsets.
32 var sampleOffsets = [0, 3, 512, 517, 1000, 1005, 20000, 21234, 37590]; 30 let sampleOffsets = [0, 3, 512, 517, 1000, 1005, 20000, 21234, 37590];
33 31
34 function createImpulse() { 32 function createImpulse() {
35 // An impulse has a value of 1 at time 0, and is otherwise 0. 33 // An impulse has a value of 1 at time 0, and is otherwise 0.
36 impulse = context.createBuffer(2, 512, sampleRate); 34 impulse = context.createBuffer(2, 512, sampleRate);
37 var sampleDataL = impulse.getChannelData(0); 35 let sampleDataL = impulse.getChannelData(0);
38 var sampleDataR = impulse.getChannelData(1); 36 let sampleDataR = impulse.getChannelData(1);
39 sampleDataL[0] = 1.0; 37 sampleDataL[0] = 1.0;
40 sampleDataR[0] = 1.0; 38 sampleDataR[0] = 1.0;
41 } 39 }
42 40
43 function playNote(time) { 41 function playNote(time) {
44 var bufferSource = context.createBufferSource(); 42 let bufferSource = context.createBufferSource();
45 bufferSource.buffer = impulse; 43 bufferSource.buffer = impulse;
46 bufferSource.connect(context.destination); 44 bufferSource.connect(context.destination);
47 bufferSource.start(time); 45 bufferSource.start(time);
48 } 46 }
49 47
50 function checkSampleAccuracy(event) { 48 function checkSampleAccuracy(buffer, should) {
51 var buffer = event.renderedBuffer; 49 let bufferDataL = buffer.getChannelData(0);
50 let bufferDataR = buffer.getChannelData(1);
52 51
53 var bufferDataL = buffer.getChannelData(0); 52 let impulseCount = 0;
54 var bufferDataR = buffer.getChannelData(1); 53 let badOffsetCount = 0;
55 54
56 var success = true; 55 // Left and right channels must be the same.
57 var impulseCount = 0; 56 should(bufferDataL, "Content of left and right channels match and")
58 var badOffsetCount = false; 57 .beEqualToArray(bufferDataR);
59 58
60 // Go through every sample and make sure it's 0, except at positions in samp leOffsets. 59 // Go through every sample and make sure it's 0, except at positions in
61 for (var i = 0; i < buffer.length; ++i) { 60 // sampleOffsets.
62 // Make sure left == right 61 for (let i = 0; i < buffer.length; ++i) {
63 if (bufferDataL[i] != bufferDataR[i]) {
64 testFailed("Rendered buffer left and right channels are not identica l.");
65 success = false;
66 break;
67 }
68
69 if (bufferDataL[i] != 0) { 62 if (bufferDataL[i] != 0) {
70 // Make sure this index is in sampleOffsets 63 // Make sure this index is in sampleOffsets
71 var found = false; 64 let found = false;
72 for (var j = 0; j < sampleOffsets.length; ++j) { 65 for (let j = 0; j < sampleOffsets.length; ++j) {
73 if (sampleOffsets[j] == i) { 66 if (sampleOffsets[j] == i) {
74 found = true; 67 found = true;
75 break; 68 break;
76 } 69 }
77 } 70 }
78 ++impulseCount; 71 ++impulseCount;
72 should(found, "Non-zero sample found at sample offset " + i)
73 .beTrue();
79 if (!found) { 74 if (!found) {
80 testFailed("Non-zero sample found at sample offset " + i);
81 success = false;
82 ++badOffsetCount; 75 ++badOffsetCount;
83 } 76 }
84 } 77 }
85 } 78 }
86 79
80 should(impulseCount, "Number of impulses found")
81 .beEqualTo(sampleOffsets.length);
82
87 if (impulseCount == sampleOffsets.length) { 83 if (impulseCount == sampleOffsets.length) {
88 if (badOffsetCount == 0) { 84 should(badOffsetCount, "bad offset")
89 testPassed("Expected number of events found."); 85 .beEqualTo(0);
90 } else {
91 testFailed("Expected number of events found, but " + badOffsetCount + " are at incorrect offsets.");
92 success = false;
93 }
94 } else {
95 testFailed("Expected " + sampleOffsets.length + " impulses but only foun d " + impulseCount);
96 success = false;
97 } 86 }
98
99 if (success) {
100 testPassed("All events rendered with sample-accuracy.");
101 } else {
102 testFailed("Events NOT rendered with sample-accuracy.");
103 }
104
105 finishJSTest();
106 } 87 }
107 88
108 function runTest() { 89 audit.define("test", function (task, should) {
109 if (window.testRunner) { 90 task.describe("Test sample-accurate scheduling");
110 testRunner.dumpAsText(); 91
111 testRunner.waitUntilDone();
112 }
113
114 window.jsTestIsAsync = true;
115
116 // Create offline audio context. 92 // Create offline audio context.
117 context = new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRat e); 93 context = new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRat e);
hongchan 2017/01/20 18:31:17 Wrap at 80.
Raymond Toy 2017/01/20 19:37:30 Done.
118 createImpulse(); 94 createImpulse();
119 95
120 for (var i = 0; i < sampleOffsets.length; ++i) { 96 for (let i = 0; i < sampleOffsets.length; ++i) {
121 var timeInSeconds = sampleOffsets[i] / sampleRate; 97 let timeInSeconds = sampleOffsets[i] / sampleRate;
122 playNote(timeInSeconds); 98 playNote(timeInSeconds);
123 } 99 }
124 100
125 context.oncomplete = checkSampleAccuracy; 101 context.startRendering()
126 context.startRendering(); 102 .then(function (buffer) {
127 } 103 checkSampleAccuracy(buffer, should);
104 })
105 .then(task.done.bind(task));;
hongchan 2017/01/20 18:31:17 Two semicolon.
Raymond Toy 2017/01/20 19:37:30 Done.
106 });
128 107
129 runTest(); 108 audit.run();
130
131 </script> 109 </script>
132 110
133 </body> 111 </body>
134 </html> 112 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/sample-accurate-scheduling-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698