OLD | NEW |
---|---|
(Empty) | |
1 <!doctype html> | |
2 <html> | |
3 <head> | |
4 <title>Test AudioBufferSourceNode looping without explicit duration</title> | |
5 <script src="resources/compatibility.js"></script> | |
6 <script src="resources/audio-testing.js"></script> | |
7 <script src="../resources/js-test.js"></script> | |
8 </head> | |
9 | |
10 <body> | |
11 <script> | |
hongchan
2015/02/12 18:36:58
I think it's better to include the URL to the crbu
Raymond Toy
2015/02/12 21:36:42
Because I ran out of ideas for a good descriptive
Raymond Toy
2015/02/13 20:07:06
Renamed file.
| |
12 description("Test AudioBufferSourceNode looping without explicit duration" ); | |
13 | |
14 var context; | |
15 var buffer; | |
16 var output; | |
17 var expected; | |
18 var sourceFrames = 8; | |
19 var loopCount = 4; | |
20 var renderFrames = sourceFrames * loopCount; | |
21 var sampleRate = 44100; | |
22 | |
23 | |
24 function checkResult(renderedBuffer) { | |
25 var badIndex = -1; | |
26 var success = true; | |
27 | |
28 expected = buffer.getChannelData(0); | |
29 output = renderedBuffer.getChannelData(0); | |
30 | |
31 // Verify the output has the expected data. | |
32 for (var k = 0; k < loopCount; ++k) { | |
33 for (var n = 0; n < sourceFrames; ++n) { | |
34 if (expected[n] != output[n + k * sourceFrames]) { | |
35 if (success) | |
36 badIndex = n + k * sourceFrames; | |
37 success = false; | |
38 } | |
39 } | |
40 } | |
41 | |
42 if (success) { | |
43 testPassed("Source looped correctly"); | |
44 } else { | |
45 testFailed("First incorrect sample at index " + badIndex); | |
46 } | |
47 } | |
48 | |
49 function runTest() { | |
50 window.jsTestIsAsync = true; | |
51 | |
52 context = new OfflineAudioContext(1, renderFrames, sampleRate); | |
53 buffer = createLinearRampBuffer(context, sourceFrames); | |
54 var source = context.createBufferSource(); | |
55 source.buffer = buffer; | |
56 source.connect(context.destination); | |
57 | |
58 // Loop the source, and start the source with an offset, but without a d uration. In this | |
59 // case, the source should loop "forever". The case where the duration is given is covered | |
60 // in other tests. | |
61 source.loop = true; | |
62 source.start(0, 0); | |
63 context.startRendering() | |
64 .then(checkResult) | |
65 .then(function () { finishJSTest(); }); | |
66 } | |
67 | |
68 runTest(); | |
hongchan
2015/02/12 18:36:58
I see this runTest() pattern a lot in our layout t
Raymond Toy
2015/02/12 21:36:42
I was mostly following Chris's existing pattern.
| |
69 </script> | |
70 </body> | |
71 </html> | |
OLD | NEW |