| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 | |
| 4 <head> | |
| 5 <script src="../resources/js-test.js"></script> | |
| 6 <script src="resources/compatibility.js"></script> | |
| 7 <script src="resources/audit-util.js"></script> | |
| 8 <script src="resources/audio-testing.js"></script> | |
| 9 </head> | |
| 10 | |
| 11 <body> | |
| 12 <script> | |
| 13 description('Test the late call of start(0) of BufferSource.'); | |
| 14 window.jsTestIsAsync = true; | |
| 15 | |
| 16 var renderQuantum = 128; | |
| 17 | |
| 18 var sampleRate = 44100; | |
| 19 var renderDuration = 0.25; | |
| 20 var startTime = 0.5 * renderDuration; | |
| 21 | |
| 22 var audit = Audit.createTaskRunner(); | |
| 23 | |
| 24 // Calculate the index for actual start time. | |
| 25 function getStartIndex(time) { | |
| 26 var startIndex = time * sampleRate; | |
| 27 return startIndex -= (startIndex) % renderQuantum; | |
| 28 } | |
| 29 | |
| 30 // Get the index of value change. | |
| 31 function getValueChangeIndex(array, targetValue) { | |
| 32 return array.findIndex(function (element, index) { | |
| 33 if (element === targetValue) | |
| 34 return true; | |
| 35 }); | |
| 36 } | |
| 37 | |
| 38 audit.defineTask('test-late-start', function (done) { | |
| 39 var context = new OfflineAudioContext(1, renderDuration * sampleRate, samp
leRate); | |
| 40 var dcOffsetbuffer = createConstantBuffer(context, 1, 1.0); | |
| 41 var source = context.createBufferSource(); | |
| 42 source.buffer = dcOffsetbuffer; | |
| 43 source.loop = true; | |
| 44 source.connect(context.destination); | |
| 45 | |
| 46 // Schedule source.start(0) at 0.01 second. The specified timing of | |
| 47 // start() call is already passed in terms of the context time. So the | |
| 48 // argument |0| will be clamped to the current context time. | |
| 49 // | |
| 50 // With the sample rate of 44100, 0.01 second is 441 samples. Rounding | |
| 51 // it down to the render quantum gives 384 samples. This is clearly larger | |
| 52 // than a single render quantum. | |
| 53 // | |
| 54 // See issue: crbug.com/462167 | |
| 55 context.suspend(startTime).then(function () { | |
| 56 source.start(0); | |
| 57 context.resume(); | |
| 58 }); | |
| 59 | |
| 60 // Start rendering and verify result: this verifies if 1) the rendered | |
| 61 // buffer contains at least one non-zero value and 2) the non-zero value i
s | |
| 62 // found later than the first output sample. | |
| 63 context.startRendering().then(function (buffer) { | |
| 64 | |
| 65 var channelData = buffer.getChannelData(0); | |
| 66 var startIndex = getStartIndex(startTime); | |
| 67 var nonZeroValueIndex = getValueChangeIndex(channelData, 1.0); | |
| 68 | |
| 69 Should('The output', channelData).containValues([0, 1]); | |
| 70 Should('The index of value change', nonZeroValueIndex) | |
| 71 .beEqualTo(startIndex); | |
| 72 | |
| 73 if (nonZeroValueIndex === 0) | |
| 74 testFailed('The first sample was non-zero value. It should be zero.'); | |
| 75 else | |
| 76 testPassed('The rendered buffer contains non-zero values after the fir
st sample.'); | |
| 77 | |
| 78 }).then(done); | |
| 79 }); | |
| 80 | |
| 81 audit.defineTask('finish-test', function (done) { | |
| 82 done(); | |
| 83 finishJSTest(); | |
| 84 }); | |
| 85 | |
| 86 audit.runTasks(); | |
| 87 | |
| 88 successfullyParsed = true; | |
| 89 </script> | |
| 90 </body> | |
| 91 | |
| 92 </html> | |
| OLD | NEW |