| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test Interpolation for AudioParam.setValueCurveAtTime</title> | 4 <title>Test Interpolation for AudioParam.setValueCurveAtTime</title> |
| 5 <script src="../../resources/js-test.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audio-testing.js"></script> |
| 8 <title>Test Interpolation for AudioParam.setValueCurveAtTime</title> | 9 <title>Test Interpolation for AudioParam.setValueCurveAtTime</title> |
| 9 </head> | 10 </head> |
| 10 | 11 |
| 11 <body> | 12 <body> |
| 12 <script> | 13 <script> |
| 13 description("Test Interpolation for AudioParam.setValueCurveAtTime"); | |
| 14 window.jsTestIsAsync = true; | |
| 15 | 14 |
| 16 // Play a constant signal through a gain node that is automated using setV
alueCurveAtTime with | 15 // Play a constant signal through a gain node that is automated using setV
alueCurveAtTime with |
| 17 // a 2-element curve. The output should be a linear change. | 16 // a 2-element curve. The output should be a linear change. |
| 18 | 17 |
| 19 // Choose a sample rate that is a multiple of 128, the rendering quantum s
ize. This makes the | 18 // Choose a sample rate that is a multiple of 128, the rendering quantum s
ize. This makes the |
| 20 // math work out to be nice numbers. | 19 // math work out to be nice numbers. |
| 21 var sampleRate = 25600; | 20 var sampleRate = 25600; |
| 22 var testDurationSec = 1; | 21 var testDurationSec = 1; |
| 23 var testDurationFrames = testDurationSec * sampleRate; | 22 var testDurationFrames = testDurationSec * sampleRate; |
| 24 | 23 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 var success = true; | 160 var success = true; |
| 162 | 161 |
| 163 success = Should("Curve value at time " + startTime, | 162 success = Should("Curve value at time " + startTime, |
| 164 data[timeToSampleFrame(startTime, context.sampleRate)]).beEqualTo(c[
0]) && success; | 163 data[timeToSampleFrame(startTime, context.sampleRate)]).beEqualTo(c[
0]) && success; |
| 165 // Due to round-off, the value at the midpoint is not exactly zero on
arm64. See | 164 // Due to round-off, the value at the midpoint is not exactly zero on
arm64. See |
| 166 // crbug.com/558563. The current value is experimentally determined. | 165 // crbug.com/558563. The current value is experimentally determined. |
| 167 success = Should("Curve value at time " + midPoint, | 166 success = Should("Curve value at time " + midPoint, |
| 168 data[timeToSampleFrame(midPoint, context.sampleRate)]).beCloseTo(0,
Math.pow(2, -51)) && success; | 167 data[timeToSampleFrame(midPoint, context.sampleRate)]).beCloseTo(0,
Math.pow(2, -51)) && success; |
| 169 success = Should("Curve value at time " + endTime, | 168 success = Should("Curve value at time " + endTime, |
| 170 data[timeToSampleFrame(endTime, context.sampleRate)]).beEqualTo(c[2]
) && success; | 169 data[timeToSampleFrame(endTime, context.sampleRate)]).beEqualTo(c[2]
) && success; |
| 171 if (success) | 170 Should("Test: crbug.com/44471", success) |
| 172 testPassed("Test: crbug.com/44471\n"); | 171 .summarize("passed", "failed"); |
| 173 else | |
| 174 testFailed("Test: crbug.com/44471\n"); | |
| 175 }).then(done); | 172 }).then(done); |
| 176 }); | 173 }); |
| 177 | 174 |
| 178 // Must be the last defined task. | 175 // Must be the last defined task. |
| 179 audit.defineTask("end", function (done) { | 176 audit.defineTask("end", function (done) { |
| 180 finishJSTest(); | |
| 181 done(); | 177 done(); |
| 182 }); | 178 }); |
| 183 | 179 |
| 184 function runTest(config) { | 180 function runTest(config) { |
| 185 context = new OfflineAudioContext(1, testDurationFrames, sampleRate); | 181 context = new OfflineAudioContext(1, testDurationFrames, sampleRate); |
| 186 | 182 |
| 187 // A constant audio source of value 1. | 183 // A constant audio source of value 1. |
| 188 var source = context.createBufferSource(); | 184 var source = context.createBufferSource(); |
| 189 source.buffer = createConstantBuffer(context, 1, 1); | 185 source.buffer = createConstantBuffer(context, 1, 1); |
| 190 source.loop = true; | 186 source.loop = true; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 if (maxDiff < diff) { | 238 if (maxDiff < diff) { |
| 243 maxDiff = diff; | 239 maxDiff = diff; |
| 244 posn = k; | 240 posn = k; |
| 245 } | 241 } |
| 246 } | 242 } |
| 247 | 243 |
| 248 success = success && Should("SNR", SNR, { | 244 success = success && Should("SNR", SNR, { |
| 249 brief: true | 245 brief: true |
| 250 }).beGreaterThanOrEqualTo(config.snrThreshold); | 246 }).beGreaterThanOrEqualTo(config.snrThreshold); |
| 251 | 247 |
| 252 if (maxDiff <= config.maxErrorThreshold) { | 248 success = Should("Max difference", maxDiff) |
| 253 testPassed("Max difference is less than or equal to " + config.maxEr
rorThreshold + "."); | 249 .beLessThanOrEqualTo(config.maxErrorThreshold) && success; |
| 254 } else { | |
| 255 testFailed("Max difference (" + maxDiff + ") NOT less than or equal
to " + | |
| 256 config.maxErrorThreshold + " at frame " + posn + "."); | |
| 257 success = false; | |
| 258 } | |
| 259 | 250 |
| 260 var message = "Test: curve length = " + config.curveLength + "; durati
on frames = " + | 251 var message = "Test: curve length = " + config.curveLength + |
| 261 config.curveDuration * sampleRate + ".\n"; | 252 "; duration frames = " + |
| 262 | 253 config.curveDuration * sampleRate; |
| 263 if (success) | 254 |
| 264 testPassed(message); | 255 Should(message, success) |
| 265 else | 256 .summarize("passed", "failed"); |
| 266 testFailed(message); | |
| 267 } | 257 } |
| 268 } | 258 } |
| 269 | 259 |
| 270 // Compute the expected result based on the config settings. | 260 // Compute the expected result based on the config settings. |
| 271 function computeExpectedResult(config) { | 261 function computeExpectedResult(config) { |
| 272 // The automation curve starts at |curveStartTime| and has duration |cu
rveDuration|. So, | 262 // The automation curve starts at |curveStartTime| and has duration |cu
rveDuration|. So, |
| 273 // the output should be zero until curveStartTime, linearly ramp up fro
m there to | 263 // the output should be zero until curveStartTime, linearly ramp up fro
m there to |
| 274 // |curveValue|, and then be constant 1 from then to the end of the buf
fer. | 264 // |curveValue|, and then be constant 1 from then to the end of the buf
fer. |
| 275 | 265 |
| 276 var expected = new Float32Array(testDurationFrames); | 266 var expected = new Float32Array(testDurationFrames); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 301 | 291 |
| 302 return expected; | 292 return expected; |
| 303 } | 293 } |
| 304 | 294 |
| 305 audit.runTasks(); | 295 audit.runTasks(); |
| 306 | 296 |
| 307 successfullyParsed = true; | 297 successfullyParsed = true; |
| 308 </script> | 298 </script> |
| 309 </body> | 299 </body> |
| 310 </html> | 300 </html> |
| OLD | NEW |