Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / audiobuffersource-loop-comprehensive.html
blobb012b24eca3c282936a308aff0de19ff37e4e206
1 <!DOCTYPE html>
3 <html>
4 <head>
5 <script src="resources/audio-testing.js"></script>
6 <script src="resources/compatibility.js"></script>
7 <script src="resources/audiobuffersource-testing.js"></script>
8 <script src="../resources/js-test.js"></script>
9 </head>
11 <body>
12 <script>
13 description("Tests AudioBufferSourceNode looping with a variety of loop points.");
15 // The following test cases assume an AudioBuffer of length 8 whose PCM data is a linear ramp, 0, 1, 2, 3,...
16 // |description| is optional and will be computed from the other parameters. |offsetFrame| is
17 // optional and defaults to 0.
19 var tests = [
21 { description: "loop whole buffer by default with loopStart == loopEnd == 0",
22 loopStartFrame: 0,
23 loopEndFrame: 0,
24 renderFrames: 16,
25 playbackRate: 1,
26 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
28 { description: "loop whole buffer explicitly",
29 loopStartFrame: 0,
30 loopEndFrame: 8,
31 renderFrames: 16,
32 playbackRate: 1,
33 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
35 { description: "loop from middle to end of buffer",
36 loopStartFrame: 4,
37 loopEndFrame: 8,
38 renderFrames: 16,
39 playbackRate: 1,
40 expected: [0,1,2,3,4,5,6,7,4,5,6,7,4,5,6,7] },
42 { description: "loop from start to middle of buffer",
43 loopStartFrame: 0,
44 loopEndFrame: 4,
45 renderFrames: 16,
46 playbackRate: 1,
47 expected: [0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3] },
49 { loopStartFrame: 4,
50 loopEndFrame: 6,
51 renderFrames: 16,
52 playbackRate: 1,
53 expected: [0,1,2,3,4,5,4,5,4,5,4,5,4,5,4,5] },
55 { loopStartFrame: 3,
56 loopEndFrame: 7,
57 renderFrames: 16,
58 playbackRate: 1,
59 expected: [0,1,2,3,4,5,6,3,4,5,6,3,4,5,6,3] },
61 { loopStartFrame: 4,
62 loopEndFrame: 6,
63 renderFrames: 16,
64 playbackRate: 0.5,
65 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] },
67 { loopStartFrame: 4,
68 loopEndFrame: 6,
69 renderFrames: 16,
70 playbackRate: 1.5,
71 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] },
73 // Offset past loop end, so playback starts at loop start
74 { loopStartFrame: 2,
75 loopEndFrame: 5,
76 renderFrames: 16,
77 playbackRate: 1,
78 offsetFrame: 6,
79 expected: [2, 3, 4, 2, 3, 4, 2, 3, 4, 2, 3, 4, 2, 3, 4, 2] },
81 // Offset before loop start, so start at offset and continue
82 { loopStartFrame: 3,
83 loopEndFrame: 6,
84 renderFrames: 16,
85 playbackRate: 1,
86 offsetFrame: 1,
87 expected: [1, 2, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4] },
89 // Offset between loop start and loop end, so start at offset and continue
90 { loopStartFrame: 3,
91 loopEndFrame: 6,
92 renderFrames: 16,
93 playbackRate: 1,
94 offsetFrame: 4,
95 expected: [4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4] },
97 { description: "illegal playbackRate of 47 greater than loop length",
98 loopStartFrame: 4,
99 loopEndFrame: 6,
100 renderFrames: 16,
101 playbackRate: 47,
102 expected: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] },
104 // Try illegal loop-points - they should be ignored and we'll loop the whole buffer.
106 { description: "illegal loop: loopStartFrame > loopEndFrame",
107 loopStartFrame: 7,
108 loopEndFrame: 3,
109 renderFrames: 16,
110 playbackRate: 1,
111 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
113 { description: "illegal loop: loopStartFrame == loopEndFrame",
114 loopStartFrame: 3,
115 loopEndFrame: 3,
116 renderFrames: 16,
117 playbackRate: 1,
118 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
120 { description: "illegal loop: loopStartFrame < 0",
121 loopStartFrame: -8,
122 loopEndFrame: 3,
123 renderFrames: 16,
124 playbackRate: 1,
125 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
127 { description: "illegal loop: loopEndFrame > bufferLength",
128 loopStartFrame: 0,
129 loopEndFrame: 30000,
130 renderFrames: 16,
131 playbackRate: 1,
132 expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
134 // Start a loop with a duration longer than the buffer. The output should be the data from frame 1
135 // to 6, and then looping from 3 to 5 until 20 frames have been played.
136 { description: "loop from 3 -> 6 with offset 1 for 20 frames",
137 loopStartFrame: 3,
138 loopEndFrame: 6,
139 playbackRate: 1,
140 offsetFrame: 1,
141 renderFrames: 30,
142 durationFrames: 20,
143 expected: [1, 2, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
145 // Start a loop with a duration less than the length of the looping frames. The output should be
146 // the data from frame 1 to 3, and then stopping because duration = 3
147 { description: "loop from 3 -> 8 with offset 1 for 3 frames",
148 loopStartFrame: 3,
149 loopEndFrame: 8,
150 playbackRate: 1,
151 offsetFrame: 1,
152 durationFrames: 3,
153 renderFrames: 30,
154 expected: [1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] },
156 // Start a loop with a duration less than the length of the looping frames. The output should be
157 // the data from frame 1 to 3, and then stopping because duration = 3
158 { description: "loop from 3 -> 8 with offset 7 for 3 frames",
159 loopStartFrame: 3,
160 loopEndFrame: 8,
161 playbackRate: 1,
162 offsetFrame: 7,
163 durationFrames: 3,
164 renderFrames: 30,
165 expected: [7, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }
169 var sampleRate = 44100;
170 var buffer;
171 var bufferFrameLength = 8;
172 var testSpacingFrames = 32;
173 var testSpacingSeconds = testSpacingFrames / sampleRate;
174 var totalRenderLengthFrames = tests.length * testSpacingFrames;
176 function runLoopTest(context, testNumber, test) {
177 var source = context.createBufferSource();
179 source.buffer = buffer;
180 source.playbackRate.value = test.playbackRate;
181 source.loop = true;
182 source.loopStart = test.loopStartFrame / context.sampleRate;
183 source.loopEnd = test.loopEndFrame / context.sampleRate;
185 var offset = test.offsetFrame ? test.offsetFrame / context.sampleRate : 0;
187 source.connect(context.destination);
189 // Render each test one after the other, spaced apart by testSpacingSeconds.
190 var startTime = testNumber * testSpacingSeconds;
192 // If durationFrames is given, run the test for the specified duration.
193 if (test.durationFrames) {
194 if (!test.renderFrames) {
195 testFailed("renderFrames is required for test " + testNumber + ": " + test.description);
196 } else {
197 if (test.durationFrames > testSpacingFrames || test.durationFrames < 0) {
198 testFailed("Test " + testNumber
199 + ": durationFrames (" + test.durationFrames + ") outside the range [0, "
200 + testSpacingFrames + "]");
202 source.start(startTime, offset, test.durationFrames / context.sampleRate);
204 } else if (test.renderFrames) {
205 var duration = test.renderFrames / context.sampleRate;
206 if (test.renderFrames > testSpacingFrames || test.renderFrames < 0) {
207 testFailed("Test " + testNumber
208 + ": renderFrames (" + test.renderFrames + ") outside the range [0, "
209 + testSpacingFrames + "]");
211 source.start(startTime, offset);
212 source.stop(startTime + duration);
213 } else {
214 testFailed("Test " + testNumber + " must specify renderFrames and possibly durationFrames");
218 function runTest() {
219 window.jsTestIsAsync = true;
221 // Create offline audio context.
222 var context = new OfflineAudioContext(1, totalRenderLengthFrames, sampleRate);
223 buffer = createTestBuffer(context, bufferFrameLength);
225 for (var i = 0; i < tests.length; ++i)
226 runLoopTest(context, i, tests[i]);
228 context.oncomplete = checkAllTests;
229 context.startRendering();
232 runTest();
233 successfullyParsed = true;
235 </script>
237 </body>
238 </html>