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 looping with a variety of loop points.");
19 // The following test cases assume an AudioBuffer of length 8 whose PCM data is a linear ramp, 0, 1, 2, 3,...
23 { description: "loop whole buffer by default with loopStart == loopEnd == 0",
24 loopStartFrame: 0, loopEndFrame: 0, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
26 { description: "loop whole buffer explicitly",
27 loopStartFrame: 0, loopEndFrame: 8, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
29 { description: "loop from middle to end of buffer",
30 loopStartFrame: 4, loopEndFrame: 8, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,4,5,6,7,4,5,6,7] },
32 { description: "loop from start to middle of buffer",
33 loopStartFrame: 0, loopEndFrame: 4, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3] },
35 { description: "loop internally from 4 -> 6",
36 loopStartFrame: 4, loopEndFrame: 6, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,4,5,4,5,4,5,4,5,4,5] },
38 { description: "loop internally from 3 -> 7",
39 loopStartFrame: 3, loopEndFrame: 7, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,3,4,5,6,3,4,5,6,3] },
41 { description: "loop internally from 4 -> 6 with playbackRate of 0.5",
42 loopStartFrame: 4, loopEndFrame: 6, renderFrames: 16, playbackRate: 0.5, expected: [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 4, 4.5, 5, 5.5] },
44 { description: "loop internally from 4 -> 6 with playbackRate of 1.5",
45 loopStartFrame: 4, loopEndFrame: 6, renderFrames: 16, playbackRate: 1.5, expected: [0, 1.5, 3, 4.5, 4, 5.5, 5, 4.5, 4, 5.5, 5, 4.5, 4, 5.5, 5, 4.5] },
47 { description: "illegal playbackRate of 47 greater than loop length",
48 loopStartFrame: 4, loopEndFrame: 6, renderFrames: 16, playbackRate: 47, expected: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] },
50 // Try illegal loop-points - they should be ignored and we'll loop the whole buffer.
52 { description: "illegal loop: loopStartFrame > loopEndFrame",
53 loopStartFrame: 7, loopEndFrame: 3, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
55 { description: "illegal loop: loopStartFrame == loopEndFrame",
56 loopStartFrame: 3, loopEndFrame: 3, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
58 { description: "illegal loop: loopStartFrame < 0",
59 loopStartFrame: -45, loopEndFrame: 3, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
61 { description: "illegal loop: loopEndFrame > bufferLength",
62 loopStartFrame: 0, loopEndFrame: 30000, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
66 var sampleRate = 44100;
68 var bufferFrameLength = 8;
69 var testSpacingFrames = 32;
70 var testSpacingSeconds = testSpacingFrames / sampleRate;
71 var totalRenderLengthFrames = tests.length * testSpacingFrames;
73 function runLoopTest(context, testNumber, test) {
74 var source = context.createBufferSource();
76 source.buffer = buffer;
77 source.playbackRate.value = test.playbackRate;
79 source.loopStart = test.loopStartFrame / context.sampleRate;
80 source.loopEnd = test.loopEndFrame / context.sampleRate;
82 source.connect(context.destination);
84 // Render each test one after the other, spaced apart by testSpacingSeconds.
85 var startTime = testNumber * testSpacingSeconds;
86 var duration = test.renderFrames / context.sampleRate;
87 source.start(startTime);
88 source.stop(startTime + duration);
92 if (window.testRunner) {
93 testRunner.dumpAsText();
94 testRunner.waitUntilDone();
97 window.jsTestIsAsync = true;
99 // Create offline audio context.
100 var context = new webkitOfflineAudioContext(1, totalRenderLengthFrames, sampleRate);
101 buffer = createTestBuffer(context, bufferFrameLength);
103 for (var i = 0; i < tests.length; ++i)
104 runLoopTest(context, i, tests[i]);
106 context.oncomplete = checkAllTests;
107 context.startRendering();
111 successfullyParsed = true;
115 <script src="../fast/js/resources/js-test-post.js"></script>