[JSC] Int52Rep(DoubleRepAnyIntUse) should not call operation function
[WebKit-https.git] / LayoutTests / webaudio / audiobuffersource-loop-comprehensive.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 looping with a variety of loop points.");
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: "loop whole buffer by default with loopStart == loopEnd == 0",
23   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] },
24
25 { description: "loop whole buffer explicitly",
26   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] },
27
28 { description: "loop from middle to end of buffer",
29   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] },
30
31 { description: "loop from start to middle of buffer",
32   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] },
33
34 { description: "loop internally from 4 -> 6",
35   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] },
36
37 { description: "loop internally from 3 -> 7",
38   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] },
39
40 { description: "loop internally from 4 -> 6 with playbackRate of 0.5",
41   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] },
42
43 { description: "loop internally from 4 -> 6 with playbackRate of 1.5",
44   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] },
45
46 { description: "illegal playbackRate of 47 greater than loop length",
47   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] },
48
49 // Try illegal loop-points - they should be ignored and we'll loop the whole buffer.
50
51 { description: "illegal loop: loopStartFrame > loopEndFrame",
52   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] },
53
54 { description: "illegal loop: loopStartFrame == loopEndFrame",
55   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] },
56
57 { description: "illegal loop: loopStartFrame < 0",
58   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] },
59
60 { description: "illegal loop: loopEndFrame > bufferLength",
61   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] },
62
63 ];
64
65 var sampleRate = 44100;
66 var buffer;
67 var bufferFrameLength = 8;
68 var testSpacingFrames = 32;
69 var testSpacingSeconds = testSpacingFrames / sampleRate;
70 var totalRenderLengthFrames = tests.length * testSpacingFrames;
71
72 function runLoopTest(context, testNumber, test) {
73     var source = context.createBufferSource();
74
75     source.buffer = buffer;
76     source.playbackRate.value = test.playbackRate;
77     source.loop = true;
78     source.loopStart = test.loopStartFrame / context.sampleRate;
79     source.loopEnd = test.loopEndFrame / context.sampleRate;
80
81     source.connect(context.destination);
82
83     // Render each test one after the other, spaced apart by testSpacingSeconds.
84     var startTime = testNumber * testSpacingSeconds;
85     var duration = test.renderFrames / context.sampleRate;
86     source.start(startTime);
87     source.stop(startTime + duration);
88 }
89
90 function runTest() {
91     window.jsTestIsAsync = true;
92
93     // Create offline audio context.
94     var context = new webkitOfflineAudioContext(1, totalRenderLengthFrames, sampleRate);
95     buffer = createTestBuffer(context, bufferFrameLength);
96
97     for (var i = 0; i < tests.length; ++i)
98         runLoopTest(context, i, tests[i]);
99
100     context.oncomplete = checkAllTests;
101     context.startRendering();
102 }
103
104 runTest();
105
106 </script>
107 </body>
108 </html>