| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 | 3 |
| 4 <head> | 4 <head> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 8 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 9 </head> | 9 </head> |
| 10 | 10 |
| 11 <body> | 11 <body> |
| 12 <script> | 12 <script> |
| 13 | 13 |
| 14 var renderQuantum = 128; | 14 var renderQuantum = 128; |
| 15 | 15 |
| 16 var sampleRate = 44100; | 16 var sampleRate = 44100; |
| 17 var renderDuration = 0.25; | 17 var renderDuration = 0.25; |
| 18 var startTime = 0.5 * renderDuration; | 18 var startTime = 0.5 * renderDuration; |
| 19 | 19 |
| 20 var audit = Audit.createTaskRunner(); | 20 var audit = Audit.createTaskRunner(); |
| 21 | 21 |
| 22 // Calculate the index for actual start time. | 22 // Calculate the index for actual start time. |
| 23 function getStartIndex(time) { | 23 function getStartIndex(time) { |
| 24 var startIndex = time * sampleRate; | 24 var startIndex = time * sampleRate; |
| 25 return startIndex -= (startIndex) % renderQuantum; | 25 return startIndex -= (startIndex) % renderQuantum; |
| 26 } | 26 } |
| 27 | 27 |
| 28 // Get the index of value change. | 28 // Get the index of value change. |
| 29 function getValueChangeIndex(array, targetValue) { | 29 function getValueChangeIndex(array, targetValue) { |
| 30 return array.findIndex(function (element, index) { | 30 return array.findIndex(function (element, index) { |
| 31 if (element === targetValue) | 31 if (element === targetValue) |
| 32 return true; | 32 return true; |
| 33 }); | 33 }); |
| 34 } | 34 } |
| 35 | 35 |
| 36 audit.defineTask('test-late-start', function (done) { | 36 audit.define('test-late-start', (task, should) => { |
| 37 var context = new OfflineAudioContext(1, renderDuration * sampleRate, samp
leRate); | 37 var context = new OfflineAudioContext(1, renderDuration * sampleRate, samp
leRate); |
| 38 var dcOffsetbuffer = createConstantBuffer(context, 1, 1.0); | 38 var dcOffsetbuffer = createConstantBuffer(context, 1, 1.0); |
| 39 var source = context.createBufferSource(); | 39 var source = context.createBufferSource(); |
| 40 source.buffer = dcOffsetbuffer; | 40 source.buffer = dcOffsetbuffer; |
| 41 source.loop = true; | 41 source.loop = true; |
| 42 source.connect(context.destination); | 42 source.connect(context.destination); |
| 43 | 43 |
| 44 // Schedule source.start(0) at 0.01 second. The specified timing of | 44 // Schedule source.start(0) at 0.01 second. The specified timing of |
| 45 // start() call is already passed in terms of the context time. So the | 45 // start() call is already passed in terms of the context time. So the |
| 46 // argument |0| will be clamped to the current context time. | 46 // argument |0| will be clamped to the current context time. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 57 | 57 |
| 58 // Start rendering and verify result: this verifies if 1) the rendered | 58 // Start rendering and verify result: this verifies if 1) the rendered |
| 59 // buffer contains at least one non-zero value and 2) the non-zero value i
s | 59 // buffer contains at least one non-zero value and 2) the non-zero value i
s |
| 60 // found later than the first output sample. | 60 // found later than the first output sample. |
| 61 context.startRendering().then(function (buffer) { | 61 context.startRendering().then(function (buffer) { |
| 62 | 62 |
| 63 var channelData = buffer.getChannelData(0); | 63 var channelData = buffer.getChannelData(0); |
| 64 var startIndex = getStartIndex(startTime); | 64 var startIndex = getStartIndex(startTime); |
| 65 var nonZeroValueIndex = getValueChangeIndex(channelData, 1.0); | 65 var nonZeroValueIndex = getValueChangeIndex(channelData, 1.0); |
| 66 | 66 |
| 67 Should('The output', channelData).containValues([0, 1]); | 67 should(channelData, 'The output').containValues([0, 1]); |
| 68 Should('The index of value change', nonZeroValueIndex) | 68 should(nonZeroValueIndex, 'The index of value change') |
| 69 .beEqualTo(startIndex); | 69 .beEqualTo(startIndex); |
| 70 | 70 |
| 71 Should('The index of the first non-zero sample', nonZeroValueIndex) | 71 should(nonZeroValueIndex, 'The index of the first non-zero sample') |
| 72 .notBeEqualTo(0) | 72 .notBeEqualTo(0) |
| 73 | 73 |
| 74 }).then(done); | 74 }).then(() => task.done()); |
| 75 }); | 75 }); |
| 76 | 76 |
| 77 audit.defineTask('finish-test', function (done) { | 77 audit.run(); |
| 78 done(); | |
| 79 }); | |
| 80 | |
| 81 audit.runTasks(); | |
| 82 | |
| 83 successfullyParsed = true; | |
| 84 </script> | 78 </script> |
| 85 </body> | 79 </body> |
| 86 | 80 |
| 87 </html> | 81 </html> |
| OLD | NEW |