5 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css"/>
6 <script src="resources/audio-testing.js"></script>
7 <script src="resources/audiobuffersource-testing.js"></script>
8 <script src="../fast/js/resources/js-test-pre.js"></script>
13 <div id="description"></div>
14 <div id="console"></div>
17 description("Tests AudioBufferSourceNode start() with a variety of offsets and durations.");
19 // The following test cases assume an AudioBuffer of length 8 whose PCM data is a linear ramp, 0, 1, 2, 3,...
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] },
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] },
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] },
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] },
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] },
38 // Enable test when AudioBufferSourceNode hack is fixed: https://bugs.webkit.org/show_bug.cgi?id=77224
39 // { description: "start(when, 3_frames, 3_frames): play a middle section with explicit offset and duration",
40 // 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] },
44 var sampleRate = 44100;
46 var bufferFrameLength = 8;
47 var testSpacingFrames = 32;
48 var testSpacingSeconds = testSpacingFrames / sampleRate;
49 var totalRenderLengthFrames = tests.length * testSpacingFrames;
51 function runLoopTest(context, testNumber, test) {
52 var source = context.createBufferSource();
54 source.buffer = buffer;
55 source.playbackRate.value = test.playbackRate;
57 source.connect(context.destination);
59 // Render each test one after the other, spaced apart by testSpacingSeconds.
60 var startTime = testNumber * testSpacingSeconds;
62 if (test.offsetFrame == "none" && test.durationFrames == "none") {
63 source.start(startTime);
64 } else if (test.durationFrames == "none") {
65 var offset = test.offsetFrame / context.sampleRate;
66 source.start(startTime, offset);
68 var offset = test.offsetFrame / context.sampleRate;
69 var duration = test.durationFrames / context.sampleRate;
70 source.start(startTime, offset, duration);
75 if (window.testRunner) {
76 testRunner.dumpAsText();
77 testRunner.waitUntilDone();
80 window.jsTestIsAsync = true;
82 // Create offline audio context.
83 var context = new webkitOfflineAudioContext(1, totalRenderLengthFrames, sampleRate);
84 buffer = createTestBuffer(context, bufferFrameLength);
86 for (var i = 0; i < tests.length; ++i)
87 runLoopTest(context, i, tests[i]);
89 context.oncomplete = checkAllTests;
90 context.startRendering();
94 successfullyParsed = true;
98 <script src="../fast/js/resources/js-test-post.js"></script>