| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/testharness.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> | 5 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/audit-util.js"></script> | 6 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 7 <script src="../resources/audit.js"></script> |
| 8 <script src="../resources/audioparam-testing.js"></script> | 8 <script src="../resources/audioparam-testing.js"></script> |
| 9 <title>Test Sampling of LinearRampToValueAtTime</title> | 9 <title>Test Sampling of LinearRampToValueAtTime</title> |
| 10 </head> | 10 </head> |
| 11 | 11 |
| 12 <body> | 12 <body> |
| 13 <script> | 13 <script> |
| 14 | 14 |
| 15 var sampleRate = 12800; | 15 var sampleRate = 12800; |
| 16 var context; | 16 var context; |
| 17 | 17 |
| 18 var audit = Audit.createTaskRunner(); | 18 var audit = Audit.createTaskRunner(); |
| 19 | 19 |
| 20 function runTest(config) { | 20 function runTest(should, config) { |
| 21 // Create a short context with a constant signal source connected to a g
ain node that will | 21 // Create a short context with a constant signal source connected to a g
ain node that will |
| 22 // be automated. | 22 // be automated. |
| 23 context = new OfflineAudioContext(1, 256, sampleRate); | 23 context = new OfflineAudioContext(1, 256, sampleRate); |
| 24 | 24 |
| 25 // Create a constant unit amplitude source. | 25 // Create a constant unit amplitude source. |
| 26 var source = context.createBufferSource(); | 26 var source = context.createBufferSource(); |
| 27 var b = createConstantBuffer(context, 1, 1); | 27 var b = createConstantBuffer(context, 1, 1); |
| 28 source.buffer = b; | 28 source.buffer = b; |
| 29 source.loop = true; | 29 source.loop = true; |
| 30 | 30 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 48 var startFrame = Math.ceil(config.startTime * sampleRate); | 48 var startFrame = Math.ceil(config.startTime * sampleRate); |
| 49 | 49 |
| 50 // The automation ends at config.endTime so the frame just before this
should have the | 50 // The automation ends at config.endTime so the frame just before this
should have the |
| 51 // automation applied. | 51 // automation applied. |
| 52 var endFrame = Math.floor(config.endTime * sampleRate); | 52 var endFrame = Math.floor(config.endTime * sampleRate); |
| 53 | 53 |
| 54 // Use the true automation to find the expected values. | 54 // Use the true automation to find the expected values. |
| 55 var expectedStart = config.expectedFunction(startFrame / sampleRate); | 55 var expectedStart = config.expectedFunction(startFrame / sampleRate); |
| 56 var expectedEnd = config.expectedFunction(endFrame / sampleRate); | 56 var expectedEnd = config.expectedFunction(endFrame / sampleRate); |
| 57 | 57 |
| 58 var success = Should(config.desc + ": Sample " + startFrame, | 58 should(resultData[startFrame], config.desc + ": Sample " + startFrame) |
| 59 resultData[startFrame], { | 59 .beCloseTo(expectedStart, {threshold: config.startValueThreshold}); |
| 60 precision: 7 | 60 should(resultData[endFrame], config.desc + ": Sample " + endFrame) |
| 61 }).beCloseTo(expectedStart, config.startValueThreshold); | 61 .beCloseTo(expectedEnd, {threshold: config.endValueThreshold}); |
| 62 success = Should(config.desc + ": Sample " + endFrame, | |
| 63 resultData[endFrame], { | |
| 64 precision: 7 | |
| 65 }).beCloseTo(expectedEnd, config.endValueThreshold) && success; | |
| 66 | |
| 67 Should(config.desc, success) | |
| 68 .summarize("passed", "failed"); | |
| 69 }); | 62 }); |
| 70 } | 63 } |
| 71 | 64 |
| 72 function expectedLinear(t) { | 65 function expectedLinear(t) { |
| 73 var slope = (this.endValue - this.startValue) / (this.endTime - this.sta
rtTime); | 66 var slope = (this.endValue - this.startValue) / (this.endTime - this.sta
rtTime); |
| 74 return this.startValue + slope * (t - this.startTime); | 67 return this.startValue + slope * (t - this.startTime); |
| 75 }; | 68 }; |
| 76 | 69 |
| 77 function expectedExponential(t) { | 70 function expectedExponential(t) { |
| 78 var ratio = this.endValue / this.startValue; | 71 var ratio = this.endValue / this.startValue; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 startValue: 1, | 141 startValue: 1, |
| 149 endValue: 1e-5, | 142 endValue: 1e-5, |
| 150 startValueThreshold: 8.035e-9, | 143 startValueThreshold: 8.035e-9, |
| 151 endValueThreshold: 1.337e-6, | 144 endValueThreshold: 1.337e-6, |
| 152 automationFunction: exponentialAutomation, | 145 automationFunction: exponentialAutomation, |
| 153 expectedFunction: expectedExponential | 146 expectedFunction: expectedExponential |
| 154 }, | 147 }, |
| 155 ]; | 148 ]; |
| 156 | 149 |
| 157 function createTaskFunction(config) { | 150 function createTaskFunction(config) { |
| 158 return function (done) { | 151 return (task, should) => { |
| 159 runTest(config).then(done); | 152 runTest(should, config).then(() => task.done()); |
| 160 }; | 153 }; |
| 161 } | 154 } |
| 162 | 155 |
| 163 // Create all of the tasks from the test configs | 156 // Create all of the tasks from the test configs |
| 164 for (var k = 0; k < testConfigs.length; ++k) { | 157 for (var k = 0; k < testConfigs.length; ++k) { |
| 165 var config = testConfigs[k]; | 158 var config = testConfigs[k]; |
| 166 var taskName = config.desc + ":task" + k; | 159 var taskName = config.desc + ":task" + k; |
| 167 audit.defineTask(taskName, createTaskFunction(config)); | 160 audit.define(taskName, createTaskFunction(config)); |
| 168 } | 161 } |
| 169 | 162 |
| 170 audit.defineTask("finish", function (done) { | 163 audit.run(); |
| 171 done(); | |
| 172 }); | |
| 173 | |
| 174 audit.runTasks(); | |
| 175 successfullyParsed = true; | |
| 176 </script> | 164 </script> |
| 177 </body> | 165 </body> |
| 178 </html> | 166 </html> |
| OLD | NEW |