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