OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title> |
| 5 audiobuffersource-start.html |
| 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 <script src="../resources/audiobuffersource-testing.js"></script> |
| 12 </head> |
| 13 <body> |
| 14 <script id="layout-test-code"> |
| 15 let audit = Audit.createTaskRunner(); |
2 | 16 |
3 <html> | 17 // The following test cases assume an AudioBuffer of length 8 whose PCM |
4 <head> | 18 // data is a linear ramp, 0, 1, 2, 3,... |
5 <script src="../../resources/testharness.js"></script> | |
6 <script src="../../resources/testharnessreport.js"></script> | |
7 <script src="../resources/audit-util.js"></script> | |
8 <script src="../resources/audit.js"></script> | |
9 <script src="../resources/audiobuffersource-testing.js"></script> | |
10 </head> | |
11 | 19 |
12 <body> | 20 let tests = [ |
13 | 21 |
14 <script> | 22 { |
15 let audit = Audit.createTaskRunner(); | 23 description: |
| 24 'start(when): implicitly play whole buffer from beginning to end', |
| 25 offsetFrame: 'none', |
| 26 durationFrames: 'none', |
| 27 renderFrames: 16, |
| 28 playbackRate: 1, |
| 29 expected: [0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0] |
| 30 }, |
16 | 31 |
17 // The following test cases assume an AudioBuffer of length 8 whose PCM data is
a linear ramp, 0, 1, 2, 3,... | 32 { |
| 33 description: |
| 34 'start(when, 0): play whole buffer from beginning to end explicitl
y giving offset of 0', |
| 35 offsetFrame: 0, |
| 36 durationFrames: 'none', |
| 37 renderFrames: 16, |
| 38 playbackRate: 1, |
| 39 expected: [0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0] |
| 40 }, |
18 | 41 |
19 let tests = [ | 42 { |
| 43 description: |
| 44 'start(when, 0, 8_frames): play whole buffer from beginning to end
explicitly giving offset of 0 and duration of 8 frames', |
| 45 offsetFrame: 0, |
| 46 durationFrames: 8, |
| 47 renderFrames: 16, |
| 48 playbackRate: 1, |
| 49 expected: [0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0] |
| 50 }, |
20 | 51 |
21 { description: "start(when): implicitly play whole buffer from beginning to end"
, | 52 { |
22 offsetFrame: "none", durationFrames: "none", renderFrames: 16, playbackRate: 1
, expected: [0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0] }, | 53 description: |
| 54 'start(when, 4_frames): play with explicit non-zero offset', |
| 55 offsetFrame: 4, |
| 56 durationFrames: 'none', |
| 57 renderFrames: 16, |
| 58 playbackRate: 1, |
| 59 expected: [4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] |
| 60 }, |
23 | 61 |
24 { description: "start(when, 0): play whole buffer from beginning to end explicit
ly giving offset of 0", | 62 { |
25 offsetFrame: 0, durationFrames: "none", renderFrames: 16, playbackRate: 1, exp
ected: [0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0] }, | 63 description: |
| 64 'start(when, 4_frames, 4_frames): play with explicit non-zero offs
et and duration', |
| 65 offsetFrame: 4, |
| 66 durationFrames: 4, |
| 67 renderFrames: 16, |
| 68 playbackRate: 1, |
| 69 expected: [4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] |
| 70 }, |
26 | 71 |
27 { description: "start(when, 0, 8_frames): play whole buffer from beginning to en
d explicitly giving offset of 0 and duration of 8 frames", | 72 { |
28 offsetFrame: 0, durationFrames: 8, renderFrames: 16, playbackRate: 1, expected
: [0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0] }, | 73 description: |
| 74 'start(when, 7_frames): play with explicit non-zero offset near en
d of buffer', |
| 75 offsetFrame: 7, |
| 76 durationFrames: 1, |
| 77 renderFrames: 16, |
| 78 playbackRate: 1, |
| 79 expected: [7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] |
| 80 }, |
29 | 81 |
30 { description: "start(when, 4_frames): play with explicit non-zero offset", | 82 { |
31 offsetFrame: 4, durationFrames: "none", renderFrames: 16, playbackRate: 1, exp
ected: [4,5,6,7,0,0,0,0,0,0,0,0,0,0,0,0] }, | 83 description: |
| 84 'start(when, 8_frames): play with explicit offset at end of buffer
', |
| 85 offsetFrame: 8, |
| 86 durationFrames: 0, |
| 87 renderFrames: 16, |
| 88 playbackRate: 1, |
| 89 expected: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] |
| 90 }, |
32 | 91 |
33 { description: "start(when, 4_frames, 4_frames): play with explicit non-zero off
set and duration", | 92 { |
34 offsetFrame: 4, durationFrames: 4, renderFrames: 16, playbackRate: 1, expected
: [4,5,6,7,0,0,0,0,0,0,0,0,0,0,0,0] }, | 93 description: |
| 94 'start(when, 9_frames): play with explicit offset past end of buff
er', |
| 95 offsetFrame: 8, |
| 96 durationFrames: 0, |
| 97 renderFrames: 16, |
| 98 playbackRate: 1, |
| 99 expected: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] |
| 100 }, |
35 | 101 |
36 { description: "start(when, 7_frames): play with explicit non-zero offset near e
nd of buffer", | 102 // When the duration exceeds the buffer, just play to the end of the |
37 offsetFrame: 7, durationFrames: 1, renderFrames: 16, playbackRate: 1, expected
: [7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] }, | 103 // buffer. (This is different from the case when we're looping, which is |
| 104 // tested in loop-comprehensive.) |
| 105 { |
| 106 description: |
| 107 'start(when, 0, 15_frames): play with whole buffer, with long dura
tion (clipped)', |
| 108 offsetFrame: 0, |
| 109 durationFrames: 15, |
| 110 renderFrames: 16, |
| 111 playbackRate: 1, |
| 112 expected: [0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0] |
| 113 }, |
38 | 114 |
39 { description: "start(when, 8_frames): play with explicit offset at end of buffe
r", | 115 // Enable test when AudioBufferSourceNode hack is fixed: |
40 offsetFrame: 8, durationFrames: 0, renderFrames: 16, playbackRate: 1, expected
: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] }, | 116 // https://bugs.webkit.org/show_bug.cgi?id=77224 { description: |
| 117 // "start(when, 3_frames, 3_frames): play a middle section with explicit |
| 118 // offset and duration", |
| 119 // offsetFrame: 3, durationFrames: 3, renderFrames: 16, playbackRate: |
| 120 // 1, expected: [4,5,6,7,0,0,0,0,0,0,0,0,0,0,0,0] }, |
41 | 121 |
42 { description: "start(when, 9_frames): play with explicit offset past end of buf
fer", | 122 ]; |
43 offsetFrame: 8, durationFrames: 0, renderFrames: 16, playbackRate: 1, expected
: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] }, | |
44 | 123 |
45 // When the duration exceeds the buffer, just play to the end of the buffer. | 124 let sampleRate = 44100; |
46 // (This is different from the case when we're looping, which is tested in loop-
comprehensive.) | 125 let buffer; |
47 { description: "start(when, 0, 15_frames): play with whole buffer, with long dur
ation (clipped)", | 126 let bufferFrameLength = 8; |
48 offsetFrame: 0, durationFrames: 15, renderFrames: 16, playbackRate: 1, expecte
d: [0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0] }, | 127 let testSpacingFrames = 32; |
49 | 128 let testSpacingSeconds = testSpacingFrames / sampleRate; |
50 // Enable test when AudioBufferSourceNode hack is fixed: https://bugs.webkit.org
/show_bug.cgi?id=77224 | 129 let totalRenderLengthFrames = tests.length * testSpacingFrames; |
51 // { description: "start(when, 3_frames, 3_frames): play a middle section with e
xplicit offset and duration", | |
52 // offsetFrame: 3, durationFrames: 3, renderFrames: 16, playbackRate: 1, expec
ted: [4,5,6,7,0,0,0,0,0,0,0,0,0,0,0,0] }, | |
53 | 130 |
54 ]; | 131 function runLoopTest(context, testNumber, test) { |
| 132 let source = context.createBufferSource(); |
55 | 133 |
56 let sampleRate = 44100; | 134 source.buffer = buffer; |
57 let buffer; | 135 source.playbackRate.value = test.playbackRate; |
58 let bufferFrameLength = 8; | |
59 let testSpacingFrames = 32; | |
60 let testSpacingSeconds = testSpacingFrames / sampleRate; | |
61 let totalRenderLengthFrames = tests.length * testSpacingFrames; | |
62 | 136 |
63 function runLoopTest(context, testNumber, test) { | 137 source.connect(context.destination); |
64 let source = context.createBufferSource(); | |
65 | 138 |
66 source.buffer = buffer; | 139 // Render each test one after the other, spaced apart by |
67 source.playbackRate.value = test.playbackRate; | 140 // testSpacingSeconds. |
| 141 let startTime = testNumber * testSpacingSeconds; |
68 | 142 |
69 source.connect(context.destination); | 143 if (test.offsetFrame == 'none' && test.durationFrames == 'none') { |
| 144 source.start(startTime); |
| 145 } else if (test.durationFrames == 'none') { |
| 146 let offset = test.offsetFrame / context.sampleRate; |
| 147 source.start(startTime, offset); |
| 148 } else { |
| 149 let offset = test.offsetFrame / context.sampleRate; |
| 150 let duration = test.durationFrames / context.sampleRate; |
| 151 source.start(startTime, offset, duration); |
| 152 } |
| 153 } |
70 | 154 |
71 // Render each test one after the other, spaced apart by testSpacingSeconds. | 155 audit.define( |
72 let startTime = testNumber * testSpacingSeconds; | 156 'Tests AudioBufferSourceNode start()', function(task, should) { |
| 157 // Create offline audio context. |
| 158 let context = |
| 159 new OfflineAudioContext(1, totalRenderLengthFrames, sampleRate); |
| 160 buffer = createTestBuffer(context, bufferFrameLength); |
73 | 161 |
74 if (test.offsetFrame == "none" && test.durationFrames == "none") { | 162 for (let i = 0; i < tests.length; ++i) |
75 source.start(startTime); | 163 runLoopTest(context, i, tests[i]); |
76 } else if (test.durationFrames == "none") { | |
77 let offset = test.offsetFrame / context.sampleRate; | |
78 source.start(startTime, offset); | |
79 } else { | |
80 let offset = test.offsetFrame / context.sampleRate; | |
81 let duration = test.durationFrames / context.sampleRate; | |
82 source.start(startTime, offset, duration); | |
83 } | |
84 } | |
85 | 164 |
86 audit.define("Tests AudioBufferSourceNode start()", function (task, should) { | 165 context.startRendering().then(function(audioBuffer) { |
87 // Create offline audio context. | 166 checkAllTests(audioBuffer, should); |
88 let context = new OfflineAudioContext(1, totalRenderLengthFrames, sampleRate
); | 167 task.done(); |
89 buffer = createTestBuffer(context, bufferFrameLength); | 168 }); |
| 169 }); |
90 | 170 |
91 for (let i = 0; i < tests.length; ++i) | 171 audit.run(); |
92 runLoopTest(context, i, tests[i]); | 172 </script> |
93 | 173 </body> |
94 context.startRendering() | |
95 .then(function (audioBuffer) { | |
96 checkAllTests(audioBuffer, should); | |
97 task.done(); | |
98 }); | |
99 }); | |
100 | |
101 audit.run(); | |
102 </script> | |
103 | |
104 </body> | |
105 </html> | 174 </html> |
OLD | NEW |