OLD | NEW |
| (Empty) |
1 <!doctype html> | |
2 <html> | |
3 <head> | |
4 <script src="../resources/js-test.js"></script> | |
5 <script src="resources/compatibility.js"></script> | |
6 <script src="resources/audit-util.js"></script> | |
7 <script src="resources/audio-testing.js"></script> | |
8 </head> | |
9 | |
10 <body> | |
11 <script> | |
12 description('Test synchronous graph manipulation with OfflineAudioContext.
suspend() and OfflineAudioContext.resume().'); | |
13 window.jsTestIsAsync = true; | |
14 | |
15 var context; | |
16 var renderQuantum = 128; | |
17 var renderDuration = 3; | |
18 | |
19 // The sample rate is multiple of the rendering quantum, so suspension | |
20 // times fall in to the render quantum boundary. | |
21 var sampleRate = renderQuantum * 100; | |
22 | |
23 context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRa
te); | |
24 | |
25 // Create a constant buffer of 1.0. | |
26 var constantBuffer = createConstantBuffer(context, 1, 1.0); | |
27 var constantSource = context.createBufferSource(); | |
28 constantSource.buffer = constantBuffer; | |
29 constantSource.loop = true; | |
30 | |
31 // The audio output from the beginning (0.0 second) to the first suspend | |
32 // time should be 0.0 because there is no connection to the destination. | |
33 | |
34 // Suspend at 1 second and activate the source node. The audio output | |
35 // should be 1.0 from |suspendTime1| to the next suspension. | |
36 var suspendTime1 = 1; | |
37 context.suspend(suspendTime1).then(function () { | |
38 if (context.currentTime === suspendTime1) | |
39 testPassed('Context is suspended at ' + suspendTime1 * sampleRate + '
frame as expected.'); | |
40 | |
41 constantSource.connect(context.destination); | |
42 constantSource.start(); | |
43 testPassed('A constant buffer is connected to destination and started at
' + | |
44 suspendTime1 * sampleRate + ' frame.'); | |
45 | |
46 context.resume(); | |
47 }); | |
48 | |
49 // Suspend at 2 seconds and disconnect the node. The audio output should | |
50 // be 0.0 from |suspendTime2| to the end. | |
51 var suspendTime2 = 2; | |
52 context.suspend(suspendTime2).then(function () { | |
53 if (context.currentTime === suspendTime2) | |
54 testPassed('Context is suspended at ' + suspendTime2 * sampleRate + '
frame as expected.'); | |
55 | |
56 constantSource.disconnect(); | |
57 testPassed('A constant buffer is disconnected at ' + suspendTime2 * samp
leRate + ' frame.'); | |
58 | |
59 context.resume(); | |
60 }); | |
61 | |
62 context.startRendering().then(function (buffer) { | |
63 verifyResult(buffer); | |
64 finishJSTest(); | |
65 }); | |
66 | |
67 function verifyResult(buffer) { | |
68 var data = buffer.getChannelData(0); | |
69 | |
70 var suspendIndex1 = suspendTime1 * sampleRate; | |
71 var suspendIndex2 = suspendTime2 * sampleRate; | |
72 var endIndex = renderDuration * sampleRate; | |
73 | |
74 // Split the rendered buffer into 3 segments: | |
75 // [0, suspendIndex1), [suspendIndex1, suspendIndex2), [suspendIndex2, | |
76 // endIndex). | |
77 var subarray0 = data.subarray(0, suspendIndex1); | |
78 var subarray1 = data.subarray(suspendIndex1, suspendIndex2); | |
79 var subarray2 = data.subarray(suspendIndex2, endIndex); | |
80 | |
81 // Each segment should contain a constant value of 0, 1 and 0 | |
82 // respectively. | |
83 Should('Buffer frame [0, ' + suspendIndex1 + ')', subarray0).beConstant
ValueOf(0); | |
84 Should('Buffer frame [' + suspendIndex1 + ', ' + suspendIndex2 + ')', su
barray1) | |
85 .beConstantValueOf(1); | |
86 Should('Buffer frame [' + suspendIndex2 + ', ' + endIndex + ')', subarra
y2) | |
87 .beConstantValueOf(0); | |
88 } | |
89 | |
90 successfullyParsed = true; | |
91 </script> | |
92 | |
93 </body> | |
94 </html> | |
OLD | NEW |