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.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 = 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 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 var suspendIndex1 = suspendTime1 * sampleRate; |
| 61 var suspendIndex2 = suspendTime2 * sampleRate; |
| 62 var endIndex = renderDuration * sampleRate; |
| 63 |
| 64 // Split the rendered buffer into 3 segments: |
| 65 // [0, suspendIndex1), [suspendIndex1, suspendIndex2), [suspendIndex2, |
| 66 // endIndex). |
| 67 var subarray0 = data.subarray(0, suspendIndex1); |
| 68 var subarray1 = data.subarray(suspendIndex1, suspendIndex2); |
| 69 var subarray2 = data.subarray(suspendIndex2, endIndex); |
| 70 |
| 71 // Each segment should contain a constant value of 0, 1 and 0 |
| 72 // respectively. |
| 73 Should('Buffer [0, ' + suspendIndex1 + ')', subarray0).beConstantValueO
f(0); |
| 74 Should('Buffer [' + suspendIndex1 + ', ' + suspendIndex2 + ')', subarray
1) |
| 75 .beConstantValueOf(1); |
| 76 Should('Buffer [' + suspendIndex2 + ', ' + endIndex + ')', subarray2) |
| 77 .beConstantValueOf(0); |
| 78 } |
| 79 |
| 80 successfullyParsed = true; |
| 81 </script> |
| 82 |
| 83 </body> |
| 84 </html> |
OLD | NEW |