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

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

Issue 1140723003: Implement suspend() and resume() for OfflineAudioContext (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added a layout test for synchronous graph manipulation Created 5 years, 6 months 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.suspend().');
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, 128, 1.0);
26 var constantSource = context.createBufferSource();
27 constantSource.buffer = dcOffsetBuffer;
Raymond Toy 2015/06/16 17:12:23 dcOffsetBuffer? How did this work?
hongchan 2015/06/16 17:34:36 I missed the variable name change. Fixing it.
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 Should('The first suspend time', context.currentTime).beEqualTo(suspendT ime1);
38 constantSource.connect(context.destination);
39 constantSource.start();
40 context.resume();
41 });
42
43 // Suspend at 2 seconds and disconnect the node. The audio output should
44 // be 0.0 from |suspendTime2| to the end.
45 var suspendTime2 = 2;
46 context.suspend(suspendTime2).then(function () {
47 Should('The second suspend time', context.currentTime).beEqualTo(suspend Time2);
48 constantSource.disconnect();
49 context.resume();
50 });
51
52 context.startRendering().then(function (buffer) {
53 verifyResult(buffer);
54 finishJSTest();
55 });
56
57 function verifyResult(buffer) {
58 var data = buffer.getChannelData(0);
59
60 // Split the rendered buffer into 3 segments: [0.0 ~ 1.0], [1.0 ~ 2.0]
Raymond Toy 2015/06/16 17:12:23 What does the ~ mean? Did you mean -?
hongchan 2015/06/16 17:34:36 I replace this with the mathematical expression fo
61 // [2.0 ~ 3.0].
62 var subarray0 = data.subarray(0, suspendTime1 * sampleRate);
63 var subarray1 = data.subarray(suspendTime1 * sampleRate, suspendTime2 * sampleRate);
64 var subarray2 = data.subarray(suspendTime2 * sampleRate, renderDuration * sampleRate);
65
66 // Each segment should contain a constant value of 0, 1 and 0
67 // respectively.
68 Should('Buffer [0~12800]', subarray0).beConstantValueOf(0);
69 Should('Buffer [12800~25600]', subarray1).beConstantValueOf(1);
70 Should('Buffer [25600~38400]', subarray2).beConstantValueOf(0);
71 }
72
73 successfullyParsed = true;
74 </script>
75
76 </body>
77 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698