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