Chromium Code Reviews| 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/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, 128, 1.0); | |
|
Raymond Toy
2015/10/21 18:22:45
Since you loop, why not just create a buffer of le
hongchan
2015/10/22 18:23:48
Done.
| |
| 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); | |
|
Raymond Toy
2015/10/21 18:22:45
slice or subarray? Which is better?
hongchan
2015/10/22 18:23:48
Array.slice() creates a new array. Array.subarray(
| |
| 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> | |
| OLD | NEW |