| 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 sampleRate = 44100; | 14 var sampleRate = 44100; |
| 15 | 15 |
| 16 // To get an observable change on playbackRate modulation, the minimum | 16 // To get an observable change on playbackRate modulation, the minimum |
| 17 // rendering length should greater than the rendering quantum. | 17 // rendering length should greater than the rendering quantum. |
| 18 var renderLength = 256; | 18 var renderLength = 256; |
| 19 var half = renderLength / 2; | 19 var half = renderLength / 2; |
| 20 | 20 |
| 21 // With the playbackRate of 1, the duration of impulse buffer should be 4 | 21 // With the playbackRate of 1, the duration of impulse buffer should be 4 |
| 22 // samples (which means the interval between impulses is 4). Doubling | 22 // samples (which means the interval between impulses is 4). Doubling |
| 23 // playback speed decrease the interval to 2 samples. | 23 // playback speed decrease the interval to 2 samples. |
| 24 var impulseLength = 4; | 24 var impulseLength = 4; |
| 25 | 25 |
| 26 var context = new OfflineAudioContext(1, renderLength, sampleRate); | 26 var context = new OfflineAudioContext(1, renderLength, sampleRate); |
| 27 var impulseBuffer, dcOffsetBuffer; | 27 var impulseBuffer, dcOffsetBuffer; |
| 28 | 28 |
| 29 var audit = Audit.createTaskRunner(); | 29 var audit = Audit.createTaskRunner(); |
| 30 | 30 |
| 31 | 31 |
| 32 // Task: build an impulse and DC-offset buffers for testing. | 32 // Task: build an impulse and DC-offset buffers for testing. |
| 33 audit.defineTask('build-buffers', function (done) { | 33 audit.define('build-buffers', (task, should) => { |
| 34 // 4-sample impulse sample. | 34 should(() => { |
| 35 impulseBuffer = createImpulseBuffer(context, impulseLength); | 35 // 4-sample impulse sample. |
| 36 impulseBuffer = createImpulseBuffer(context, impulseLength); |
| 36 | 37 |
| 37 // Create a DC offset buffer with 2 values [0, 1] for modulating | 38 // Create a DC offset buffer with 2 values [0, 1] for modulating |
| 38 // playbackRate. The first half of buffer is 0 and the rest is 1. | 39 // playbackRate. The first half of buffer is 0 and the rest is 1. |
| 39 dcOffsetBuffer = context.createBuffer(1, renderLength, sampleRate); | 40 dcOffsetBuffer = context.createBuffer(1, renderLength, sampleRate); |
| 40 var dcOffsetArray = dcOffsetBuffer.getChannelData(0); | 41 var dcOffsetArray = dcOffsetBuffer.getChannelData(0); |
| 41 for (i = 0; i < dcOffsetArray.length; i++) { | 42 for (i = 0; i < dcOffsetArray.length; i++) { |
| 42 | 43 |
| 43 // Note that these values will be added to the playbackRate AudioParam | 44 // Note that these values will be added to the playbackRate AudioPar
am |
| 44 // value. For example, 0 DC offset value will result playbackRate of 1 | 45 // value. For example, 0 DC offset value will result playbackRate of
1 |
| 45 // because the default playbackRate value is 1. | 46 // because the default playbackRate value is 1. |
| 46 dcOffsetArray[i] = i < half ? 0 : 1; | 47 dcOffsetArray[i] = i < half ? 0 : 1; |
| 47 } | 48 } |
| 49 }, "Build buffers") |
| 50 .notThrow(); |
| 48 | 51 |
| 49 done(); | 52 task.done(); |
| 50 }); | 53 }); |
| 51 | 54 |
| 52 | 55 |
| 53 // Task: Render the actual buffer and compare with the reference. | 56 // Task: Render the actual buffer and compare with the reference. |
| 54 audit.defineTask('synthesize-verify', function (done) { | 57 audit.define('synthesize-verify', (task, should) => { |
| 55 var impulse = context.createBufferSource(); | 58 var impulse = context.createBufferSource(); |
| 56 var dcOffset = context.createBufferSource(); | 59 var dcOffset = context.createBufferSource(); |
| 57 | 60 |
| 58 impulse.buffer = impulseBuffer; | 61 impulse.buffer = impulseBuffer; |
| 59 dcOffset.buffer = dcOffsetBuffer; | 62 dcOffset.buffer = dcOffsetBuffer; |
| 60 impulse.loop = true; | 63 impulse.loop = true; |
| 61 | 64 |
| 62 impulse.connect(context.destination); | 65 impulse.connect(context.destination); |
| 63 dcOffset.connect(impulse.playbackRate); | 66 dcOffset.connect(impulse.playbackRate); |
| 64 | 67 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 77 nextImpulseIndex += (i < half) ? impulseLength : impulseLength / 2; | 80 nextImpulseIndex += (i < half) ? impulseLength : impulseLength / 2; |
| 78 } else if (data[i] !== 0) { | 81 } else if (data[i] !== 0) { |
| 79 // If a value is neither 0 or 1, break the loop and fail the test. | 82 // If a value is neither 0 or 1, break the loop and fail the test. |
| 80 passed = false; | 83 passed = false; |
| 81 break; | 84 break; |
| 82 } | 85 } |
| 83 | 86 |
| 84 i++; | 87 i++; |
| 85 } | 88 } |
| 86 | 89 |
| 87 Should('Doubling playbackRate', passed) | 90 should(passed, 'Doubling playbackRate') |
| 88 .summarize( | 91 .message( |
| 89 'decreased the interval between impulses to half', | 92 'decreased the interval between impulses to half', |
| 90 'produced the incorrect result' + 'at the index ' + i) | 93 'produced the incorrect result' + 'at the index ' + i) |
| 91 }).then(done); | 94 }).then(() => task.done()); |
| 92 }); | 95 }); |
| 93 | 96 |
| 94 audit.defineTask('finish', function (done) { | 97 audit.run(); |
| 95 done(); | |
| 96 }); | |
| 97 | |
| 98 audit.runTasks( | |
| 99 'build-buffers', | |
| 100 'synthesize-verify', | |
| 101 'finish' | |
| 102 ); | |
| 103 | 98 |
| 104 successfullyParsed = true; | 99 successfullyParsed = true; |
| 105 </script> | 100 </script> |
| 106 </body> | 101 </body> |
| 107 | 102 |
| 108 </html> | 103 </html> |
| OLD | NEW |