Refactoring: Pull all fullscreen code out of Document and into its own helper class
[WebKit-https.git] / LayoutTests / webaudio / audiobuffersource-start.html
1 <!DOCTYPE html>
2
3 <html>
4 <head>
5 <script src="resources/audio-testing.js"></script>
6 <script src="resources/audiobuffersource-testing.js"></script>
7 <script src="../resources/js-test.js"></script>
8 </head>
9
10 <body>
11
12 <div id="description"></div>
13 <div id="console"></div>
14
15 <script>
16 description("Tests AudioBufferSourceNode start() with a variety of offsets and durations.");
17
18 // The following test cases assume an AudioBuffer of length 8 whose PCM data is a linear ramp, 0, 1, 2, 3,...
19
20 var tests = [
21
22 { description: "start(when): implicitly play whole buffer from beginning to end",
23   offsetFrame: "none", durationFrames: "none", renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0] },
24
25 { description: "start(when, 0): play whole buffer from beginning to end explicitly giving offset of 0",
26   offsetFrame: 0, durationFrames: "none", renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0] },
27
28 { description: "start(when, 0, 8_frames): play whole buffer from beginning to end explicitly giving offset of 0 and duration of 8 frames",
29   offsetFrame: 0, durationFrames: 8, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0] },
30
31 { description: "start(when, 4_frames): play with explicit non-zero offset",
32   offsetFrame: 4, durationFrames: "none", renderFrames: 16, playbackRate: 1, expected: [4,5,6,7,0,0,0,0,0,0,0,0,0,0,0,0] },
33
34 { description: "start(when, 4_frames, 4_frames): play with explicit non-zero offset and duration",
35   offsetFrame: 4, durationFrames: 4, renderFrames: 16, playbackRate: 1, expected: [4,5,6,7,0,0,0,0,0,0,0,0,0,0,0,0] },
36
37 // Enable test when AudioBufferSourceNode hack is fixed: https://bugs.webkit.org/show_bug.cgi?id=77224
38 // { description: "start(when, 3_frames, 3_frames): play a middle section with explicit offset and duration",
39 //   offsetFrame: 3, durationFrames: 3, renderFrames: 16, playbackRate: 1, expected: [4,5,6,7,0,0,0,0,0,0,0,0,0,0,0,0] },
40
41 ];
42
43 var sampleRate = 44100;
44 var buffer;
45 var bufferFrameLength = 8;
46 var testSpacingFrames = 32;
47 var testSpacingSeconds = testSpacingFrames / sampleRate;
48 var totalRenderLengthFrames = tests.length * testSpacingFrames;
49
50 function runLoopTest(context, testNumber, test) {
51     var source = context.createBufferSource();
52
53     source.buffer = buffer;
54     source.playbackRate.value = test.playbackRate;
55
56     source.connect(context.destination);
57
58     // Render each test one after the other, spaced apart by testSpacingSeconds.
59     var startTime = testNumber * testSpacingSeconds;
60
61     if (test.offsetFrame == "none" && test.durationFrames == "none") {
62         source.start(startTime);
63     } else if (test.durationFrames == "none") {
64         var offset = test.offsetFrame / context.sampleRate;
65         source.start(startTime, offset);
66     } else {
67         var offset = test.offsetFrame / context.sampleRate;
68         var duration = test.durationFrames / context.sampleRate;
69         source.start(startTime, offset, duration);
70     }
71 }
72
73 function runTest() {
74     window.jsTestIsAsync = true;
75
76     // Create offline audio context.
77     var context = new webkitOfflineAudioContext(1, totalRenderLengthFrames, sampleRate);
78     buffer = createTestBuffer(context, bufferFrameLength);
79
80     for (var i = 0; i < tests.length; ++i)
81         runLoopTest(context, i, tests[i]);
82
83     context.oncomplete = checkAllTests;
84     context.startRendering();
85 }
86
87 runTest();
88
89 </script>
90 </body>
91 </html>