OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html> | |
3 | |
4 <head> | |
5 <title>Test AudioBufferSourceNode premature loop stop</title> | |
6 <script src="../resources/js-test.js"></script> | |
7 <script src="resources/compatibility.js"></script> | |
8 <script src="resources/audit-util.js"></script> | |
9 <script src="resources/audio-testing.js"></script> | |
10 </head> | |
11 | |
12 <body> | |
13 <script> | |
14 description("Test if AudioBufferSourceNode stops prematurely after the loop
attribute change."); | |
15 window.jsTestIsAsync = true; | |
16 | |
17 // Reasonably low sample rate for the optimum test speed. | |
18 var sampleRate = 4096; | |
19 | |
20 var audit = Audit.createTaskRunner(); | |
21 | |
22 // Task: Create a buffer with 3 regions filled with constant value of [1, 2, | |
23 // 3]. Then set a loop range over the second region. Start the loop and | |
24 // disable it in the middle of looping. Verify the rendered buffer has the | |
25 // entire content including the looped region. | |
26 audit.defineTask('premature-loop-stop', function (done) { | |
27 var regionValues = [1, 2, 3]; | |
28 | |
29 // The region length is 2 * render quantum size to be able to suspend the | |
30 // rendering at the half of the region. | |
31 var regionLength = 256; | |
32 | |
33 // The test will repeat the second region 3 times, thus the rendered audio | |
34 // have the length of 5 * regionLength. | |
35 var context = new OfflineAudioContext(1, 5 * regionLength, sampleRate); | |
36 | |
37 // Create 3 constant buffers of [1, 2, 3] and concatenate them together: | |
38 // | 1 | 2 | 3 | | |
39 var testBuffer = context.createBuffer(1, 3 * regionLength, sampleRate); | |
40 var testChannel = testBuffer.getChannelData(0); | |
41 for (var i = 0; i < regionValues.length; i++) { | |
42 var region = createConstantBuffer(context, regionLength, regionValues[i]
); | |
43 testChannel.set(region.getChannelData(0), regionLength * i);; | |
44 } | |
45 | |
46 var source = context.createBufferSource(); | |
47 source.connect(context.destination); | |
48 | |
49 source.buffer = testBuffer; | |
50 source.loop = true; | |
51 | |
52 // Set loop points over the region 2. | |
53 source.loopStart = regionLength/sampleRate; | |
54 source.loopEnd = 2 * regionLength/sampleRate; | |
55 | |
56 source.start(); | |
57 | |
58 // Disengage the loop at |3.5 * regionLength / sampleRate| which is the | |
59 // end of 7th rendering quantum and also the half of the third iteration | |
60 // of region #2. | |
61 context.suspend(3.5 * regionLength/sampleRate).then(function () { | |
62 source.loop = false; | |
63 context.resume(); | |
64 }); | |
65 | |
66 context.startRendering().then(function (renderedBuffer) { | |
67 var channel = renderedBuffer.getChannelData(0); | |
68 | |
69 // Verify if the rendered buffer has the following structure: | |
70 // | 1 | 2 | 2 | 2 | 3 | | |
71 var region1 = channel.subarray(0, regionLength - 1); | |
72 var region2 = channel.subarray(regionLength, 4 * regionLength - 1); | |
73 var region3 = channel.subarray(4 * regionLength, 5 * regionLength - 1); | |
74 | |
75 Should('Region #1', region1).beConstantValueOf(1); | |
76 Should('Region #2 (looped)', region2).beConstantValueOf(2); | |
77 Should('Region #3', region3).beConstantValueOf(3); | |
78 }).then(done); | |
79 }); | |
80 | |
81 audit.defineTask('finish', function (done) { | |
82 finishJSTest(); | |
83 done(); | |
84 }); | |
85 | |
86 audit.runTasks(); | |
87 | |
88 successfullyParsed = true; | |
89 </script> | |
90 </body> | |
91 | |
92 </html> | |
OLD | NEW |