Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/offlineaudiocontext-suspend-resume-graph-manipulation.html

Issue 1405413004: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating UseCounter.h after L-G-T-M Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/audio-testing.js"></script>
7 </head>
8
9 <body>
10 <script>
11 description('Test synchronous graph manipulation with OfflineAudioContext. suspend() and OfflineAudioContext.resume().');
12 window.jsTestIsAsync = true;
13
14 var context;
15 var renderQuantum = 128;
16 var renderDuration = 3;
17
18 // The sample rate is multiple of the rendering quantum, so suspension
19 // times fall in to the render quantum boundary.
20 var sampleRate = renderQuantum * 100;
21
22 context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRa te);
23
24 // Create a constant buffer of 1.0.
25 var constantBuffer = createConstantBuffer(context, 1, 1.0);
26 var constantSource = context.createBufferSource();
27 constantSource.buffer = constantBuffer;
28 constantSource.loop = true;
29
30 // The audio output from the beginning (0.0 second) to the first suspend
31 // time should be 0.0 because there is no connection to the destination.
32
33 // Suspend at 1 second and activate the source node. The audio output
34 // should be 1.0 from |suspendTime1| to the next suspension.
35 var suspendTime1 = 1;
36 context.suspend(suspendTime1).then(function () {
37 if (context.currentTime === suspendTime1)
38 testPassed('Context is suspended at ' + suspendTime1 * sampleRate + ' frame as expected.');
39
40 constantSource.connect(context.destination);
41 constantSource.start();
42 testPassed('A constant buffer is connected to destination and started at ' +
43 suspendTime1 * sampleRate + ' frame.');
44
45 context.resume();
46 });
47
48 // Suspend at 2 seconds and disconnect the node. The audio output should
49 // be 0.0 from |suspendTime2| to the end.
50 var suspendTime2 = 2;
51 context.suspend(suspendTime2).then(function () {
52 if (context.currentTime === suspendTime2)
53 testPassed('Context is suspended at ' + suspendTime2 * sampleRate + ' frame as expected.');
54
55 constantSource.disconnect();
56 testPassed('A constant buffer is disconnected at ' + suspendTime2 * samp leRate + ' frame.');
57
58 context.resume();
59 });
60
61 context.startRendering().then(function (buffer) {
62 verifyResult(buffer);
63 finishJSTest();
64 });
65
66 function verifyResult(buffer) {
67 var data = buffer.getChannelData(0);
68
69 var suspendIndex1 = suspendTime1 * sampleRate;
70 var suspendIndex2 = suspendTime2 * sampleRate;
71 var endIndex = renderDuration * sampleRate;
72
73 // Split the rendered buffer into 3 segments:
74 // [0, suspendIndex1), [suspendIndex1, suspendIndex2), [suspendIndex2,
75 // endIndex).
76 var subarray0 = data.subarray(0, suspendIndex1);
77 var subarray1 = data.subarray(suspendIndex1, suspendIndex2);
78 var subarray2 = data.subarray(suspendIndex2, endIndex);
79
80 // Each segment should contain a constant value of 0, 1 and 0
81 // respectively.
82 Should('Buffer frame [0, ' + suspendIndex1 + ')', subarray0).beConstant ValueOf(0);
83 Should('Buffer frame [' + suspendIndex1 + ', ' + suspendIndex2 + ')', su barray1)
84 .beConstantValueOf(1);
85 Should('Buffer frame [' + suspendIndex2 + ', ' + endIndex + ')', subarra y2)
86 .beConstantValueOf(0);
87 }
88
89 successfullyParsed = true;
90 </script>
91
92 </body>
93 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698