Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / sample-accurate-scheduling.html
blob72f259ecb73e5eecae8e16029221d93e49cf31b4
1 <!DOCTYPE html>
3 <!--
4 Tests that we are able to schedule a series of notes to playback with sample-accuracy.
5 We use an impulse so we can tell exactly where the rendering is happening.
6 -->
8 <html>
9 <head>
10 <script src="../resources/js-test.js"></script>
11 <script src="resources/compatibility.js"></script>
12 <script type="text/javascript" src="resources/audio-testing.js"></script>
13 <script type="text/javascript" src="resources/buffer-loader.js"></script>
14 </head>
16 <body>
18 <div id="description"></div>
19 <div id="console"></div>
21 <script>
22 description("Tests sample-accurate scheduling.");
24 var sampleRate = 44100.0;
25 var lengthInSeconds = 4;
27 var context = 0;
28 var bufferLoader = 0;
29 var impulse;
31 // See if we can render at exactly these sample offsets.
32 var sampleOffsets = [0, 3, 512, 517, 1000, 1005, 20000, 21234, 37590];
34 function createImpulse() {
35 // An impulse has a value of 1 at time 0, and is otherwise 0.
36 impulse = context.createBuffer(2, 512, sampleRate);
37 var sampleDataL = impulse.getChannelData(0);
38 var sampleDataR = impulse.getChannelData(1);
39 sampleDataL[0] = 1.0;
40 sampleDataR[0] = 1.0;
43 function playNote(time) {
44 var bufferSource = context.createBufferSource();
45 bufferSource.buffer = impulse;
46 bufferSource.connect(context.destination);
47 bufferSource.start(time);
50 function checkSampleAccuracy(event) {
51 var buffer = event.renderedBuffer;
53 var bufferDataL = buffer.getChannelData(0);
54 var bufferDataR = buffer.getChannelData(1);
56 var success = true;
57 var impulseCount = 0;
58 var badOffsetCount = false;
60 // Go through every sample and make sure it's 0, except at positions in sampleOffsets.
61 for (var i = 0; i < buffer.length; ++i) {
62 // Make sure left == right
63 if (bufferDataL[i] != bufferDataR[i]) {
64 testFailed("Rendered buffer left and right channels are not identical.");
65 success = false;
66 break;
69 if (bufferDataL[i] != 0) {
70 // Make sure this index is in sampleOffsets
71 var found = false;
72 for (var j = 0; j < sampleOffsets.length; ++j) {
73 if (sampleOffsets[j] == i) {
74 found = true;
75 break;
78 ++impulseCount;
79 if (!found) {
80 testFailed("Non-zero sample found at sample offset " + i);
81 success = false;
82 ++badOffsetCount;
87 if (impulseCount == sampleOffsets.length) {
88 if (badOffsetCount == 0) {
89 testPassed("Expected number of events found.");
90 } else {
91 testFailed("Expected number of events found, but " + badOffsetCount + " are at incorrect offsets.");
92 success = false;
94 } else {
95 testFailed("Expected " + sampleOffsets.length + " impulses but only found " + impulseCount);
96 success = false;
99 if (success) {
100 testPassed("All events rendered with sample-accuracy.");
101 } else {
102 testFailed("Events NOT rendered with sample-accuracy.");
105 finishJSTest();
108 function runTest() {
109 if (window.testRunner) {
110 testRunner.dumpAsText();
111 testRunner.waitUntilDone();
114 window.jsTestIsAsync = true;
116 // Create offline audio context.
117 context = new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
118 createImpulse();
120 for (var i = 0; i < sampleOffsets.length; ++i) {
121 var timeInSeconds = sampleOffsets[i] / sampleRate;
122 playNote(timeInSeconds);
125 context.oncomplete = checkSampleAccuracy;
126 context.startRendering();
129 runTest();
131 </script>
133 </body>
134 </html>