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

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

Issue 2581463002: Refactor WebAudio test directory (Closed)
Patch Set: Use correct path for wav result files Created 3 years, 12 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
(Empty)
1 <!DOCTYPE html>
2
3 <!--
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.
6 -->
7
8 <html>
9 <head>
10 <script src="../resources/js-test.js"></script>
11 <script src="resources/compatibility.js"></script>
12 <script src="resources/audit-util.js"></script>
13 <script src="resources/audio-testing.js"></script>
14 <script type="text/javascript" src="resources/buffer-loader.js"></script>
15 </head>
16
17 <body>
18
19 <div id="description"></div>
20 <div id="console"></div>
21
22 <script>
23 description("Tests sample-accurate scheduling.");
24
25 var sampleRate = 44100.0;
26 var lengthInSeconds = 4;
27
28 var context = 0;
29 var bufferLoader = 0;
30 var impulse;
31
32 // See if we can render at exactly these sample offsets.
33 var sampleOffsets = [0, 3, 512, 517, 1000, 1005, 20000, 21234, 37590];
34
35 function createImpulse() {
36 // An impulse has a value of 1 at time 0, and is otherwise 0.
37 impulse = context.createBuffer(2, 512, sampleRate);
38 var sampleDataL = impulse.getChannelData(0);
39 var sampleDataR = impulse.getChannelData(1);
40 sampleDataL[0] = 1.0;
41 sampleDataR[0] = 1.0;
42 }
43
44 function playNote(time) {
45 var bufferSource = context.createBufferSource();
46 bufferSource.buffer = impulse;
47 bufferSource.connect(context.destination);
48 bufferSource.start(time);
49 }
50
51 function checkSampleAccuracy(event) {
52 var buffer = event.renderedBuffer;
53
54 var bufferDataL = buffer.getChannelData(0);
55 var bufferDataR = buffer.getChannelData(1);
56
57 var success = true;
58 var impulseCount = 0;
59 var badOffsetCount = false;
60
61 // Go through every sample and make sure it's 0, except at positions in samp leOffsets.
62 for (var i = 0; i < buffer.length; ++i) {
63 // Make sure left == right
64 if (bufferDataL[i] != bufferDataR[i]) {
65 testFailed("Rendered buffer left and right channels are not identica l.");
66 success = false;
67 break;
68 }
69
70 if (bufferDataL[i] != 0) {
71 // Make sure this index is in sampleOffsets
72 var found = false;
73 for (var j = 0; j < sampleOffsets.length; ++j) {
74 if (sampleOffsets[j] == i) {
75 found = true;
76 break;
77 }
78 }
79 ++impulseCount;
80 if (!found) {
81 testFailed("Non-zero sample found at sample offset " + i);
82 success = false;
83 ++badOffsetCount;
84 }
85 }
86 }
87
88 if (impulseCount == sampleOffsets.length) {
89 if (badOffsetCount == 0) {
90 testPassed("Expected number of events found.");
91 } else {
92 testFailed("Expected number of events found, but " + badOffsetCount + " are at incorrect offsets.");
93 success = false;
94 }
95 } else {
96 testFailed("Expected " + sampleOffsets.length + " impulses but only foun d " + impulseCount);
97 success = false;
98 }
99
100 if (success) {
101 testPassed("All events rendered with sample-accuracy.");
102 } else {
103 testFailed("Events NOT rendered with sample-accuracy.");
104 }
105
106 finishJSTest();
107 }
108
109 function runTest() {
110 if (window.testRunner) {
111 testRunner.dumpAsText();
112 testRunner.waitUntilDone();
113 }
114
115 window.jsTestIsAsync = true;
116
117 // Create offline audio context.
118 context = new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRat e);
119 createImpulse();
120
121 for (var i = 0; i < sampleOffsets.length; ++i) {
122 var timeInSeconds = sampleOffsets[i] / sampleRate;
123 playNote(timeInSeconds);
124 }
125
126 context.oncomplete = checkSampleAccuracy;
127 context.startRendering();
128 }
129
130 runTest();
131
132 </script>
133
134 </body>
135 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698