OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html> | |
3 | |
4 <head> | |
5 <title>Test AudioBufferSourceNode looping without explicit duration</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 AudioBufferSourceNode looping without explicit duration"); | |
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 short linear ramp and enable looping. The test will | |
23 // verify that the ramp was looped the appropriate number of times. | |
24 audit.defineTask('loop-count', function (done) { | |
25 // How many loops of the source we want to render. Any whole number | |
26 // greater than 1 will work. | |
27 var loopCount = 4; | |
28 var sourceFrames = 8; | |
29 var renderFrames = sourceFrames * loopCount; | |
30 | |
31 var context = new OfflineAudioContext(1, renderFrames, sampleRate); | |
32 var source = context.createBufferSource(); | |
33 var linearRampBuffer = createLinearRampBuffer(context, sourceFrames); | |
34 | |
35 source.buffer = linearRampBuffer; | |
36 source.connect(context.destination); | |
37 | |
38 // Enable looping and start the source with an offset, but without a | |
39 // duration. In this case, the source should loop "forever". | |
40 // See crbug.com/457009. | |
41 source.loop = true; | |
42 source.start(0, 0); | |
43 | |
44 context.startRendering().then(function (renderedBuffer) { | |
45 var badIndex = -1; | |
46 var success = true; | |
47 | |
48 var actual = renderedBuffer.getChannelData(0); | |
49 var linearRamp = linearRampBuffer.getChannelData(0); | |
50 | |
51 // Manually create a |loopCount| copies of linear ramps. | |
52 var expected = new Float32Array(linearRamp.length * loopCount); | |
53 for (var i = 0; i < loopCount; i++) | |
54 expected.set(linearRamp, linearRamp.length * i); | |
55 | |
56 // The actual output should match the created loop. | |
57 Should('The output of actual and expected loops', actual) | |
58 .beEqualToArray(expected); | |
59 }).then(done); | |
60 }); | |
61 | |
62 // Task: Test that looping an AudioBufferSource works correctly if the | |
63 // source is started and the buffer is assigned later, but before the source | |
64 // would start. | |
65 audit.defineTask('delayed-start', function (done) { | |
66 var renderDuration = 2; | |
67 var context = new OfflineAudioContext(2, sampleRate * renderDuration, samp
leRate); | |
68 var linearRampBuffer = createLinearRampBuffer(context, 128); | |
69 | |
70 var normal = context.createBufferSource(); | |
71 var delayed = context.createBufferSource(); | |
72 var merger = context.createChannelMerger(2); | |
73 | |
74 // Connect the normally started source to the left channel, and the | |
75 // delayed to the right channel. | |
76 normal.connect(merger, 0, 0); | |
77 delayed.connect(merger, 0, 1); | |
78 merger.connect(context.destination); | |
79 | |
80 normal.buffer = linearRampBuffer; | |
81 normal.loop = true; | |
82 delayed.loop = true; | |
83 | |
84 normal.start(1, 0); | |
85 delayed.start(1, 0); | |
86 | |
87 // Assign the buffer to the delayed source node at 0.5 second. | |
88 context.suspend(0.5).then(function () { | |
89 delayed.buffer = linearRampBuffer; | |
90 context.resume(); | |
91 }); | |
92 | |
93 context.startRendering().then(function (buffer) { | |
94 // The left and right channel must match regardless of the timing | |
95 // of buffer assignment. | |
96 Should('The content of the left and right channel', | |
97 buffer.getChannelData(0)).beEqualToArray(buffer.getChannelData(1)); | |
98 }).then(done); | |
99 }); | |
100 | |
101 audit.defineTask('finish', function (done) { | |
102 finishJSTest(); | |
103 done(); | |
104 }); | |
105 | |
106 audit.runTasks( | |
107 'loop-count', | |
108 'delayed-start', | |
109 'finish' | |
110 ); | |
111 | |
112 successfullyParsed = true; | |
113 </script> | |
114 </body> | |
115 | |
116 </html> | |
OLD | NEW |